Skip to content

Commit

Permalink
fix: fix single types being incorrectly parsed as union_type
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jan 13, 2024
1 parent b569a5f commit 60d322e
Show file tree
Hide file tree
Showing 13 changed files with 3,895 additions and 3,904 deletions.
8 changes: 6 additions & 2 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function defineGrammar(dialect) {
[$._array_destructing_element, $.array_element_initializer],
[$._primary_expression, $._array_destructing_element],

[$.union_type, $.intersection_type],
[$._type, $.union_type, $.intersection_type],
[$.intersection_type],
[$.if_statement],

Expand Down Expand Up @@ -517,7 +517,11 @@ module.exports = function defineGrammar(dialect) {
field('name', $.variable_name),
),

_type: $ => choice($.union_type, $.intersection_type),
_type: $ => choice(
$._types,
$.union_type,
$.intersection_type,
),

_types: $ => choice(
$.optional_type,
Expand Down
129 changes: 43 additions & 86 deletions common/test/corpus/class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ class A {
body: (declaration_list
(property_declaration
(visibility_modifier)
type: (union_type (primitive_type))
type: (primitive_type)
(property_element (variable_name (name)))
)
(property_declaration
(visibility_modifier)
(static_modifier)
type: (union_type (named_type (name)))
type: (named_type (name))
(property_element (variable_name (name)))
)
(property_declaration
(visibility_modifier)
type: (union_type (optional_type (primitive_type)))
type: (optional_type (primitive_type))
(property_element (variable_name (name)))
)
(property_declaration
Expand Down Expand Up @@ -371,20 +371,19 @@ class Point {
parameters: (formal_parameters
(property_promotion_parameter
visibility: (visibility_modifier)
type: (union_type
(primitive_type)
)
type: (primitive_type)

name: (variable_name (name))
default_value: (float)
)
(simple_parameter
type: (union_type (primitive_type))
type: (primitive_type)
name: (variable_name (name))
default_value: (float)
)
(property_promotion_parameter
visibility: (visibility_modifier)
type: (union_type (primitive_type))
type: (primitive_type)
name: (variable_name (name))
default_value: (float)
)
Expand Down Expand Up @@ -451,282 +450,240 @@ class A {
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name)))))))
Expand Down Expand Up @@ -765,7 +722,7 @@ class Point {
(property_promotion_parameter
visibility: (visibility_modifier)
readonly: (readonly_modifier)
type: (union_type (primitive_type))
type: (primitive_type)
name: (variable_name (name))))
body: (compound_statement)))))

Expand Down
Loading

0 comments on commit 60d322e

Please sign in to comment.