Skip to content

[APPS] Add scoped AST walker#348

Closed
sdkennedy2 wants to merge 1 commit into
masterfrom
sdkennedy2/add-ast-scope-walker
Closed

[APPS] Add scoped AST walker#348
sdkennedy2 wants to merge 1 commit into
masterfrom
sdkennedy2/add-ast-scope-walker

Conversation

@sdkennedy2
Copy link
Copy Markdown
Collaborator

@sdkennedy2 sdkennedy2 commented May 7, 2026

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?

  • Add walkWithScope, Scope, and collectPatternNames.
  • Track imports, variables, functions, classes, params, catch bindings, loop bindings, and destructuring patterns.
  • Add focused tests for shadowing, ignored bindings, namespace binding shadowing, and nested pattern collection.

Testing

  • yarn workspace @dd/tests test:unit packages/plugins/apps/src/backend/ast-parsing/walk-with-scope.test.ts --runInBand
  • yarn 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

Copy link
Copy Markdown
Collaborator Author

sdkennedy2 commented May 7, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sdkennedy2 sdkennedy2 changed the title Add scoped AST walker [APPS] Add scoped AST walker May 7, 2026
@sdkennedy2
Copy link
Copy Markdown
Collaborator Author

@codex review
@cursor review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +63 to +65
const blockScope = addShadowedNames(
scope,
collectStatementDeclarations(block.body),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +199 to +200
default:
walkChildNodes(node, scope, trackedNames, visit, options);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@sdkennedy2
Copy link
Copy Markdown
Collaborator Author

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.

@sdkennedy2 sdkennedy2 closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant