Bug Report
Current Behavior
The commonjs and amd plugins create invalid throw new Error('"' + "foo" + '" is read-only.'); statements in the output when there is an import with the same name as used in the destructuring even though it's shadowed by a function parameter.
Input Code
import { foo } from "./x";
function test(foo) {
console.log(foo);
[foo] = [1];
({foo} = { foo: 1 });
console.log(foo);
}
test(0);
Output:
"use strict";
var _x = require("./x");
function test(foo) {
console.log(foo);
[foo] = ([1], function () {
throw new Error('"' + "foo" + '" is read-only.');
}());
({
foo
} = ({
foo: 1
}, function () {
throw new Error('"' + "foo" + '" is read-only.');
}()));
console.log(foo);
}
test(0);
Expected behavior/code
No Error's in output, like this when the import name is changed:
"use strict";
var _x = require("./x");
function test(foo) {
console.log(foo);
[foo] = [1];
({
foo
} = {
foo: 1
});
console.log(foo);
}
test(0);
Babel Configuration (.babelrc, package.json, cli command)
"babel": {
"plugins": [
"@babel/plugin-transform-modules-commonjs"
]
}
Environment
- Babel version(s): v7.6.4
- Node/npm version: Node 12
- OS: OSX
- Monorepo: no
- How you are using Babel: cli or REPL
Possible Solution
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.
Bug Report
Current Behavior
The commonjs and amd plugins create invalid
throw new Error('"' + "foo" + '" is read-only.');statements in the output when there is an import with the same name as used in the destructuring even though it's shadowed by a function parameter.Input Code
Output:
Expected behavior/code
No Error's in output, like this when the import name is changed:
Babel Configuration (.babelrc, package.json, cli command)
Environment
Possible Solution
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.