Skip to content

Commit

Permalink
feat: support parenthesized expressions in decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jul 20, 2024
1 parent 043fc26 commit e0ffcd0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ module.exports = function defineGrammar(dialect) {
choice($._semicolon, $._function_signature_automatic_semicolon),
),

decorator: $ => seq(
'@',
choice(
$.identifier,
alias($.decorator_member_expression, $.member_expression),
alias($.decorator_call_expression, $.call_expression),
alias($.decorator_parenthesized_expression, $.parenthesized_expression),
),
),

decorator_call_expression: $ => prec('call', seq(
field('function', choice(
$.identifier,
Expand All @@ -396,6 +406,16 @@ module.exports = function defineGrammar(dialect) {
field('arguments', $.arguments),
)),

decorator_parenthesized_expression: $ => seq(
'(',
choice(
$.identifier,
alias($.decorator_member_expression, $.member_expression),
alias($.decorator_call_expression, $.call_expression),
),
')',
),

class_body: $ => seq(
'{',
repeat(choice(
Expand Down
25 changes: 25 additions & 0 deletions test/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,31 @@ abstract class Foo {
name: (type_identifier)
body: (class_body)))

=======================================
Decorator with parenthesized expression
=======================================

class C {
@(super.decorate)
method2() { }
}

---

(program
(class_declaration
(type_identifier)
(class_body
(decorator
(parenthesized_expression
(member_expression
(identifier)
(property_identifier))))
(method_definition
(property_identifier)
(formal_parameters)
(statement_block)))))

==================================
Index type queries
==================================
Expand Down

0 comments on commit e0ffcd0

Please sign in to comment.