Skip to content

Commit f32cb83

Browse files
committed
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
1 parent 194507c commit f32cb83

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/parsers/javascript.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,4 +908,27 @@ 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(
916+
expect.objectContaining({ enclosingFunc: 'f' }),
917+
);
918+
});
919+
920+
it('tracks exported const arrow function on funcStack for for-of loop', () => {
921+
const symbols = parseJS(`export const f = (arr) => { for (const x of arr) x(); };`);
922+
expect(symbols.forOfBindings).toContainEqual(
923+
expect.objectContaining({ enclosingFunc: 'f' }),
924+
);
925+
});
926+
927+
it('records correct varName and sourceName for exported arrow for-of', () => {
928+
const symbols = parseJS(`export const process = (items) => { for (const cb of items) cb(); };`);
929+
expect(symbols.forOfBindings).toContainEqual(
930+
expect.objectContaining({ varName: 'cb', sourceName: 'items', enclosingFunc: 'process' }),
931+
);
932+
});
933+
});
911934
});

0 commit comments

Comments
 (0)