Skip to content

Commit 8b74716

Browse files
committed
fix(extractor): restore class expression handling and use method kind for static blocks
Two regressions introduced during merge conflict resolution in 6e72569: 1. `walkJavaScriptNode` lost the `case 'class':` branch that was responsible for extracting extends relationships from named class expressions (e.g. `const Foo = class Child extends Parent { ... }`). This caused `ctx.classes` to miss named class expressions, breaking super-dispatch resolution for class expression patterns. 2. `handleStaticBlock` emitted `kind: 'function'` instead of `kind: 'method'` for `ClassName.<static>` synthetic definitions. Static blocks are logically method-scoped — they run as part of class initialization in the context of the class, and CHA dispatch requires a method-kind node to walk up the parent class for `super.method()` resolution. Update the "extracts static blocks as function definitions" test to reflect the correct `kind: 'method'` behavior. Impact: 2 functions changed, 17 affected
1 parent 95d8ba8 commit 8b74716

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/extractors/javascript.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ function walkJavaScriptNode(node: TreeSitterNode, ctx: ExtractorOutput): void {
734734
break;
735735
case 'class_declaration':
736736
case 'abstract_class_declaration':
737+
// class expressions: `return class Foo extends Bar { ... }` or `const X = class Foo { ... }`
738+
case 'class':
737739
handleClassDecl(node, ctx);
738740
break;
739741
case 'method_definition':
@@ -874,7 +876,7 @@ function handleStaticBlock(node: TreeSitterNode, definitions: Definition[]): voi
874876
if (!className) return;
875877
definitions.push({
876878
name: `${className}.<static>`,
877-
kind: 'function',
879+
kind: 'method',
878880
line: nodeStartLine(node),
879881
endLine: nodeEndLine(node),
880882
});

tests/parsers/javascript.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ describe('JavaScript parser', () => {
105105
);
106106
});
107107

108-
it('extracts static blocks as function definitions', () => {
108+
it('extracts static blocks as method definitions', () => {
109109
const symbols = parseJS(`class C6 { static { f1(); } static { f2(); } }`);
110110
const staticDefs = symbols.definitions.filter((d) => d.name === 'C6.<static>');
111111
expect(staticDefs).toHaveLength(2);
112-
expect(staticDefs[0]).toMatchObject({ kind: 'function' });
113-
expect(staticDefs[1]).toMatchObject({ kind: 'function' });
112+
expect(staticDefs[0]).toMatchObject({ kind: 'method' });
113+
expect(staticDefs[1]).toMatchObject({ kind: 'method' });
114114
});
115115

116116
it('extracts import statements', () => {

0 commit comments

Comments
 (0)