diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index 1ae00f1c3c..8fd67773c6 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -319,9 +319,12 @@ export default function () { } } else if (id.isArrayPattern() && id.node.elements) { for (let i = 0; i < id.node.elements.length; i++) { - const elem = id.node.elements[i]; + let elem = id.node.elements[i]; if (!elem) continue; if (!t.isRestElement(elem)) { + if (t.isAssignmentPattern(elem)) { + elem = elem.left; + } const name = elem.name; addTo(exports, name, elem); exportsToInsert.push(buildExportsAssignment(elem, elem)); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/actual.js index 1b7752d6c5..ae9b52c168 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/actual.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/actual.js @@ -1 +1 @@ -export const [ foo, bar ] = []; +export const [foo, bar = 2] = [1]; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/expected.js index e2fafbd5ca..62eda5c150 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/expected.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-array/expected.js @@ -1,5 +1,5 @@ "use strict"; -const [foo, bar] = []; +const [foo, bar = 2] = [1]; exports.foo = foo; exports.bar = bar;