[@babel/parser] Add "allowUndeclaredExports" option (#9864)
Ref: https://github.com/babel/notes/blob/master/2019/04/09.md#export-changes-in-scope-pr-break-meteor-issue
This commit is contained in:
parent
77fd7cd4c4
commit
ca67637da4
@ -15,6 +15,7 @@ export type Options = {
|
|||||||
allowReturnOutsideFunction: boolean,
|
allowReturnOutsideFunction: boolean,
|
||||||
allowImportExportEverywhere: boolean,
|
allowImportExportEverywhere: boolean,
|
||||||
allowSuperOutsideMethod: boolean,
|
allowSuperOutsideMethod: boolean,
|
||||||
|
allowUndeclaredExports: boolean,
|
||||||
plugins: PluginList,
|
plugins: PluginList,
|
||||||
strictMode: ?boolean,
|
strictMode: ?boolean,
|
||||||
ranges: boolean,
|
ranges: boolean,
|
||||||
@ -41,6 +42,8 @@ export const defaultOptions: Options = {
|
|||||||
allowImportExportEverywhere: false,
|
allowImportExportEverywhere: false,
|
||||||
// TODO
|
// TODO
|
||||||
allowSuperOutsideMethod: false,
|
allowSuperOutsideMethod: false,
|
||||||
|
// When enabled, export statements can reference undeclared variables.
|
||||||
|
allowUndeclaredExports: false,
|
||||||
// An array of plugins to enable
|
// An array of plugins to enable
|
||||||
plugins: [],
|
plugins: [],
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
@ -45,7 +45,11 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
|
|
||||||
this.parseBlockBody(program, true, true, tt.eof);
|
this.parseBlockBody(program, true, true, tt.eof);
|
||||||
|
|
||||||
if (this.inModule && this.scope.undefinedExports.size > 0) {
|
if (
|
||||||
|
this.inModule &&
|
||||||
|
!this.options.allowUndeclaredExports &&
|
||||||
|
this.scope.undefinedExports.size > 0
|
||||||
|
) {
|
||||||
for (const [name] of Array.from(this.scope.undefinedExports)) {
|
for (const [name] of Array.from(this.scope.undefinedExports)) {
|
||||||
const pos = this.scope.undefinedExports.get(name);
|
const pos = this.scope.undefinedExports.get(name);
|
||||||
// $FlowIssue
|
// $FlowIssue
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { foo };
|
||||||
4
packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"allowUndeclaredExports": true
|
||||||
|
}
|
||||||
103
packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/output.json
vendored
Normal file
103
packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/output.json
vendored
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 15,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 15,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "module",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExportNamedDeclaration",
|
||||||
|
"start": 0,
|
||||||
|
"end": 15,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"specifiers": [
|
||||||
|
{
|
||||||
|
"type": "ExportSpecifier",
|
||||||
|
"start": 9,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 9
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"local": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 9,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 9
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
},
|
||||||
|
"identifierName": "foo"
|
||||||
|
},
|
||||||
|
"name": "foo"
|
||||||
|
},
|
||||||
|
"exported": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 9,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 9
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
},
|
||||||
|
"identifierName": "foo"
|
||||||
|
},
|
||||||
|
"name": "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": null,
|
||||||
|
"declaration": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user