Skip to content

Commit

Permalink
fix: decorator_call_expression type arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nohehf authored and amaanq committed Jun 18, 2024
1 parent 4ad3010 commit 2f181af
Show file tree
Hide file tree
Showing 6 changed files with 482,186 additions and 481,773 deletions.
9 changes: 9 additions & 0 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ module.exports = function defineGrammar(dialect) {
choice($._semicolon, $._function_signature_automatic_semicolon),
),

decorator_call_expression: $ => prec('call', seq(
field('function', choice(
$.identifier,
alias($.decorator_member_expression, $.member_expression),
)),
optional(field('type_arguments', $.type_arguments)),
field('arguments', $.arguments),
)),

class_body: ($) => seq(
'{',
repeat(choice(
Expand Down
27 changes: 27 additions & 0 deletions test/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,33 @@ class Foo {
(string
(string_fragment))))))

===========================================================
Classes with decorator calls that have type arguments
===========================================================

class Foo {
@bar<T>()
method() {
}
}

---

(program
(class_declaration
(type_identifier)
(class_body
(decorator
(call_expression
(identifier)
(type_arguments
(type_identifier))
(arguments)))
(method_definition
(property_identifier)
(formal_parameters)
(statement_block)))))

=======================================
Classes with decorators
=======================================
Expand Down
27 changes: 17 additions & 10 deletions tsx/src/grammar.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"0": "j",
"1": "a",
"2": "v",
"3": "a",
"4": "s",
"5": "c",
"6": "r",
"7": "i",
"8": "p",
"9": "t",
"name": "tsx",
"inherits": "javascript",
"word": "identifier",
"rules": {
"program": {
Expand Down Expand Up @@ -6549,6 +6540,22 @@
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "type_arguments",
"content": {
"type": "SYMBOL",
"name": "type_arguments"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "arguments",
Expand Down
Loading

0 comments on commit 2f181af

Please sign in to comment.