Always register global bindings as exportable (#9865)
This commit is contained in:
parent
d7757f6d08
commit
cf3668779c
@ -90,21 +90,17 @@ export default class ScopeHandler {
|
||||
|
||||
declareName(name: string, bindingType: ?BindingTypes, pos: number) {
|
||||
let redeclared = false;
|
||||
let scope = this.currentScope();
|
||||
|
||||
if (bindingType === BIND_LEXICAL) {
|
||||
const scope = this.currentScope();
|
||||
redeclared =
|
||||
scope.lexical.indexOf(name) > -1 ||
|
||||
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);
|
||||
} else if (bindingType === BIND_FUNCTION) {
|
||||
const scope = this.currentScope();
|
||||
if (this.treatFunctionsAsVar) {
|
||||
redeclared = scope.lexical.indexOf(name) > -1;
|
||||
} else {
|
||||
@ -114,7 +110,7 @@ export default class ScopeHandler {
|
||||
scope.functions.push(name);
|
||||
} else {
|
||||
for (let i = this.scopeStack.length - 1; i >= 0; --i) {
|
||||
const scope = this.scopeStack[i];
|
||||
scope = this.scopeStack[i];
|
||||
if (
|
||||
(scope.lexical.indexOf(name) > -1 &&
|
||||
!(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical[0] === name)) ||
|
||||
@ -126,13 +122,12 @@ 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;
|
||||
}
|
||||
}
|
||||
if (this.inModule && scope.flags & SCOPE_PROGRAM) {
|
||||
this.undefinedExports.delete(name);
|
||||
}
|
||||
if (redeclared) {
|
||||
this.raise(pos, `Identifier '${name}' has already been declared`);
|
||||
}
|
||||
|
||||
2
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export { a };
|
||||
function a() {}
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"strictMode": false
|
||||
}
|
||||
155
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/output.json
vendored
Normal file
155
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/output.json
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 0,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"specifiers": [
|
||||
{
|
||||
"type": "ExportSpecifier",
|
||||
"start": 9,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start": 9,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"exported": {
|
||||
"type": "Identifier",
|
||||
"start": 9,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": null,
|
||||
"declaration": null
|
||||
},
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start": 14,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 23,
|
||||
"end": 24,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 10
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 27,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user