Skip to content

Commit 9fb1a8b

Browse files
authored
test(extractor): verify exported arrow function funcStack tracking in extractSpreadForOfWalk (#1359)
* test(extractor): verify exported arrow function funcStack tracking in extractSpreadForOfWalk (#1354) Add regression tests confirming that `export const f = (arr) => { for (const x of arr) x(); }` correctly pushes `f` onto the funcStack so for-of bindings record the right enclosing caller. The recursive walk visits `variable_declarator` regardless of whether it is nested under a plain `lexical_declaration` or an `export_statement`, so the gap reported in the PR #1331 review was already closed by commit a6c5d2d. These tests document and gate that behavior. Closes #1354 * fix: remove duplicate paramBindings in SerializedExtractorOutput and rename process test identifier The merge at 3c164f2 introduced a second `paramBindings` field (using the top-level ParamBinding import) alongside the existing inline-import form at line 68, causing TS2300 duplicate-identifier errors that broke every CI job. Removed the duplicate and the now-unused ParamBinding top-level import. Also renamed the `process` arrow-function identifier in the Phase 8.3e test to `handleItems` — `process` is a Node.js global and its presence in the test obscures that the test is solely about the export-wrapping code path.
1 parent 8407fcf commit 9fb1a8b

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/domain/wasm-worker-protocol.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
Export,
2020
Import,
2121
LanguageId,
22-
ParamBinding,
2322
TypeMapEntry,
2423
} from '../types.js';
2524

@@ -74,7 +73,6 @@ export interface SerializedExtractorOutput {
7473
newExpressions?: readonly string[];
7574
returnTypeMap?: Array<[string, TypeMapEntry]>;
7675
callAssignments?: CallAssignment[];
77-
paramBindings?: ParamBinding[];
7876
}
7977

8078
export interface WorkerParseResponseOk {

tests/parsers/javascript.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,4 +908,29 @@ describe('JavaScript parser', () => {
908908
);
909909
});
910910
});
911+
912+
describe('Phase 8.3e: extractSpreadForOfWalk — exported arrow function funcStack (#1354)', () => {
913+
it('tracks plain const arrow function on funcStack for for-of loop', () => {
914+
const symbols = parseJS(`const f = (arr) => { for (const x of arr) x(); };`);
915+
expect(symbols.forOfBindings).toContainEqual(expect.objectContaining({ enclosingFunc: 'f' }));
916+
});
917+
918+
it('tracks exported const arrow function on funcStack for for-of loop', () => {
919+
const symbols = parseJS(`export const f = (arr) => { for (const x of arr) x(); };`);
920+
expect(symbols.forOfBindings).toContainEqual(expect.objectContaining({ enclosingFunc: 'f' }));
921+
});
922+
923+
it('records correct varName and sourceName for exported arrow for-of', () => {
924+
const symbols = parseJS(
925+
`export const handleItems = (items) => { for (const cb of items) cb(); };`,
926+
);
927+
expect(symbols.forOfBindings).toContainEqual(
928+
expect.objectContaining({
929+
varName: 'cb',
930+
sourceName: 'items',
931+
enclosingFunc: 'handleItems',
932+
}),
933+
);
934+
});
935+
});
911936
});

0 commit comments

Comments
 (0)