Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip id-destructuring bugfix when binding info is not found #13910

Merged
merged 1 commit into from Nov 1, 2021

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Nov 1, 2021

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

In #13842 we detect the pattern function a([a]) {} from the scope info. This PR handles situations when

  1. babel-helper-function-name injects the function id and mark them as NOT_LOCAL_BINDING, in this case the id will not be registered as constant violation
  2. a plugin injects an id but does not update scope info accordingly

For the plugin to work, the assumption now is that the scope info of function parameters can be trusted: so we can avoid scanning parameters.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories i: regression labels Nov 1, 2021
@babel-bot
Copy link
Collaborator

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 1, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9197856:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

Comment on lines +25 to +26
// Case 2: the function id is injected by a third party plugin which does not update the
// scope info
Copy link
Member

Choose a reason for hiding this comment

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

If we are in Case 2, it means that the function didn't originally have a paramter with the same name of the new injected id?

e.g. does this work?

let x = function ([a]) {};
// plugin
Function(path) {
  path.node.id = t.identifier("a");
}

(if it doesn't it's ok - the plugin needs to be fixed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it works if the path is then requeued (as is shown in the https://github.com/babel/babel/pull/13910/files#diff-9c3e0b47cab12356380982d8d3c8b5c3bbf3e160e18448619c2b54e9106bcb03) so that the bugfix can have a chance to be executed again.

@JLHwung JLHwung merged commit 833b391 into babel:main Nov 1, 2021
@JLHwung JLHwung deleted the fix-13907 branch November 1, 2021 19:11
@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 Feb 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot read properties of undefined (reading 'constantViolations')
4 participants