diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap index 805ca4407a6..20840a8e540 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap @@ -178,6 +178,18 @@ decorators-comments.ts:41:5 parse ━━━━━━━━━━━━━━━ 42 │ } 43 │ +decorators-comments.ts:39:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 38 │ class Something3 { + > 39 │ @foo() + │ ^^^^^^ + 40 │ // comment + 41 │ abstract method(): Array + + i Decorators are only valid on class declarations, class expressions, and class methods. + ``` diff --git a/crates/rome_js_parser/src/syntax/class.rs b/crates/rome_js_parser/src/syntax/class.rs index 3376eaaee68..9f1542206d5 100644 --- a/crates/rome_js_parser/src/syntax/class.rs +++ b/crates/rome_js_parser/src/syntax/class.rs @@ -2140,9 +2140,6 @@ impl ClassMemberModifiers { | JS_METHOD_CLASS_MEMBER | JS_GETTER_CLASS_MEMBER | JS_SETTER_CLASS_MEMBER - | TS_METHOD_SIGNATURE_CLASS_MEMBER - | TS_GETTER_SIGNATURE_CLASS_MEMBER - | TS_SETTER_SIGNATURE_CLASS_MEMBER | TS_PROPERTY_SIGNATURE_CLASS_MEMBER | TS_INITIALIZED_PROPERTY_SIGNATURE_CLASS_MEMBER ) @@ -2154,14 +2151,6 @@ impl ClassMemberModifiers { // class Bar { // @dec readonly foo = '123'; // } - // declare class Foo { - // @dec method(); - // } - // declare class Baz { - // @dec method(); - // @dec get foo(); - // @dec set foo(a); - // } // test_err ts decorator_class_member // class Foo { @@ -2177,6 +2166,11 @@ impl ClassMemberModifiers { // constructor(a: String) // constructor(a?: String) {} // } + // declare class Baz { + // @dec method(); + // @dec get foo(); + // @dec set foo(a); + // } return Some(decorators_not_allowed(p, modifier.as_text_range())); } else if member_kind == TS_INDEX_SIGNATURE_CLASS_MEMBER && !matches!(modifier.kind, ModifierKind::Static | ModifierKind::Readonly) diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_class_member.rast b/crates/rome_js_parser/test_data/inline/err/decorator_class_member.rast index ec4d921718d..d3adcb9dcb9 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_class_member.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_class_member.rast @@ -258,14 +258,105 @@ JsModule { ], r_curly_token: R_CURLY@234..236 "}" [Newline("\n")] [], }, + TsDeclareStatement { + declare_token: DECLARE_KW@236..245 "declare" [Newline("\n")] [Whitespace(" ")], + declaration: JsClassDeclaration { + decorators: JsDecoratorList [], + abstract_token: missing (optional), + class_token: CLASS_KW@245..251 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@251..255 "Baz" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@255..256 "{" [] [], + members: JsClassMemberList [ + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@256..260 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@260..264 "dec" [] [Whitespace(" ")], + }, + }, + }, + ], + JsLiteralMemberName { + value: IDENT@264..270 "method" [] [], + }, + JsParameters { + l_paren_token: L_PAREN@270..271 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@271..272 ")" [] [], + }, + SEMICOLON@272..273 ";" [] [], + ], + }, + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@273..277 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@277..281 "dec" [] [Whitespace(" ")], + }, + }, + }, + ], + GET_KW@281..285 "get" [] [Whitespace(" ")], + JsLiteralMemberName { + value: IDENT@285..288 "foo" [] [], + }, + L_PAREN@288..289 "(" [] [], + R_PAREN@289..290 ")" [] [], + SEMICOLON@290..291 ";" [] [], + ], + }, + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@291..295 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@295..299 "dec" [] [Whitespace(" ")], + }, + }, + }, + ], + SET_KW@299..303 "set" [] [Whitespace(" ")], + JsLiteralMemberName { + value: IDENT@303..306 "foo" [] [], + }, + L_PAREN@306..307 "(" [] [], + JsFormalParameter { + binding: JsIdentifierBinding { + name_token: IDENT@307..308 "a" [] [], + }, + question_mark_token: missing (optional), + type_annotation: missing (optional), + initializer: missing (optional), + }, + R_PAREN@308..309 ")" [] [], + SEMICOLON@309..310 ";" [] [], + ], + }, + ], + r_curly_token: R_CURLY@310..312 "}" [Newline("\n")] [], + }, + }, ], - eof_token: EOF@236..237 "" [Newline("\n")] [], + eof_token: EOF@312..313 "" [Newline("\n")] [], } -0: JS_MODULE@0..237 +0: JS_MODULE@0..313 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..236 + 2: JS_MODULE_ITEM_LIST@0..312 0: JS_CLASS_DECLARATION@0..81 0: JS_DECORATOR_LIST@0..0 1: (empty) @@ -435,7 +526,67 @@ JsModule { 2: JS_STATEMENT_LIST@233..233 3: R_CURLY@233..234 "}" [] [] 9: R_CURLY@234..236 "}" [Newline("\n")] [] - 3: EOF@236..237 "" [Newline("\n")] [] + 3: TS_DECLARE_STATEMENT@236..312 + 0: DECLARE_KW@236..245 "declare" [Newline("\n")] [Whitespace(" ")] + 1: JS_CLASS_DECLARATION@245..312 + 0: JS_DECORATOR_LIST@245..245 + 1: (empty) + 2: CLASS_KW@245..251 "class" [] [Whitespace(" ")] + 3: JS_IDENTIFIER_BINDING@251..255 + 0: IDENT@251..255 "Baz" [] [Whitespace(" ")] + 4: (empty) + 5: (empty) + 6: (empty) + 7: L_CURLY@255..256 "{" [] [] + 8: JS_CLASS_MEMBER_LIST@256..310 + 0: JS_BOGUS_MEMBER@256..273 + 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@256..264 + 0: JS_DECORATOR@256..264 + 0: AT@256..260 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@260..264 + 0: JS_REFERENCE_IDENTIFIER@260..264 + 0: IDENT@260..264 "dec" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@264..270 + 0: IDENT@264..270 "method" [] [] + 2: JS_PARAMETERS@270..272 + 0: L_PAREN@270..271 "(" [] [] + 1: JS_PARAMETER_LIST@271..271 + 2: R_PAREN@271..272 ")" [] [] + 3: SEMICOLON@272..273 ";" [] [] + 1: JS_BOGUS_MEMBER@273..291 + 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@273..281 + 0: JS_DECORATOR@273..281 + 0: AT@273..277 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@277..281 + 0: JS_REFERENCE_IDENTIFIER@277..281 + 0: IDENT@277..281 "dec" [] [Whitespace(" ")] + 1: GET_KW@281..285 "get" [] [Whitespace(" ")] + 2: JS_LITERAL_MEMBER_NAME@285..288 + 0: IDENT@285..288 "foo" [] [] + 3: L_PAREN@288..289 "(" [] [] + 4: R_PAREN@289..290 ")" [] [] + 5: SEMICOLON@290..291 ";" [] [] + 2: JS_BOGUS_MEMBER@291..310 + 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@291..299 + 0: JS_DECORATOR@291..299 + 0: AT@291..295 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@295..299 + 0: JS_REFERENCE_IDENTIFIER@295..299 + 0: IDENT@295..299 "dec" [] [Whitespace(" ")] + 1: SET_KW@299..303 "set" [] [Whitespace(" ")] + 2: JS_LITERAL_MEMBER_NAME@303..306 + 0: IDENT@303..306 "foo" [] [] + 3: L_PAREN@306..307 "(" [] [] + 4: JS_FORMAL_PARAMETER@307..308 + 0: JS_IDENTIFIER_BINDING@307..308 + 0: IDENT@307..308 "a" [] [] + 1: (empty) + 2: (empty) + 3: (empty) + 5: R_PAREN@308..309 ")" [] [] + 6: SEMICOLON@309..310 ";" [] [] + 9: R_CURLY@310..312 "}" [Newline("\n")] [] + 3: EOF@312..313 "" [Newline("\n")] [] -- decorator_class_member.ts:2:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -491,6 +642,48 @@ decorator_class_member.ts:9:4 parse ━━━━━━━━━━━━━━ i Decorators are only valid on class declarations, class expressions, and class methods. +-- +decorator_class_member.ts:15:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 13 │ } + 14 │ declare class Baz { + > 15 │ @dec method(); + │ ^^^^ + 16 │ @dec get foo(); + 17 │ @dec set foo(a); + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +decorator_class_member.ts:16:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 14 │ declare class Baz { + 15 │ @dec method(); + > 16 │ @dec get foo(); + │ ^^^^ + 17 │ @dec set foo(a); + 18 │ } + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +decorator_class_member.ts:17:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 15 │ @dec method(); + 16 │ @dec get foo(); + > 17 │ @dec set foo(a); + │ ^^^^ + 18 │ } + 19 │ + + i Decorators are only valid on class declarations, class expressions, and class methods. + -- class Foo { @dec constructor() {} @@ -505,3 +698,8 @@ class Bar extends Foo { constructor(a: String) constructor(a?: String) {} } +declare class Baz { + @dec method(); + @dec get foo(); + @dec set foo(a); +} diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_class_member.ts b/crates/rome_js_parser/test_data/inline/err/decorator_class_member.ts index 7e3b16fc211..3992060aa08 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_class_member.ts +++ b/crates/rome_js_parser/test_data/inline/err/decorator_class_member.ts @@ -11,3 +11,8 @@ class Bar extends Foo { constructor(a: String) constructor(a?: String) {} } +declare class Baz { + @dec method(); + @dec get foo(); + @dec set foo(a); +} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_invalid_decorated_class_members.rast b/crates/rome_js_parser/test_data/inline/err/ts_invalid_decorated_class_members.rast index 88088c4941d..df37c5345d8 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_invalid_decorated_class_members.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_invalid_decorated_class_members.rast @@ -64,30 +64,28 @@ JsModule { property_annotation: missing (optional), semicolon_token: SEMICOLON@67..68 ";" [] [], }, - TsMethodSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@68..72 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@72..77 "test" [] [Whitespace(" ")], + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@68..72 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@72..77 "test" [] [Whitespace(" ")], + }, }, }, + ], + JsLiteralMemberName { + value: IDENT@77..83 "method" [] [], + }, + JsParameters { + l_paren_token: L_PAREN@83..84 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@84..85 ")" [] [], }, + SEMICOLON@85..86 ";" [] [], ], - async_token: missing (optional), - name: JsLiteralMemberName { - value: IDENT@77..83 "method" [] [], - }, - question_mark_token: missing (optional), - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@83..84 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@84..85 ")" [] [], - }, - return_type_annotation: missing (optional), - semicolon_token: SEMICOLON@85..86 ";" [] [], }, JsBogusMember { items: [ @@ -125,86 +123,87 @@ JsModule { SEMICOLON@118..119 ";" [] [], ], }, - TsMethodSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@119..123 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@123..128 "test" [] [Whitespace(" ")], + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@119..123 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@123..128 "test" [] [Whitespace(" ")], + }, }, }, + TsAbstractModifier { + modifier_token: ABSTRACT_KW@128..137 "abstract" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@137..144 "method2" [] [], }, - TsAbstractModifier { - modifier_token: ABSTRACT_KW@128..137 "abstract" [] [Whitespace(" ")], + JsParameters { + l_paren_token: L_PAREN@144..145 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@145..146 ")" [] [], }, + SEMICOLON@146..147 ";" [] [], ], - async_token: missing (optional), - name: JsLiteralMemberName { - value: IDENT@137..144 "method2" [] [], - }, - question_mark_token: missing (optional), - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@144..145 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@145..146 ")" [] [], - }, - return_type_annotation: missing (optional), - semicolon_token: SEMICOLON@146..147 ";" [] [], }, - TsGetterSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@147..151 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@151..156 "test" [] [Whitespace(" ")], + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@147..151 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@151..156 "test" [] [Whitespace(" ")], + }, }, }, + TsAbstractModifier { + modifier_token: ABSTRACT_KW@156..165 "abstract" [] [Whitespace(" ")], + }, + ], + GET_KW@165..169 "get" [] [Whitespace(" ")], + JsLiteralMemberName { + value: IDENT@169..175 "getter" [] [], }, - TsAbstractModifier { - modifier_token: ABSTRACT_KW@156..165 "abstract" [] [Whitespace(" ")], - }, + L_PAREN@175..176 "(" [] [], + R_PAREN@176..177 ")" [] [], + SEMICOLON@177..178 ";" [] [], ], - get_token: GET_KW@165..169 "get" [] [Whitespace(" ")], - name: JsLiteralMemberName { - value: IDENT@169..175 "getter" [] [], - }, - l_paren_token: L_PAREN@175..176 "(" [] [], - r_paren_token: R_PAREN@176..177 ")" [] [], - return_type: missing (optional), - semicolon_token: SEMICOLON@177..178 ";" [] [], }, - TsSetterSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@178..182 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@182..187 "test" [] [Whitespace(" ")], + JsBogusMember { + items: [ + TsMethodSignatureModifierList [ + JsDecorator { + at_token: AT@178..182 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@182..187 "test" [] [Whitespace(" ")], + }, }, }, + TsAbstractModifier { + modifier_token: ABSTRACT_KW@187..196 "abstract" [] [Whitespace(" ")], + }, + ], + SET_KW@196..200 "set" [] [Whitespace(" ")], + JsLiteralMemberName { + value: IDENT@200..206 "setter" [] [], }, - TsAbstractModifier { - modifier_token: ABSTRACT_KW@187..196 "abstract" [] [Whitespace(" ")], + L_PAREN@206..207 "(" [] [], + JsFormalParameter { + binding: JsIdentifierBinding { + name_token: IDENT@207..210 "val" [] [], + }, + question_mark_token: missing (optional), + type_annotation: missing (optional), + initializer: missing (optional), }, + R_PAREN@210..211 ")" [] [], + SEMICOLON@211..212 ";" [] [], ], - set_token: SET_KW@196..200 "set" [] [Whitespace(" ")], - name: JsLiteralMemberName { - value: IDENT@200..206 "setter" [] [], - }, - l_paren_token: L_PAREN@206..207 "(" [] [], - parameter: JsFormalParameter { - binding: JsIdentifierBinding { - name_token: IDENT@207..210 "val" [] [], - }, - question_mark_token: missing (optional), - type_annotation: missing (optional), - initializer: missing (optional), - }, - r_paren_token: R_PAREN@210..211 ")" [] [], - semicolon_token: SEMICOLON@211..212 ";" [] [], }, ], r_curly_token: R_CURLY@212..214 "}" [Newline("\n")] [], @@ -259,24 +258,20 @@ JsModule { 0: IDENT@63..67 "prop" [] [] 2: (empty) 3: SEMICOLON@67..68 ";" [] [] - 2: TS_METHOD_SIGNATURE_CLASS_MEMBER@68..86 + 2: JS_BOGUS_MEMBER@68..86 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@68..77 0: JS_DECORATOR@68..77 0: AT@68..72 "@" [Newline("\n"), Whitespace(" ")] [] 1: JS_IDENTIFIER_EXPRESSION@72..77 0: JS_REFERENCE_IDENTIFIER@72..77 0: IDENT@72..77 "test" [] [Whitespace(" ")] - 1: (empty) - 2: JS_LITERAL_MEMBER_NAME@77..83 + 1: JS_LITERAL_MEMBER_NAME@77..83 0: IDENT@77..83 "method" [] [] - 3: (empty) - 4: (empty) - 5: JS_PARAMETERS@83..85 + 2: JS_PARAMETERS@83..85 0: L_PAREN@83..84 "(" [] [] 1: JS_PARAMETER_LIST@84..84 2: R_PAREN@84..85 ")" [] [] - 6: (empty) - 7: SEMICOLON@85..86 ";" [] [] + 3: SEMICOLON@85..86 ";" [] [] 3: JS_BOGUS_MEMBER@86..119 0: JS_BOGUS@86..95 0: JS_DECORATOR@86..95 @@ -298,7 +293,7 @@ JsModule { 1: TS_STRING_TYPE@112..118 0: STRING_KW@112..118 "string" [] [] 5: SEMICOLON@118..119 ";" [] [] - 4: TS_METHOD_SIGNATURE_CLASS_MEMBER@119..147 + 4: JS_BOGUS_MEMBER@119..147 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@119..137 0: JS_DECORATOR@119..128 0: AT@119..123 "@" [Newline("\n"), Whitespace(" ")] [] @@ -307,18 +302,14 @@ JsModule { 0: IDENT@123..128 "test" [] [Whitespace(" ")] 1: TS_ABSTRACT_MODIFIER@128..137 0: ABSTRACT_KW@128..137 "abstract" [] [Whitespace(" ")] - 1: (empty) - 2: JS_LITERAL_MEMBER_NAME@137..144 + 1: JS_LITERAL_MEMBER_NAME@137..144 0: IDENT@137..144 "method2" [] [] - 3: (empty) - 4: (empty) - 5: JS_PARAMETERS@144..146 + 2: JS_PARAMETERS@144..146 0: L_PAREN@144..145 "(" [] [] 1: JS_PARAMETER_LIST@145..145 2: R_PAREN@145..146 ")" [] [] - 6: (empty) - 7: SEMICOLON@146..147 ";" [] [] - 5: TS_GETTER_SIGNATURE_CLASS_MEMBER@147..178 + 3: SEMICOLON@146..147 ";" [] [] + 5: JS_BOGUS_MEMBER@147..178 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@147..165 0: JS_DECORATOR@147..156 0: AT@147..151 "@" [Newline("\n"), Whitespace(" ")] [] @@ -332,9 +323,8 @@ JsModule { 0: IDENT@169..175 "getter" [] [] 3: L_PAREN@175..176 "(" [] [] 4: R_PAREN@176..177 ")" [] [] - 5: (empty) - 6: SEMICOLON@177..178 ";" [] [] - 6: TS_SETTER_SIGNATURE_CLASS_MEMBER@178..212 + 5: SEMICOLON@177..178 ";" [] [] + 6: JS_BOGUS_MEMBER@178..212 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@178..196 0: JS_DECORATOR@178..187 0: AT@178..182 "@" [Newline("\n"), Whitespace(" ")] [] @@ -370,6 +360,20 @@ ts_invalid_decorated_class_members.ts:2:3 parse ━━━━━━━━━━ i Decorators are only valid on class declarations, class expressions, and class methods. +-- +ts_invalid_decorated_class_members.ts:4:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 2 │ @test constructor() {} + 3 │ @test declare prop; + > 4 │ @test method(); + │ ^^^^^ + 5 │ @test [index: string]: string; + 6 │ @test abstract method2(); + + i Decorators are only valid on class declarations, class expressions, and class methods. + -- ts_invalid_decorated_class_members.ts:5:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -384,6 +388,48 @@ ts_invalid_decorated_class_members.ts:5:3 parse ━━━━━━━━━━ i Decorators are only valid on class declarations, class expressions, and class methods. +-- +ts_invalid_decorated_class_members.ts:6:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 4 │ @test method(); + 5 │ @test [index: string]: string; + > 6 │ @test abstract method2(); + │ ^^^^^ + 7 │ @test abstract get getter(); + 8 │ @test abstract set setter(val); + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +ts_invalid_decorated_class_members.ts:7:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 5 │ @test [index: string]: string; + 6 │ @test abstract method2(); + > 7 │ @test abstract get getter(); + │ ^^^^^ + 8 │ @test abstract set setter(val); + 9 │ } + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +ts_invalid_decorated_class_members.ts:8:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 6 │ @test abstract method2(); + 7 │ @test abstract get getter(); + > 8 │ @test abstract set setter(val); + │ ^^^^^ + 9 │ } + 10 │ + + i Decorators are only valid on class declarations, class expressions, and class methods. + -- abstract class Test { @test constructor() {} diff --git a/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.rast b/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.rast index db8d1e9b5bd..ee4e9a0b232 100644 --- a/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.rast +++ b/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.rast @@ -86,147 +86,14 @@ JsModule { ], r_curly_token: R_CURLY@99..101 "}" [Newline("\n")] [], }, - TsDeclareStatement { - declare_token: DECLARE_KW@101..110 "declare" [Newline("\n")] [Whitespace(" ")], - declaration: JsClassDeclaration { - decorators: JsDecoratorList [], - abstract_token: missing (optional), - class_token: CLASS_KW@110..116 "class" [] [Whitespace(" ")], - id: JsIdentifierBinding { - name_token: IDENT@116..120 "Foo" [] [Whitespace(" ")], - }, - type_parameters: missing (optional), - extends_clause: missing (optional), - implements_clause: missing (optional), - l_curly_token: L_CURLY@120..121 "{" [] [], - members: JsClassMemberList [ - TsMethodSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@121..124 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@124..128 "dec" [] [Whitespace(" ")], - }, - }, - }, - ], - async_token: missing (optional), - name: JsLiteralMemberName { - value: IDENT@128..134 "method" [] [], - }, - question_mark_token: missing (optional), - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@134..135 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@135..136 ")" [] [], - }, - return_type_annotation: missing (optional), - semicolon_token: SEMICOLON@136..137 ";" [] [], - }, - ], - r_curly_token: R_CURLY@137..139 "}" [Newline("\n")] [], - }, - }, - TsDeclareStatement { - declare_token: DECLARE_KW@139..148 "declare" [Newline("\n")] [Whitespace(" ")], - declaration: JsClassDeclaration { - decorators: JsDecoratorList [], - abstract_token: missing (optional), - class_token: CLASS_KW@148..154 "class" [] [Whitespace(" ")], - id: JsIdentifierBinding { - name_token: IDENT@154..158 "Baz" [] [Whitespace(" ")], - }, - type_parameters: missing (optional), - extends_clause: missing (optional), - implements_clause: missing (optional), - l_curly_token: L_CURLY@158..159 "{" [] [], - members: JsClassMemberList [ - TsMethodSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@159..163 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@163..167 "dec" [] [Whitespace(" ")], - }, - }, - }, - ], - async_token: missing (optional), - name: JsLiteralMemberName { - value: IDENT@167..173 "method" [] [], - }, - question_mark_token: missing (optional), - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@173..174 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@174..175 ")" [] [], - }, - return_type_annotation: missing (optional), - semicolon_token: SEMICOLON@175..176 ";" [] [], - }, - TsGetterSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@176..180 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@180..184 "dec" [] [Whitespace(" ")], - }, - }, - }, - ], - get_token: GET_KW@184..188 "get" [] [Whitespace(" ")], - name: JsLiteralMemberName { - value: IDENT@188..191 "foo" [] [], - }, - l_paren_token: L_PAREN@191..192 "(" [] [], - r_paren_token: R_PAREN@192..193 ")" [] [], - return_type: missing (optional), - semicolon_token: SEMICOLON@193..194 ";" [] [], - }, - TsSetterSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - JsDecorator { - at_token: AT@194..198 "@" [Newline("\n"), Whitespace(" ")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@198..202 "dec" [] [Whitespace(" ")], - }, - }, - }, - ], - set_token: SET_KW@202..206 "set" [] [Whitespace(" ")], - name: JsLiteralMemberName { - value: IDENT@206..209 "foo" [] [], - }, - l_paren_token: L_PAREN@209..210 "(" [] [], - parameter: JsFormalParameter { - binding: JsIdentifierBinding { - name_token: IDENT@210..211 "a" [] [], - }, - question_mark_token: missing (optional), - type_annotation: missing (optional), - initializer: missing (optional), - }, - r_paren_token: R_PAREN@211..212 ")" [] [], - semicolon_token: SEMICOLON@212..213 ";" [] [], - }, - ], - r_curly_token: R_CURLY@213..215 "}" [Newline("\n")] [], - }, - }, ], - eof_token: EOF@215..216 "" [Newline("\n")] [], + eof_token: EOF@101..102 "" [Newline("\n")] [], } -0: JS_MODULE@0..216 +0: JS_MODULE@0..102 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..215 + 2: JS_MODULE_ITEM_LIST@0..101 0: JS_CLASS_DECLARATION@0..57 0: JS_DECORATOR_LIST@0..0 1: ABSTRACT_KW@0..9 "abstract" [] [Whitespace(" ")] @@ -286,101 +153,4 @@ JsModule { 0: JS_STRING_LITERAL@93..98 "'123'" [] [] 4: SEMICOLON@98..99 ";" [] [] 9: R_CURLY@99..101 "}" [Newline("\n")] [] - 2: TS_DECLARE_STATEMENT@101..139 - 0: DECLARE_KW@101..110 "declare" [Newline("\n")] [Whitespace(" ")] - 1: JS_CLASS_DECLARATION@110..139 - 0: JS_DECORATOR_LIST@110..110 - 1: (empty) - 2: CLASS_KW@110..116 "class" [] [Whitespace(" ")] - 3: JS_IDENTIFIER_BINDING@116..120 - 0: IDENT@116..120 "Foo" [] [Whitespace(" ")] - 4: (empty) - 5: (empty) - 6: (empty) - 7: L_CURLY@120..121 "{" [] [] - 8: JS_CLASS_MEMBER_LIST@121..137 - 0: TS_METHOD_SIGNATURE_CLASS_MEMBER@121..137 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@121..128 - 0: JS_DECORATOR@121..128 - 0: AT@121..124 "@" [Newline("\n"), Whitespace(" ")] [] - 1: JS_IDENTIFIER_EXPRESSION@124..128 - 0: JS_REFERENCE_IDENTIFIER@124..128 - 0: IDENT@124..128 "dec" [] [Whitespace(" ")] - 1: (empty) - 2: JS_LITERAL_MEMBER_NAME@128..134 - 0: IDENT@128..134 "method" [] [] - 3: (empty) - 4: (empty) - 5: JS_PARAMETERS@134..136 - 0: L_PAREN@134..135 "(" [] [] - 1: JS_PARAMETER_LIST@135..135 - 2: R_PAREN@135..136 ")" [] [] - 6: (empty) - 7: SEMICOLON@136..137 ";" [] [] - 9: R_CURLY@137..139 "}" [Newline("\n")] [] - 3: TS_DECLARE_STATEMENT@139..215 - 0: DECLARE_KW@139..148 "declare" [Newline("\n")] [Whitespace(" ")] - 1: JS_CLASS_DECLARATION@148..215 - 0: JS_DECORATOR_LIST@148..148 - 1: (empty) - 2: CLASS_KW@148..154 "class" [] [Whitespace(" ")] - 3: JS_IDENTIFIER_BINDING@154..158 - 0: IDENT@154..158 "Baz" [] [Whitespace(" ")] - 4: (empty) - 5: (empty) - 6: (empty) - 7: L_CURLY@158..159 "{" [] [] - 8: JS_CLASS_MEMBER_LIST@159..213 - 0: TS_METHOD_SIGNATURE_CLASS_MEMBER@159..176 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@159..167 - 0: JS_DECORATOR@159..167 - 0: AT@159..163 "@" [Newline("\n"), Whitespace(" ")] [] - 1: JS_IDENTIFIER_EXPRESSION@163..167 - 0: JS_REFERENCE_IDENTIFIER@163..167 - 0: IDENT@163..167 "dec" [] [Whitespace(" ")] - 1: (empty) - 2: JS_LITERAL_MEMBER_NAME@167..173 - 0: IDENT@167..173 "method" [] [] - 3: (empty) - 4: (empty) - 5: JS_PARAMETERS@173..175 - 0: L_PAREN@173..174 "(" [] [] - 1: JS_PARAMETER_LIST@174..174 - 2: R_PAREN@174..175 ")" [] [] - 6: (empty) - 7: SEMICOLON@175..176 ";" [] [] - 1: TS_GETTER_SIGNATURE_CLASS_MEMBER@176..194 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@176..184 - 0: JS_DECORATOR@176..184 - 0: AT@176..180 "@" [Newline("\n"), Whitespace(" ")] [] - 1: JS_IDENTIFIER_EXPRESSION@180..184 - 0: JS_REFERENCE_IDENTIFIER@180..184 - 0: IDENT@180..184 "dec" [] [Whitespace(" ")] - 1: GET_KW@184..188 "get" [] [Whitespace(" ")] - 2: JS_LITERAL_MEMBER_NAME@188..191 - 0: IDENT@188..191 "foo" [] [] - 3: L_PAREN@191..192 "(" [] [] - 4: R_PAREN@192..193 ")" [] [] - 5: (empty) - 6: SEMICOLON@193..194 ";" [] [] - 2: TS_SETTER_SIGNATURE_CLASS_MEMBER@194..213 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@194..202 - 0: JS_DECORATOR@194..202 - 0: AT@194..198 "@" [Newline("\n"), Whitespace(" ")] [] - 1: JS_IDENTIFIER_EXPRESSION@198..202 - 0: JS_REFERENCE_IDENTIFIER@198..202 - 0: IDENT@198..202 "dec" [] [Whitespace(" ")] - 1: SET_KW@202..206 "set" [] [Whitespace(" ")] - 2: JS_LITERAL_MEMBER_NAME@206..209 - 0: IDENT@206..209 "foo" [] [] - 3: L_PAREN@209..210 "(" [] [] - 4: JS_FORMAL_PARAMETER@210..211 - 0: JS_IDENTIFIER_BINDING@210..211 - 0: IDENT@210..211 "a" [] [] - 1: (empty) - 2: (empty) - 3: (empty) - 5: R_PAREN@211..212 ")" [] [] - 6: SEMICOLON@212..213 ";" [] [] - 9: R_CURLY@213..215 "}" [Newline("\n")] [] - 3: EOF@215..216 "" [Newline("\n")] [] + 3: EOF@101..102 "" [Newline("\n")] [] diff --git a/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.ts b/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.ts index 51dbc65c7f7..8f3d4ebd87a 100644 --- a/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.ts +++ b/crates/rome_js_parser/test_data/inline/ok/decorator_class_member_in_ts.ts @@ -4,11 +4,3 @@ abstract class Qux { class Bar { @dec readonly foo = '123'; } -declare class Foo { - @dec method(); -} -declare class Baz { - @dec method(); - @dec get foo(); - @dec set foo(a); -}