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 |
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
Babel Configuration (.babelrc, package.json, cli command)
{ "plugins": ["transform-es2015-modules-commonjs"] }Expected Generated Code
Current Generated Code
Possible Solution
Add a line to keep the local variable and the export value in sync when destructuring into export variables.