Skip to content

Commit

Permalink
fix: fix conditional type parsing association
Browse files Browse the repository at this point in the history
fix #231
  • Loading branch information
HerringtonDarkholme authored and amaanq committed Jul 15, 2023
1 parent 6e695f4 commit bf4331c
Show file tree
Hide file tree
Showing 6 changed files with 12,511 additions and 12,499 deletions.
52 changes: 26 additions & 26 deletions common/corpus/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1179,23 +1179,23 @@ type T<X> = T extends { x: infer X extends number } ? X : never;
(identifier)
(type_annotation (type_identifier))))
(conditional_type
(type_identifier)
(type_identifier)
(type_identifier)
(conditional_type
(type_identifier)
(function_type
(formal_parameters
(required_parameter
(identifier)
(type_annotation (type_identifier))))
(conditional_type
(type_identifier)
(type_identifier)
(type_identifier)
(type_identifier)))
(type_identifier)
(type_identifier)
(type_identifier))
(function_type
(formal_parameters
(required_parameter
(identifier)
(type_annotation (type_identifier))))
(conditional_type
(type_identifier)
(type_identifier)
(type_identifier)
(type_identifier)))
(type_identifier)
(type_identifier))))
(type_identifier)))))
(type_alias_declaration
(type_identifier)
(type_parameters
Expand All @@ -1205,20 +1205,20 @@ type T<X> = T extends { x: infer X extends number } ? X : never;
(type_identifier)
(generic_type
(type_identifier)
(type_arguments
(infer_type (type_identifier))))
(type_arguments (infer_type (type_identifier))))
(type_identifier)
(type_identifier)))
(type_alias_declaration
(type_alias_declaration
(type_identifier)
(type_parameters
(type_parameter (type_identifier)))
(conditional_type
(type_identifier)
(type_parameters
(type_parameter (type_identifier)))
(conditional_type
(type_identifier)
(array_type
(parenthesized_type (infer_type (type_identifier))))
(type_identifier)
(predefined_type)))
(array_type
(parenthesized_type
(infer_type (type_identifier))))
(type_identifier)
(predefined_type)))
(type_alias_declaration
(type_identifier)
(type_parameters
Expand Down Expand Up @@ -1568,7 +1568,7 @@ type Foo<T> = abstract new () => T;

---

(program (type_alias_declaration (type_identifier) (type_parameters (type_parameter (type_identifier))) (constructor_type (formal_parameters) (type_identifier))))
(program (type_alias_declaration (type_identifier) (type_parameters (type_parameter (type_identifier))) (constructor_type (formal_parameters) (type_identifier))))

=========================
Indexed Access Precedence
Expand Down
6 changes: 3 additions & 3 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module.exports = function defineGrammar(dialect) {
optional('declare'),
optional($.accessibility_modifier),
choice(
seq(optional('static'), optional($.override_modifier), optional('readonly')),
seq(optional('static'), optional($.override_modifier), optional('readonly')),
seq(optional('abstract'), optional('readonly')),
seq(optional('readonly'), optional('abstract')),
),
Expand Down Expand Up @@ -386,7 +386,7 @@ module.exports = function defineGrammar(dialect) {
// *definition*, not a declaration. Example:
// public foo()
// { <--- this brace made the method signature become a definition
// }
// }
// The same rule applies for functions and that's why we use
// "_function_signature_automatic_semicolon".
seq($.method_signature, choice($._function_signature_automatic_semicolon, ',')),
Expand Down Expand Up @@ -716,7 +716,7 @@ module.exports = function defineGrammar(dialect) {
))
)),

conditional_type: $ => prec.left(seq(
conditional_type: $ => prec.right(seq(
field('left', $._type),
'extends',
field('right', $._type),
Expand Down
2 changes: 1 addition & 1 deletion tsx/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8992,7 +8992,7 @@
}
},
"conditional_type": {
"type": "PREC_LEFT",
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
Expand Down
Loading

0 comments on commit bf4331c

Please sign in to comment.