test(extractor): verify exported arrow function funcStack tracking in extractSpreadForOfWalk#1359
Conversation
… 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
|
Claude finished @carlos-alm's task —— View job PR Review
Root Cause AnalysisProblem Being Solved: Issue #1354 flagged a potential gap: when an arrow function is Why This Approach: The claim (and these tests confirm it) is that the gap never actually existed: the Risk Assessment: Low. This is test-only; no production code is touched. The three tests are positive-case only, with no weakened assertions or skipped validation. Test Quality AssessmentTest 1 ( Test 2 ( Test 3 ( Describe block naming — No assertions weakened, no skipped tests, no config changes — clean bill of health for Phases 1-3. Backlog Compliance
Critical ConcernsNone. One minor suggestion:
Final Recommendation
|
Greptile SummaryThis PR adds three regression tests verifying that
Confidence Score: 5/5Safe to merge — changes are test additions and an import style cleanup with no behavioral impact. The test additions directly correspond to real branches in No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[extractSpreadForOfWalk walk node] --> B{node.type?}
B -->|function_declaration| C[push nameNode.text to funcStack]
B -->|method_definition| D[push qualified name to funcStack]
B -->|variable_declarator| E{value is arrow_function or function_expression?}
E -->|yes| F[push nameNode.text to funcStack]
E -->|no| G[skip]
B -->|for_of_statement| H[record ForOfBinding enclosingFunc = funcStack.top]
B -->|export_statement| I[recurse into children]
I --> B
C --> J[recurse into children]
D --> J
F --> J
G --> J
J --> K[pop funcStack if pushed]
Reviews (3): Last reviewed commit: "fix: remove duplicate paramBindings in S..." | Re-trigger Greptile |
| it('records correct varName and sourceName for exported arrow for-of', () => { | ||
| const symbols = parseJS(`export const process = (items) => { for (const cb of items) cb(); };`); | ||
| expect(symbols.forOfBindings).toContainEqual( | ||
| expect.objectContaining({ varName: 'cb', sourceName: 'items', enclosingFunc: 'process' }), | ||
| ); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
process shadows a BUILTIN_GLOBALS entry, obscuring test intent
process appears on line 88 of src/extractors/javascript.ts inside BUILTIN_GLOBALS. A future reader of this test may reasonably assume it was chosen to verify how a built-in-named function interacts with the BUILTIN_GLOBALS guard — but BUILTIN_GLOBALS is never checked for enclosingFunc, so the name carries no semantic weight here. Using a clearly made-up name like handleItems or processItems would communicate that the test is purely about the export-wrapping path, not about built-in shadowing.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed — renamed process to handleItems in commit f01c339. The test now uses a clearly made-up name that conveys it's purely about the export-wrapping code path, not built-in shadowing.
…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.
|
Addressed both concerns in commit f01c339: CI fix (TS2300 duplicate identifier): The merge at 3c164f2 introduced a second Greptile / Claude nit (test identifier): Renamed |
|
Claude finished @carlos-alm's task —— View job PR Re-Review
Follow-up Review (commit f01c339)Both concerns from the previous review have been addressed correctly. CI fix — duplicate Test identifier rename ( No new concerns. Rating: ⭐⭐⭐⭐⭐ (5/5) — APPROVE |
Summary
tests/parsers/javascript.test.tsconfirming thatexport const f = (arr) => { for (const x of arr) x(); }correctly setsenclosingFunc: 'f'inforOfBindingsextractSpreadForOfWalkvisitsvariable_declaratorregardless of whether it is nested under a plainlexical_declarationor anexport_statement, so the gap reported in the PR feat(resolver): resolve prototype-based method calls, spread/iteration callbacks, func-prop this-dispatch, and object-rest param dispatch (JS) #1331 review was already closed by commita6c5d2dwhen thevariable_declaratorbranch was added to thefuncStackpush chainTest plan
npx vitest run tests/parsers/javascript.test.ts -t "Phase 8.3e: extractSpreadForOfWalk"— all 3 new tests passtests/parsers/javascript.test.tssuite remains green (91/91)Closes #1354