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 -6
View File
@@ -158,12 +158,13 @@ function cFamilySpec(extra?: { special?: string[]; addressOfOnly?: boolean }): F
};
}
// NOTE: deliberately NO `member_expression` (`this.handleClick`) capture for
// TS/JS. Class fields with type annotations are extracted as method-kind
// nodes (pre-existing extractor behavior), so `this.X` value positions —
// which in real code are mostly DATA reads (`setCursor(this.canvas)`)
// resolved to those field nodes and produced wrong "registration" edges
// (excalidraw A/B finding). Revisit if/when TS field classification is fixed.
// `this.handleClick` capture (member_expression) emits a `this.`-PREFIXED
// candidate name: resolution scopes it to the enclosing symbol's class
// (qualified-name prefix), so `this.fonts` (a property, post-#808) and
// inherited/unknown members yield no edge, while same-class methods
// `btn.on('click', this.handleClick)`, the observer-registration idiom —
// resolve precisely. Bare identifiers stay function-kind-only (a bare id can
// never be a method value in JS).
const TS_JS_SPEC: FnRefSpec = {
idTypes: new Set(['identifier']),
dispatch: new Map<string, CaptureRule>([
@@ -173,6 +174,7 @@ const TS_JS_SPEC: FnRefSpec = {
['pair', { mode: 'value', field: 'value' }],
['array', { mode: 'list' }],
]),
special: new Set(['member_expression']),
};
const PYTHON_SPEC: FnRefSpec = {
@@ -613,6 +615,18 @@ function normalizeSpecial(
return name ? [{ name, node: sym }] : [];
}
// `this.handleClick` (TS/JS) — object must be EXACTLY `this`. The name
// keeps the `this.` prefix so resolution can scope it to the enclosing
// class (see resolveThisMemberFnRef) instead of bare name-matching.
case 'member_expression': {
const obj = getChildByField(node, 'object');
const prop = getChildByField(node, 'property');
if (obj && prop && obj.type === 'this' && prop.type === 'property_identifier') {
return [{ name: `this.${getNodeText(prop, source)}`, node: prop }];
}
return [];
}
// `self.handle_click` (Python) — object must be EXACTLY `self`.
case 'attribute': {
const obj = getChildByField(node, 'object');