Loose: ES6 import, export.
Removed "kind" from tests for ES6 import/export as it's left only for backward compatibility.
This commit is contained in:
parent
4647f966eb
commit
d4565fed53
@ -449,6 +449,12 @@
|
||||
case tt._class:
|
||||
return parseObj(true, true);
|
||||
|
||||
case tt._import:
|
||||
return parseImport();
|
||||
|
||||
case tt._export:
|
||||
return parseExport();
|
||||
|
||||
default:
|
||||
var expr = parseExpression();
|
||||
if (isDummy(expr)) {
|
||||
@ -963,6 +969,96 @@
|
||||
return finishNode(node, "ArrowFunctionExpression");
|
||||
}
|
||||
|
||||
function parseExport() {
|
||||
var node = startNode();
|
||||
next();
|
||||
node['default'] = eat(tt._default);
|
||||
node.specifiers = node.source = null;
|
||||
if (node['default']) {
|
||||
node.declaration = parseExpression();
|
||||
semicolon();
|
||||
} else if (token.type.keyword) {
|
||||
node.declaration = parseStatement();
|
||||
} else {
|
||||
node.declaration = null;
|
||||
parseSpecifierList(node, "Export");
|
||||
}
|
||||
return finishNode(node, "ExportDeclaration");
|
||||
}
|
||||
|
||||
function parseImport() {
|
||||
var node = startNode();
|
||||
next();
|
||||
if (token.type === tt.string) {
|
||||
node.specifiers = [];
|
||||
node.source = parseExprAtom();
|
||||
node.kind = '';
|
||||
} else {
|
||||
if (token.type === tt.name && token.value !== "from") {
|
||||
var elt = startNode();
|
||||
elt.id = parseIdent();
|
||||
elt.name = null;
|
||||
elt['default'] = true;
|
||||
finishNode(elt, "ImportSpecifier");
|
||||
eat(tt.comma);
|
||||
}
|
||||
parseSpecifierList(node, "Import");
|
||||
var specs = node.specifiers;
|
||||
for (var i = 0; i < specs.length; i++) specs[i]['default'] = false;
|
||||
if (elt) node.specifiers.unshift(elt);
|
||||
}
|
||||
return finishNode(node, "ImportDeclaration");
|
||||
}
|
||||
|
||||
function parseSpecifierList(node, prefix) {
|
||||
var elts = node.specifiers = [];
|
||||
if (token.type === tt.star) {
|
||||
var elt = startNode();
|
||||
next();
|
||||
if (token.type === tt.name && token.value === "as") {
|
||||
next();
|
||||
elt.name = parseIdent();
|
||||
}
|
||||
elts.push(finishNode(elt, prefix + "BatchSpecifier"));
|
||||
} else {
|
||||
var indent = curIndent, line = curLineStart, continuedLine = nextLineStart;
|
||||
pushCx();
|
||||
eat(tt.braceL);
|
||||
if (curLineStart > continuedLine) continuedLine = curLineStart;
|
||||
while (!closes(tt.braceR, indent + (curLineStart <= continuedLine ? 1 : 0), line)) {
|
||||
var elt = startNode();
|
||||
if (token.type === tt.star) {
|
||||
next();
|
||||
if (token.type === tt.name && token.value === "as") {
|
||||
next();
|
||||
elt.name = parseIdent();
|
||||
}
|
||||
finishNode(elt, prefix + "BatchSpecifier");
|
||||
} else {
|
||||
if (token.type === tt.name && token.value === "from") break;
|
||||
elt.id = parseIdent();
|
||||
if (token.type === tt.name && token.value === "as") {
|
||||
next();
|
||||
elt.name = parseIdent();
|
||||
} else {
|
||||
elt.name = null;
|
||||
}
|
||||
finishNode(elt, prefix + "Specifier");
|
||||
}
|
||||
elts.push(elt);
|
||||
eat(tt.comma);
|
||||
}
|
||||
eat(tt.braceR);
|
||||
popCx();
|
||||
}
|
||||
if (token.type === tt.name && token.value === "from") {
|
||||
next();
|
||||
node.source = parseExprAtom();
|
||||
} else {
|
||||
node.source = null;
|
||||
}
|
||||
}
|
||||
|
||||
function parseExprList(close, allowEmpty) {
|
||||
var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart;
|
||||
next(); // Opening bracket
|
||||
|
||||
@ -5113,7 +5113,6 @@ test("import $ from \"jquery\"", {
|
||||
end: {line: 1, column: 8}
|
||||
}
|
||||
}],
|
||||
kind: "default",
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: "jquery",
|
||||
@ -5176,7 +5175,6 @@ test("import { encrypt, decrypt } from \"crypto\"", {
|
||||
}
|
||||
}
|
||||
],
|
||||
kind: "named",
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: "crypto",
|
||||
@ -5228,7 +5226,6 @@ test("import { encrypt as enc } from \"crypto\"", {
|
||||
end: {line: 1, column: 23}
|
||||
}
|
||||
}],
|
||||
kind: "named",
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: "crypto",
|
||||
@ -5333,8 +5330,7 @@ test("import crypto, { decrypt, encrypt as enc } from \"crypto\"", {
|
||||
},
|
||||
value: "crypto",
|
||||
raw: "\"crypto\""
|
||||
},
|
||||
kind: "default"
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
ecmaVersion: 6,
|
||||
@ -5371,7 +5367,6 @@ test("import { null as nil } from \"bar\"", {
|
||||
end: {line: 1, column: 20}
|
||||
}
|
||||
}],
|
||||
kind: "named",
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: "bar",
|
||||
@ -5431,8 +5426,7 @@ test("import * as crypto from \"crypto\"", {
|
||||
},
|
||||
value: "crypto",
|
||||
raw: "\"crypto\""
|
||||
},
|
||||
kind: "named"
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
ecmaVersion: 6,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user