From 0b85a4cb312ebd5d66289f2e03327dc990548245 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 9 Oct 2015 13:42:26 -0700 Subject: [PATCH] Make sure that exports \{default\} throws an error Fixes #326 --- src/statement.js | 7 +++++++ test/tests-harmony.js | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/statement.js b/src/statement.js index a93250728..b39b10a5a 100644 --- a/src/statement.js +++ b/src/statement.js @@ -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() diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 0f8e7ab4e..8bed97e41 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -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: [{