Mark FOO in "var { x: FOO }˝ as a binding, not as a reference#9492
Mark FOO in "var { x: FOO }˝ as a binding, not as a reference#9492nicolo-ribaudo merged 2 commits intobabel:masterfrom
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10040/ |
| const pattern = t.objectPattern([property]); | ||
|
|
||
| return t.isReferenced(node, property, pattern) ? 1 : 0; | ||
| })(); |
There was a problem hiding this comment.
This is why this might be considered a breaking change: we were relying on the wrong behavior.
This code is needed to make new versions of the plugin work with new and old versions of @babel/types.
| Foo | ||
| } = ({}, function () { | ||
| throw new Error('"' + "Foo" + '" is read-only.'); | ||
| }())); |
There was a problem hiding this comment.
This change is correct. You can see the input file at https://github.com/babel/babel/blob/93ec6ee62a10ea022c902962dc989f1045fb1637/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/import-const-throw/input.mjs
import Foo from "foo";
// ...
({Foo} = {});
danez
left a comment
There was a problem hiding this comment.
looks good, I'm not sure what you are saying about the breaking change. Even with the compat code it could be still breaking?
|
With the compact mode it shouldn't break, but as we did rely on the wrong behavior someone else could have done the same thing. |
|
@nicolo-ribaudo this fixes #4694 ? |
Before this PR, babel incorrectly marks
FOOas aReferencedIdentifierinvar { a: FOO }and as a binding identifier in({ a: FOO }): this is because we needed to know not only the parent but also its grandparent to know it. Array patterns don't have this problem, since there isn't something like anArrayElementnode between the identifier and the pattern.This code shows the bug; you can test the old version on ASTExplorer (https://astexplorer.net/#/gist/3dc1c7fd69ee5f7478c2229e4bdce428/latest)
Plugin
Input code
Old output
New output