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

Don't throw when destructuring into a var named as an import #10628

Conversation

nicolo-ribaudo
Copy link
Member

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

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: modules labels Nov 2, 2019
@buildsize
Copy link

buildsize bot commented Nov 2, 2019

File name Previous Size New Size Change
babel-preset-env.js 2.77 MB 2.73 MB -37.19 KB (1%)
babel-preset-env.min.js 1.67 MB 1.65 MB -17.8 KB (1%)
babel.js 2.95 MB 2.92 MB -31.92 KB (1%)
babel.min.js 1.63 MB 1.61 MB -15.94 KB (1%)
test262.tap 4.84 MB [deleted]

} = {});
}

_x.foo = (2, function () {
Copy link
Member Author

Choose a reason for hiding this comment

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

In a follow up PR, this could be left as foo since we are throwing anyway.

@JLHwung JLHwung self-requested a review November 3, 2019 22:41
.pop();
const programScopeIds = Object.keys(ids).filter(
localName =>
scope.getBinding(localName) === path.scope.getBinding(localName),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider to guard with scope.hasBinding to avoid unnecessary path.scope.getBinding.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do it and found a bug which, if fixed, would break @babel/plugin-transform-runtime <= 7.6 😢

This is what currently happens:

  1. The imports are analyzed
  2. The imports are removed -> The bindings are removed
  3. References to imported bindings are rewritten (this file)
    i) When we are comparing the bindings, the global one is undefined
    ii) If the local binding is undefined, it hasn't been redefined.

I tried to swap 2 and 3, but I still can optimize away the check for the local binding because @babel/transform-runtime doesn't register the import it injects in the scope tracker.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: modules 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.

Invalid read-only when using destructuring shadowed by import
3 participants