From 43eed1ac922400cb486bfe6af74883c48ac1d3ed Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 26 Feb 2019 13:28:10 -0800 Subject: [PATCH] Check exported bindings are defined (#9589) * Check exported bindings are defined * Add tests * Update flow whitelist * Add tests for builtins --- .../fixtures/edgecase/unary-op/options.json | 3 + .../fixtures/flow/declare-exports/input.js | 1 + .../fixtures/flow/declare-exports/output.js | 1 + .../fixtures/flow/type-annotations/input.js | 2 +- .../fixtures/flow/type-annotations/output.js | 4 +- .../harmony-edgecase/exports/input.js | 1 + .../harmony-edgecase/exports/output.js | 1 + .../fixtures/types/ExportSpecifier11/input.js | 1 + .../types/ExportSpecifier11/output.js | 3 +- .../fixtures/types/ExportSpecifier12/input.js | 1 + .../types/ExportSpecifier12/output.js | 3 +- .../fixtures/types/ExportSpecifier13/input.js | 1 + .../types/ExportSpecifier13/output.js | 3 +- .../fixtures/types/ExportSpecifier14/input.js | 1 + .../types/ExportSpecifier14/output.js | 3 +- .../fixtures/types/ExportSpecifier15/input.js | 1 + .../types/ExportSpecifier15/output.js | 3 +- .../types/UnaryExpression/options.json | 3 + .../fixtures/types/WithStatement/options.json | 3 + packages/babel-generator/test/index.js | 2 +- packages/babel-parser/src/parser/statement.js | 18 +- packages/babel-parser/src/types.js | 1 + packages/babel-parser/src/util/scope.js | 19 ++ .../scope/undecl-export-as-default/input.js | 1 + .../undecl-export-as-default/options.json | 4 + .../core/scope/undecl-export-as/input.js | 2 + .../core/scope/undecl-export-as/options.json | 4 + .../core/scope/undecl-export-block/input.js | 4 + .../scope/undecl-export-block/options.json | 4 + .../scope/undecl-export-builtin-as/input.js | 1 + .../undecl-export-builtin-as/options.json | 4 + .../core/scope/undecl-export-builtin/input.js | 1 + .../scope/undecl-export-builtin/options.json | 4 + .../core/scope/undecl-export-if/input.js | 2 + .../core/scope/undecl-export-if/options.json | 4 + .../core/scope/undecl-export-var/input.js | 4 + .../core/scope/undecl-export-var/options.json | 3 + .../core/scope/undecl-export-var/output.json | 172 +++++++++++++++++ .../core/scope/undecl-export/input.js | 1 + .../core/scope/undecl-export/options.json | 4 + .../duplicate-named-export-builtin/input.js | 2 + .../output.json | 114 +++++++++--- .../fixtures/es2015/uncategorised/86/input.js | 3 +- .../es2015/uncategorised/86/output.json | 68 ++++++- .../fixtures/es2015/uncategorised/87/input.js | 4 +- .../es2015/uncategorised/87/output.json | 165 +++++++++++++---- .../fixtures/es2015/uncategorised/88/input.js | 3 +- .../es2015/uncategorised/88/output.json | 111 ++++++++--- .../fixtures/es2015/uncategorised/89/input.js | 4 +- .../es2015/uncategorised/89/output.json | 165 +++++++++++++---- .../export-named-as-default/input.js | 1 + .../export-named-as-default/output.json | 67 ++++++- .../export-named-as-specifier/input.js | 1 + .../export-named-as-specifier/output.json | 128 ++++++++++--- .../export-named-as-specifiers/input.js | 1 + .../export-named-as-specifiers/output.json | 100 +++++++++- .../export-named-specifier/input.js | 1 + .../export-named-specifier/output.json | 95 +++++++--- .../export-named-specifiers-comma/input.js | 2 + .../export-named-specifiers-comma/output.json | 174 ++++++++++++++---- .../export-named-specifiers/input.js | 2 + .../export-named-specifiers/output.json | 174 ++++++++++++++---- .../export-named-pattern/input.js | 1 + .../export-named-pattern/output.json | 65 ++++++- .../flow/type-exports/specifier/input.js | 1 + .../flow/type-exports/specifier/output.json | 87 +++++++-- .../strip-type-annotations/input.mjs | 2 +- .../systemjs/export-named-2/input.mjs | 1 + .../systemjs/export-named-2/output.mjs | 13 +- .../systemjs/export-named-3/input.mjs | 1 + .../systemjs/export-named-3/output.mjs | 8 +- .../systemjs/export-named-4/input.mjs | 1 + .../systemjs/export-named-4/output.mjs | 8 +- .../systemjs/export-named-5/input.mjs | 1 + .../systemjs/export-named-5/output.mjs | 13 +- .../fixtures/systemjs/export-named/input.mjs | 1 + .../fixtures/systemjs/export-named/output.mjs | 8 +- .../test/fixtures/systemjs/overview/input.mjs | 4 +- .../fixtures/systemjs/overview/output.mjs | 4 +- scripts/tests/flow/flow_tests_whitelist.txt | 3 + scripts/tests/test262/test262_whitelist.txt | 4 - 81 files changed, 1594 insertions(+), 315 deletions(-) create mode 100644 packages/babel-generator/test/fixtures/edgecase/unary-op/options.json create mode 100644 packages/babel-generator/test/fixtures/types/UnaryExpression/options.json create mode 100644 packages/babel-generator/test/fixtures/types/WithStatement/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json diff --git a/packages/babel-generator/test/fixtures/edgecase/unary-op/options.json b/packages/babel-generator/test/fixtures/edgecase/unary-op/options.json new file mode 100644 index 0000000000..a2e80d9ec2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/unary-op/options.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} diff --git a/packages/babel-generator/test/fixtures/flow/declare-exports/input.js b/packages/babel-generator/test/fixtures/flow/declare-exports/input.js index 279e6ab4f9..97544d82b9 100644 --- a/packages/babel-generator/test/fixtures/flow/declare-exports/input.js +++ b/packages/babel-generator/test/fixtures/flow/declare-exports/input.js @@ -17,6 +17,7 @@ declare export * from 'asd'; declare export { a, b }; declare export {}; declare export { c, d } from 'bar'; +var a, b; declare module B { declare export type B = {}; diff --git a/packages/babel-generator/test/fixtures/flow/declare-exports/output.js b/packages/babel-generator/test/fixtures/flow/declare-exports/output.js index 877c430994..59f3a4c568 100644 --- a/packages/babel-generator/test/fixtures/flow/declare-exports/output.js +++ b/packages/babel-generator/test/fixtures/flow/declare-exports/output.js @@ -26,6 +26,7 @@ declare export * from 'asd'; declare export { a, b }; declare export {}; declare export { c, d } from 'bar'; +var a, b; declare module B { declare export type B = {}; declare export interface Moon {} diff --git a/packages/babel-generator/test/fixtures/flow/type-annotations/input.js b/packages/babel-generator/test/fixtures/flow/type-annotations/input.js index 76be1b446f..e7335c30b7 100644 --- a/packages/babel-generator/test/fixtures/flow/type-annotations/input.js +++ b/packages/babel-generator/test/fixtures/flow/type-annotations/input.js @@ -107,7 +107,7 @@ import { type Foo12 } from "bar"; import { typeof Foo13 } from "bar"; import { type Foo as Bar1 } from "bar"; import { typeof Foo as Bar2 } from "bar"; -export type { foo }; +export type { foo1 }; export type { bar } from "bar"; export interface baz { p: number } export interface qux { p: T } diff --git a/packages/babel-generator/test/fixtures/flow/type-annotations/output.js b/packages/babel-generator/test/fixtures/flow/type-annotations/output.js index cd69710614..6465359f33 100644 --- a/packages/babel-generator/test/fixtures/flow/type-annotations/output.js +++ b/packages/babel-generator/test/fixtures/flow/type-annotations/output.js @@ -231,7 +231,7 @@ import { type Foo12 } from "bar"; import { typeof Foo13 } from "bar"; import { type Foo as Bar1 } from "bar"; import { typeof Foo as Bar2 } from "bar"; -export type { foo }; +export type { foo1 }; export type { bar } from "bar"; export interface baz { p: number @@ -293,4 +293,4 @@ function foo27(numVal: number = 2) {} function foo28(numVal?: number = 2) {} -export type * from "foo"; +export type * from "foo"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js index ec680f05ac..540245d565 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js @@ -1,3 +1,4 @@ +var a, c; export * from "OK" export { name } from "OK" export { a as b, c as d } from "hello" diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js index 5482292b19..84c968fe12 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js @@ -1,3 +1,4 @@ +var a, c; export * from "OK"; export { name } from "OK"; export { a as b, c as d } from "hello"; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js index f40ac5c343..701c971b89 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js @@ -1 +1,2 @@ export { foo }; +var foo; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js index f604032cb6..520c0fb1dd 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js @@ -1 +1,2 @@ -export { foo }; \ No newline at end of file +export { foo }; +var foo; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js index 9dfa348be3..5e6c660603 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js @@ -1 +1,2 @@ export { foo, bar }; +var foo, bar; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js index 4cb44a4b25..be6d973b81 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js @@ -1 +1,2 @@ -export { foo, bar }; \ No newline at end of file +export { foo, bar }; +var foo, bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js index e4cca384da..dd1cfea6d7 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js @@ -1 +1,2 @@ export { foo as bar }; +var foo; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js index 5d4569c099..d6e7ac5025 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js @@ -1 +1,2 @@ -export { foo as bar }; \ No newline at end of file +export { foo as bar }; +var foo; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js index 95daad9d96..5e840fff92 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js @@ -1 +1,2 @@ export { foo as default }; +var foo; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js index f96da82b3b..4a3a9fe44e 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js @@ -1 +1,2 @@ -export { foo as default }; \ No newline at end of file +export { foo as default }; +var foo; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js index ebd14b2d96..022457fd87 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js @@ -1 +1,2 @@ export { foo as default, bar }; +var foo, bar; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js index 2ef73817d5..974c22ae14 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js @@ -1 +1,2 @@ -export { foo as default, bar }; \ No newline at end of file +export { foo as default, bar }; +var foo, bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/UnaryExpression/options.json b/packages/babel-generator/test/fixtures/types/UnaryExpression/options.json new file mode 100644 index 0000000000..a2e80d9ec2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/UnaryExpression/options.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} diff --git a/packages/babel-generator/test/fixtures/types/WithStatement/options.json b/packages/babel-generator/test/fixtures/types/WithStatement/options.json new file mode 100644 index 0000000000..a2e80d9ec2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/WithStatement/options.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index c8b60b4051..0574528850 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -489,7 +489,7 @@ suites.forEach(function(testSuite) { const actualAst = parse(actualCode, { filename: actual.loc, plugins: task.options.plugins || [], - strictMode: false, + strictMode: task.options.strictMode === false ? false : true, sourceType: "module", sourceMaps: !!task.sourceMap, }); diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 2d98842c8b..d2981c2400 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -49,6 +49,14 @@ export default class StatementParser extends ExpressionParser { this.parseBlockBody(program, true, true, tt.eof); + if (this.inModule && this.scope.undefinedExports.size > 0) { + for (const [name] of Array.from(this.scope.undefinedExports)) { + const pos = this.scope.undefinedExports.get(name); + // $FlowIssue + this.raise(pos, `Export '${name}' is not defined`); + } + } + file.program = this.finishNode(program, "Program"); file.comments = this.state.comments; @@ -1631,7 +1639,7 @@ export default class StatementParser extends ExpressionParser { } if (isFromRequired || hasSpecifiers || hasDeclaration) { - this.checkExport(node, true); + this.checkExport(node, true, false, !!node.source); return this.finishNode(node, "ExportNamedDeclaration"); } @@ -1845,8 +1853,9 @@ export default class StatementParser extends ExpressionParser { checkExport( node: N.ExportNamedDeclaration, - checkNames: ?boolean, + checkNames?: boolean, isDefault?: boolean, + isFrom?: boolean, ): void { if (checkNames) { // Check for duplicate exports @@ -1857,6 +1866,11 @@ export default class StatementParser extends ExpressionParser { // Named exports for (const specifier of node.specifiers) { this.checkDuplicateExports(specifier, specifier.exported.name); + // check if export is defined + // $FlowIgnore + if (!isFrom && specifier.local) { + this.scope.checkLocalExport(specifier.local); + } } } else if (node.declaration) { // Exported declarations diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index 06e5a03a71..696589b3e6 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -831,6 +831,7 @@ export type ExportNamedDeclaration = NodeBase & { export type ExportSpecifier = NodeBase & { type: "ExportSpecifier", exported: Identifier, + local: Identifier, }; export type ExportDefaultSpecifier = NodeBase & { diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index 496814cd96..8d9e08b1a8 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -16,6 +16,7 @@ import { type BindingTypes, SCOPE_CLASS, } from "./scopeflags"; +import * as N from "../types"; // Start an AST node, attaching a start offset. class Scope { @@ -40,6 +41,7 @@ export default class ScopeHandler { scopeStack: Array = []; raise: raiseFunction; inModule: boolean; + undefinedExports: Map = new Map(); constructor(raise: raiseFunction, inModule: boolean) { this.raise = raise; @@ -95,6 +97,9 @@ export default class ScopeHandler { scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1; scope.lexical.push(name); + if (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); + } } else if (bindingType === BIND_SIMPLE_CATCH) { const scope = this.currentScope(); scope.lexical.push(name); @@ -122,6 +127,10 @@ export default class ScopeHandler { } scope.var.push(name); + if (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); + } + if (scope.flags & SCOPE_VAR) break; } } @@ -130,6 +139,16 @@ export default class ScopeHandler { } } + checkLocalExport(id: N.Identifier) { + // scope.functions must be empty as Module code is always strict. + if ( + this.scopeStack[0].lexical.indexOf(id.name) === -1 && + this.scopeStack[0].var.indexOf(id.name) === -1 + ) { + this.undefinedExports.set(id.name, id.start); + } + } + currentScope(): Scope { return this.scopeStack[this.scopeStack.length - 1]; } diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js new file mode 100644 index 0000000000..df3d927613 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js @@ -0,0 +1 @@ +export { encrypt as default }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json new file mode 100644 index 0000000000..8448889cf2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js new file mode 100644 index 0000000000..f14dc07986 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js @@ -0,0 +1,2 @@ +export { encrypt as decrypt }; +function decrypt() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json new file mode 100644 index 0000000000..8448889cf2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js new file mode 100644 index 0000000000..1e993e373a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js @@ -0,0 +1,4 @@ +{ + function encrypt() {} +} +export { encrypt } diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json new file mode 100644 index 0000000000..0844d3e80e --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (4:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js new file mode 100644 index 0000000000..2ab393fc23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js @@ -0,0 +1 @@ +export { Object as Obj }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json new file mode 100644 index 0000000000..cbab706133 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'Object' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js new file mode 100644 index 0000000000..8ddd96dff3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js @@ -0,0 +1 @@ +export { Object }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json new file mode 100644 index 0000000000..cbab706133 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'Object' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js new file mode 100644 index 0000000000..6d6c87fb7a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js @@ -0,0 +1,2 @@ +export { encrypt }; +if (true) function encrypt() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json new file mode 100644 index 0000000000..2c97b3ce5a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "In strict mode code, functions can only be declared at top level or inside a block (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js new file mode 100644 index 0000000000..b8a0b52235 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js @@ -0,0 +1,4 @@ +{ + var encrypt +} +export { encrypt } diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json new file mode 100644 index 0000000000..91e34252db --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 4, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "id": { + "type": "Identifier", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + }, + { + "type": "ExportNamedDeclaration", + "start": 18, + "end": 36, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "local": { + "type": "Identifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "exported": { + "type": "Identifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js new file mode 100644 index 0000000000..7ec871cd2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js @@ -0,0 +1 @@ +export { encrypt }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json new file mode 100644 index 0000000000..8448889cf2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js index 01d2b22e0b..30c0f0d29b 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js @@ -1 +1,3 @@ +const toString = 1; + export { toString }; diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json index 190e09b286..7d37c8dcb6 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 20, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 20, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 20 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 20, + "end": 19, "loc": { "start": { "line": 1, @@ -40,36 +40,105 @@ }, "end": { "line": 1, - "column": 20 + "column": 19 } }, - "declaration": null, - "specifiers": [ + "declarations": [ { - "type": "ExportSpecifier", - "start": 9, - "end": 17, + "type": "VariableDeclarator", + "start": 6, + "end": 18, "loc": { "start": { "line": 1, - "column": 9 + "column": 6 }, "end": { "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "toString" + }, + "name": "toString" + }, + "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": "const" + }, + { + "type": "ExportNamedDeclaration", + "start": 21, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 30, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, "column": 17 } }, "local": { "type": "Identifier", - "start": 9, - "end": 17, + "start": 30, + "end": 38, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 17 }, "identifierName": "toString" @@ -78,15 +147,15 @@ }, "exported": { "type": "Identifier", - "start": 9, - "end": 17, + "start": 30, + "end": 38, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 17 }, "identifierName": "toString" @@ -95,7 +164,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js index ebdd242449..bc9adbfd19 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js @@ -1 +1,2 @@ -export { encrypt } \ No newline at end of file +export { encrypt } +function encrypt () {} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json index 6f2e67893c..7e4ade4989 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 18, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 2, + "column": 22 } }, "program": { "type": "Program", "start": 0, - "end": 18, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 2, + "column": 22 } }, "sourceType": "module", @@ -43,7 +43,6 @@ "column": 18 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -95,7 +94,60 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "FunctionDeclaration", + "start": 19, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "body": [], + "directives": [] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js index 04615d4b6f..9e82122a40 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js @@ -1 +1,3 @@ -export { encrypt, decrypt } \ No newline at end of file +function encrypt () {} +class decrypt{} +export { encrypt, decrypt } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json index f7a0baef79..28e7320743 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 27, + "end": 66, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 27 } }, "program": { "type": "Program", "start": 0, - "end": 27, + "end": 66, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 27 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "FunctionDeclaration", "start": 0, - "end": 27, + "end": 22, "loc": { "start": { "line": 1, @@ -40,36 +40,136 @@ }, "end": { "line": 1, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassDeclaration", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "decrypt" + }, + "name": "decrypt" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "body": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 39, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, "column": 27 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 } }, "local": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -78,15 +178,15 @@ }, "exported": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -96,29 +196,29 @@ }, { "type": "ExportSpecifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 } }, "local": { "type": "Identifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 }, "identifierName": "decrypt" @@ -127,15 +227,15 @@ }, "exported": { "type": "Identifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 }, "identifierName": "decrypt" @@ -144,7 +244,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js index 9f663623f9..1f9f9289b1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js @@ -1 +1,2 @@ -export { encrypt as default } \ No newline at end of file +import encrypt from ""; +export { encrypt as default } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json index 425419eb95..25b0fd9741 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 29, + "end": 53, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 29 } }, "program": { "type": "Program", "start": 0, - "end": 29, + "end": 53, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 29 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "ImportDeclaration", "start": 0, - "end": 29, + "end": 23, "loc": { "start": { "line": 1, @@ -40,36 +40,104 @@ }, "end": { "line": 1, - "column": 29 + "column": 23 } }, - "declaration": null, "specifiers": [ { - "type": "ExportSpecifier", - "start": 9, - "end": 27, + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 14, "loc": { "start": { "line": 1, - "column": 9 + "column": 7 }, "end": { "line": 1, + "column": 14 + } + }, + "local": { + "type": "Identifier", + "start": 7, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "extra": { + "rawValue": "", + "raw": "\"\"" + }, + "value": "" + } + }, + { + "type": "ExportNamedDeclaration", + "start": 24, + "end": 53, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, "column": 27 } }, "local": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 33, + "end": 40, "loc": { "start": { - "line": 1, + "line": 2, "column": 9 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "encrypt" @@ -78,15 +146,15 @@ }, "exported": { "type": "Identifier", - "start": 20, - "end": 27, + "start": 44, + "end": 51, "loc": { "start": { - "line": 1, + "line": 2, "column": 20 }, "end": { - "line": 1, + "line": 2, "column": 27 }, "identifierName": "default" @@ -95,7 +163,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js index fec65aa2e8..f1526616e3 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js @@ -1 +1,3 @@ -export { encrypt, decrypt as dec } \ No newline at end of file +function encrypt() {} +class decrypt {} +export { encrypt, decrypt as dec } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json index 7f1186d778..6e52c6fd4d 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 34, + "end": 73, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 34 } }, "program": { "type": "Program", "start": 0, - "end": 34, + "end": 73, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 34 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "FunctionDeclaration", "start": 0, - "end": 34, + "end": 21, "loc": { "start": { "line": 1, @@ -40,36 +40,136 @@ }, "end": { "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassDeclaration", + "start": 22, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "decrypt" + }, + "name": "decrypt" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 39, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, "column": 34 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 } }, "local": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -78,15 +178,15 @@ }, "exported": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -96,29 +196,29 @@ }, { "type": "ExportSpecifier", - "start": 18, - "end": 32, + "start": 57, + "end": 71, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 32 } }, "local": { "type": "Identifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 }, "identifierName": "decrypt" @@ -127,15 +227,15 @@ }, "exported": { "type": "Identifier", - "start": 29, - "end": 32, + "start": 68, + "end": 71, "loc": { "start": { - "line": 1, + "line": 3, "column": 29 }, "end": { - "line": 1, + "line": 3, "column": 32 }, "identifierName": "dec" @@ -144,7 +244,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js index 5d32a24de0..974ab55e43 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js @@ -1 +1,2 @@ export {foo as default}; +var foo; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json index c3d6819265..ab9dd47bd5 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 24, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 24 + "line": 2, + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 24, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 24 + "line": 2, + "column": 8 } }, "sourceType": "module", @@ -43,7 +43,6 @@ "column": 24 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -95,7 +94,59 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 25, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js index e7820a6f02..1d873bf860 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js @@ -1 +1,2 @@ +var foo, bar; export {foo as bar}; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json index e1652693b1..0b8670ce2e 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 20, + "end": 34, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 20, + "end": 34, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 20, + "end": 13, "loc": { "start": { "line": 1, @@ -40,36 +40,119 @@ }, "end": { "line": 1, - "column": 20 + "column": 13 } }, - "declaration": null, - "specifiers": [ + "declarations": [ { - "type": "ExportSpecifier", - "start": 8, - "end": 18, + "type": "VariableDeclarator", + "start": 4, + "end": 7, "loc": { "start": { "line": 1, - "column": 8 + "column": 4 }, "end": { "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExportNamedDeclaration", + "start": 14, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, "column": 18 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +161,15 @@ }, "exported": { "type": "Identifier", - "start": 15, - "end": 18, + "start": 29, + "end": 32, "loc": { "start": { - "line": 1, + "line": 2, "column": 15 }, "end": { - "line": 1, + "line": 2, "column": 18 }, "identifierName": "bar" @@ -95,7 +178,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js index ff57927839..f0218dfca8 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js @@ -1 +1,2 @@ export {foo as default, bar}; +var foo, bar; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json index 8114c32e29..2a876f042e 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 29, + "end": 43, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 29 + "line": 2, + "column": 13 } }, "program": { "type": "Program", "start": 0, - "end": 29, + "end": 43, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 29 + "line": 2, + "column": 13 } }, "sourceType": "module", @@ -43,7 +43,6 @@ "column": 29 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -144,7 +143,92 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 30, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js index df5f5e609e..1c36f43461 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js @@ -1 +1,2 @@ +let foo; export {foo}; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json index 49c37926ad..4faa60a28f 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 13, + "end": 22, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 13 } }, "program": { "type": "Program", "start": 0, - "end": 13, + "end": 22, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 13 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 13, + "end": 8, "loc": { "start": { "line": 1, @@ -40,36 +40,86 @@ }, "end": { "line": 1, - "column": 13 + "column": 8 } }, - "declaration": null, - "specifiers": [ + "declarations": [ { - "type": "ExportSpecifier", - "start": 8, - "end": 11, + "type": "VariableDeclarator", + "start": 4, + "end": 7, "loc": { "start": { "line": 1, - "column": 8 + "column": 4 }, "end": { "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, "column": 11 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -95,7 +145,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js index 61bc40fd77..12c55903d5 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js @@ -1 +1,3 @@ +var bar; export {foo, bar,}; +var foo; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json index 0c439126a9..3616570c15 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json @@ -1,38 +1,38 @@ { "type": "File", "start": 0, - "end": 19, + "end": 37, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 19 + "line": 3, + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 19, + "end": 37, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 19 + "line": 3, + "column": 8 } }, "sourceType": "module", "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 19, + "end": 8, "loc": { "start": { "line": 1, @@ -40,36 +40,86 @@ }, "end": { "line": 1, - "column": 19 + "column": 8 } }, - "declaration": null, - "specifiers": [ + "declarations": [ { - "type": "ExportSpecifier", - "start": 8, - "end": 11, + "type": "VariableDeclarator", + "start": 4, + "end": 7, "loc": { "start": { "line": 1, - "column": 8 + "column": 4 }, "end": { "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, "column": 11 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -96,29 +146,29 @@ }, { "type": "ExportSpecifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 } }, "local": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -127,15 +177,15 @@ }, "exported": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -144,7 +194,59 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 29, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js index fdbc942750..8e2977a9e7 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js @@ -1 +1,3 @@ +var foo; export {foo, bar}; +var bar; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json index b28aaf0d65..51d2d56a1f 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json @@ -1,38 +1,38 @@ { "type": "File", "start": 0, - "end": 18, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 3, + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 18, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 3, + "column": 8 } }, "sourceType": "module", "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 18, + "end": 8, "loc": { "start": { "line": 1, @@ -40,36 +40,86 @@ }, "end": { "line": 1, - "column": 18 + "column": 8 } }, - "declaration": null, - "specifiers": [ + "declarations": [ { - "type": "ExportSpecifier", - "start": 8, - "end": 11, + "type": "VariableDeclarator", + "start": 4, + "end": 7, "loc": { "start": { "line": 1, - "column": 8 + "column": 4 }, "end": { "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, "column": 11 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -96,29 +146,29 @@ }, { "type": "ExportSpecifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 } }, "local": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -127,15 +177,15 @@ }, "exported": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -144,7 +194,59 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 28, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js index 6a25a18365..9c00baefd0 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js @@ -1 +1,2 @@ declare module "foo" { declare export {a,}; } +var a; diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json index dda5b894d1..c3b63e8c23 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 45, + "end": 52, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 45 + "line": 2, + "column": 6 } }, "program": { "type": "Program", "start": 0, - "end": 45, + "end": 52, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 45 + "line": 2, + "column": 6 } }, "sourceType": "module", @@ -92,7 +92,6 @@ "column": 43 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -145,11 +144,63 @@ } ], "source": null, + "declaration": null, "default": false } ] }, "kind": "ES" + }, + { + "type": "VariableDeclaration", + "start": 46, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js index e34ea63759..168e2cff4a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js @@ -1 +1,2 @@ +let foo; export type { foo }; diff --git a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json index 4481726d78..f4d18be825 100644 --- a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 20, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 20, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 20, + "end": 8, "loc": { "start": { "line": 1, @@ -40,35 +40,86 @@ }, "end": { "line": 1, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 20 } }, "specifiers": [ { "type": "ExportSpecifier", - "start": 14, - "end": 17, + "start": 23, + "end": 26, "loc": { "start": { - "line": 1, + "line": 2, "column": 14 }, "end": { - "line": 1, + "line": 2, "column": 17 } }, "local": { "type": "Identifier", - "start": 14, - "end": 17, + "start": 23, + "end": 26, "loc": { "start": { - "line": 1, + "line": 2, "column": 14 }, "end": { - "line": 1, + "line": 2, "column": 17 }, "identifierName": "foo" @@ -77,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 14, - "end": 17, + "start": 23, + "end": 26, "loc": { "start": { - "line": 1, + "line": 2, "column": 14 }, "end": { - "line": 1, + "line": 2, "column": 17 }, "identifierName": "foo" diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/input.mjs b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/input.mjs index 4be37364cf..8fdbffd7f8 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/input.mjs +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/input.mjs @@ -99,7 +99,7 @@ import type { imp2, imp3 } from "baz"; import type { foo as imp4 } from "baz"; import type from "foo"; import typeof * as namespace from "bar"; -export type { foo }; +export type { foo1 }; export type { foo2 } from "bar"; import {type T} from "foo"; import {type T2, V1} from "foo"; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/input.mjs index fdbc942750..97b218259d 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/input.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/input.mjs @@ -1 +1,2 @@ export {foo, bar}; +var foo, bar; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/output.mjs index ab82079a7c..bed82c2841 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-2/output.mjs @@ -1,12 +1,15 @@ System.register([], function (_export, _context) { "use strict"; + var foo, bar; + + _export({ + foo: void 0, + bar: void 0 + }); + return { setters: [], - execute: function () { - _export("foo", foo); - - _export("bar", bar); - } + execute: function () {} }; }); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/input.mjs index e7820a6f02..2ad49c002c 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/input.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/input.mjs @@ -1 +1,2 @@ export {foo as bar}; +var foo; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/output.mjs index 418e0cea95..d613ff78b9 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-3/output.mjs @@ -1,10 +1,12 @@ System.register([], function (_export, _context) { "use strict"; + var foo; + + _export("foo", void 0); + return { setters: [], - execute: function () { - _export("bar", foo); - } + execute: function () {} }; }); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/input.mjs index 5d32a24de0..974ab55e43 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/input.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/input.mjs @@ -1 +1,2 @@ export {foo as default}; +var foo; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/output.mjs index 25834444d1..d613ff78b9 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-4/output.mjs @@ -1,10 +1,12 @@ System.register([], function (_export, _context) { "use strict"; + var foo; + + _export("foo", void 0); + return { setters: [], - execute: function () { - _export("default", foo); - } + execute: function () {} }; }); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/input.mjs index ff57927839..f0218dfca8 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/input.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/input.mjs @@ -1 +1,2 @@ export {foo as default, bar}; +var foo, bar; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/output.mjs index bc1c7593c0..bed82c2841 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named-5/output.mjs @@ -1,12 +1,15 @@ System.register([], function (_export, _context) { "use strict"; + var foo, bar; + + _export({ + foo: void 0, + bar: void 0 + }); + return { setters: [], - execute: function () { - _export("default", foo); - - _export("bar", bar); - } + execute: function () {} }; }); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/input.mjs index df5f5e609e..ff265b20ef 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/input.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/input.mjs @@ -1 +1,2 @@ export {foo}; +var foo; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/output.mjs index 0981d53ba5..d613ff78b9 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-named/output.mjs @@ -1,10 +1,12 @@ System.register([], function (_export, _context) { "use strict"; + var foo; + + _export("foo", void 0); + return { setters: [], - execute: function () { - _export("foo", foo); - } + execute: function () {} }; }); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/input.mjs index 1623f8b61e..3e062136f2 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/input.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/input.mjs @@ -6,7 +6,7 @@ import * as foo2 from "foo"; import {bar} from "foo"; import {foo as bar2} from "foo"; -export {test}; +export {foo}; export var test2 = 5; -export default test; +export default foo; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/output.mjs index 97f9581aa1..e84b007dcd 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/overview/output.mjs @@ -10,11 +10,11 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export, _c bar2 = _foo.foo; }, function (_fooBar) {}, function (_directoryFooBar) {}], execute: function () { - _export("test", test); + _export("foo", foo); _export("test2", test2 = 5); - _export("default", test); + _export("default", foo); } }; }); diff --git a/scripts/tests/flow/flow_tests_whitelist.txt b/scripts/tests/flow/flow_tests_whitelist.txt index c5a154762b..4c850ac527 100644 --- a/scripts/tests/flow/flow_tests_whitelist.txt +++ b/scripts/tests/flow/flow_tests_whitelist.txt @@ -35,3 +35,6 @@ numbers/underscored_float_whole.js numbers/underscored_hex.js numbers/underscored_number.js numbers/underscored_oct.js +ES6/modules/migrated_0020.js +export_import_reserved_words/migrated_0003.js +export_statements/export_trailing_comma.js diff --git a/scripts/tests/test262/test262_whitelist.txt b/scripts/tests/test262/test262_whitelist.txt index 0c385c9bc7..ea959b5802 100644 --- a/scripts/tests/test262/test262_whitelist.txt +++ b/scripts/tests/test262/test262_whitelist.txt @@ -600,10 +600,6 @@ language/literals/string/unicode-escape-nls-err-double.js(default) language/literals/string/unicode-escape-nls-err-double.js(strict mode) language/literals/string/unicode-escape-nls-err-single.js(default) language/literals/string/unicode-escape-nls-err-single.js(strict mode) -language/module-code/early-export-global.js(default) -language/module-code/early-export-global.js(strict mode) -language/module-code/early-export-unresolvable.js(default) -language/module-code/early-export-unresolvable.js(strict mode) language/module-code/privatename-not-valid-earlyerr-module-1.js(default) language/module-code/privatename-not-valid-earlyerr-module-1.js(strict mode) language/module-code/privatename-not-valid-earlyerr-module-2.js(default)