Skip to content

Commit

Permalink
fix(es/parsing): Fix parsing of type satisfies = 0; (#8305)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8121
  • Loading branch information
Zzzen authored Nov 20, 2023
1 parent a8bd170 commit 51042e0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
13 changes: 13 additions & 0 deletions crates/swc_ecma_parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion crates/swc_ecma_parser/src/parser/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type satisfies = 0;
49 changes: 49 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/issue-8121/input.ts.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 51042e0

Please sign in to comment.