Consider rest params for array pattern in exports.

This commit is contained in:
Artem Yavorsky 2017-03-18 16:02:06 +02:00
parent 06f67e1ad3
commit b608e28aa7
7 changed files with 23 additions and 10 deletions

View File

@ -321,9 +321,10 @@ export default function () {
for (let i = 0; i < id.node.elements.length; i++) { for (let i = 0; i < id.node.elements.length; i++) {
let elem = id.node.elements[i]; let elem = id.node.elements[i];
if (!elem) continue; if (!elem) continue;
if (!t.isRestElement(elem)) {
if (t.isAssignmentPattern(elem)) { if (t.isAssignmentPattern(elem)) {
elem = elem.left; elem = elem.left;
} else if (t.isRestElement(elem)) {
elem = elem.argument;
} }
const name = elem.name; const name = elem.name;
addTo(exports, name, elem); addTo(exports, name, elem);
@ -331,7 +332,6 @@ export default function () {
nonHoistedExportNames[name] = true; nonHoistedExportNames[name] = true;
} }
} }
}
path.insertAfter(exportsToInsert); path.insertAfter(exportsToInsert);
} }
path.replaceWith(declaration.node); path.replaceWith(declaration.node);

View File

@ -0,0 +1,5 @@
"use strict";
const [foo, bar = 2] = [];
exports.foo = foo;
exports.bar = bar;

View File

@ -0,0 +1 @@
export const [foo, bar, ...baz] = [];

View File

@ -0,0 +1,6 @@
"use strict";
const [foo, bar, ...baz] = [];
exports.foo = foo;
exports.bar = bar;
exports.bar = baz;

View File

@ -1 +1 @@
export const [foo, bar = 2] = [1]; export const [foo, bar] = [];

View File

@ -1,5 +1,5 @@
"use strict"; "use strict";
const [foo, bar = 2] = [1]; const [foo, bar] = [];
exports.foo = foo; exports.foo = foo;
exports.bar = bar; exports.bar = bar;