Support exporting deep destructuring (#5953)
This commit is contained in:
parent
8a5488e59f
commit
827c70e015
@ -11,9 +11,9 @@ define(["exports"], function (exports) {
|
|||||||
|
|
||||||
var foo3 = exports.foo3 = function () {};
|
var foo3 = exports.foo3 = function () {};
|
||||||
|
|
||||||
var foo4 = exports.foo4 = undefined;
|
var foo4 = exports.foo4 = void 0;
|
||||||
let foo5 = exports.foo5 = 2;
|
let foo5 = exports.foo5 = 2;
|
||||||
let foo6 = exports.foo6 = undefined;
|
let foo6 = exports.foo6 = void 0;
|
||||||
const foo7 = exports.foo7 = 3;
|
const foo7 = exports.foo7 = 3;
|
||||||
|
|
||||||
function foo8() {}
|
function foo8() {}
|
||||||
|
|||||||
@ -372,55 +372,27 @@ export default function() {
|
|||||||
]);
|
]);
|
||||||
nonHoistedExportNames[id.name] = true;
|
nonHoistedExportNames[id.name] = true;
|
||||||
} else if (declaration.isVariableDeclaration()) {
|
} else if (declaration.isVariableDeclaration()) {
|
||||||
const declarators = declaration.get("declarations");
|
const ids = declaration.getBindingIdentifierPaths();
|
||||||
for (const decl of declarators) {
|
const exportsToInsert = [];
|
||||||
const id = decl.get("id");
|
for (const name in ids) {
|
||||||
|
const id = ids[name];
|
||||||
|
const { parentPath, node } = id;
|
||||||
|
|
||||||
const init = decl.get("init");
|
addTo(exports, name, node);
|
||||||
const exportsToInsert = [];
|
nonHoistedExportNames[name] = true;
|
||||||
|
|
||||||
if (!init.node) init.replaceWith(t.identifier("undefined"));
|
if (parentPath.isVariableDeclarator()) {
|
||||||
|
const init = parentPath.get("init");
|
||||||
if (id.isIdentifier()) {
|
const assignment = buildExportsAssignment(
|
||||||
addTo(exports, id.node.name, id.node);
|
node,
|
||||||
init.replaceWith(
|
init.node || path.scope.buildUndefinedNode(),
|
||||||
buildExportsAssignment(id.node, init.node).expression,
|
|
||||||
);
|
);
|
||||||
nonHoistedExportNames[id.node.name] = true;
|
init.replaceWith(assignment.expression);
|
||||||
} else if (id.isObjectPattern()) {
|
} else {
|
||||||
for (let i = 0; i < id.node.properties.length; i++) {
|
exportsToInsert.push(buildExportsAssignment(node, node));
|
||||||
const prop = id.node.properties[i];
|
|
||||||
let propValue = prop.value;
|
|
||||||
if (t.isAssignmentPattern(propValue)) {
|
|
||||||
propValue = propValue.left;
|
|
||||||
} else if (t.isRestProperty(prop)) {
|
|
||||||
propValue = prop.argument;
|
|
||||||
}
|
|
||||||
addTo(exports, propValue.name, propValue);
|
|
||||||
exportsToInsert.push(
|
|
||||||
buildExportsAssignment(propValue, propValue),
|
|
||||||
);
|
|
||||||
nonHoistedExportNames[propValue.name] = true;
|
|
||||||
}
|
|
||||||
} else if (id.isArrayPattern() && id.node.elements) {
|
|
||||||
for (let i = 0; i < id.node.elements.length; i++) {
|
|
||||||
let elem = id.node.elements[i];
|
|
||||||
if (!elem) continue;
|
|
||||||
if (t.isAssignmentPattern(elem)) {
|
|
||||||
elem = elem.left;
|
|
||||||
} else if (t.isRestElement(elem)) {
|
|
||||||
elem = elem.argument;
|
|
||||||
}
|
|
||||||
const name = elem.name;
|
|
||||||
addTo(exports, name, elem);
|
|
||||||
exportsToInsert.push(
|
|
||||||
buildExportsAssignment(elem, elem),
|
|
||||||
);
|
|
||||||
nonHoistedExportNames[name] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
path.insertAfter(exportsToInsert);
|
|
||||||
}
|
}
|
||||||
|
path.insertAfter(exportsToInsert);
|
||||||
path.replaceWith(declaration.node);
|
path.replaceWith(declaration.node);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -10,9 +10,9 @@ var foo2 = exports.foo2 = 1,
|
|||||||
|
|
||||||
var foo3 = exports.foo3 = function () {};
|
var foo3 = exports.foo3 = function () {};
|
||||||
|
|
||||||
var foo4 = exports.foo4 = undefined;
|
var foo4 = exports.foo4 = void 0;
|
||||||
let foo5 = exports.foo5 = 2;
|
let foo5 = exports.foo5 = 2;
|
||||||
let foo6 = exports.foo6 = undefined;
|
let foo6 = exports.foo6 = void 0;
|
||||||
const foo7 = exports.foo7 = 3;
|
const foo7 = exports.foo7 = 3;
|
||||||
|
|
||||||
function foo8() {}
|
function foo8() {}
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
export const { foo: { bar: [baz, qux] } } = {};
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const {
|
||||||
|
foo: {
|
||||||
|
bar: [baz, qux]
|
||||||
|
}
|
||||||
|
} = {};
|
||||||
|
exports.baz = baz;
|
||||||
|
exports.qux = qux;
|
||||||
@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
var foo3 = exports.foo3 = function () {};
|
var foo3 = exports.foo3 = function () {};
|
||||||
|
|
||||||
var foo4 = exports.foo4 = undefined;
|
var foo4 = exports.foo4 = void 0;
|
||||||
let foo5 = exports.foo5 = 2;
|
let foo5 = exports.foo5 = 2;
|
||||||
let foo6 = exports.foo6 = undefined;
|
let foo6 = exports.foo6 = void 0;
|
||||||
const foo7 = exports.foo7 = 3;
|
const foo7 = exports.foo7 = 3;
|
||||||
|
|
||||||
function foo8() {}
|
function foo8() {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user