[@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:
Nicolò Ribaudo
2019-06-30 11:16:05 +02:00
committed by GitHub
parent 77fd7cd4c4
commit ca67637da4
5 changed files with 116 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ export type Options = {
allowReturnOutsideFunction: boolean,
allowImportExportEverywhere: boolean,
allowSuperOutsideMethod: boolean,
allowUndeclaredExports: boolean,
plugins: PluginList,
strictMode: ?boolean,
ranges: boolean,
@@ -41,6 +42,8 @@ export const defaultOptions: Options = {
allowImportExportEverywhere: false,
// TODO
allowSuperOutsideMethod: false,
// When enabled, export statements can reference undeclared variables.
allowUndeclaredExports: false,
// An array of plugins to enable
plugins: [],
// TODO

View File

@@ -45,7 +45,11 @@ export default class StatementParser extends ExpressionParser {
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)) {
const pos = this.scope.undefinedExports.get(name);
// $FlowIssue