diff --git a/src/parser/statement.js b/src/parser/statement.js index 3d61f047e9..d2dfce09e2 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -861,22 +861,8 @@ pp.parseExport = function (node) { return this.finishNode(node, "ExportNamedDeclaration"); }; -pp.shouldParseExportDeclaration = function () { - return this.state.type.keyword || this.isContextual("async"); -}; - -pp.isDeclaration = function (node): boolean { - return node.type === "VariableDeclaration" - || node.type === "FunctionDeclaration" - || node.type === "ClassDeclaration"; -}; - pp.parseExportDeclaration = function () { - const statement = this.parseStatement(true); - if (!this.isDeclaration(statement)) { - this.unexpected(statement.start); - } - return statement; + return this.parseStatement(true); }; pp.isExportDefaultSpecifier = function () { @@ -915,6 +901,15 @@ pp.parseExportFrom = function (node, expect?) { this.semicolon(); }; +pp.shouldParseExportDeclaration = function (): boolean { + return this.state.type.keyword === "var" + || this.state.type.keyword === "const" + || this.state.type.keyword === "let" + || this.state.type.keyword === "function" + || this.state.type.keyword === "class" + || this.isContextual("async"); +}; + pp.checkExport = function (node, checkNames, isDefault) { if (checkNames) { // Check for duplicate exports diff --git a/test/fixtures/es2015/uncategorised/385/actual.js b/test/fixtures/es2015/uncategorised/385/actual.js index 8c53b5ac08..7c26b9ed68 100644 --- a/test/fixtures/es2015/uncategorised/385/actual.js +++ b/test/fixtures/es2015/uncategorised/385/actual.js @@ -1 +1 @@ -export typeof foo; +export async function foo() {} diff --git a/test/fixtures/es2015/uncategorised/385/expected.json b/test/fixtures/es2015/uncategorised/385/expected.json new file mode 100644 index 0000000000..a3bcbae858 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/385/expected.json @@ -0,0 +1,104 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "FunctionDeclaration", + "start": 7, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "expression": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/385/options.json b/test/fixtures/es2015/uncategorised/385/options.json index 5a52b64b0f..2104ca4328 100644 --- a/test/fixtures/es2015/uncategorised/385/options.json +++ b/test/fixtures/es2015/uncategorised/385/options.json @@ -1,4 +1,3 @@ { - "sourceType": "module", - "throws": "Unexpected token (1:7)" + "sourceType": "module" } diff --git a/test/fixtures/es2015/uncategorised/386/actual.js b/test/fixtures/es2015/uncategorised/386/actual.js index b569071349..8c53b5ac08 100644 --- a/test/fixtures/es2015/uncategorised/386/actual.js +++ b/test/fixtures/es2015/uncategorised/386/actual.js @@ -1 +1 @@ -export new Foo(); +export typeof foo; diff --git a/test/fixtures/es2015/uncategorised/386/options.json b/test/fixtures/es2015/uncategorised/386/options.json index 5a52b64b0f..29139e4969 100644 --- a/test/fixtures/es2015/uncategorised/386/options.json +++ b/test/fixtures/es2015/uncategorised/386/options.json @@ -1,4 +1,5 @@ { "sourceType": "module", - "throws": "Unexpected token (1:7)" + "throws": "Unexpected token, expected { (1:7)" } + diff --git a/test/fixtures/es2015/uncategorised/387/actual.js b/test/fixtures/es2015/uncategorised/387/actual.js index bcaa553a7f..b569071349 100644 --- a/test/fixtures/es2015/uncategorised/387/actual.js +++ b/test/fixtures/es2015/uncategorised/387/actual.js @@ -1 +1 @@ -export function() {}; +export new Foo(); diff --git a/test/fixtures/es2015/uncategorised/387/options.json b/test/fixtures/es2015/uncategorised/387/options.json index a717563a6b..c09368b80c 100644 --- a/test/fixtures/es2015/uncategorised/387/options.json +++ b/test/fixtures/es2015/uncategorised/387/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "Unexpected token (1:15)" + "throws": "Unexpected token, expected { (1:7)" } diff --git a/test/fixtures/es2015/uncategorised/388/actual.js b/test/fixtures/es2015/uncategorised/388/actual.js index 70aa81cacc..bcaa553a7f 100644 --- a/test/fixtures/es2015/uncategorised/388/actual.js +++ b/test/fixtures/es2015/uncategorised/388/actual.js @@ -1 +1 @@ -export for (;;); +export function() {}; diff --git a/test/fixtures/es2015/uncategorised/388/options.json b/test/fixtures/es2015/uncategorised/388/options.json index 5a52b64b0f..a717563a6b 100644 --- a/test/fixtures/es2015/uncategorised/388/options.json +++ b/test/fixtures/es2015/uncategorised/388/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "Unexpected token (1:7)" + "throws": "Unexpected token (1:15)" } diff --git a/test/fixtures/es2015/uncategorised/389/actual.js b/test/fixtures/es2015/uncategorised/389/actual.js index d564bed3d2..70aa81cacc 100644 --- a/test/fixtures/es2015/uncategorised/389/actual.js +++ b/test/fixtures/es2015/uncategorised/389/actual.js @@ -1 +1 @@ -export while(foo); +export for (;;); diff --git a/test/fixtures/es2015/uncategorised/389/options.json b/test/fixtures/es2015/uncategorised/389/options.json index 5a52b64b0f..c09368b80c 100644 --- a/test/fixtures/es2015/uncategorised/389/options.json +++ b/test/fixtures/es2015/uncategorised/389/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "Unexpected token (1:7)" + "throws": "Unexpected token, expected { (1:7)" } diff --git a/test/fixtures/es2015/uncategorised/390/actual.js b/test/fixtures/es2015/uncategorised/390/actual.js new file mode 100644 index 0000000000..d564bed3d2 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/390/actual.js @@ -0,0 +1 @@ +export while(foo); diff --git a/test/fixtures/es2015/uncategorised/390/options.json b/test/fixtures/es2015/uncategorised/390/options.json new file mode 100644 index 0000000000..c09368b80c --- /dev/null +++ b/test/fixtures/es2015/uncategorised/390/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token, expected { (1:7)" +} diff --git a/test/fixtures/es2015/uncategorised/391/actual.js b/test/fixtures/es2015/uncategorised/391/actual.js new file mode 100644 index 0000000000..e2f75533f0 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/391/actual.js @@ -0,0 +1 @@ +export function* foo() {}; diff --git a/test/fixtures/es2015/uncategorised/391/expected.json b/test/fixtures/es2015/uncategorised/391/expected.json new file mode 100644 index 0000000000..b426a8f949 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/391/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "FunctionDeclaration", + "start": 7, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "EmptyStatement", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/391/options.json b/test/fixtures/es2015/uncategorised/391/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/391/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +}