fix(extraction): classify TS/JS class fields by value — properties, not methods (#808) (#809)

Every TS `public_field_definition` / JS `field_definition` extracted as a
method-kind node, so a plain field (`public fonts: Fonts;`) was reported
as callable: class shape was misrepresented, kind-based filtering was
defeated, and bare-name call resolution landed on data fields — typeorm's
boolean `ColumnMetadata::isArray` field was soaking up Array.isArray(...)
call edges (685 such wrong edges on typeorm alone).

Classification now follows the VALUE (classifyMethodNode hook, mirroring
resolveBody's callable detection): arrow-function / function-expression
fields and HOF-wrapped ones (`onScroll = throttle(() => {…})`) stay
methods with their bodies walked; everything else becomes a property that
keeps its type-annotation references edge, visibility, static-ness, and
decorators. Field initializers are now walked too (`history =
createHistory()` attributes the call to the property — previously
invisible), and JS class fields — whose name lives in the grammar's
`property` field, so they never extracted a symbol at all — now appear in
the graph (resolveName on the JS extractor).

With fields correctly kinded, `this.X` callback registration is re-enabled
for TS/JS (removed in #807 because field pseudo-methods made it mostly
wrong): `this.<member>` candidates resolve CLASS-SCOPED
(resolveThisMemberFnRef) — the target must be a function/method sharing
the from-symbol's qualified-name class prefix, same file, no fallback —
so `addEventListener("online", this.onOfflineStatusToggle)` and API-object
wiring (`{ mutateElement: this.mutateElement }`) produce registration
edges to the enclosing class's own method, while `this.fonts` (a
property) and inherited/unknown members yield no edge.

A/B (baseline = #807 main): excalidraw / typeorm / express — node counts
identical on all three; kinds shift method→property only (typeorm: exactly
7,406 swapped; excalidraw also corrects 5 anonymous-class mock fields that
were function-kind); every one of the 736 dropped call edges targeted a
node that is now a property (calls into data fields — verified 100%);
gains are retargets to real callables, initializer-call attributions, and
+74/+7 class-scoped this.X registration edges (sampled: addEventListener/
removeEventListener wiring, imperative-API method maps). Full suite green
(1386).

EXTRACTION_VERSION 19 → 20 (re-index to benefit).

Closes #808

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-06-11 14:48:11 -05:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 8a114ba53c
commit 38eb4e688c
12 changed files with 419 additions and 42 deletions
+20 -13
View File
@@ -44,7 +44,7 @@ custom `visitNode` hooks like Scala's val/var handler) get a candidates-only
|---|---|---|---|---|---|
| C / ObjC | `argument_list` | `assignment_expression.right` | `initializer_pair.value` | `initializer_list`, `init_declarator.value` | `&fn` (`pointer_expression`), `@selector(...)` (ObjC) |
| C++ | **`&` forms only** in args/rhs/varinit | (same — explicit `&` only) | bare ids at FILE scope only | bare ids at FILE scope only | `&fn`, `&Cls::method` (resolved scoped to the class) |
| TS / JS (tsx/jsx) | `arguments` | `assignment_expression.right` | `pair.value` | `array`, `variable_declarator.value` | — (see TS notes) |
| TS / JS (tsx/jsx) | `arguments` | `assignment_expression.right` | `pair.value` | `array`, `variable_declarator.value` | `this.method` (`member_expression`, class-scoped — see rule 3) |
| Python | `argument_list`, `keyword_argument.value` | `assignment.right` | `pair.value` | `list` | `self.method` (`attribute`) |
| Go | `argument_list` | `assignment_statement` / `short_var_declaration` (`expression_list`) | `keyed_element` | `literal_value`, `var_spec.value` | — |
| Rust | `arguments` | `assignment_expression.right` | `field_initializer.value` | `array_expression`, `static_item` / `let_declaration.value` | — |
@@ -77,16 +77,19 @@ custom `visitNode` hooks like Scala's val/var handler) get a candidates-only
were ungated.
3. **TS/JS/Python: bare ids resolve to `function` kind only.** A bare
identifier can never be a method value in these languages (methods need a
receiver — `this.m` / `self.m`), and TS class FIELDS are extracted as
method-kind nodes (pre-existing extractor quirk), so allowing method
targets soaked up locals passed as arguments
(`new Set(selectedPointsIndices)` → a same-named "method" field;
docopt.py's `name`/`match` params). For the same reason `this.X` capture
is disabled for TS/JS — in real code `this.X` value positions are mostly
data reads (`setCursor(this.canvas)`). Python's `self.m` form keeps method
targets through its own capture shape. C#/Swift/Dart/Java/Kotlin keep
method targets (method groups, implicit-self, method references are real
method values).
receiver — `this.m` / `self.m`), so allowing method targets soaked up
locals passed as arguments (`new Set(selectedPointsIndices)`;
docopt.py's `name`/`match` params — excalidraw/fmt A/B findings).
TS/JS `this.X` values are captured as `this.`-PREFIXED candidates and
resolved CLASS-SCOPED (`resolveThisMemberFnRef` in
`src/resolution/index.ts`): the target must be a function/method whose
qualified name shares the from-symbol's class prefix, same file, no
fallback of any kind — `addEventListener(…, this.onResize)` hits the
enclosing class's method; `this.fonts` (a property, post-#808 field
classification) and inherited/unknown members yield no edge. Python's
`self.m` form keeps method targets through its own capture shape.
C#/Swift/Dart/Java/Kotlin keep method targets (method groups,
implicit-self, method references are real method values).
4. **C++ is `&`-explicit** (`addressOfOnly`): bare identifiers qualify only in
FILE-scope initializer tables; everywhere else (args, assignments, local
braced-init lists `{begin, size}`) only `&fn` / `&Cls::method` count.
@@ -184,5 +187,9 @@ Index cost on redis: +6% time, +5% db size.
imports, so cross-file bare callbacks only resolve when repo-unique.
- **PHP string callables**, **Ruby bare symbols** outside `method(:sym)`,
**`obj.method` member values** where `obj` isn't `this`/`self`: deferred.
- **TS `this.X`**: disabled until TS class-field kind classification is fixed
(fields currently extract as method-kind nodes).
- **TS/JS `this.X` to inherited members**: the class-scoped resolver matches
the enclosing class's OWN members only — `this.handleClick` defined on a
superclass yields no edge (would need the supertype walk; deliberate v1).
Reading a getter into a local (`const s = this.snapshot`) produces a
references edge to the getter — a true dependency with an imperfect
"registration" flavor.