fix es7 export extensions compound list
This commit is contained in:
@@ -558,9 +558,10 @@ pp.parseClassSuper = function(node) {
|
||||
pp.parseExport = function(node) {
|
||||
this.next()
|
||||
// export * from '...'
|
||||
if (this.eat(tt.star)) {
|
||||
if (this.type === tt.star) {
|
||||
let specifier = this.startNode()
|
||||
this.next()
|
||||
if (this.options.features["es7.exportExtensions"] && this.eatContextual("as")) {
|
||||
let specifier = this.startNode()
|
||||
specifier.exported = this.parseIdent()
|
||||
node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")]
|
||||
this.parseExportSpecifiersMaybe(node)
|
||||
@@ -573,7 +574,16 @@ pp.parseExport = function(node) {
|
||||
let specifier = this.startNode()
|
||||
specifier.exported = this.parseIdent(true)
|
||||
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]
|
||||
this.parseExportSpecifiersMaybe(node)
|
||||
if (this.type === tt.comma && this.lookahead().type === tt.star) {
|
||||
this.expect(tt.comma)
|
||||
let specifier = this.startNode()
|
||||
this.expect(tt.star)
|
||||
this.expectContextual("as")
|
||||
specifier.exported = this.parseIdent()
|
||||
node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"))
|
||||
} else {
|
||||
this.parseExportSpecifiersMaybe(node)
|
||||
}
|
||||
this.parseExportFrom(node)
|
||||
} else if (this.eat(tt._default)) { // export default ...
|
||||
let expr = this.parseMaybeAssign()
|
||||
|
||||
@@ -10,28 +10,32 @@ export function check(node) {
|
||||
return t.isExportDefaultSpecifier(node) || t.isExportNamespaceSpecifier(node);
|
||||
}
|
||||
|
||||
export function ExportNamedDeclaration(node, parent, scope) {
|
||||
var nodes = [];
|
||||
function build(node, nodes, scope) {
|
||||
var first = node.specifiers[0];
|
||||
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
|
||||
|
||||
if (t.isExportNamespaceSpecifier(node.specifiers[0])) {
|
||||
var specifier = node.specifiers.shift();
|
||||
var uid = scope.generateUidIdentifier(specifier.exported.name);
|
||||
nodes.push(
|
||||
t.importDeclaration([t.importNamespaceSpecifier(uid)], node.source),
|
||||
t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)])
|
||||
);
|
||||
} else if (t.isExportDefaultSpecifier(node.specifiers[0])) {
|
||||
var specifier = node.specifiers.shift();
|
||||
var uid = scope.generateUidIdentifier(specifier.exported.name);
|
||||
nodes.push(
|
||||
t.importDeclaration([t.importSpecifier(uid, specifier.exported)], node.source),
|
||||
t.exportNamedDeclaration(null, [t.exportSpecifier(uid, t.identifier("default"))])
|
||||
);
|
||||
var specifier = node.specifiers.shift();
|
||||
var uid = scope.generateUidIdentifier(specifier.exported.name);
|
||||
|
||||
var newSpecifier;
|
||||
if (t.isExportNamespaceSpecifier(specifier)) {
|
||||
newSpecifier = t.importNamespaceSpecifier(uid);
|
||||
} else {
|
||||
newSpecifier = t.importDefaultSpecifier(uid);
|
||||
}
|
||||
|
||||
nodes.push(t.importDeclaration([newSpecifier], node.source));
|
||||
nodes.push(t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)]));
|
||||
|
||||
build(node, nodes, scope);
|
||||
}
|
||||
|
||||
export function ExportNamedDeclaration(node, parent, scope) {
|
||||
var nodes = [];
|
||||
build(node, nodes, scope);
|
||||
if (!nodes.length) return;
|
||||
|
||||
if (node.specifiers.length > 1) {
|
||||
if (node.specifiers.length >= 1) {
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ var templateVisitor = {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node) && has(nodes, node.name)) {
|
||||
this.skip();
|
||||
this.replaceInline(nodes[node.name]);
|
||||
|
||||
Reference in New Issue
Block a user