Modules might be in loose mode when checking for undecl exports (#9725)
This commit is contained in:
parent
7f8ded9851
commit
2201fd839b
@ -139,10 +139,13 @@ 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.scopeStack[0].var.indexOf(id.name) === -1 &&
|
||||
// In strict mode, scope.functions will always be empty.
|
||||
// Modules are strict by default, but the `scriptMode` option
|
||||
// can overwrite this behavior.
|
||||
this.scopeStack[0].functions.indexOf(id.name) === -1
|
||||
) {
|
||||
this.undefinedExports.set(id.name, id.start);
|
||||
}
|
||||
|
||||
3
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
function a() {}
|
||||
|
||||
export { a };
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"strictMode": false
|
||||
}
|
||||
155
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode/output.json
vendored
Normal file
155
packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode/output.json
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start": 0,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 9,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 13,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 17,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"specifiers": [
|
||||
{
|
||||
"type": "ExportSpecifier",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 10
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"exported": {
|
||||
"type": "Identifier",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 10
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": null,
|
||||
"declaration": null
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user