-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
Has PRoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
When destructuring into an exported variable, transform-es2015-modules-commonjs fails to generate code to keep the local variable and the exports value in sync.
Input Code
export let x = 0;
export function f1(){
x = 1;
}
export function f2(){
[x] = [2];
}
export function f3(){
({x} = {x: 3});
}Babel Configuration (.babelrc, package.json, cli command)
{
"plugins": ["transform-es2015-modules-commonjs"]
}Expected Generated Code
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.f1 = f1;
exports.f2 = f2;
exports.f3 = f3;
let x = exports.x = 0;
function f1() {
exports.x = x = 1;
}
function f2() {
[x] = [2];
exports.x = x; //this is one possible solution
}
function f3() {
({ x } = { x: 3 });
exports.x = x;
}Current Generated Code
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.f1 = f1;
exports.f2 = f2;
exports.f3 = f3;
let x = exports.x = 0;
function f1() {
exports.x = x = 1;
}
function f2() {
[x] = [2];
}
function f3() {
({ x } = { x: 3 });
}Possible Solution
Add a line to keep the local variable and the export value in sync when destructuring into export variables.
| software | version(s) |
|---|---|
| Babel | 6.24.1 |
| babel-plugin-transform-es2015-modules-commonjs | 6.24.1 |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Has PRoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue