mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 12:18:08 +03:00
fix(es/parser): Fix parsing of module
identifier (#7400)
**Related issue:** - Closes #4176. - Closes #7372.
This commit is contained in:
parent
820f29ffc1
commit
1d3f32056c
@ -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
|
||||
|
@ -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 = {}));
|
||||
|
@ -1 +1,3 @@
|
||||
//// [asiPreventsParsingAsAmbientExternalModule02.ts]
|
||||
var container;
|
||||
container || (container = {});
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
2
crates/swc_ecma_parser/tests/js/issue-4176/1/input.js
Normal file
2
crates/swc_ecma_parser/tests/js/issue-4176/1/input.js
Normal file
@ -0,0 +1,2 @@
|
||||
const module = 'left-pad'
|
||||
module
|
71
crates/swc_ecma_parser/tests/js/issue-4176/1/input.js.json
Normal file
71
crates/swc_ecma_parser/tests/js/issue-4176/1/input.js.json
Normal 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
|
||||
}
|
@ -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
|
||||
|
@ -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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -0,0 +1 @@
|
||||
module
|
@ -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
|
||||
}
|
@ -0,0 +1 @@
|
||||
module
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user