Visitar URL original
fix(traverse): do not evaluate destructured bindings in `path.evaluate` by wulu007 · Pull Request #18250 · babel/babel · GitHub
Skip to content

fix(traverse): do not evaluate destructured bindings in path.evaluate - #18250

Merged
JLHwung merged 2 commits into
babel:mainfrom
wulu007:fix-issue-18238
Sep 26, 2026
Merged

JLHwung merged 2 commits into
babel:mainfrom
wulu007:fix-issue-18238

Conversation

@wulu007

@wulu007 wulu007 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Fixes #18238
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Description

When evaluating an identifier whose binding is created by a destructuring pattern (such as const { e } = O), binding.path points to the VariableDeclarator. Previously, path.evaluate() evaluated the init expression directly, returning the entire object { e: 80 } when the binding was only referenced once.

This PR deopts when bindingPath.get("id") is not a simple identifier.

Copilot AI lite review requested due to automatic review settings September 23, 2026 14:52
@github-actions

Copy link
Copy Markdown

Thanks for opening this pull request! 🎉

We really appreciate you taking the time to contribute, @wulu007.

A maintainer will take a look as soon as they can. In the meantime, please make sure that:

  • the description explains what changed and why
  • any related issues are linked
  • existing tests still pass

If anything needs adjusting we'll leave comments here. Thanks again!

@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62173

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pkg-pr-new

pkg-pr-new Bot commented Sep 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: cfba87f

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused guard resolves the incorrect evaluation and is covered by representative tests.

Review effort: Balanced
Findings: None

@JLHwung
JLHwung merged commit f92e1af into babel:main Sep 26, 2026
57 of 58 checks passed
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Oct 5, 2026
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18281.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

path.evaluate() is confidently wrong for destructured bindings (returns the whole object)

5 participants