Skip to content

Commit 35218f6

Browse files
committed
fix(extractor): add case 'class' to walk path and use kind 'method' for static blocks (#1389)
The merge conflict resolution in 8d5ba14 dropped two changes from ca3123f: 1. The 'class' case in walkJavaScriptNode's switch — class expressions like 'return class Child extends Parent { ... }' were never dispatched to handleClassDecl, so ctx.classes remained empty and no extends relationship was recorded. 2. handleStaticBlock used kind: 'function' instead of kind: 'method', so the CHA parents map could not walk up to the parent class for super.method() resolution. Also update the existing test that asserted kind: 'function'.
1 parent c662808 commit 35218f6

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)