fix(es/parser): Fix parsing of module identifier (#7400)

**Related issue:**

 - Closes #4176.
 - Closes #7372.
This commit is contained in:
Donny/강동윤 2023-05-17 13:51:57 +09:00 committed by GitHub
parent 820f29ffc1
commit 1d3f32056c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 284 additions and 45 deletions

View File

@ -1,4 +1,10 @@
//// [asiPreventsParsingAsAmbientExternalModule01.ts]
var declare;
var module;
// this is a block body
declare // this is the identifier 'declare'
;
module // this is the identifier 'module'
;
"my external module" // this is just a string
;
{} // this is a block body

View File

@ -1,3 +1,13 @@
//// [asiPreventsParsingAsAmbientExternalModule02.ts]
var declare;
var module;
var container;
(function(container) {
"my external module" // this is just a string
;
declare // this is the identifier 'declare'
;
module // this is the identifier 'module'
;
{}
})(container || (container = {}));

View File

@ -1 +1,3 @@
//// [asiPreventsParsingAsAmbientExternalModule02.ts]
var container;
container || (container = {});

View File

@ -1,4 +1,8 @@
//// [asiPreventsParsingAsNamespace02.ts]
var module;
var m;
// this is a block body
module // this is the identifier 'namespace'
;
m // this is the identifier 'm'
;
{} // this is a block body

View File

@ -2556,7 +2556,7 @@ impl<I: Tokens> Parser<I> {
}
}
js_word!("module") => {
js_word!("module") if !self.input.had_line_break_before_cur() => {
if next {
bump!(self);
}

View File

@ -0,0 +1,2 @@
const module = 'left-pad'
module

View File

@ -0,0 +1,71 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 33,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 1,
"end": 26,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 7,
"end": 26,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 7,
"end": 13,
"ctxt": 0
},
"value": "module",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "StringLiteral",
"span": {
"start": 16,
"end": 26,
"ctxt": 0
},
"value": "left-pad",
"raw": "'left-pad'"
},
"definite": false
}
]
},
{
"type": "ExpressionStatement",
"span": {
"start": 27,
"end": 33,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 27,
"end": 33,
"ctxt": 0
},
"value": "module",
"optional": false
}
}
],
"interpreter": null
}

View File

@ -105,15 +105,49 @@
]
},
{
"type": "TsModuleDeclaration",
"type": "ExpressionStatement",
"span": {
"start": 44,
"end": 212,
"end": 51,
"ctxt": 0
},
"declare": true,
"global": false,
"id": {
"expression": {
"type": "Identifier",
"span": {
"start": 44,
"end": 51,
"ctxt": 0
},
"value": "declare",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 103,
"end": 109,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 103,
"end": 109,
"ctxt": 0
},
"value": "module",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 161,
"end": 181,
"ctxt": 0
},
"expression": {
"type": "StringLiteral",
"span": {
"start": 161,
@ -122,16 +156,16 @@
},
"value": "my external module",
"raw": "\"my external module\""
},
"body": {
"type": "TsModuleBlock",
"span": {
"start": 209,
"end": 212,
"ctxt": 0
},
"body": []
}
},
{
"type": "BlockStatement",
"span": {
"start": 209,
"end": 212,
"ctxt": 0
},
"stmts": []
}
],
"interpreter": null

View File

@ -132,15 +132,49 @@
},
"body": [
{
"type": "TsModuleDeclaration",
"type": "ExpressionStatement",
"span": {
"start": 67,
"end": 247,
"end": 74,
"ctxt": 0
},
"declare": true,
"global": false,
"id": {
"expression": {
"type": "Identifier",
"span": {
"start": 67,
"end": 74,
"ctxt": 0
},
"value": "declare",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 130,
"end": 136,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 130,
"end": 136,
"ctxt": 0
},
"value": "module",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 192,
"end": 212,
"ctxt": 0
},
"expression": {
"type": "StringLiteral",
"span": {
"start": 192,
@ -149,16 +183,16 @@
},
"value": "my external module",
"raw": "\"my external module\""
},
"body": {
"type": "TsModuleBlock",
"span": {
"start": 244,
"end": 247,
"ctxt": 0
},
"body": []
}
},
{
"type": "BlockStatement",
"span": {
"start": 244,
"end": 247,
"ctxt": 0
},
"stmts": []
}
]
}

View File

@ -105,15 +105,31 @@
]
},
{
"type": "TsModuleDeclaration",
"type": "ExpressionStatement",
"span": {
"start": 38,
"end": 135,
"end": 44,
"ctxt": 0
},
"declare": false,
"global": false,
"id": {
"expression": {
"type": "Identifier",
"span": {
"start": 38,
"end": 44,
"ctxt": 0
},
"value": "module",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 89,
"end": 90,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 89,
@ -122,16 +138,16 @@
},
"value": "m",
"optional": false
},
"body": {
"type": "TsModuleBlock",
"span": {
"start": 132,
"end": 135,
"ctxt": 0
},
"body": []
}
},
{
"type": "BlockStatement",
"span": {
"start": 132,
"end": 135,
"ctxt": 0
},
"stmts": []
}
],
"interpreter": null

View File

@ -0,0 +1 @@
module

View File

@ -0,0 +1,29 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"value": "module",
"optional": false
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
module

View File

@ -0,0 +1,29 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"value": "module",
"optional": false
}
}
],
"interpreter": null
}