diff --git a/acorn.js b/acorn.js index 526c3a4f35..753ba2b384 100644 --- a/acorn.js +++ b/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) { diff --git a/test/tests-harmony.js b/test/tests-harmony.js index f5064c8a94..15e3b98545 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -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});