This commit is contained in:
Sebastian McKenzie 2014-12-10 20:32:56 +11:00
commit 1b760db578
3 changed files with 31 additions and 15 deletions

View File

@ -3096,7 +3096,6 @@
if (tokType === _string) {
node.specifiers = [];
node.source = parseExprAtom();
node.kind = "";
} else {
node.specifiers = parseImportSpecifiers();
if (tokType !== _name || tokVal !== "from") unexpected();
@ -3114,10 +3113,11 @@
if (tokType === _name) {
// import defaultObj, { x, y as z } from '...'
var node = startNode();
node.id = parseIdent();
checkLVal(node.id, true);
node.name = null;
node['default'] = true;
node.id = startNode();
node.name = parseIdent();
checkLVal(node.name, true);
node.id.name = "default";
finishNode(node.id, "Identifier");
nodes.push(finishNode(node, "ImportSpecifier"));
if (!eat(_comma)) return nodes;
}

View File

@ -1016,9 +1016,10 @@
} else {
if (token.type === tt.name && token.value !== "from") {
var elt = startNode();
elt.id = parseIdent();
elt.name = null;
elt['default'] = true;
elt.id = startNode();
elt.name = parseIdent();
elt.id.name = "default";
finishNode(elt.id, "Identifier");
finishNode(elt, "ImportSpecifier");
eat(tt.comma);
}

View File

@ -5153,6 +5153,14 @@ test("import $ from \"jquery\"", {
specifiers: [{
type: "ImportSpecifier",
id: {
type: "Identifier",
name: "default",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 8}
}
},
name: {
type: "Identifier",
name: "$",
loc: {
@ -5160,7 +5168,6 @@ test("import $ from \"jquery\"", {
end: {line: 1, column: 8}
}
},
name: null,
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 8}
@ -5328,10 +5335,16 @@ test("import crypto, { decrypt, encrypt as enc } from \"crypto\"", {
start: {line: 1, column: 7},
end: {line: 1, column: 13}
},
name: "crypto"
name: "default"
},
name: null,
default: true
name: {
type: "Identifier",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 13}
},
name: "crypto"
}
},
{
type: "ImportSpecifier",
@ -14217,10 +14230,12 @@ test("import foo, * as bar from 'baz';", {
type: "ImportSpecifier",
id: {
type: "Identifier",
name: "foo"
name: "default"
},
name: null,
default: true
name: {
type: "Identifier",
name: "foo"
}
},
{
type: "ImportBatchSpecifier",