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:
co-authored by
Claude Opus 4.8
parent
8a114ba53c
commit
38eb4e688c
@@ -675,6 +675,11 @@ export class ReferenceResolver {
|
||||
// (same-file first, unique-only cross-file, function/method targets only).
|
||||
// They never reach the framework or fuzzy strategies below.
|
||||
if (ref.referenceKind === 'function_ref') {
|
||||
// `this.<member>` values (TS/JS) resolve ONLY against the enclosing
|
||||
// class's own members — never a same-named symbol elsewhere.
|
||||
if (ref.referenceName.startsWith('this.')) {
|
||||
return this.gateLanguage(this.resolveThisMemberFnRef(ref), ref);
|
||||
}
|
||||
const viaImport = this.gateLanguage(resolveViaImport(ref, this.context), ref);
|
||||
if (viaImport) {
|
||||
const target = this.queries.getNodeById(viaImport.targetNodeId);
|
||||
@@ -1184,6 +1189,41 @@ export class ReferenceResolver {
|
||||
return { original: ref, targetNodeId: target.id, confidence: 0.9, resolvedBy: 'import' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a `this.<member>` function-as-value reference (#756/#808) to the
|
||||
* ENCLOSING CLASS's own member — never a same-named symbol elsewhere. The
|
||||
* registration idiom (`btn.on('click', this.handleClick)`) names a member
|
||||
* of the class being defined, so the only valid target shares the
|
||||
* from-symbol's qualified-name scope. Function/method targets only — a
|
||||
* property (a data field, post-#808 classification) yields no edge — same
|
||||
* file required, no fallback of any kind.
|
||||
*/
|
||||
private resolveThisMemberFnRef(ref: UnresolvedRef): ResolvedRef | null {
|
||||
const member = ref.referenceName.slice('this.'.length);
|
||||
if (!member) return null;
|
||||
const fromNode = this.queries.getNodeById(ref.fromNodeId);
|
||||
if (!fromNode) return null;
|
||||
const sep = fromNode.qualifiedName.lastIndexOf('::');
|
||||
if (sep <= 0) return null; // not inside a class scope
|
||||
const classPrefix = fromNode.qualifiedName.slice(0, sep);
|
||||
const candidates = this.context
|
||||
.getNodesByQualifiedName(`${classPrefix}::${member}`)
|
||||
.filter(
|
||||
(n) =>
|
||||
(n.kind === 'function' || n.kind === 'method') &&
|
||||
n.filePath === ref.filePath &&
|
||||
n.id !== ref.fromNodeId
|
||||
);
|
||||
if (candidates.length === 0) return null;
|
||||
const target = candidates.reduce((a, b) => (a.startLine <= b.startLine ? a : b));
|
||||
return {
|
||||
original: ref,
|
||||
targetNodeId: target.id,
|
||||
confidence: 0.95,
|
||||
resolvedBy: 'function-ref',
|
||||
};
|
||||
}
|
||||
|
||||
private gateLanguage(result: ResolvedRef | null, ref: UnresolvedRef): ResolvedRef | null {
|
||||
if (!result) return result;
|
||||
const tgt = this.getLanguageFromNodeId(result.targetNodeId);
|
||||
|
||||
@@ -180,6 +180,10 @@ export function matchFunctionRef(
|
||||
ref: UnresolvedRef,
|
||||
context: ResolutionContext
|
||||
): ResolvedRef | null {
|
||||
// `this.<member>` refs are resolved ONLY by the class-scoped resolver in
|
||||
// resolveOne (resolveThisMemberFnRef) — never by name matching here.
|
||||
if (ref.referenceName.startsWith('this.')) return null;
|
||||
|
||||
// In JS/TS/Python a bare identifier can never be a method value (methods
|
||||
// are only reachable through a receiver — `this.m` / `self.m` /
|
||||
// `Cls.m`), so bare fn-refs match FUNCTIONS only. This also sidesteps the
|
||||
|
||||
Reference in New Issue
Block a user