Modules might be in loose mode when checking for undecl exports (#9725)

This commit is contained in:
Nicolò Ribaudo 2019-03-21 01:57:12 +01:00 committed by Daniel Tschinder
parent 7f8ded9851
commit 2201fd839b
4 changed files with 167 additions and 2 deletions

View File

@ -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);
}

View File

@ -0,0 +1,3 @@
function a() {}
export { a };

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"strictMode": false
}

View 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": []
}
}