buildNativeField function presentation exported ✓ 100.0%
Last updated: 2026-02-24T19:46:21.770Z
Metrics
LOC: 65
Complexity: 21
Params: 1
Coverage: 100.0% (14/14 lines, 32x executed)
Signature
buildNativeField(element: NativeElement): : FormField
Summary
Builds a bare FormField from a native DOM element. Extracts selector, label, DOM metadata and context signals — no classification yet.
Architecture violations
- [warning] max-cyclomatic-complexity: 'buildNativeField' has cyclomatic complexity 21 (max 10)
Source Code
export function buildNativeField(element: NativeElement): FormField {
const labelResult = findLabelWithStrategy(element);
// ── DOM metadata ────────────────────────────────────────────────────────────
const inputType =
element instanceof HTMLInputElement ? element.type : undefined;
const pattern =
element instanceof HTMLInputElement && element.pattern
? element.pattern
: undefined;
const maxLength =
(element instanceof HTMLInputElement ||
element instanceof HTMLTextAreaElement) &&
element.maxLength > 0
? element.maxLength
: undefined;
const minLength =
(element instanceof HTMLInputElement ||
element instanceof HTMLTextAreaElement) &&
element.minLength > 0
? element.minLength
: undefined;
// ── Select options ──────────────────────────────────────────────────────────
const options =
element instanceof HTMLSelectElement
? Array.from(element.options)
.filter((o) => o.value !== "")
.map((o) => ({ value: o.value, text: o.text.trim() }))
: undefined;
// ── Checkbox / Radio ────────────────────────────────────────────────────────
const isCheckable =
element instanceof HTMLInputElement &&
(element.type === "checkbox" || element.type === "radio");
const checkboxValue = isCheckable
? (element as HTMLInputElement).value || undefined
: undefined;
const checkboxChecked = isCheckable
? (element as HTMLInputElement).checked
: undefined;
const field: FormField = {
element,
selector: getUniqueSelector(element),
category: "unknown",
fieldType: "unknown",
label: labelResult?.text,
name: element.name || undefined,
id: element.id || undefined,
placeholder:
("placeholder" in element ? element.placeholder : undefined) || undefined,
autocomplete: element.autocomplete || undefined,
inputType,
required: element.required,
pattern,
maxLength,
minLength,
options,
checkboxValue,
checkboxChecked,
};
field.contextSignals = buildSignals(field);
return field;
}
No outgoing dependencies.
Impact (Incoming)
| Source | Type |
|---|---|
| getActiveClassifiers | uses |
| reclassifyFieldBySelector | calls |
| mockRect | uses |