diff --git a/src/parser/statement.js b/src/parser/statement.js index 26bc4e5525..3d61f047e9 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -848,7 +848,7 @@ pp.parseExport = function (node) { if (needsSemi) this.semicolon(); this.checkExport(node, true, true); return this.finishNode(node, "ExportDefaultDeclaration"); - } else if (this.state.type.keyword || this.shouldParseExportDeclaration()) { + } else if (this.shouldParseExportDeclaration()) { node.specifiers = []; node.source = null; node.declaration = this.parseExportDeclaration(node); @@ -861,8 +861,22 @@ 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 () { - return this.parseStatement(true); + const statement = this.parseStatement(true); + if (!this.isDeclaration(statement)) { + this.unexpected(statement.start); + } + return statement; }; pp.isExportDefaultSpecifier = function () { @@ -901,10 +915,6 @@ pp.parseExportFrom = function (node, expect?) { this.semicolon(); }; -pp.shouldParseExportDeclaration = function () { - return this.isContextual("async"); -}; - pp.checkExport = function (node, checkNames, isDefault) { if (checkNames) { // Check for duplicate exports diff --git a/test/fixtures/es2015/uncategorised/380/actual.js b/test/fixtures/es2015/uncategorised/380/actual.js new file mode 100644 index 0000000000..e2e71aa4fc --- /dev/null +++ b/test/fixtures/es2015/uncategorised/380/actual.js @@ -0,0 +1 @@ +export var foo = 1; diff --git a/test/fixtures/es2015/uncategorised/380/expected.json b/test/fixtures/es2015/uncategorised/380/expected.json new file mode 100644 index 0000000000..ce76b426cc --- /dev/null +++ b/test/fixtures/es2015/uncategorised/380/expected.json @@ -0,0 +1,121 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "VariableDeclaration", + "start": 7, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 11, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "var" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/380/options.json b/test/fixtures/es2015/uncategorised/380/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/380/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/es2015/uncategorised/381/actual.js b/test/fixtures/es2015/uncategorised/381/actual.js new file mode 100644 index 0000000000..bb1843d113 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/381/actual.js @@ -0,0 +1 @@ +export const foo = 1; diff --git a/test/fixtures/es2015/uncategorised/381/expected.json b/test/fixtures/es2015/uncategorised/381/expected.json new file mode 100644 index 0000000000..db5aee3169 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/381/expected.json @@ -0,0 +1,121 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "VariableDeclaration", + "start": 7, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "const" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/381/options.json b/test/fixtures/es2015/uncategorised/381/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/381/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/es2015/uncategorised/382/actual.js b/test/fixtures/es2015/uncategorised/382/actual.js new file mode 100644 index 0000000000..9d2b01ce65 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/382/actual.js @@ -0,0 +1 @@ +export let foo = 1; diff --git a/test/fixtures/es2015/uncategorised/382/expected.json b/test/fixtures/es2015/uncategorised/382/expected.json new file mode 100644 index 0000000000..b263cee065 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/382/expected.json @@ -0,0 +1,121 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "VariableDeclaration", + "start": 7, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 11, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "let" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/382/options.json b/test/fixtures/es2015/uncategorised/382/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/382/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/es2015/uncategorised/383/actual.js b/test/fixtures/es2015/uncategorised/383/actual.js new file mode 100644 index 0000000000..223d0a8b39 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/383/actual.js @@ -0,0 +1 @@ +export class Foo {} diff --git a/test/fixtures/es2015/uncategorised/383/expected.json b/test/fixtures/es2015/uncategorised/383/expected.json new file mode 100644 index 0000000000..2c2fd9b6a1 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/383/expected.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "ClassDeclaration", + "start": 7, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/383/options.json b/test/fixtures/es2015/uncategorised/383/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/383/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/es2015/uncategorised/384/actual.js b/test/fixtures/es2015/uncategorised/384/actual.js new file mode 100644 index 0000000000..f99d427777 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/384/actual.js @@ -0,0 +1 @@ +export function foo() {} diff --git a/test/fixtures/es2015/uncategorised/384/expected.json b/test/fixtures/es2015/uncategorised/384/expected.json new file mode 100644 index 0000000000..5113890dce --- /dev/null +++ b/test/fixtures/es2015/uncategorised/384/expected.json @@ -0,0 +1,104 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "FunctionDeclaration", + "start": 7, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/384/options.json b/test/fixtures/es2015/uncategorised/384/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/384/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/es2015/uncategorised/385/actual.js b/test/fixtures/es2015/uncategorised/385/actual.js new file mode 100644 index 0000000000..8c53b5ac08 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/385/actual.js @@ -0,0 +1 @@ +export typeof foo; diff --git a/test/fixtures/es2015/uncategorised/385/options.json b/test/fixtures/es2015/uncategorised/385/options.json new file mode 100644 index 0000000000..5a52b64b0f --- /dev/null +++ b/test/fixtures/es2015/uncategorised/385/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token (1:7)" +} diff --git a/test/fixtures/es2015/uncategorised/386/actual.js b/test/fixtures/es2015/uncategorised/386/actual.js new file mode 100644 index 0000000000..b569071349 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/386/actual.js @@ -0,0 +1 @@ +export new Foo(); diff --git a/test/fixtures/es2015/uncategorised/386/options.json b/test/fixtures/es2015/uncategorised/386/options.json new file mode 100644 index 0000000000..5a52b64b0f --- /dev/null +++ b/test/fixtures/es2015/uncategorised/386/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token (1:7)" +} diff --git a/test/fixtures/es2015/uncategorised/387/actual.js b/test/fixtures/es2015/uncategorised/387/actual.js new file mode 100644 index 0000000000..bcaa553a7f --- /dev/null +++ b/test/fixtures/es2015/uncategorised/387/actual.js @@ -0,0 +1 @@ +export function() {}; diff --git a/test/fixtures/es2015/uncategorised/387/options.json b/test/fixtures/es2015/uncategorised/387/options.json new file mode 100644 index 0000000000..a717563a6b --- /dev/null +++ b/test/fixtures/es2015/uncategorised/387/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token (1:15)" +} diff --git a/test/fixtures/es2015/uncategorised/388/actual.js b/test/fixtures/es2015/uncategorised/388/actual.js new file mode 100644 index 0000000000..70aa81cacc --- /dev/null +++ b/test/fixtures/es2015/uncategorised/388/actual.js @@ -0,0 +1 @@ +export for (;;); diff --git a/test/fixtures/es2015/uncategorised/388/options.json b/test/fixtures/es2015/uncategorised/388/options.json new file mode 100644 index 0000000000..5a52b64b0f --- /dev/null +++ b/test/fixtures/es2015/uncategorised/388/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token (1:7)" +} diff --git a/test/fixtures/es2015/uncategorised/389/actual.js b/test/fixtures/es2015/uncategorised/389/actual.js new file mode 100644 index 0000000000..d564bed3d2 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/389/actual.js @@ -0,0 +1 @@ +export while(foo); diff --git a/test/fixtures/es2015/uncategorised/389/options.json b/test/fixtures/es2015/uncategorised/389/options.json new file mode 100644 index 0000000000..5a52b64b0f --- /dev/null +++ b/test/fixtures/es2015/uncategorised/389/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token (1:7)" +}