fix explosion of modules and colliding identifiers
This commit is contained in:
parent
1aa0bbfac9
commit
c4ebfeb0fa
@ -13,6 +13,18 @@ function buildClone(bindingKey, refKey) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildListClone(listKey, bindingKey, refKey) {
|
||||||
|
var clone = buildClone(bindingKey, refKey);
|
||||||
|
|
||||||
|
return function (node) {
|
||||||
|
if (!node[listKey]) return;
|
||||||
|
|
||||||
|
for (var subNode of (node[listKey]: Array)) {
|
||||||
|
clone(subNode);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export var Property = buildClone("value", "key");
|
export var Property = buildClone("value", "key");
|
||||||
export var ExportSpecifier = buildClone("local", "exported");
|
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
|
||||||
export var ImportSpecifier = buildClone("local", "imported");
|
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");
|
||||||
|
|||||||
@ -49,6 +49,10 @@ export function ExportDefaultDeclaration(node, parent, scope) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildExportSpecifier(id) {
|
||||||
|
return t.exportSpecifier(clone(id), clone(id));
|
||||||
|
}
|
||||||
|
|
||||||
export function ExportNamedDeclaration(node, parent, scope) {
|
export function ExportNamedDeclaration(node, parent, scope) {
|
||||||
ImportDeclaration.apply(this, arguments);
|
ImportDeclaration.apply(this, arguments);
|
||||||
|
|
||||||
@ -61,12 +65,12 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
|||||||
|
|
||||||
if (t.isClassDeclaration(declar)) {
|
if (t.isClassDeclaration(declar)) {
|
||||||
// export class Foo {}
|
// export class Foo {}
|
||||||
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
node.specifiers = [buildExportSpecifier(declar.id)];
|
||||||
node.declaration = null;
|
node.declaration = null;
|
||||||
return [getDeclar(), node];
|
return [getDeclar(), node];
|
||||||
} else if (t.isFunctionDeclaration(declar)) {
|
} else if (t.isFunctionDeclaration(declar)) {
|
||||||
// export function Foo() {}
|
// export function Foo() {}
|
||||||
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
node.specifiers = [buildExportSpecifier(declar.id)];
|
||||||
node.declaration = null;
|
node.declaration = null;
|
||||||
node._blockHoist = 2;
|
node._blockHoist = 2;
|
||||||
return [getDeclar(), node];
|
return [getDeclar(), node];
|
||||||
@ -75,8 +79,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
|||||||
var specifiers = [];
|
var specifiers = [];
|
||||||
var bindings = this.get("declaration").getBindingIdentifiers();
|
var bindings = this.get("declaration").getBindingIdentifiers();
|
||||||
for (var key in bindings) {
|
for (var key in bindings) {
|
||||||
var id = bindings[key];
|
specifiers.push(buildExportSpecifier(bindings[key]));
|
||||||
specifiers.push(t.exportSpecifier(clone(id), clone(id)));
|
|
||||||
}
|
}
|
||||||
return [declar, t.exportNamedDeclaration(null, specifiers)];
|
return [declar, t.exportNamedDeclaration(null, specifiers)];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user