X Tutup
Skip to content

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

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

fix(babel-traverse): check variable shadowing for global object callees#17702
nicolo-ribaudo merged 1 commit intobabel:mainfrom
wulu007:fix-issue-17698

Conversation

@wulu007
Copy link
Contributor

@wulu007 wulu007 commented Jan 10, 2026

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
Collaborator

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 10, 2026

Open in StackBlitz

commit: ec00ac5

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks.

Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x: needs backport 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

X Tutup