Fixed import declaration for default+batch case.
Also removed deprecated `kind` property. Fixes #161.
This commit is contained in:
parent
f48a921e24
commit
4496ca411a
23
acorn.js
23
acorn.js
@ -2551,9 +2551,6 @@
|
||||
if (tokType !== _name || tokVal !== "from") unexpected();
|
||||
next();
|
||||
node.source = tokType === _string ? parseExprAtom() : unexpected();
|
||||
// only for backward compatibility with Esprima's AST
|
||||
// (it doesn't support mixed default + named yet)
|
||||
node.kind = node.specifiers[0]['default'] ? "default" : "named";
|
||||
}
|
||||
semicolon();
|
||||
return finishNode(node, "ImportDeclaration");
|
||||
@ -2563,16 +2560,6 @@
|
||||
|
||||
function parseImportSpecifiers() {
|
||||
var nodes = [], first = true;
|
||||
if (tokType === _star) {
|
||||
var node = startNode();
|
||||
next();
|
||||
if (tokType !== _name || tokVal !== "as") unexpected();
|
||||
next();
|
||||
node.name = parseIdent();
|
||||
checkLVal(node.name, true);
|
||||
nodes.push(finishNode(node, "ImportBatchSpecifier"));
|
||||
return nodes;
|
||||
}
|
||||
if (tokType === _name) {
|
||||
// import defaultObj, { x, y as z } from '...'
|
||||
var node = startNode();
|
||||
@ -2583,6 +2570,16 @@
|
||||
nodes.push(finishNode(node, "ImportSpecifier"));
|
||||
if (!eat(_comma)) return nodes;
|
||||
}
|
||||
if (tokType === _star) {
|
||||
var node = startNode();
|
||||
next();
|
||||
if (tokType !== _name || tokVal !== "as") unexpected();
|
||||
next();
|
||||
node.name = parseIdent();
|
||||
checkLVal(node.name, true);
|
||||
nodes.push(finishNode(node, "ImportBatchSpecifier"));
|
||||
return nodes;
|
||||
}
|
||||
expect(_braceL);
|
||||
while (!eat(_braceR)) {
|
||||
if (!first) {
|
||||
|
||||
@ -14160,3 +14160,34 @@ test("(for (x of array) for (y of array2) if (x === test) x)", {
|
||||
}
|
||||
}]
|
||||
}, {ecmaVersion: 7, preserveParens: true});
|
||||
|
||||
// https://github.com/marijnh/acorn/issues/161
|
||||
test("import foo, * as bar from 'baz';", {
|
||||
type: "Program",
|
||||
body: [{
|
||||
type: "ImportDeclaration",
|
||||
specifiers: [
|
||||
{
|
||||
type: "ImportSpecifier",
|
||||
id: {
|
||||
type: "Identifier",
|
||||
name: "foo"
|
||||
},
|
||||
name: null,
|
||||
default: true
|
||||
},
|
||||
{
|
||||
type: "ImportBatchSpecifier",
|
||||
name: {
|
||||
type: "Identifier",
|
||||
name: "bar"
|
||||
}
|
||||
}
|
||||
],
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: "baz",
|
||||
raw: "'baz'"
|
||||
}
|
||||
}]
|
||||
}, {ecmaVersion: 6});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user