[APPS] Add scoped AST walker#348
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02cd4c73e9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const blockScope = addShadowedNames( | ||
| scope, | ||
| collectStatementDeclarations(block.body), |
There was a problem hiding this comment.
Propagate nested var bindings to the function scope
When a tracked name is declared with var inside a nested block, e.g. if (cond) { var request = local; } request(...), JavaScript hoists that binding to the enclosing function, but this block-only collection adds it only while walking the nested block. The later call in the same function is therefore visited with scope.has('request') === false, so consumers can incorrectly treat a local var binding as the imported action.
Useful? React with 👍 / 👎.
| default: | ||
| walkChildNodes(node, scope, trackedNames, visit, options); |
There was a problem hiding this comment.
Track declarations inside switch cases
For SwitchStatement/SwitchCase, the walker falls through to the generic child traversal, so declarations in a case are never added to scope. In code such as switch (x) { case 1: const request = local; request(...); }, the call is visited with scope.has('request') === false even though the case-local declaration shadows the tracked import, which can produce false extraction results for backends that branch with switch.
Useful? React with 👍 / 👎.
|
Closing this draft as superseded by #349. We decided to keep binding resolution and traversal in the inline extractor PR using eslint-scope and zimmerframe instead of introducing a separate walk-with-scope helper. |

What and why?
Adds a narrow scoped ESTree walker under backend AST parsing so extractor PRs can share lexical binding and shadowing behavior without reviewing that traversal inside #346.
How?
walkWithScope,Scope, andcollectPatternNames.Testing
yarn workspace @dd/tests test:unit packages/plugins/apps/src/backend/ast-parsing/walk-with-scope.test.ts --runInBandyarn eslint packages/plugins/apps/src/backend/ast-parsing/walk-with-scope.ts packages/plugins/apps/src/backend/ast-parsing/walk-with-scope.test.ts --quiet