Skip to content

fix(babel-traverse): check variable shadowing for global object callees - #17702

Merged
nicolo-ribaudo merged 1 commit into
babel:mainfrom
wulu007:fix-issue-17698
Jan 27, 2026
Merged

nicolo-ribaudo merged 1 commit into
babel:mainfrom
wulu007:fix-issue-17698

Conversation

@wulu007

@wulu007 wulu007 commented Jan 10, 2026

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

Currently, path.evaluate() attempts to evaluate methods on global objects (like Math.min, String.raw, etc.) even when the global object identifier is shadowed by a local variable. This can lead to incorrect constant folding (evaluating code that shouldn't be evaluated).

Example of the bug:

const Math = { min: () => 999 };
// Before fix: evaluates to 1 (incorrectly uses global Math.min)
// After fix: confident = false (bails out correctly)
Math.min(1, 2);

@babel-bot

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Jan 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: ec00ac5

@JLHwung JLHwung 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.

Thanks.

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Jan 27, 2026
@nicolo-ribaudo
nicolo-ribaudo merged commit 5b8870d into babel:main Jan 27, 2026
54 checks passed
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release and removed PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Jan 27, 2026
@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Mar 7, 2026
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 28, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 28, 2026
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18480.

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

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

path.evaluate() ignores shadowed binding for Math methods in MemberExpression

5 participants