fix(es/parser): Fix a typescript instantiation expression followed by EOF (#3699)

This commit is contained in:
Pig Fang 2022-02-23 23:48:17 +08:00 committed by GitHub
parent dd010a5a8c
commit 010fe048c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 7 deletions

View File

@ -572,7 +572,7 @@ impl<'a, I: Tokens> Parser<I> {
return_if_arrow!(self, obj); return_if_arrow!(self, obj);
let type_args = if self.syntax().typescript() && is!(self, '<') { let type_args = if self.syntax().typescript() && is!(self, '<') {
self.try_parse_type_args_of_ts_expr_with_type_args() self.try_parse_ts_type_args()
} else { } else {
None None
}; };
@ -1109,7 +1109,7 @@ impl<'a, I: Tokens> Parser<I> {
} }
let type_args = if self.syntax().typescript() && is!(self, '<') { let type_args = if self.syntax().typescript() && is!(self, '<') {
self.try_parse_type_args_of_ts_expr_with_type_args() self.try_parse_ts_type_args()
} else { } else {
None None
}; };
@ -1143,7 +1143,7 @@ impl<'a, I: Tokens> Parser<I> {
}; };
let type_args = if self.syntax().typescript() && is!(self, '<') { let type_args = if self.syntax().typescript() && is!(self, '<') {
self.try_parse_type_args_of_ts_expr_with_type_args() self.try_parse_ts_type_args()
} else { } else {
None None
}; };
@ -1262,7 +1262,7 @@ impl<'a, I: Tokens> Parser<I> {
debug_assert_eq!(prop.span().hi(), span.hi()); debug_assert_eq!(prop.span().hi(), span.hi());
let type_args = if self.syntax().typescript() && is!(self, '<') { let type_args = if self.syntax().typescript() && is!(self, '<') {
self.try_parse_type_args_of_ts_expr_with_type_args() self.try_parse_ts_type_args()
} else { } else {
None None
}; };

View File

@ -506,9 +506,7 @@ impl<I: Tokens> Parser<I> {
} }
} }
pub(super) fn try_parse_type_args_of_ts_expr_with_type_args( pub(super) fn try_parse_ts_type_args(&mut self) -> Option<TsTypeParamInstantiation> {
&mut self,
) -> Option<TsTypeParamInstantiation> {
debug_assert!(self.input.syntax().typescript()); debug_assert!(self.input.syntax().typescript());
self.try_parse_ts(|p| { self.try_parse_ts(|p| {
@ -517,6 +515,7 @@ impl<I: Tokens> Parser<I> {
p, ',', '.', '?', ')', ']', ':', '&', '|', '^', '}', "??", "==", "===", "!=", p, ',', '.', '?', ')', ']', ':', '&', '|', '^', '}', "??", "==", "===", "!=",
"!==", "&&", "||" "!==", "&&", "||"
) || is_exact!(p, ';') ) || is_exact!(p, ';')
|| eof!(p)
{ {
Ok(Some(type_args)) Ok(Some(type_args))
} else { } else {

View File

@ -0,0 +1 @@
let v = f<x>

View File

@ -0,0 +1,90 @@
{
"type": "Script",
"span": {
"start": 0,
"end": 12,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 0,
"end": 12,
"ctxt": 0
},
"kind": "let",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 4,
"end": 12,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 4,
"end": 5,
"ctxt": 0
},
"value": "v",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "TsInstantiation",
"span": {
"start": 8,
"end": 12,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 8,
"end": 9,
"ctxt": 0
},
"value": "f",
"optional": false
},
"typeArguments": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 9,
"end": 12,
"ctxt": 0
},
"params": [
{
"type": "TsTypeReference",
"span": {
"start": 10,
"end": 11,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 10,
"end": 11,
"ctxt": 0
},
"value": "x",
"optional": false
},
"typeParams": null
}
]
}
},
"definite": false
}
]
}
],
"interpreter": null
}