Skip to content

Commit

Permalink
Make sure that exports \{default\} throws an error
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Oct 12, 2015
1 parent ec539d3 commit 0b85a4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ pp.parseExport = function(node) {
if (this.eatContextual("from")) {
node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
} else {
// check for keywords used as local names
for (let i = 0; i < node.specifiers.length; i++) {
if (this.keywords.test(node.specifiers[i].local.name) || this.reservedWords.test(node.specifiers[i].local.name)) {
this.unexpected(node.specifiers[i].local.start)
}
}

node.source = null
}
this.semicolon()
Expand Down
6 changes: 6 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -4977,6 +4977,12 @@ test("export { default } from \"other\"", {
locations: true
});

testFail("export { default }", "Unexpected token (1:9)", {ecmaVersion: 6, sourceType: "module" });
testFail("export { if }", "Unexpected token (1:9)", {ecmaVersion: 6, sourceType: "module" });
testFail("export { if } from 'foo'", "Unexpected token (1:9)", {ecmaVersion: 6, sourceType: "module" });
testFail("export { default as foo }", "Unexpected token (1:9)", {ecmaVersion: 6, sourceType: "module" });
testFail("export { if as foo }", "Unexpected token (1:9)", {ecmaVersion: 6, sourceType: "module" });

test("import \"jquery\"", {
type: "Program",
body: [{
Expand Down

0 comments on commit 0b85a4c

Please sign in to comment.