Skip to content

fix: Should not evaluate vars in child scope#17151

Merged
JLHwung merged 4 commits intobabel:mainfrom
liuxingbaoyu:evaluate-sub-scope-var
Feb 26, 2025
Merged

fix: Should not evaluate vars in child scope#17151
JLHwung merged 4 commits intobabel:mainfrom
liuxingbaoyu:evaluate-sub-scope-var

Conversation

@liuxingbaoyu
Copy link
Copy Markdown
Member

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

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: traverse labels Feb 24, 2025
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Feb 24, 2025

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

@liuxingbaoyu liuxingbaoyu marked this pull request as draft February 24, 2025 15:04
@liuxingbaoyu liuxingbaoyu marked this pull request as ready for review February 24, 2025 15:10
Comment on lines +362 to +365
{
var doesExist = true;
doesExist;
}
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.

Can you also add these test cases?

var doesExist = true;
{ doesExist }
{
  var doesExist = true;
  { doesExist }
}
{ var doesExist = true;
doesExist

(this last one could return a confident result, but it's not a big deal if it does not)

break;
}
if (scope.path.parentPath?.isIfStatement()) {
hasIf = true;
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.

Also while, for, for-of, try-catch. I'd prefer to list "known to be safe" statements (i.e. do-while and block), rather than potentially unsafe ones.

@JLHwung JLHwung merged commit 51ec746 into babel:main Feb 26, 2025
@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 May 29, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 29, 2025
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 pkg: traverse 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 wrongly retruns with confidence for "block-scoped" var's

4 participants