fix(es/parsing): Fix parsing of type satisfies = 0; (#8305)

**Related issue:**

 - Closes #8121
This commit is contained in:
Zzzen 2023-11-21 06:49:15 +08:00 committed by GitHub
parent a8bd170634
commit 51042e090d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 1 deletions

View File

@ -336,6 +336,19 @@ impl<'a, I: Tokens> Parser<I> {
}
}
tok!("type") => {
if is_typescript
&& peeked_is!(self, IdentName)
&& !self.input.has_linebreak_between_cur_and_peeked()
{
let start = self.input.cur_pos();
bump!(self);
return Ok(Stmt::Decl(Decl::TsTypeAlias(
self.parse_ts_type_alias_decl(start)?,
)));
}
}
tok!("enum") => {
if is_typescript
&& peeked_is!(self, IdentName)

View File

@ -1113,7 +1113,10 @@ impl<I: Tokens> Parser<I> {
}
/// `tsParseTypeAliasDeclaration`
fn parse_ts_type_alias_decl(&mut self, start: BytePos) -> PResult<Box<TsTypeAliasDecl>> {
pub(super) fn parse_ts_type_alias_decl(
&mut self,
start: BytePos,
) -> PResult<Box<TsTypeAliasDecl>> {
debug_assert!(self.input.syntax().typescript());
let id = self.parse_ident_name()?;

View File

@ -0,0 +1 @@
type satisfies = 0;

View File

@ -0,0 +1,49 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 20,
"ctxt": 0
},
"body": [
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 1,
"end": 20,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 6,
"end": 15,
"ctxt": 0
},
"value": "satisfies",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsLiteralType",
"span": {
"start": 18,
"end": 19,
"ctxt": 0
},
"literal": {
"type": "NumericLiteral",
"span": {
"start": 18,
"end": 19,
"ctxt": 0
},
"value": 0.0,
"raw": "0"
}
}
}
],
"interpreter": null
}