Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions common/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -877,3 +877,122 @@ export interface I { }
(export_statement (class_declaration (type_identifier) (class_body)))
(export_statement (interface_declaration (type_identifier) (object_type)))
(export_statement (interface_declaration (type_identifier) (object_type))))

=======================================
Classes with generic parameters
=======================================

class A<
B,
C,
> {}

class D extends A<
X,
Y,
> {}

---

(program
(class_declaration
(type_identifier)
(type_parameters (type_parameter (type_identifier)) (type_parameter (type_identifier)))
(class_body))
(class_declaration
(type_identifier)
(class_heritage (extends_clause (generic_type
(type_identifier)
(type_arguments (type_identifier) (type_identifier)))))
(class_body)))

=======================================
Classes with extensions
=======================================

class A extends B<C>(D) implements C {}
export class A extends B<C>(D) implements C {}

class A extends B<C>(D)<E> implements C {}
export class A extends B<C>(D)<E> implements C {}

export class A extends B<C, D> implements C {}

---

(program
(class_declaration
(type_identifier)
(class_heritage
(extends_clause
(functional_extension
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(arguments
(identifier))))
(implements_clause
(type_identifier)))
(class_body))
(export_statement
(class_declaration
(type_identifier)
(class_heritage
(extends_clause
(functional_extension
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(arguments
(identifier))))
(implements_clause
(type_identifier)))
(class_body)))
(class_declaration
(type_identifier)
(class_heritage
(extends_clause
(functional_extension
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(arguments
(identifier))
(type_arguments
(type_identifier))))
(implements_clause
(type_identifier)))
(class_body))
(export_statement
(class_declaration
(type_identifier)
(class_heritage
(extends_clause
(functional_extension
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(arguments
(identifier))
(type_arguments
(type_identifier))))
(implements_clause
(type_identifier)))
(class_body)))
(export_statement
(class_declaration
(type_identifier)
(class_heritage
(extends_clause
(generic_type
(type_identifier)
(type_arguments
(type_identifier)
(type_identifier))))
(implements_clause
(type_identifier)))
(class_body))))
2 changes: 1 addition & 1 deletion common/corpus/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ interface Enum extends Bar, Baz, funThatEvalsToInterface() {
(extends_clause
(type_identifier)
(type_identifier)
(call_expression (identifier) (arguments)))
(functional_extension (type_identifier) (arguments)))
(object_type
(method_signature
(accessibility_modifier)
Expand Down
21 changes: 12 additions & 9 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function defineGrammar(dialect) {
[$.mapped_type_clause, $.primary_expression],
[$.accessibility_modifier, $.primary_expression],
['unary_void', $.expression],
['extends_type', $.primary_expression],
[$._extends_type, $.extends_clause, $.primary_expression],
['unary', 'assign'],
['declaration', $.expression],
[$.predefined_type, $.unary_expression],
Expand Down Expand Up @@ -255,7 +255,7 @@ module.exports = function defineGrammar(dialect) {
previous,
seq('export', 'type', $.export_clause),
seq('export', '=', $.identifier, $._semicolon),
seq('export', 'as', 'namespace', $.identifier, $._semicolon)
seq('export', 'as', 'namespace', $.identifier, $._semicolon),
),

non_null_expression: $ => prec.left('unary', seq(
Expand Down Expand Up @@ -458,17 +458,20 @@ module.exports = function defineGrammar(dialect) {
field('body', $.object_type)
),

extends_clause: $ => prec('extends_type', seq(
_extends_type: $ => choice(
$._type_identifier,
$.nested_type_identifier,
$.generic_type,
),
functional_extension: $ => seq($._extends_type, $.arguments, optional($.type_arguments)),

extends_clause: $ => seq(
'extends',
commaSep1(choice(
prec('extends_type', choice(
$._type_identifier,
$.nested_type_identifier,
$.generic_type
)),
choice($._extends_type, $.functional_extension),
$.expression
))
)),
),

enum_declaration: $ => seq(
optional('const'),
Expand Down
Loading