add support for export extensions https://github.com/leebyron/ecmascript-more-export-from - closes #1091
This commit is contained in:
@@ -559,10 +559,10 @@ pp.parseExport = function(node) {
|
||||
this.next()
|
||||
// export * from '...'
|
||||
if (this.eat(tt.star)) {
|
||||
this.expectContextual("from")
|
||||
node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
|
||||
this.semicolon()
|
||||
this.checkExport(node)
|
||||
if (this.options.features["es7.exportExtensions"] && this.eatContextual("as")) {
|
||||
node.exported = this.parseIdent()
|
||||
}
|
||||
this.parseExportFrom(node)
|
||||
return this.finishNode(node, "ExportAllDeclaration")
|
||||
}
|
||||
if (this.eat(tt._default)) { // export default ...
|
||||
@@ -587,6 +587,10 @@ pp.parseExport = function(node) {
|
||||
node.declaration = this.parseStatement(true)
|
||||
node.specifiers = []
|
||||
node.source = null
|
||||
} else if (this.type === tt.name) {
|
||||
node.exported = this.parseIdent()
|
||||
this.parseExportFrom(node)
|
||||
return this.finishNode(node, "ExportNamespaceDeclaration")
|
||||
} else { // export { x, y as z } [from '...']
|
||||
node.declaration = null
|
||||
node.specifiers = this.parseExportSpecifiers()
|
||||
@@ -601,6 +605,13 @@ pp.parseExport = function(node) {
|
||||
return this.finishNode(node, "ExportNamedDeclaration")
|
||||
}
|
||||
|
||||
pp.parseExportFrom = function(node) {
|
||||
this.expectContextual("from")
|
||||
node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
|
||||
this.semicolon()
|
||||
this.checkExport(node)
|
||||
}
|
||||
|
||||
pp.shouldParseExportDeclaration = function() {
|
||||
return this.options.features["es7.asyncFunctions"] && this.isContextual("async")
|
||||
}
|
||||
|
||||
@@ -21,8 +21,21 @@ export function ExportSpecifier(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
export function ExportNamespaceDeclaration(node, print) {
|
||||
this.push("export ");
|
||||
print(node.exported);
|
||||
this.push(" from ");
|
||||
print(node.source);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function ExportAllDeclaration(node, print) {
|
||||
this.push("export * from ");
|
||||
this.push("export *");
|
||||
if (node.exported) {
|
||||
this.push(" as ");
|
||||
print(node.exported);
|
||||
}
|
||||
this.push(" from ");
|
||||
print(node.source);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ var exportsVisitor = traverse.explode({
|
||||
extend(formatter.localExports, declar.getBindingIdentifiers());
|
||||
}
|
||||
|
||||
if (!t.isExportDefaultDeclaration(node)) {
|
||||
if (!t.isExportDefaultDeclaration(node) && !t.isExportNamespaceDeclaration(node)) {
|
||||
formatter.hasNonDefaultExports = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// https://github.com/leebyron/ecmascript-more-export-from
|
||||
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function check(node) {
|
||||
return t.isExportNamespaceDeclaration(node) || (t.isExportAllDeclaration(node) && node.exported);
|
||||
}
|
||||
|
||||
export function ExportNamespaceDeclaration(node, parent, scope) {
|
||||
var uid = scope.generateUidIdentifier("default");
|
||||
return [
|
||||
t.importDeclaration([t.importDefaultSpecifier(uid)], node.source),
|
||||
t.exportDefaultDeclaration(uid)
|
||||
];
|
||||
}
|
||||
|
||||
export function ExportAllDeclaration(node, parent, scope) {
|
||||
if (node.exported) {
|
||||
var uid = scope.generateUidIdentifier(node.exported.name);
|
||||
return [
|
||||
t.importDeclaration([t.importNamespaceSpecifier(uid)], node.source),
|
||||
t.exportNamedDeclaration(null, [t.exportSpecifier(uid, node.exported)])
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ export default {
|
||||
runtime: require("./other/runtime"),
|
||||
|
||||
// needs to be before `_blockHoist` due to function hoisting etc
|
||||
"es7.exportExtensions": require("./es7/export-extensions"),
|
||||
"es6.modules": require("./es6/modules"),
|
||||
|
||||
_blockHoist: require("./internal/block-hoist"),
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
"EmptyStatement": ["Statement"],
|
||||
"LabeledStatement": ["Statement"],
|
||||
"VariableDeclaration": ["Statement", "Declaration"],
|
||||
"ExportAllDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ExportDefaultDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
|
||||
|
||||
"ExportNamespaceDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ExportAllDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ExportDefaultDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
|
||||
|
||||
"ArrowFunctionExpression": ["Scopable", "Function", "Expression"],
|
||||
"FunctionDeclaration": ["Scopable", "Function", "Statement", "Declaration"],
|
||||
|
||||
@@ -22,10 +22,6 @@
|
||||
"DoWhileStatement": ["body", "test"],
|
||||
"DoExpression": ["body"],
|
||||
"EmptyStatement": [],
|
||||
"ExportAllDeclaration": ["source"],
|
||||
"ExportDefaultDeclaration": ["declaration"],
|
||||
"ExportNamedDeclaration": ["declaration", "specifiers", "source"],
|
||||
"ExportSpecifier": ["local", "exported"],
|
||||
"ExpressionStatement": ["expression"],
|
||||
"File": ["program"],
|
||||
"ForInStatement": ["left", "right", "body"],
|
||||
@@ -72,6 +68,12 @@
|
||||
"WithStatement": ["object", "body"],
|
||||
"YieldExpression": ["argument"],
|
||||
|
||||
"ExportAllDeclaration": ["source", "exported"],
|
||||
"ExportNamespaceDeclaration": ["exported"],
|
||||
"ExportDefaultDeclaration": ["declaration"],
|
||||
"ExportNamedDeclaration": ["declaration", "specifiers", "source"],
|
||||
"ExportSpecifier": ["local", "exported"],
|
||||
|
||||
"AnyTypeAnnotation": [],
|
||||
"ArrayTypeAnnotation": ["elementType"],
|
||||
"BooleanTypeAnnotation": [],
|
||||
|
||||
Reference in New Issue
Block a user