Skip to content

Commit

Permalink
Properly parse 'as const'
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebrunerie committed Jul 12, 2023
1 parent a232b3a commit e82410a
Show file tree
Hide file tree
Showing 6 changed files with 206,908 additions and 206,675 deletions.
7 changes: 6 additions & 1 deletion common/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ Type casts

foo as any as Array<number>
bar satisfies number[]
"foobar" as const

---

Expand All @@ -466,7 +467,11 @@ bar satisfies number[]
(as_expression (identifier) (predefined_type))
(generic_type (type_identifier) (type_arguments (predefined_type)))))
(expression_statement
(satisfies_expression (identifier) (array_type (predefined_type)))))
(satisfies_expression (identifier) (array_type (predefined_type))))
(expression_statement
(as_expression
(string
(string_fragment)))))

=================================
Ambient export function declarations
Expand Down
2 changes: 1 addition & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ module.exports = function defineGrammar(dialect) {
as_expression: $ => prec.left('binary', seq(
$.expression,
'as',
$._type
choice('const', $._type)
)),

satisfies_expression: $ => prec.left('binary', seq(
Expand Down
13 changes: 11 additions & 2 deletions tsx/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7573,8 +7573,17 @@
"value": "as"
},
{
"type": "SYMBOL",
"name": "_type"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "const"
},
{
"type": "SYMBOL",
"name": "_type"
}
]
}
]
}
Expand Down
Loading

0 comments on commit e82410a

Please sign in to comment.