diff --git a/crates/rome_js_formatter/src/generated.rs b/crates/rome_js_formatter/src/generated.rs index 79f20d8846c..2645b382328 100644 --- a/crates/rome_js_formatter/src/generated.rs +++ b/crates/rome_js_formatter/src/generated.rs @@ -6841,40 +6841,6 @@ impl IntoFormat for rome_js_syntax::TsThisParameter { ) } } -impl FormatRule - for crate::js::auxiliary::decorator::FormatJsDecorator -{ - type Context = JsFormatContext; - #[inline(always)] - fn fmt(&self, node: &rome_js_syntax::JsDecorator, f: &mut JsFormatter) -> FormatResult<()> { - FormatNodeRule::::fmt(self, node, f) - } -} -impl AsFormat for rome_js_syntax::JsDecorator { - type Format<'a> = FormatRefWithRule< - 'a, - rome_js_syntax::JsDecorator, - crate::js::auxiliary::decorator::FormatJsDecorator, - >; - fn format(&self) -> Self::Format<'_> { - FormatRefWithRule::new( - self, - crate::js::auxiliary::decorator::FormatJsDecorator::default(), - ) - } -} -impl IntoFormat for rome_js_syntax::JsDecorator { - type Format = FormatOwnedWithRule< - rome_js_syntax::JsDecorator, - crate::js::auxiliary::decorator::FormatJsDecorator, - >; - fn into_format(self) -> Self::Format { - FormatOwnedWithRule::new( - self, - crate::js::auxiliary::decorator::FormatJsDecorator::default(), - ) - } -} impl FormatRule for crate::ts::types::any_type::FormatTsAnyType { type Context = JsFormatContext; #[inline(always)] diff --git a/crates/rome_js_formatter/tests/quick_test.rs b/crates/rome_js_formatter/tests/quick_test.rs index 1fc3d441c91..057deb5a01e 100644 --- a/crates/rome_js_formatter/tests/quick_test.rs +++ b/crates/rome_js_formatter/tests/quick_test.rs @@ -13,13 +13,11 @@ mod language { // use this test check if your snippet prints as you wish, without using a snapshot fn quick_test() { let src = r#" -const bar = - ( - @deco - class { - // - } - ); +class A { + @dec() + // comment + accessor b; +} "#; let syntax = SourceType::tsx(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-comments/comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-comments/comments.js.snap index 8cf4e3e1e0c..1d52fa192ba 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-comments/comments.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-comments/comments.js.snap @@ -45,16 +45,16 @@ class Something { comments.js:4:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × return types can only be used in TypeScript files - + 2 │ @Annotateme() 3 │ // comment > 4 │ static property: Array; │ ^^^^^^^^^^^^^^^ 5 │ } - 6 │ - + 6 │ + i remove this type annotation - + ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap index dd3cc9111cf..c21028ce0a5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap @@ -23,12 +23,11 @@ export default @decorator class {} -@decorator +export @decorator class Foo {} - + -export default -@decorator --class {} -+export default (@decorator -+class {}); ++export default @decorator + class {} ``` # Output @@ -37,8 +36,8 @@ export default @decorator class {} export @decorator class Foo {} -export default (@decorator -class {}); +export default @decorator +class {} ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap index 748742dc987..01266db2ad0 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap @@ -33,7 +33,7 @@ const bar = @@ -7,18 +7,12 @@ @deco export default class Baz {} - + -const foo = - ( - @deco @@ -45,7 +45,7 @@ const bar = +class { + // +}; - + -const bar = - ( - @deco @@ -82,31 +82,4 @@ class { }; ``` -# Errors -``` -classes.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - 1 │ @deco class Foo {} - 2 │ - > 3 │ @deco export class Bar {} - │ ^^^^^ - 4 │ - 5 │ @deco export default class Baz {} - -classes.js:5:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - 3 │ @deco export class Bar {} - 4 │ - > 5 │ @deco export default class Baz {} - │ ^^^^^ - 6 │ - 7 │ const foo = @deco class { - - -``` - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.snap deleted file mode 100644 index 1c602776a9e..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.snap +++ /dev/null @@ -1,128 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/comments.js ---- - -# Input - -```js -var x = 100 - -@Hello({ - a: 'a', // Comment is in the wrong place - // test - b: '2' -}) -class X { - -} - - -@NgModule({ - // Imports. - imports: [ - // Angular modules. - BrowserModule, - - // App modules. - CoreModule, - SharedModule, - ], -}) -export class AppModule {} - -// A -@Foo() -// B -@Bar() -// C -export class Bar{} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,9 +1,9 @@ - var x = 100; - - @Hello({ -- a: "a", // Comment is in the wrong place -+ a: 'a', // Comment is in the wrong place - // test -- b: "2", -+ b: '2' - }) - class X {} - -``` - -# Output - -```js -var x = 100; - -@Hello({ - a: 'a', // Comment is in the wrong place - // test - b: '2' -}) -class X {} - -@NgModule({ - // Imports. - imports: [ - // Angular modules. - BrowserModule, - - // App modules. - CoreModule, - SharedModule, - ], -}) -export class AppModule {} - -// A -@Foo() -// B -@Bar() -// C -export class Bar {} -``` - -# Errors -``` -comments.js:13:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - > 13 │ @NgModule({ - │ ^^^^^^^^^^^ - > 14 │ // Imports. - ... - > 22 │ ], - > 23 │ }) - │ ^^ - 24 │ export class AppModule {} - 25 │ - -comments.js:27:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - 26 │ // A - > 27 │ @Foo() - │ ^^^^^^ - > 28 │ // B - > 29 │ @Bar() - │ ^^^^^^ - 30 │ // C - 31 │ export class Bar{} - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap index ac64593e657..2ec98c44717 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap @@ -74,7 +74,7 @@ info: js/decorators/member-expression.js }, class { - @decorators [0]; -+ @decorators[0]; ++ @decorators[0] method() {} }, class { @@ -100,21 +100,20 @@ info: js/decorators/member-expression.js method() {} }, class { -- @decorators[first] + @(decorators[first]) + method() {} + }, + class { -+ @decorators[first]; -+ method() {} -+ }, -+ class { -+ @(decorators["first"]) + @decorators[first] method() {} }, -+ @(decorators[first]) class { - @decorators [first]; ++ @(decorators["first"]) ++ method() {} ++ }, ++ @(decorators[first]) ++ class { method() {} }, + @(decorators[0]) @@ -134,7 +133,8 @@ info: js/decorators/member-expression.js - method() {} - } - ), - ]; +-]; ++] ``` # Output @@ -146,7 +146,7 @@ info: js/decorators/member-expression.js method() {} }, class { - @decorators[0]; + @decorators[0] method() {} }, class { @@ -174,7 +174,7 @@ info: js/decorators/member-expression.js method() {} }, class { - @decorators[first]; + @decorators[first] method() {} }, class { @@ -189,7 +189,552 @@ info: js/decorators/member-expression.js class { method() {} }, -]; +] +``` + +# Errors +``` +member-expression.js:3:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '@' + + 1 │ [ + 2 │ class { + > 3 │ @(decorators[0]) + │ ^ + 4 │ method() {} + 5 │ }, + + i Expected an identifier, a string literal, a number literal, a private field name, or a computed name here + + 1 │ [ + 2 │ class { + > 3 │ @(decorators[0]) + │ ^ + 4 │ method() {} + 5 │ }, + +member-expression.js:4:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 2 │ class { + 3 │ @(decorators[0]) + > 4 │ method() {} + │ ^ + 5 │ }, + 6 │ class { + + i Remove { + +member-expression.js:5:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 3 │ @(decorators[0]) + 4 │ method() {} + > 5 │ }, + │ ^ + 6 │ class { + 7 │ @decorators[0] + + i Remove } + +member-expression.js:7:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 5 │ }, + 6 │ class { + > 7 │ @decorators[0] + │ ^ + 8 │ method() {} + 9 │ }, + + i Remove [ + +member-expression.js:8:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 6 │ class { + 7 │ @decorators[0] + > 8 │ method() {} + │ ^^^^^^ + 9 │ }, + 10 │ class { + + i Remove method + +member-expression.js:8:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 6 │ class { + 7 │ @decorators[0] + > 8 │ method() {} + │ ^ + 9 │ }, + 10 │ class { + + i Remove { + +member-expression.js:9:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 7 │ @decorators[0] + 8 │ method() {} + > 9 │ }, + │ ^ + 10 │ class { + 11 │ @(decorators?.[0]) + + i Remove } + +member-expression.js:11:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 9 │ }, + 10 │ class { + > 11 │ @(decorators?.[0]) + │ ^ + 12 │ method() {} + 13 │ }, + + i Remove ( + +member-expression.js:12:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 10 │ class { + 11 │ @(decorators?.[0]) + > 12 │ method() {} + │ ^^^^^^ + 13 │ }, + 14 │ class { + + i Remove method + +member-expression.js:12:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 10 │ class { + 11 │ @(decorators?.[0]) + > 12 │ method() {} + │ ^ + 13 │ }, + 14 │ class { + + i Remove { + +member-expression.js:13:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 11 │ @(decorators?.[0]) + 12 │ method() {} + > 13 │ }, + │ ^ + 14 │ class { + 15 │ @(decorators.at(0)) + + i Remove } + +member-expression.js:15:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 13 │ }, + 14 │ class { + > 15 │ @(decorators.at(0)) + │ ^ + 16 │ method() {} + 17 │ }, + + i Remove ( + +member-expression.js:16:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 14 │ class { + 15 │ @(decorators.at(0)) + > 16 │ method() {} + │ ^^^^^^ + 17 │ }, + 18 │ class { + + i Remove method + +member-expression.js:16:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 14 │ class { + 15 │ @(decorators.at(0)) + > 16 │ method() {} + │ ^ + 17 │ }, + 18 │ class { + + i Remove { + +member-expression.js:17:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 15 │ @(decorators.at(0)) + 16 │ method() {} + > 17 │ }, + │ ^ + 18 │ class { + 19 │ @(decorators?.at(0)) + + i Remove } + +member-expression.js:19:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 17 │ }, + 18 │ class { + > 19 │ @(decorators?.at(0)) + │ ^ + 20 │ method() {} + 21 │ }, + + i Remove ( + +member-expression.js:20:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 18 │ class { + 19 │ @(decorators?.at(0)) + > 20 │ method() {} + │ ^^^^^^ + 21 │ }, + 22 │ class { + + i Remove method + +member-expression.js:20:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 18 │ class { + 19 │ @(decorators?.at(0)) + > 20 │ method() {} + │ ^ + 21 │ }, + 22 │ class { + + i Remove { + +member-expression.js:21:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 19 │ @(decorators?.at(0)) + 20 │ method() {} + > 21 │ }, + │ ^ + 22 │ class { + 23 │ @(decorators.first) + + i Remove } + +member-expression.js:23:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 21 │ }, + 22 │ class { + > 23 │ @(decorators.first) + │ ^ + 24 │ method() {} + 25 │ }, + + i Remove ( + +member-expression.js:24:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 22 │ class { + 23 │ @(decorators.first) + > 24 │ method() {} + │ ^^^^^^ + 25 │ }, + 26 │ class { + + i Remove method + +member-expression.js:24:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 22 │ class { + 23 │ @(decorators.first) + > 24 │ method() {} + │ ^ + 25 │ }, + 26 │ class { + + i Remove { + +member-expression.js:25:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 23 │ @(decorators.first) + 24 │ method() {} + > 25 │ }, + │ ^ + 26 │ class { + 27 │ @(decorators?.first) + + i Remove } + +member-expression.js:27:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 25 │ }, + 26 │ class { + > 27 │ @(decorators?.first) + │ ^ + 28 │ method() {} + 29 │ }, + + i Remove ( + +member-expression.js:28:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 26 │ class { + 27 │ @(decorators?.first) + > 28 │ method() {} + │ ^^^^^^ + 29 │ }, + 30 │ class { + + i Remove method + +member-expression.js:28:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 26 │ class { + 27 │ @(decorators?.first) + > 28 │ method() {} + │ ^ + 29 │ }, + 30 │ class { + + i Remove { + +member-expression.js:29:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 27 │ @(decorators?.first) + 28 │ method() {} + > 29 │ }, + │ ^ + 30 │ class { + 31 │ @(decorators[first]) + + i Remove } + +member-expression.js:31:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 29 │ }, + 30 │ class { + > 31 │ @(decorators[first]) + │ ^ + 32 │ method() {} + 33 │ }, + + i Remove ( + +member-expression.js:32:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 30 │ class { + 31 │ @(decorators[first]) + > 32 │ method() {} + │ ^^^^^^ + 33 │ }, + 34 │ class { + + i Remove method + +member-expression.js:32:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 30 │ class { + 31 │ @(decorators[first]) + > 32 │ method() {} + │ ^ + 33 │ }, + 34 │ class { + + i Remove { + +member-expression.js:33:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 31 │ @(decorators[first]) + 32 │ method() {} + > 33 │ }, + │ ^ + 34 │ class { + 35 │ @decorators[first] + + i Remove } + +member-expression.js:35:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 33 │ }, + 34 │ class { + > 35 │ @decorators[first] + │ ^ + 36 │ method() {} + 37 │ }, + + i Remove [ + +member-expression.js:36:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 34 │ class { + 35 │ @decorators[first] + > 36 │ method() {} + │ ^^^^^^ + 37 │ }, + 38 │ class { + + i Remove method + +member-expression.js:36:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 34 │ class { + 35 │ @decorators[first] + > 36 │ method() {} + │ ^ + 37 │ }, + 38 │ class { + + i Remove { + +member-expression.js:37:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 35 │ @decorators[first] + 36 │ method() {} + > 37 │ }, + │ ^ + 38 │ class { + 39 │ @(decorators["first"]) + + i Remove } + +member-expression.js:39:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 37 │ }, + 38 │ class { + > 39 │ @(decorators["first"]) + │ ^ + 40 │ method() {} + 41 │ }, + + i Remove ( + +member-expression.js:40:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `method` + + 38 │ class { + 39 │ @(decorators["first"]) + > 40 │ method() {} + │ ^^^^^^ + 41 │ }, + 42 │ @(decorators[first]) + + i Remove method + +member-expression.js:40:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 38 │ class { + 39 │ @(decorators["first"]) + > 40 │ method() {} + │ ^ + 41 │ }, + 42 │ @(decorators[first]) + + i Remove { + +member-expression.js:41:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `}` + + 39 │ @(decorators["first"]) + 40 │ method() {} + > 41 │ }, + │ ^ + 42 │ @(decorators[first]) + 43 │ class { + + i Remove } + +member-expression.js:42:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `(` + + 40 │ method() {} + 41 │ }, + > 42 │ @(decorators[first]) + │ ^ + 43 │ class { + 44 │ method() {} + + i Remove ( + +member-expression.js:43:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `class` + + 41 │ }, + 42 │ @(decorators[first]) + > 43 │ class { + │ ^^^^^ + 44 │ method() {} + 45 │ }, + + i Remove class + + ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap index fd760fb1072..a547c14df8a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/decorators/methods.js --- @@ -26,13 +25,23 @@ class Yo { ```diff --- Prettier +++ Rome -@@ -5,6 +5,5 @@ - @anotherDecoratorWithALongName("and a very long string as a first argument") - async plip() {} - +@@ -1,10 +1,11 @@ + class Yo { +- @foo("hello") +- async plop() {} ++ @foo("hello") async plop() {} + +- @anotherDecoratorWithALongName("and a very long string as a first argument") +- async plip() {} ++ @anotherDecoratorWithALongName( ++ "and a very long string as a first argument", ++ ) async plip() {} + - @anotherDecoratorWithALongName("another very long string, but now inline") - async plip() {} -+ @anotherDecoratorWithALongName("another very long string, but now inline") async plip() {} ++ @anotherDecoratorWithALongName( ++ "another very long string, but now inline", ++ ) async plip() {} } ``` @@ -40,19 +49,16 @@ class Yo { ```js class Yo { - @foo("hello") - async plop() {} + @foo("hello") async plop() {} - @anotherDecoratorWithALongName("and a very long string as a first argument") - async plip() {} + @anotherDecoratorWithALongName( + "and a very long string as a first argument", + ) async plip() {} - @anotherDecoratorWithALongName("another very long string, but now inline") async plip() {} + @anotherDecoratorWithALongName( + "another very long string, but now inline", + ) async plip() {} } ``` -# Lines exceeding max width of 80 characters -``` - 8: @anotherDecoratorWithALongName("another very long string, but now inline") async plip() {} -``` - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap index 400a5ee0d56..686f9673b3a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap @@ -43,20 +43,4 @@ export default class MyComponent { } ``` -# Errors -``` -mixed.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - 1 │ // https://github.com/prettier/prettier/issues/6747 - 2 │ - > 3 │ @foo - │ ^^^^ - 4 │ export default class MyComponent { - 5 │ @task - - -``` - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap index 12c96eef3ce..5d8d2458c12 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap @@ -33,13 +33,13 @@ import {observable} from "mobx"; setPrice(price) { this.price = price; } - + @computed @computed @computed @computed @computed @computed @computed get total() { return this.price * this.amount; } @action handleDecrease = (event: React.ChangeEvent) => this.count--; - + @action handleSomething = (event: React.ChangeEvent) => doSomething(); } @@ -52,20 +52,32 @@ import {observable} from "mobx"; --- Prettier +++ Rome @@ -2,8 +2,8 @@ - + @observer class OrderLine { - @observable price: number = 0; - @observable amount: number = 1; + @observable price:number = 0; + @observable amount:number = 1; - + constructor(price) { this.price = price; -@@ -27,20 +27,11 @@ +@@ -17,30 +17,19 @@ this.price = price; } - + +- @computed +- get total() { ++ @computed get total() { + return this.price * this.amount; + } + +- @action.bound +- setPrice(price) { ++ @action.bound setPrice(price) { + this.price = price; + } + - @computed - @computed - @computed @@ -77,11 +89,11 @@ import {observable} from "mobx"; + @computed @computed @computed @computed @computed @computed @computed get total() { return this.price * this.amount; } - + - @action handleDecrease = (event: React.ChangeEvent) => - this.count--; + @action handleDecrease = (event: React.ChangeEvent) => this.count--; - + - @action handleSomething = (event: React.ChangeEvent) => - doSomething(); + @action handleSomething = (event: React.ChangeEvent) => doSomething(); @@ -110,13 +122,11 @@ class OrderLine { this.price = price; } - @computed - get total() { + @computed get total() { return this.price * this.amount; } - @action.bound - setPrice(price) { + @action.bound setPrice(price) { this.price = price; } @@ -135,62 +145,62 @@ class OrderLine { mobx.js:4:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × return types can only be used in TypeScript files - + 3 │ @observer class OrderLine { > 4 │ @observable price:number = 0; │ ^^^^^^^ 5 │ @observable amount:number = 1; - 6 │ - + 6 │ + i remove this type annotation - + mobx.js:5:21 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × return types can only be used in TypeScript files - + 3 │ @observer class OrderLine { 4 │ @observable price:number = 0; > 5 │ @observable amount:number = 1; │ ^^^^^^^ - 6 │ + 6 │ 7 │ constructor(price) { - + i remove this type annotation - + mobx.js:33:34 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax. - + 31 │ } - 32 │ + 32 │ > 33 │ @action handleDecrease = (event: React.ChangeEvent) => this.count--; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 34 │ + 34 │ 35 │ @action handleSomething = (event: React.ChangeEvent) => doSomething(); - + i TypeScript only syntax - + mobx.js:35:35 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax. - + 33 │ @action handleDecrease = (event: React.ChangeEvent) => this.count--; - 34 │ + 34 │ > 35 │ @action handleSomething = (event: React.ChangeEvent) => doSomething(); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 36 │ } - 37 │ - + 37 │ + i TypeScript only syntax - + ``` # Lines exceeding max width of 80 characters ``` - 30: @computed @computed @computed @computed @computed @computed @computed get total() { - 34: @action handleDecrease = (event: React.ChangeEvent) => this.count--; - 36: @action handleSomething = (event: React.ChangeEvent) => doSomething(); + 28: @computed @computed @computed @computed @computed @computed @computed get total() { + 32: @action handleDecrease = (event: React.ChangeEvent) => this.count--; + 34: @action handleSomething = (event: React.ChangeEvent) => doSomething(); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiline.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiline.js.snap deleted file mode 100644 index cd90acf997e..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiline.js.snap +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: js/decorators/multiline.js ---- - -# Input - -```js -class Foo { - @deco([ - foo, - bar - ]) prop = value; - - @decorator([]) method() {} - - @decorator([ - ]) method() {} - - @decorator({}) method() {} - - @decorator({ - }) method() {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,11 +1,16 @@ - class Foo { -- @deco([foo, bar]) prop = value; -+ @deco([ -+ foo, -+ bar -+ ]) prop = value; - - @decorator([]) method() {} - -- @decorator([]) method() {} -+ @decorator([ -+ ]) method() {} - - @decorator({}) method() {} - -- @decorator({}) method() {} -+ @decorator({ -+ }) method() {} - } -``` - -# Output - -```js -class Foo { - @deco([ - foo, - bar - ]) prop = value; - - @decorator([]) method() {} - - @decorator([ - ]) method() {} - - @decorator({}) method() {} - - @decorator({ - }) method() {} -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap index dcd1cb0279a..a04cfa7e43d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap @@ -38,7 +38,7 @@ const foo = { @doubledValue - legs: 4, +legs: 4, - + @readonly @nonenumerable @doubledValue @@ -47,7 +47,7 @@ const foo = { + eyes +: 2 +} - + const foo = { - @multipleDecorators - @inline @@ -86,27 +86,27 @@ aVeryLongPropName: "A very long string as value"; multiple.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a property, a shorthand property, a getter, a setter, or a method but instead found '@' - + 1 │ const dog = { > 2 │ @readonly │ ^ 3 │ @nonenumerable 4 │ @doubledValue - + i Expected a property, a shorthand property, a getter, a setter, or a method here - + 1 │ const dog = { > 2 │ @readonly │ ^ 3 │ @nonenumerable 4 │ @doubledValue - + multiple.js:7:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 5 │ legs: 4, - 6 │ + 6 │ > 7 │ @readonly │ ^^^^^^^^^ > 8 │ @nonenumerable @@ -114,80 +114,80 @@ multiple.js:7:3 parse ━━━━━━━━━━━━━━━━━━━ │ ^^^^^^^^^^^^^ 10 │ eyes: 2 11 │ }; - + i Decorators are only valid on class declarations, class expressions, and class methods. - + multiple.js:10:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 8 │ @nonenumerable 9 │ @doubledValue > 10 │ eyes: 2 │ ^ 11 │ }; - 12 │ - + 12 │ + i An explicit or implicit semicolon is expected here... - + 8 │ @nonenumerable 9 │ @doubledValue > 10 │ eyes: 2 │ ^ 11 │ }; - 12 │ - + 12 │ + i ...Which is required to end this statement - + 3 │ @nonenumerable 4 │ @doubledValue > 5 │ legs: 4, │ ^^ - > 6 │ + > 6 │ > 7 │ @readonly > 8 │ @nonenumerable > 9 │ @doubledValue > 10 │ eyes: 2 │ ^^^^^ 11 │ }; - 12 │ - + 12 │ + multiple.js:14:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a property, a shorthand property, a getter, a setter, or a method but instead found '@' - + 13 │ const foo = { > 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" │ ^ 15 │ }; - 16 │ - + 16 │ + i Expected a property, a shorthand property, a getter, a setter, or a method here - + 13 │ const foo = { > 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" │ ^ 15 │ }; - 16 │ - + 16 │ + multiple.js:15:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '}' - + 13 │ const foo = { 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" > 15 │ }; │ ^ - 16 │ - + 16 │ + i Expected a statement here - + 13 │ const foo = { 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" > 15 │ }; │ ^ - 16 │ - + 16 │ + ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/angular.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/angular.ts.snap index 1f86a5e55de..abe2142d483 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/angular.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/angular.ts.snap @@ -46,22 +46,4 @@ export class HeroButtonComponent { } ``` -# Errors -``` -angular.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - > 1 │ @Component({ - │ ^^^^^^^^^^^^ - > 2 │ selector: 'toh-hero-button', - > 3 │ template: `` - > 4 │ }) - │ ^^ - 5 │ export class HeroButtonComponent { - 6 │ @Output() change = new EventEmitter(); - - -``` - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap index 65d03e4ca81..105671c1320 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap @@ -37,7 +37,7 @@ export class Board { ```diff --- Prettier +++ Rome -@@ -1,20 +1,14 @@ +@@ -1,20 +1,17 @@ @Entity() export class Board { - @PrimaryGeneratedColumn() @@ -62,7 +62,10 @@ export class Board { - @OneToMany((type) => Topic, (topic) => topic.board) - topics: Topic[]; -+ @OneToMany(type => Topic, topic => topic.board) topics: Topic[]; ++ @OneToMany( ++ (type) => Topic, ++ (topic) => topic.board, ++ ) topics: Topic[]; } ``` @@ -81,22 +84,11 @@ export class Board { @Column() description: string; - @OneToMany(type => Topic, topic => topic.board) topics: Topic[]; + @OneToMany( + (type) => Topic, + (topic) => topic.board, + ) topics: Topic[]; } ``` -# Errors -``` -typeorm.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here - - > 1 │ @Entity() - │ ^^^^^^^^^ - 2 │ export class Board { - 3 │ - - -``` - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/argument-list-preserve-line.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/argument-list-preserve-line.ts.snap index 3002e38e985..ba011291f32 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/argument-list-preserve-line.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/argument-list-preserve-line.ts.snap @@ -69,7 +69,7 @@ class Foo { ``` argument-list-preserve-line.ts:3:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 1 │ class Foo { 2 │ constructor( @@ -78,9 +78,11 @@ argument-list-preserve-line.ts:3:9 parse ━━━━━━━━━━━━━ 4 │ private readonly bar: IBar, 5 │ + i Decorators are only valid on class declarations, class expressions, and class methods. + argument-list-preserve-line.ts:6:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 4 │ private readonly bar: IBar, 5 │ @@ -89,9 +91,11 @@ argument-list-preserve-line.ts:6:9 parse ━━━━━━━━━━━━━ 7 │ private readonly myProcessor: IMyProcessor, 8 │ + i Decorators are only valid on class declarations, class expressions, and class methods. + argument-list-preserve-line.ts:9:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 7 │ private readonly myProcessor: IMyProcessor, 8 │ @@ -100,6 +104,8 @@ argument-list-preserve-line.ts:9:9 parse ━━━━━━━━━━━━━ 10 │ 11 │ private readonly anotherThing: IAnotherThing | undefined, + i Decorators are only valid on class declarations, class expressions, and class methods. + ``` 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 5364c875e0b..653e2fa9557 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 @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: typescript/decorators/decorators-comments.ts --- @@ -58,8 +57,45 @@ class Something3 { ```diff --- Prettier +++ Rome -@@ -30,12 +30,12 @@ - +@@ -1,41 +1,36 @@ + class Foo1 { +- @foo +- // comment +- async method() {} ++ @foo async // comment ++ method() {} + } + + class Foo2 { +- @foo +- // comment ++ @foo // comment + private method() {} + } + + class Foo3 { +- @foo +- // comment +- *method() {} ++ @foo *// comment ++ method() {} + } + + class Foo4 { +- @foo +- // comment +- async *method() {} ++ @foo async *// comment ++ method() {} + } + + class Something { +- @foo() +- // comment ++ @foo() // comment + readonly property: Array; + } + class Something2 { @foo() - // comment @@ -67,7 +103,7 @@ class Something3 { + // comment + abstract property: Array } - + class Something3 { @foo() - // comment @@ -81,32 +117,27 @@ class Something3 { ```ts class Foo1 { - @foo - // comment - async method() {} + @foo async // comment + method() {} } class Foo2 { - @foo - // comment + @foo // comment private method() {} } class Foo3 { - @foo - // comment - *method() {} + @foo *// comment + method() {} } class Foo4 { - @foo - // comment - async *method() {} + @foo async *// comment + method() {} } class Something { - @foo() - // comment + @foo() // comment readonly property: Array; } @@ -128,25 +159,49 @@ class Something3 { decorators-comments.ts:35:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Only abstract classes can have abstract members - + 33 │ @foo() 34 │ // comment > 35 │ abstract property: Array │ ^^^^^^^^ 36 │ } - 37 │ - + 37 │ + +decorators-comments.ts:33:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 32 │ class Something2 { + > 33 │ @foo() + │ ^^^^^^ + 34 │ // comment + 35 │ abstract property: Array + + i Decorators are only valid on class declarations, class expressions, and class methods. + decorators-comments.ts:41:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Only abstract classes can have abstract members - + 39 │ @foo() 40 │ // comment > 41 │ abstract method(): Array │ ^^^^^^^^ 42 │ } - 43 │ - + 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_formatter/tests/specs/prettier/typescript/decorators/decorators.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators.ts.snap index c04c92715bc..1915050b253 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators.ts.snap @@ -92,25 +92,26 @@ class Class6 { ```diff --- Prettier +++ Rome -@@ -1,5 +1,7 @@ +@@ -1,5 +1,8 @@ export class TestTextFileService { - constructor(@ILifecycleService lifecycleService) {} + constructor( -+ @ILifecycleService lifecycleService, -+ ) {} ++ @ILifecycleService lifecycleService, ++ ) { ++ } } - + @commonEditorContribution -@@ -50,12 +52,24 @@ +@@ -50,12 +53,24 @@ } - + class Class5 { - method(@Decorator { prop1 }: Type) {} + method( + @Decorator { prop1 }: Type, + ) {} } - + class Class6 { - method(@Decorator({}) { prop1 }: Type) {} - method(@Decorator({}) { prop1 }: Type) {} @@ -138,8 +139,9 @@ class Class6 { ```ts export class TestTextFileService { constructor( - @ILifecycleService lifecycleService, - ) {} + @ILifecycleService lifecycleService, + ) { + } } @commonEditorContribution @@ -213,4 +215,22 @@ class Class6 { } ``` +# Errors +``` +decorators.ts:3:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 1 │ export class TestTextFileService { + 2 │ constructor( + > 3 │ @ILifecycleService lifecycleService, + │ ^^^^^^^^^^^^^^^^^^ + 4 │ ) { + 5 │ } + + i Decorators are only valid on class declarations, class expressions, and class methods. + + +``` + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap index 1cf9afad02e..e4ce3729e0c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap @@ -64,20 +64,32 @@ class MyContainerComponent { ```diff --- Prettier +++ Rome -@@ -6,9 +6,9 @@ - +@@ -5,20 +5,13 @@ + class Class1 {} + class Class2 { - @d1 +- @d1 - @d2(foo) - @d3.bar - @d4.baz() -+ @d2(foo) -+ @d3.bar -+ @d4.baz() - method1() {} - - @d1 -@@ -30,11 +30,10 @@ +- method1() {} ++ @d1 @d2(foo) @d3.bar @d4.baz() method1() {} + +- @d1 +- method2() {} ++ @d1 method2() {} + +- @d2(foo) +- method3() {} ++ @d2(foo) method3() {} + +- @d3.bar +- method4() {} ++ @d3.bar method4() {} + } + + class Class3 { +@@ -30,11 +23,10 @@ constructor( @d1 private x: number, @d2(foo) private y: number, @@ -91,14 +103,16 @@ class MyContainerComponent { + }) private a: string, ) {} } - -@@ -46,6 +45,5 @@ + +@@ -46,6 +38,7 @@ } - + class MyContainerComponent { - @ContentChildren(MyComponent) - components: QueryListSomeBigName; -+ @ContentChildren(MyComponent) components: QueryListSomeBigName; ++ @ContentChildren( ++ MyComponent, ++ ) components: QueryListSomeBigName; } ``` @@ -112,20 +126,13 @@ class MyContainerComponent { class Class1 {} class Class2 { - @d1 - @d2(foo) - @d3.bar - @d4.baz() - method1() {} + @d1 @d2(foo) @d3.bar @d4.baz() method1() {} - @d1 - method2() {} + @d1 method2() {} - @d2(foo) - method3() {} + @d2(foo) method3() {} - @d3.bar - method4() {} + @d3.bar method4() {} } class Class3 { @@ -152,13 +159,69 @@ class Bar { } class MyContainerComponent { - @ContentChildren(MyComponent) components: QueryListSomeBigName; + @ContentChildren( + MyComponent, + ) components: QueryListSomeBigName; } ``` -# Lines exceeding max width of 80 characters +# Errors ``` - 48: @ContentChildren(MyComponent) components: QueryListSomeBigName; +inline-decorators.ts:32:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 31 │ constructor ( + > 32 │ @d1 private x: number, + │ ^^^ + 33 │ @d2(foo) private y: number, + 34 │ @d3('foo') private z: number, + + i Decorators are only valid on class declarations, class expressions, and class methods. + +inline-decorators.ts:33:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 31 │ constructor ( + 32 │ @d1 private x: number, + > 33 │ @d2(foo) private y: number, + │ ^^^^^^^^ + 34 │ @d3('foo') private z: number, + 35 │ @d4({ + + i Decorators are only valid on class declarations, class expressions, and class methods. + +inline-decorators.ts:34:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 32 │ @d1 private x: number, + 33 │ @d2(foo) private y: number, + > 34 │ @d3('foo') private z: number, + │ ^^^^^^^^^^ + 35 │ @d4({ + 36 │ x: string + + i Decorators are only valid on class declarations, class expressions, and class methods. + +inline-decorators.ts:35:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 33 │ @d2(foo) private y: number, + 34 │ @d3('foo') private z: number, + > 35 │ @d4({ + │ ^^^^^ + > 36 │ x: string + > 37 │ }) private a: string, + │ ^^ + 38 │ ) {} + 39 │ } + + 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 c0120b7bf46..01dbbba10a0 100644 --- a/crates/rome_js_parser/src/syntax/class.rs +++ b/crates/rome_js_parser/src/syntax/class.rs @@ -6,8 +6,7 @@ use crate::state::{ }; use crate::syntax::binding::parse_binding; use crate::syntax::expr::{ - parse_assignment_expression_or_higher, parse_expression, parse_lhs_expr, parse_private_name, - ExpressionContext, + parse_assignment_expression_or_higher, parse_lhs_expr, parse_private_name, ExpressionContext, }; use crate::syntax::function::{ parse_any_parameter, parse_formal_parameter, parse_function_body, parse_parameter_list, diff --git a/crates/rome_js_parser/test_data/inline/err/decorator.rast b/crates/rome_js_parser/test_data/inline/err/decorator.rast index 99f704d844e..21eb31746fa 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator.rast @@ -1112,730 +1112,730 @@ JsModule { decorator.ts:1:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `'dsads'` - + > 1 │ @'dsads' class MyClass {} │ ^^^^^^^ 2 │ @1 class MyClass {} 3 │ @++1 class MyClass {} - + -- decorator.ts:2:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `1` - + 1 │ @'dsads' class MyClass {} > 2 │ @1 class MyClass {} │ ^ 3 │ @++1 class MyClass {} 4 │ @[] in 1 class MyClass {} - + -- decorator.ts:3:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression but instead found '++' - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + i Expected an expression here - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + -- decorator.ts:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:3:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid assignment to `1` - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + i This expression cannot be assigned to - + -- decorator.ts:3:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^^^^^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + i An explicit or implicit semicolon is expected here... - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^^^^^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + i ...Which is required to end this statement - + 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} > 3 │ @++1 class MyClass {} │ ^^^^^^^^^ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} - + -- decorator.ts:4:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `[]` - + 2 │ @1 class MyClass {} 3 │ @++1 class MyClass {} > 4 │ @[] in 1 class MyClass {} │ ^^ 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} - + -- decorator.ts:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 2 │ @1 class MyClass {} 3 │ @++1 class MyClass {} > 4 │ @[] in 1 class MyClass {} │ ^^^ 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:4:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found 'in 1' - + 2 │ @1 class MyClass {} 3 │ @++1 class MyClass {} > 4 │ @[] in 1 class MyClass {} │ ^^^^ 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} - + i Expected a statement here - + 2 │ @1 class MyClass {} 3 │ @++1 class MyClass {} > 4 │ @[] in 1 class MyClass {} │ ^^^^ 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} - + -- decorator.ts:5:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `[]` - + 3 │ @++1 class MyClass {} 4 │ @[] in 1 class MyClass {} > 5 │ @[] class MyClass {} │ ^^ 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} - + -- decorator.ts:6:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Parenthesized expression didnt contain anything - + 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} > 6 │ @() => {} class MyClass {} │ ^ 7 │ @1 == 2 ? true : false class MyClass {} 8 │ @await fn class MyClass {} - + i Expected an expression here - + -- decorator.ts:6:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} > 6 │ @() => {} class MyClass {} │ ^^^ 7 │ @1 == 2 ? true : false class MyClass {} 8 │ @await fn class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '=>' - + 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} > 6 │ @() => {} class MyClass {} │ ^^ 7 │ @1 == 2 ? true : false class MyClass {} 8 │ @await fn class MyClass {} - + i Expected a statement here - + 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} > 6 │ @() => {} class MyClass {} │ ^^ 7 │ @1 == 2 ? true : false class MyClass {} 8 │ @await fn class MyClass {} - + -- decorator.ts:7:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `1` - + 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} > 7 │ @1 == 2 ? true : false class MyClass {} │ ^ 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} - + -- decorator.ts:7:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} > 7 │ @1 == 2 ? true : false class MyClass {} │ ^^ 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:7:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '== 2 ? true : false' - + 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} > 7 │ @1 == 2 ? true : false class MyClass {} │ ^^^^^^^^^^^^^^^^^^^ 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} - + i Expected a statement here - + 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} > 7 │ @1 == 2 ? true : false class MyClass {} │ ^^^^^^^^^^^^^^^^^^^ 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} - + -- decorator.ts:8:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Illegal use of `await` as an identifier in an async context - + 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} > 8 │ @await fn class MyClass {} │ ^^^^^ 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} - + -- decorator.ts:8:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} > 8 │ @await fn class MyClass {} │ ^^^^^^ 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:8:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} > 8 │ @await fn class MyClass {} │ ^^^^^ 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} - + i An explicit or implicit semicolon is expected here... - + 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} > 8 │ @await fn class MyClass {} │ ^^^^^ 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} - + i ...Which is required to end this statement - + 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} > 8 │ @await fn class MyClass {} │ ^^^^^^^^ 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} - + -- decorator.ts:9:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `function(){}` - + 7 │ @1 == 2 ? true : false class MyClass {} 8 │ @await fn class MyClass {} > 9 │ @function(){} class MyClass {} │ ^^^^^^^^^^^^ 10 │ @obj instanceof Object class MyClass {} 11 │ @1 === 2 class MyClass {} - + -- decorator.ts:10:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} > 10 │ @obj instanceof Object class MyClass {} │ ^^^^ 11 │ @1 === 2 class MyClass {} 12 │ @new Object() class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:10:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found 'instanceof Object' - + 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} > 10 │ @obj instanceof Object class MyClass {} │ ^^^^^^^^^^^^^^^^^ 11 │ @1 === 2 class MyClass {} 12 │ @new Object() class MyClass {} - + i Expected a statement here - + 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} > 10 │ @obj instanceof Object class MyClass {} │ ^^^^^^^^^^^^^^^^^ 11 │ @1 === 2 class MyClass {} 12 │ @new Object() class MyClass {} - + -- decorator.ts:11:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `1` - + 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} > 11 │ @1 === 2 class MyClass {} │ ^ 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} - + -- decorator.ts:11:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} > 11 │ @1 === 2 class MyClass {} │ ^^ 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:11:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '=== 2' - + 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} > 11 │ @1 === 2 class MyClass {} │ ^^^^^ 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} - + i Expected a statement here - + 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} > 11 │ @1 === 2 class MyClass {} │ ^^^^^ 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} - + -- decorator.ts:12:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `new Object()` - + 10 │ @obj instanceof Object class MyClass {} 11 │ @1 === 2 class MyClass {} > 12 │ @new Object() class MyClass {} │ ^^^^^^^^^^^^ 13 │ @{} class MyClass {} 14 │ @a++ class MyClass {} - + -- decorator.ts:13:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `{}` - + 11 │ @1 === 2 class MyClass {} 12 │ @new Object() class MyClass {} > 13 │ @{} class MyClass {} │ ^^ 14 │ @a++ class MyClass {} 15 │ @a,b class MyClass {} - + -- decorator.ts:14:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} > 14 │ @a++ class MyClass {} │ ^^ 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:14:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid assignment to `class MyClass {}` - + 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} > 14 │ @a++ class MyClass {} │ ^^^^^^^^^^^^^^^^ 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} - + i This expression cannot be assigned to - + -- decorator.ts:15:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 13 │ @{} class MyClass {} 14 │ @a++ class MyClass {} > 15 │ @a,b class MyClass {} │ ^^ 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:15:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found ',b' - + 13 │ @{} class MyClass {} 14 │ @a++ class MyClass {} > 15 │ @a,b class MyClass {} │ ^^ 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} - + i Expected a statement here - + 13 │ @{} class MyClass {} 14 │ @a++ class MyClass {} > 15 │ @a,b class MyClass {} │ ^^ 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} - + -- decorator.ts:16:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator ``${d}foo`` - + 14 │ @a++ class MyClass {} 15 │ @a,b class MyClass {} > 16 │ @`${d}foo` class MyClass {} │ ^^^^^^^^^ 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} - + -- decorator.ts:17:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:17:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + i An explicit or implicit semicolon is expected here... - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + i ...Which is required to end this statement - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^^^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + -- decorator.ts:17:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + i An explicit or implicit semicolon is expected here... - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + i ...Which is required to end this statement - + 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} > 17 │ @obj as MyType class MyClass {} │ ^^^^^^^^^^^^ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} - + -- decorator.ts:18:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression but instead found '<' - + 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} > 18 │ @obj class MyClass {} │ ^ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} - + i Expected an expression here - + 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} > 18 │ @obj class MyClass {} │ ^ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} - + -- decorator.ts:18:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} > 18 │ @obj class MyClass {} │ ^ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:18:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} > 18 │ @obj class MyClass {} │ ^^^^^ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} - + i An explicit or implicit semicolon is expected here... - + 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} > 18 │ @obj class MyClass {} │ ^^^^^ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} - + i ...Which is required to end this statement - + 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} > 18 │ @obj class MyClass {} │ ^^^^^^^^^^^^^^^^^ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} - + -- decorator.ts:19:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator.ts:19:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + i An explicit or implicit semicolon is expected here... - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + i ...Which is required to end this statement - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^^^^^^^^^^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + -- decorator.ts:19:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a semicolon or an implicit semicolon after a statement, but found none - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + i An explicit or implicit semicolon is expected here... - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + i ...Which is required to end this statement - + 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} > 19 │ @obj satisfies MyType class MyClass {} │ ^^^^^^^^^^^^ 20 │ @obj! class MyClass {} - 21 │ - + 21 │ + -- decorator.ts:20:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Invalid decorator `obj!` - + 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} > 20 │ @obj! class MyClass {} │ ^^^^ - 21 │ - + 21 │ + -- @'dsads' class MyClass {} @1 class MyClass {} diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast index 2d2f8b13db3..e7cc27b4329 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast @@ -166,29 +166,29 @@ JsModule { decorator_class_declaration.js:2:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ function bar() { > 2 │ @decorator │ ^^^^^^^^^^ 3 │ let a; 4 │ @decorator @decorator2 - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator_class_declaration.js:4:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 2 │ @decorator 3 │ let a; > 4 │ @decorator @decorator2 │ ^^^^^^^^^^^^^^^^^^^^^^ 5 │ function Foo() { } 6 │ } - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- function bar() { @decorator diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast index 3961d6c9525..77d4dc45f5b 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast @@ -127,28 +127,28 @@ JsModule { decorator_class_declaration_top_level.js:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + > 1 │ @decorator │ ^^^^^^^^^^ 2 │ let a; 3 │ @decorator1 @decorator2 - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator_class_declaration_top_level.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ @decorator 2 │ let a; > 3 │ @decorator1 @decorator2 │ ^^^^^^^^^^^^^^^^^^^^^^^ 4 │ function Foo() { } - 5 │ - + 5 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- @decorator let a; 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 76c36f22424..e20b5a57b5c 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 @@ -673,7 +673,7 @@ JsModule { -- decorator_class_member.ts:2:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 1 │ class Foo { > 2 │ @dec constructor() {} @@ -681,10 +681,12 @@ decorator_class_member.ts:2:4 parse ━━━━━━━━━━━━━━ 3 │ @dec [index: string]: { props: string } 4 │ } + i Decorators are only valid on class declarations, class expressions, and class methods. + -- decorator_class_member.ts:3:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 1 │ class Foo { 2 │ @dec constructor() {} @@ -693,10 +695,12 @@ decorator_class_member.ts:3:4 parse ━━━━━━━━━━━━━━ 4 │ } 5 │ class Quiz { + i Decorators are only valid on class declarations, class expressions, and class methods. + -- decorator_class_member.ts:6:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 4 │ } 5 │ class Quiz { @@ -705,10 +709,12 @@ decorator_class_member.ts:6:4 parse ━━━━━━━━━━━━━━ 7 │ } 8 │ class Bar extends Foo { + i Decorators are only valid on class declarations, class expressions, and class methods. + -- decorator_class_member.ts:9:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 7 │ } 8 │ class Bar extends Foo { @@ -717,10 +723,12 @@ decorator_class_member.ts:9:4 parse ━━━━━━━━━━━━━━ 10 │ constructor(); 11 │ constructor(a: String) + 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 + × Decorators are not valid here. 13 │ } 14 │ declare class Baz { @@ -729,10 +737,12 @@ decorator_class_member.ts:15:3 parse ━━━━━━━━━━━━━━ 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 + × Decorators are not valid here. 14 │ declare class Baz { 15 │ @dec method(); @@ -741,10 +751,12 @@ decorator_class_member.ts:16:3 parse ━━━━━━━━━━━━━━ 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 + × Decorators are not valid here. 15 │ @dec method(); 16 │ @dec get foo(); @@ -753,10 +765,12 @@ decorator_class_member.ts:17:3 parse ━━━━━━━━━━━━━━ 18 │ } 19 │ abstract class Qux { + i Decorators are only valid on class declarations, class expressions, and class methods. + -- decorator_class_member.ts:20:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here + × Decorators are not valid here. 18 │ } 19 │ abstract class Qux { @@ -765,6 +779,8 @@ decorator_class_member.ts:20:3 parse ━━━━━━━━━━━━━━ 21 │ } 22 │ + i Decorators are only valid on class declarations, class expressions, and class methods. + -- class Foo { @dec constructor() {} diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast index 778f589f949..7cffc766315 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast @@ -141,28 +141,28 @@ JsModule { decorator_export_class_clause.js:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + > 1 │ @decorator │ ^^^^^^^^^^ 2 │ export let a; 3 │ @decorator1 @decorator2 - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator_export_class_clause.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ @decorator 2 │ export let a; > 3 │ @decorator1 @decorator2 │ ^^^^^^^^^^^^^^^^^^^^^^^ 4 │ export function Foo() { } - 5 │ - + 5 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- @decorator export let a; diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast b/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast index fff3346aafe..a4f72217709 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast @@ -306,74 +306,74 @@ JsModule { decorator_expression_class.js:1:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + > 1 │ let a = @decorator () => {}; │ ^^^^^^^^^^^^^ 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) - + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator_expression_class.js:1:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a parenthesis '(' but instead found '=>' - + > 1 │ let a = @decorator () => {}; │ ^^ 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) - + i Expected a parenthesis '(' here - + > 1 │ let a = @decorator () => {}; │ ^^ 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) - + -- decorator_expression_class.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ let a = @decorator () => {}; > 2 │ let b = @first @second function foo() {} │ ^^^^^^^^^^^^^^ 3 │ let a = @decorator ( () => {} ) - 4 │ - + 4 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator_expression_class.js:3:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ let a = @decorator () => {}; 2 │ let b = @first @second function foo() {} > 3 │ let a = @decorator ( () => {} ) │ ^^^^^^^^^^^^^^^^^^^^^^^ - 4 │ - + 4 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- decorator_expression_class.js:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found the end of the file - + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) - > 4 │ - │ - + > 4 │ + │ + i Expected an expression, or an assignment here - + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) - > 4 │ - │ - + > 4 │ + │ + -- let a = @decorator () => {}; let b = @first @second function foo() {} diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_parameters.rast b/crates/rome_js_parser/test_data/inline/err/decorator_parameters.rast new file mode 100644 index 00000000000..9290f312bed --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/decorator_parameters.rast @@ -0,0 +1,133 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsClassDeclaration { + decorators: JsDecoratorList [], + abstract_token: missing (optional), + class_token: CLASS_KW@0..6 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@6..10 "Foo" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@10..11 "{" [] [], + members: JsClassMemberList [ + JsConstructorClassMember { + modifiers: JsConstructorModifierList [], + name: JsLiteralMemberName { + value: IDENT@11..26 "constructor" [Newline("\n"), Whitespace(" ")] [], + }, + parameters: JsConstructorParameters { + l_paren_token: L_PAREN@26..27 "(" [] [], + parameters: JsConstructorParameterList [ + JsBogusParameter { + items: [ + JsBogus { + items: [ + JsDecorator { + at_token: AT@27..28 "@" [] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@28..32 "dec" [] [Whitespace(" ")], + }, + }, + }, + ], + }, + JsFormalParameter { + binding: JsIdentifierBinding { + name_token: IDENT@32..33 "a" [] [], + }, + question_mark_token: missing (optional), + type_annotation: TsTypeAnnotation { + colon_token: COLON@33..35 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@35..41 "string" [] [], + }, + }, + initializer: missing (optional), + }, + ], + }, + ], + r_paren_token: R_PAREN@41..43 ")" [] [Whitespace(" ")], + }, + body: JsFunctionBody { + l_curly_token: L_CURLY@43..44 "{" [] [], + directives: JsDirectiveList [], + statements: JsStatementList [], + r_curly_token: R_CURLY@44..45 "}" [] [], + }, + }, + ], + r_curly_token: R_CURLY@45..47 "}" [Newline("\n")] [], + }, + ], + eof_token: EOF@47..48 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..48 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..47 + 0: JS_CLASS_DECLARATION@0..47 + 0: JS_DECORATOR_LIST@0..0 + 1: (empty) + 2: CLASS_KW@0..6 "class" [] [Whitespace(" ")] + 3: JS_IDENTIFIER_BINDING@6..10 + 0: IDENT@6..10 "Foo" [] [Whitespace(" ")] + 4: (empty) + 5: (empty) + 6: (empty) + 7: L_CURLY@10..11 "{" [] [] + 8: JS_CLASS_MEMBER_LIST@11..45 + 0: JS_CONSTRUCTOR_CLASS_MEMBER@11..45 + 0: JS_CONSTRUCTOR_MODIFIER_LIST@11..11 + 1: JS_LITERAL_MEMBER_NAME@11..26 + 0: IDENT@11..26 "constructor" [Newline("\n"), Whitespace(" ")] [] + 2: JS_CONSTRUCTOR_PARAMETERS@26..43 + 0: L_PAREN@26..27 "(" [] [] + 1: JS_CONSTRUCTOR_PARAMETER_LIST@27..41 + 0: JS_BOGUS_PARAMETER@27..41 + 0: JS_BOGUS@27..32 + 0: JS_DECORATOR@27..32 + 0: AT@27..28 "@" [] [] + 1: JS_IDENTIFIER_EXPRESSION@28..32 + 0: JS_REFERENCE_IDENTIFIER@28..32 + 0: IDENT@28..32 "dec" [] [Whitespace(" ")] + 1: JS_FORMAL_PARAMETER@32..41 + 0: JS_IDENTIFIER_BINDING@32..33 + 0: IDENT@32..33 "a" [] [] + 1: (empty) + 2: TS_TYPE_ANNOTATION@33..41 + 0: COLON@33..35 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@35..41 + 0: STRING_KW@35..41 "string" [] [] + 3: (empty) + 2: R_PAREN@41..43 ")" [] [Whitespace(" ")] + 3: JS_FUNCTION_BODY@43..45 + 0: L_CURLY@43..44 "{" [] [] + 1: JS_DIRECTIVE_LIST@44..44 + 2: JS_STATEMENT_LIST@44..44 + 3: R_CURLY@44..45 "}" [] [] + 9: R_CURLY@45..47 "}" [Newline("\n")] [] + 3: EOF@47..48 "" [Newline("\n")] [] +-- +decorator_parameters.ts:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 1 │ class Foo { + > 2 │ constructor(@dec a: string) {} + │ ^^^^ + 3 │ } + 4 │ + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +class Foo { + constructor(@dec a: string) {} +} diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_parameters.ts b/crates/rome_js_parser/test_data/inline/err/decorator_parameters.ts new file mode 100644 index 00000000000..cac9e6790d7 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/decorator_parameters.ts @@ -0,0 +1,3 @@ +class Foo { + constructor(@dec a: string) {} +} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast b/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast index 906db442436..b43e1c3f458 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast @@ -117,26 +117,26 @@ JsModule { ts_declare_const_initializer.ts:1:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + > 1 │ declare @decorator class D {} │ ^^^^^^^^^^ 2 │ declare @decorator abstract class D {} - 3 │ - + 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- ts_declare_const_initializer.ts:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ declare @decorator class D {} > 2 │ declare @decorator abstract class D {} │ ^^^^^^^^^^ - 3 │ - + 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- declare @decorator class D {} declare @decorator abstract class D {} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast b/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast index 4a303b1377a..032f272ccbf 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast @@ -135,26 +135,26 @@ JsModule { ts_export_declare.ts:1:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + > 1 │ export declare @decorator class D {} │ ^^^^^^^^^^ 2 │ export declare @decorator abstract class D {} - 3 │ - + 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- ts_export_declare.ts:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Decorators are not valid here. - + 1 │ export declare @decorator class D {} > 2 │ export declare @decorator abstract class D {} │ ^^^^^^^^^^ - 3 │ - + 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods. - + -- export declare @decorator class D {} export declare @decorator abstract class D {} 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 b359822afc2..338851b7ae9 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 @@ -14,107 +14,220 @@ JsModule { implements_clause: missing (optional), l_curly_token: L_CURLY@20..21 "{" [] [], members: JsClassMemberList [ - TsMethodSignatureClassMember { - modifiers: TsMethodSignatureModifierList [], - async_token: missing (optional), - name: JsLiteralMemberName { - value: IDENT@21..36 "method" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [], - }, - question_mark_token: missing (optional), - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@36..37 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@37..38 ")" [] [], - }, - return_type_annotation: missing (optional), - semicolon_token: SEMICOLON@38..39 ";" [] [], + JsBogusMember { + items: [ + JsBogus { + items: [ + JsDecorator { + at_token: AT@21..25 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@25..30 "test" [] [Whitespace(" ")], + }, + }, + }, + ], + }, + JsLiteralMemberName { + value: IDENT@30..41 "constructor" [] [], + }, + JsConstructorParameters { + l_paren_token: L_PAREN@41..42 "(" [] [], + parameters: JsConstructorParameterList [], + r_paren_token: R_PAREN@42..44 ")" [] [Whitespace(" ")], + }, + JsFunctionBody { + l_curly_token: L_CURLY@44..45 "{" [] [], + directives: JsDirectiveList [], + statements: JsStatementList [], + r_curly_token: R_CURLY@45..46 "}" [] [], + }, + ], }, - TsIndexSignatureClassMember { - modifiers: TsIndexSignatureModifierList [], - l_brack_token: L_BRACK@39..49 "[" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [], - parameter: TsIndexSignatureParameter { - binding: JsIdentifierBinding { - name_token: IDENT@49..54 "index" [] [], - }, - type_annotation: TsTypeAnnotation { - colon_token: COLON@54..56 ":" [] [Whitespace(" ")], - ty: TsStringType { - string_token: STRING_KW@56..62 "string" [] [], + JsBogusMember { + items: [ + JsBogus { + items: [ + JsDecorator { + at_token: AT@46..50 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@50..55 "test" [] [Whitespace(" ")], + }, + }, + }, + TsDeclareModifier { + modifier_token: DECLARE_KW@55..63 "declare" [] [Whitespace(" ")], + }, + ], + }, + JsLiteralMemberName { + value: IDENT@63..67 "prop" [] [], + }, + SEMICOLON@67..68 ";" [] [], + ], + }, + JsBogusMember { + items: [ + JsBogus { + items: [ + 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 ";" [] [], + ], + }, + JsBogusMember { + items: [ + JsBogus { + items: [ + JsDecorator { + at_token: AT@86..90 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@90..95 "test" [] [Whitespace(" ")], + }, + }, + }, + ], + }, + L_BRACK@95..96 "[" [] [], + TsIndexSignatureParameter { + binding: JsIdentifierBinding { + name_token: IDENT@96..101 "index" [] [], + }, + type_annotation: TsTypeAnnotation { + colon_token: COLON@101..103 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@103..109 "string" [] [], + }, }, }, - }, - r_brack_token: R_BRACK@62..63 "]" [] [], - type_annotation: TsTypeAnnotation { - colon_token: COLON@63..65 ":" [] [Whitespace(" ")], - ty: TsStringType { - string_token: STRING_KW@65..71 "string" [] [], + R_BRACK@109..110 "]" [] [], + TsTypeAnnotation { + colon_token: COLON@110..112 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@112..118 "string" [] [], + }, }, - }, - semicolon_token: SEMICOLON@71..72 ";" [] [], + SEMICOLON@118..119 ";" [] [], + ], }, - TsMethodSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - TsAbstractModifier { - modifier_token: ABSTRACT_KW@72..90 "abstract" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")], + JsBogusMember { + items: [ + JsBogus { + items: [ + 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" [] [], + }, + 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@90..97 "method2" [] [], - }, - question_mark_token: missing (optional), - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@97..98 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@98..99 ")" [] [], - }, - return_type_annotation: missing (optional), - semicolon_token: SEMICOLON@99..100 ";" [] [], }, - TsGetterSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - TsAbstractModifier { - modifier_token: ABSTRACT_KW@100..118 "abstract" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")], + JsBogusMember { + items: [ + JsBogus { + items: [ + 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" [] [], + }, + L_PAREN@175..176 "(" [] [], + R_PAREN@176..177 ")" [] [], + SEMICOLON@177..178 ";" [] [], ], - get_token: GET_KW@118..122 "get" [] [Whitespace(" ")], - name: JsLiteralMemberName { - value: IDENT@122..128 "getter" [] [], - }, - l_paren_token: L_PAREN@128..129 "(" [] [], - r_paren_token: R_PAREN@129..130 ")" [] [], - return_type: missing (optional), - semicolon_token: SEMICOLON@130..131 ";" [] [], }, - TsSetterSignatureClassMember { - modifiers: TsMethodSignatureModifierList [ - TsAbstractModifier { - modifier_token: ABSTRACT_KW@131..149 "abstract" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")], + JsBogusMember { + items: [ + JsBogus { + items: [ + 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" [] [], + }, + 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@149..153 "set" [] [Whitespace(" ")], - name: JsLiteralMemberName { - value: IDENT@153..159 "setter" [] [], - }, - l_paren_token: L_PAREN@159..160 "(" [] [], - parameter: missing (required), - r_paren_token: R_PAREN@160..161 ")" [] [], - semicolon_token: SEMICOLON@161..162 ";" [] [], }, ], - r_curly_token: R_CURLY@162..164 "}" [Newline("\n")] [], + r_curly_token: R_CURLY@212..214 "}" [Newline("\n")] [], }, ], - eof_token: EOF@164..165 "" [Newline("\n")] [], + eof_token: EOF@214..215 "" [Newline("\n")] [], } -0: JS_MODULE@0..165 +0: JS_MODULE@0..215 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..164 - 0: JS_CLASS_DECLARATION@0..164 + 2: JS_MODULE_ITEM_LIST@0..214 + 0: JS_CLASS_DECLARATION@0..214 0: JS_DECORATOR_LIST@0..0 1: ABSTRACT_KW@0..9 "abstract" [] [Whitespace(" ")] 2: CLASS_KW@9..15 "class" [] [Whitespace(" ")] @@ -124,101 +237,230 @@ JsModule { 5: (empty) 6: (empty) 7: L_CURLY@20..21 "{" [] [] - 8: JS_CLASS_MEMBER_LIST@21..162 - 0: TS_METHOD_SIGNATURE_CLASS_MEMBER@21..39 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@21..21 - 1: (empty) - 2: JS_LITERAL_MEMBER_NAME@21..36 - 0: IDENT@21..36 "method" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [] - 3: (empty) - 4: (empty) - 5: JS_PARAMETERS@36..38 - 0: L_PAREN@36..37 "(" [] [] - 1: JS_PARAMETER_LIST@37..37 - 2: R_PAREN@37..38 ")" [] [] - 6: (empty) - 7: SEMICOLON@38..39 ";" [] [] - 1: TS_INDEX_SIGNATURE_CLASS_MEMBER@39..72 - 0: TS_INDEX_SIGNATURE_MODIFIER_LIST@39..39 - 1: L_BRACK@39..49 "[" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [] - 2: TS_INDEX_SIGNATURE_PARAMETER@49..62 - 0: JS_IDENTIFIER_BINDING@49..54 - 0: IDENT@49..54 "index" [] [] - 1: TS_TYPE_ANNOTATION@54..62 - 0: COLON@54..56 ":" [] [Whitespace(" ")] - 1: TS_STRING_TYPE@56..62 - 0: STRING_KW@56..62 "string" [] [] - 3: R_BRACK@62..63 "]" [] [] - 4: TS_TYPE_ANNOTATION@63..71 - 0: COLON@63..65 ":" [] [Whitespace(" ")] - 1: TS_STRING_TYPE@65..71 - 0: STRING_KW@65..71 "string" [] [] - 5: SEMICOLON@71..72 ";" [] [] - 2: TS_METHOD_SIGNATURE_CLASS_MEMBER@72..100 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@72..90 - 0: TS_ABSTRACT_MODIFIER@72..90 - 0: ABSTRACT_KW@72..90 "abstract" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")] - 1: (empty) - 2: JS_LITERAL_MEMBER_NAME@90..97 - 0: IDENT@90..97 "method2" [] [] - 3: (empty) - 4: (empty) - 5: JS_PARAMETERS@97..99 - 0: L_PAREN@97..98 "(" [] [] - 1: JS_PARAMETER_LIST@98..98 - 2: R_PAREN@98..99 ")" [] [] - 6: (empty) - 7: SEMICOLON@99..100 ";" [] [] - 3: TS_GETTER_SIGNATURE_CLASS_MEMBER@100..131 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@100..118 - 0: TS_ABSTRACT_MODIFIER@100..118 - 0: ABSTRACT_KW@100..118 "abstract" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")] - 1: GET_KW@118..122 "get" [] [Whitespace(" ")] - 2: JS_LITERAL_MEMBER_NAME@122..128 - 0: IDENT@122..128 "getter" [] [] - 3: L_PAREN@128..129 "(" [] [] - 4: R_PAREN@129..130 ")" [] [] - 5: (empty) - 6: SEMICOLON@130..131 ";" [] [] - 4: TS_SETTER_SIGNATURE_CLASS_MEMBER@131..162 - 0: TS_METHOD_SIGNATURE_MODIFIER_LIST@131..149 - 0: TS_ABSTRACT_MODIFIER@131..149 - 0: ABSTRACT_KW@131..149 "abstract" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")] - 1: SET_KW@149..153 "set" [] [Whitespace(" ")] - 2: JS_LITERAL_MEMBER_NAME@153..159 - 0: IDENT@153..159 "setter" [] [] - 3: L_PAREN@159..160 "(" [] [] - 4: (empty) - 5: R_PAREN@160..161 ")" [] [] - 6: SEMICOLON@161..162 ";" [] [] - 9: R_CURLY@162..164 "}" [Newline("\n")] [] - 3: EOF@164..165 "" [Newline("\n")] [] + 8: JS_CLASS_MEMBER_LIST@21..212 + 0: JS_BOGUS_MEMBER@21..46 + 0: JS_BOGUS@21..30 + 0: JS_DECORATOR@21..30 + 0: AT@21..25 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@25..30 + 0: JS_REFERENCE_IDENTIFIER@25..30 + 0: IDENT@25..30 "test" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@30..41 + 0: IDENT@30..41 "constructor" [] [] + 2: JS_CONSTRUCTOR_PARAMETERS@41..44 + 0: L_PAREN@41..42 "(" [] [] + 1: JS_CONSTRUCTOR_PARAMETER_LIST@42..42 + 2: R_PAREN@42..44 ")" [] [Whitespace(" ")] + 3: JS_FUNCTION_BODY@44..46 + 0: L_CURLY@44..45 "{" [] [] + 1: JS_DIRECTIVE_LIST@45..45 + 2: JS_STATEMENT_LIST@45..45 + 3: R_CURLY@45..46 "}" [] [] + 1: JS_BOGUS_MEMBER@46..68 + 0: JS_BOGUS@46..63 + 0: JS_DECORATOR@46..55 + 0: AT@46..50 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@50..55 + 0: JS_REFERENCE_IDENTIFIER@50..55 + 0: IDENT@50..55 "test" [] [Whitespace(" ")] + 1: TS_DECLARE_MODIFIER@55..63 + 0: DECLARE_KW@55..63 "declare" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@63..67 + 0: IDENT@63..67 "prop" [] [] + 2: SEMICOLON@67..68 ";" [] [] + 2: JS_BOGUS_MEMBER@68..86 + 0: JS_BOGUS@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: JS_LITERAL_MEMBER_NAME@77..83 + 0: IDENT@77..83 "method" [] [] + 2: JS_PARAMETERS@83..85 + 0: L_PAREN@83..84 "(" [] [] + 1: JS_PARAMETER_LIST@84..84 + 2: R_PAREN@84..85 ")" [] [] + 3: SEMICOLON@85..86 ";" [] [] + 3: JS_BOGUS_MEMBER@86..119 + 0: JS_BOGUS@86..95 + 0: JS_DECORATOR@86..95 + 0: AT@86..90 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@90..95 + 0: JS_REFERENCE_IDENTIFIER@90..95 + 0: IDENT@90..95 "test" [] [Whitespace(" ")] + 1: L_BRACK@95..96 "[" [] [] + 2: TS_INDEX_SIGNATURE_PARAMETER@96..109 + 0: JS_IDENTIFIER_BINDING@96..101 + 0: IDENT@96..101 "index" [] [] + 1: TS_TYPE_ANNOTATION@101..109 + 0: COLON@101..103 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@103..109 + 0: STRING_KW@103..109 "string" [] [] + 3: R_BRACK@109..110 "]" [] [] + 4: TS_TYPE_ANNOTATION@110..118 + 0: COLON@110..112 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@112..118 + 0: STRING_KW@112..118 "string" [] [] + 5: SEMICOLON@118..119 ";" [] [] + 4: JS_BOGUS_MEMBER@119..147 + 0: JS_BOGUS@119..137 + 0: JS_DECORATOR@119..128 + 0: AT@119..123 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@123..128 + 0: JS_REFERENCE_IDENTIFIER@123..128 + 0: IDENT@123..128 "test" [] [Whitespace(" ")] + 1: TS_ABSTRACT_MODIFIER@128..137 + 0: ABSTRACT_KW@128..137 "abstract" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@137..144 + 0: IDENT@137..144 "method2" [] [] + 2: JS_PARAMETERS@144..146 + 0: L_PAREN@144..145 "(" [] [] + 1: JS_PARAMETER_LIST@145..145 + 2: R_PAREN@145..146 ")" [] [] + 3: SEMICOLON@146..147 ";" [] [] + 5: JS_BOGUS_MEMBER@147..178 + 0: JS_BOGUS@147..165 + 0: JS_DECORATOR@147..156 + 0: AT@147..151 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@151..156 + 0: JS_REFERENCE_IDENTIFIER@151..156 + 0: IDENT@151..156 "test" [] [Whitespace(" ")] + 1: TS_ABSTRACT_MODIFIER@156..165 + 0: ABSTRACT_KW@156..165 "abstract" [] [Whitespace(" ")] + 1: GET_KW@165..169 "get" [] [Whitespace(" ")] + 2: JS_LITERAL_MEMBER_NAME@169..175 + 0: IDENT@169..175 "getter" [] [] + 3: L_PAREN@175..176 "(" [] [] + 4: R_PAREN@176..177 ")" [] [] + 5: SEMICOLON@177..178 ";" [] [] + 6: JS_BOGUS_MEMBER@178..212 + 0: JS_BOGUS@178..196 + 0: JS_DECORATOR@178..187 + 0: AT@178..182 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@182..187 + 0: JS_REFERENCE_IDENTIFIER@182..187 + 0: IDENT@182..187 "test" [] [Whitespace(" ")] + 1: TS_ABSTRACT_MODIFIER@187..196 + 0: ABSTRACT_KW@187..196 "abstract" [] [Whitespace(" ")] + 1: SET_KW@196..200 "set" [] [Whitespace(" ")] + 2: JS_LITERAL_MEMBER_NAME@200..206 + 0: IDENT@200..206 "setter" [] [] + 3: L_PAREN@206..207 "(" [] [] + 4: JS_FORMAL_PARAMETER@207..210 + 0: JS_IDENTIFIER_BINDING@207..210 + 0: IDENT@207..210 "val" [] [] + 1: (empty) + 2: (empty) + 3: (empty) + 5: R_PAREN@210..211 ")" [] [] + 6: SEMICOLON@211..212 ";" [] [] + 9: R_CURLY@212..214 "}" [Newline("\n")] [] + 3: EOF@214..215 "" [Newline("\n")] [] -- -ts_invalid_decorated_class_members.ts:6:29 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +ts_invalid_decorated_class_members.ts:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × expected a parameter but instead found ')' + × Decorators are not valid here. + + 1 │ abstract class Test { + > 2 │ @test constructor() {} + │ ^^^^^ + 3 │ @test declare prop; + 4 │ @test method(); + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +ts_invalid_decorated_class_members.ts:3:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Decorators are not valid here. + + 1 │ abstract class Test { + 2 │ @test constructor() {} + > 3 │ @test declare prop; + │ ^^^^^ + 4 │ @test method(); + 5 │ @test [index: string]: string; + + 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - 4 │ @test abstract method2(); - 5 │ @test abstract get getter(); - > 6 │ @test abstract set setter(); - │ ^ - 7 │ } - 8 │ + × Decorators are not valid here. + + 3 │ @test declare prop; + 4 │ @test method(); + > 5 │ @test [index: string]: string; + │ ^^^^^ + 6 │ @test abstract method2(); + 7 │ @test abstract get getter(); + + i Decorators are only valid on class declarations, class expressions, and class methods. + +-- +ts_invalid_decorated_class_members.ts:6:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Expected a parameter here + × 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - 4 │ @test abstract method2(); - 5 │ @test abstract get getter(); - > 6 │ @test abstract set setter(); - │ ^ - 7 │ } - 8 │ + × 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() {} + @test declare prop; @test method(); @test [index: string]: string; @test abstract method2(); @test abstract get getter(); - @test abstract set setter(); + @test abstract set setter(val); } diff --git a/crates/rome_js_parser/test_data/inline/ok/ts_decorated_class_members.rast b/crates/rome_js_parser/test_data/inline/ok/ts_decorated_class_members.rast index c8c0907cdae..301d0dd9258 100644 --- a/crates/rome_js_parser/test_data/inline/ok/ts_decorated_class_members.rast +++ b/crates/rome_js_parser/test_data/inline/ok/ts_decorated_class_members.rast @@ -15,9 +15,18 @@ JsModule { l_curly_token: L_CURLY@11..12 "{" [] [], members: JsClassMemberList [ JsPropertyClassMember { - modifiers: JsPropertyModifierList [], + modifiers: JsPropertyModifierList [ + JsDecorator { + at_token: AT@12..16 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@16..21 "test" [] [Whitespace(" ")], + }, + }, + }, + ], name: JsLiteralMemberName { - value: IDENT@12..25 "prop" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [], + value: IDENT@21..25 "prop" [] [], }, property_annotation: TsTypeAnnotation { colon_token: COLON@25..27 ":" [] [Whitespace(" ")], @@ -29,11 +38,20 @@ JsModule { semicolon_token: SEMICOLON@33..34 ";" [] [], }, JsMethodClassMember { - modifiers: JsMethodModifierList [], + modifiers: JsMethodModifierList [ + JsDecorator { + at_token: AT@34..38 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@38..43 "test" [] [Whitespace(" ")], + }, + }, + }, + ], async_token: missing (optional), star_token: missing (optional), name: JsLiteralMemberName { - value: IDENT@34..49 "method" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [], + value: IDENT@43..49 "method" [] [], }, question_mark_token: missing (optional), type_parameters: missing (optional), @@ -51,8 +69,17 @@ JsModule { }, }, JsGetterClassMember { - modifiers: JsMethodModifierList [], - get_token: GET_KW@54..67 "get" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")], + modifiers: JsMethodModifierList [ + JsDecorator { + at_token: AT@54..58 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@58..63 "test" [] [Whitespace(" ")], + }, + }, + }, + ], + get_token: GET_KW@63..67 "get" [] [Whitespace(" ")], name: JsLiteralMemberName { value: IDENT@67..73 "getter" [] [], }, @@ -67,8 +94,17 @@ JsModule { }, }, JsSetterClassMember { - modifiers: JsMethodModifierList [], - set_token: SET_KW@78..91 "set" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")], + modifiers: JsMethodModifierList [ + JsDecorator { + at_token: AT@78..82 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@82..87 "test" [] [Whitespace(" ")], + }, + }, + }, + ], + set_token: SET_KW@87..91 "set" [] [Whitespace(" ")], name: JsLiteralMemberName { value: IDENT@91..97 "setter" [] [], }, @@ -89,47 +125,18 @@ JsModule { r_curly_token: R_CURLY@102..103 "}" [] [], }, }, - JsConstructorClassMember { - modifiers: JsConstructorModifierList [], - name: JsLiteralMemberName { - value: IDENT@103..123 "constructor" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [], - }, - parameters: JsConstructorParameters { - l_paren_token: L_PAREN@123..124 "(" [] [], - parameters: JsConstructorParameterList [], - r_paren_token: R_PAREN@124..126 ")" [] [Whitespace(" ")], - }, - body: JsFunctionBody { - l_curly_token: L_CURLY@126..127 "{" [] [], - directives: JsDirectiveList [], - statements: JsStatementList [], - r_curly_token: R_CURLY@127..128 "}" [] [], - }, - }, - TsPropertySignatureClassMember { - modifiers: TsPropertySignatureModifierList [ - TsDeclareModifier { - modifier_token: DECLARE_KW@128..145 "declare" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")], - }, - ], - name: JsLiteralMemberName { - value: IDENT@145..149 "prop" [] [], - }, - property_annotation: missing (optional), - semicolon_token: SEMICOLON@149..150 ";" [] [], - }, ], - r_curly_token: R_CURLY@150..152 "}" [Newline("\n")] [], + r_curly_token: R_CURLY@103..105 "}" [Newline("\n")] [], }, ], - eof_token: EOF@152..153 "" [Newline("\n")] [], + eof_token: EOF@105..106 "" [Newline("\n")] [], } -0: JS_MODULE@0..153 +0: JS_MODULE@0..106 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..152 - 0: JS_CLASS_DECLARATION@0..152 + 2: JS_MODULE_ITEM_LIST@0..105 + 0: JS_CLASS_DECLARATION@0..105 0: JS_DECORATOR_LIST@0..0 1: (empty) 2: CLASS_KW@0..6 "class" [] [Whitespace(" ")] @@ -139,11 +146,16 @@ JsModule { 5: (empty) 6: (empty) 7: L_CURLY@11..12 "{" [] [] - 8: JS_CLASS_MEMBER_LIST@12..150 + 8: JS_CLASS_MEMBER_LIST@12..103 0: JS_PROPERTY_CLASS_MEMBER@12..34 - 0: JS_PROPERTY_MODIFIER_LIST@12..12 - 1: JS_LITERAL_MEMBER_NAME@12..25 - 0: IDENT@12..25 "prop" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [] + 0: JS_PROPERTY_MODIFIER_LIST@12..21 + 0: JS_DECORATOR@12..21 + 0: AT@12..16 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@16..21 + 0: JS_REFERENCE_IDENTIFIER@16..21 + 0: IDENT@16..21 "test" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@21..25 + 0: IDENT@21..25 "prop" [] [] 2: TS_TYPE_ANNOTATION@25..33 0: COLON@25..27 ":" [] [Whitespace(" ")] 1: TS_STRING_TYPE@27..33 @@ -151,11 +163,16 @@ JsModule { 3: (empty) 4: SEMICOLON@33..34 ";" [] [] 1: JS_METHOD_CLASS_MEMBER@34..54 - 0: JS_METHOD_MODIFIER_LIST@34..34 + 0: JS_METHOD_MODIFIER_LIST@34..43 + 0: JS_DECORATOR@34..43 + 0: AT@34..38 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@38..43 + 0: JS_REFERENCE_IDENTIFIER@38..43 + 0: IDENT@38..43 "test" [] [Whitespace(" ")] 1: (empty) 2: (empty) - 3: JS_LITERAL_MEMBER_NAME@34..49 - 0: IDENT@34..49 "method" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [] + 3: JS_LITERAL_MEMBER_NAME@43..49 + 0: IDENT@43..49 "method" [] [] 4: (empty) 5: (empty) 6: JS_PARAMETERS@49..52 @@ -169,8 +186,13 @@ JsModule { 2: JS_STATEMENT_LIST@53..53 3: R_CURLY@53..54 "}" [] [] 2: JS_GETTER_CLASS_MEMBER@54..78 - 0: JS_METHOD_MODIFIER_LIST@54..54 - 1: GET_KW@54..67 "get" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")] + 0: JS_METHOD_MODIFIER_LIST@54..63 + 0: JS_DECORATOR@54..63 + 0: AT@54..58 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@58..63 + 0: JS_REFERENCE_IDENTIFIER@58..63 + 0: IDENT@58..63 "test" [] [Whitespace(" ")] + 1: GET_KW@63..67 "get" [] [Whitespace(" ")] 2: JS_LITERAL_MEMBER_NAME@67..73 0: IDENT@67..73 "getter" [] [] 3: L_PAREN@73..74 "(" [] [] @@ -182,8 +204,13 @@ JsModule { 2: JS_STATEMENT_LIST@77..77 3: R_CURLY@77..78 "}" [] [] 3: JS_SETTER_CLASS_MEMBER@78..103 - 0: JS_METHOD_MODIFIER_LIST@78..78 - 1: SET_KW@78..91 "set" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")] + 0: JS_METHOD_MODIFIER_LIST@78..87 + 0: JS_DECORATOR@78..87 + 0: AT@78..82 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_IDENTIFIER_EXPRESSION@82..87 + 0: JS_REFERENCE_IDENTIFIER@82..87 + 0: IDENT@82..87 "test" [] [Whitespace(" ")] + 1: SET_KW@87..91 "set" [] [Whitespace(" ")] 2: JS_LITERAL_MEMBER_NAME@91..97 0: IDENT@91..97 "setter" [] [] 3: L_PAREN@97..98 "(" [] [] @@ -199,26 +226,5 @@ JsModule { 1: JS_DIRECTIVE_LIST@102..102 2: JS_STATEMENT_LIST@102..102 3: R_CURLY@102..103 "}" [] [] - 4: JS_CONSTRUCTOR_CLASS_MEMBER@103..128 - 0: JS_CONSTRUCTOR_MODIFIER_LIST@103..103 - 1: JS_LITERAL_MEMBER_NAME@103..123 - 0: IDENT@103..123 "constructor" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [] - 2: JS_CONSTRUCTOR_PARAMETERS@123..126 - 0: L_PAREN@123..124 "(" [] [] - 1: JS_CONSTRUCTOR_PARAMETER_LIST@124..124 - 2: R_PAREN@124..126 ")" [] [Whitespace(" ")] - 3: JS_FUNCTION_BODY@126..128 - 0: L_CURLY@126..127 "{" [] [] - 1: JS_DIRECTIVE_LIST@127..127 - 2: JS_STATEMENT_LIST@127..127 - 3: R_CURLY@127..128 "}" [] [] - 5: TS_PROPERTY_SIGNATURE_CLASS_MEMBER@128..150 - 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@128..145 - 0: TS_DECLARE_MODIFIER@128..145 - 0: DECLARE_KW@128..145 "declare" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("test"), Whitespace(" ")] [Whitespace(" ")] - 1: JS_LITERAL_MEMBER_NAME@145..149 - 0: IDENT@145..149 "prop" [] [] - 2: (empty) - 3: SEMICOLON@149..150 ";" [] [] - 9: R_CURLY@150..152 "}" [Newline("\n")] [] - 3: EOF@152..153 "" [Newline("\n")] [] + 9: R_CURLY@103..105 "}" [Newline("\n")] [] + 3: EOF@105..106 "" [Newline("\n")] [] diff --git a/crates/rome_js_parser/test_data/inline/ok/ts_decorator_call_expression_with_arrow.rast b/crates/rome_js_parser/test_data/inline/ok/ts_decorator_call_expression_with_arrow.rast index 19ee51e12fc..957fd595b1c 100644 --- a/crates/rome_js_parser/test_data/inline/ok/ts_decorator_call_expression_with_arrow.rast +++ b/crates/rome_js_parser/test_data/inline/ok/ts_decorator_call_expression_with_arrow.rast @@ -18,9 +18,53 @@ JsModule { l_curly_token: L_CURLY@17..18 "{" [] [], members: JsClassMemberList [ JsPropertyClassMember { - modifiers: JsPropertyModifierList [], + modifiers: JsPropertyModifierList [ + JsDecorator { + at_token: AT@18..21 "@" [Newline("\n"), Whitespace(" ")] [], + expression: JsCallExpression { + callee: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@21..30 "Decorator" [] [], + }, + }, + optional_chain_token: missing (optional), + type_arguments: missing (optional), + arguments: JsCallArguments { + l_paren_token: L_PAREN@30..31 "(" [] [], + args: JsCallArgumentList [ + JsArrowFunctionExpression { + async_token: missing (optional), + type_parameters: missing (optional), + parameters: JsParameters { + l_paren_token: L_PAREN@31..32 "(" [] [], + items: JsParameterList [ + JsFormalParameter { + binding: JsIdentifierBinding { + name_token: IDENT@32..35 "val" [] [], + }, + question_mark_token: missing (optional), + type_annotation: missing (optional), + initializer: missing (optional), + }, + ], + r_paren_token: R_PAREN@35..37 ")" [] [Whitespace(" ")], + }, + return_type_annotation: missing (optional), + fat_arrow_token: FAT_ARROW@37..40 "=>" [] [Whitespace(" ")], + body: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@40..43 "val" [] [], + }, + }, + }, + ], + r_paren_token: R_PAREN@43..44 ")" [] [], + }, + }, + }, + ], name: JsLiteralMemberName { - value: IDENT@18..54 "badField" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("Decorator"), Skipped("("), Skipped("("), Skipped("val"), Skipped(")"), Whitespace(" "), Skipped("=>"), Whitespace(" "), Skipped("val"), Skipped(")"), Newline("\n"), Whitespace(" ")] [], + value: IDENT@44..54 "badField" [Newline("\n"), Whitespace(" ")] [], }, property_annotation: TsDefinitePropertyAnnotation { excl_token: BANG@54..55 "!" [] [], @@ -61,9 +105,39 @@ JsModule { 7: L_CURLY@17..18 "{" [] [] 8: JS_CLASS_MEMBER_LIST@18..63 0: JS_PROPERTY_CLASS_MEMBER@18..63 - 0: JS_PROPERTY_MODIFIER_LIST@18..18 - 1: JS_LITERAL_MEMBER_NAME@18..54 - 0: IDENT@18..54 "badField" [Newline("\n"), Whitespace(" "), Skipped("@"), Skipped("Decorator"), Skipped("("), Skipped("("), Skipped("val"), Skipped(")"), Whitespace(" "), Skipped("=>"), Whitespace(" "), Skipped("val"), Skipped(")"), Newline("\n"), Whitespace(" ")] [] + 0: JS_PROPERTY_MODIFIER_LIST@18..44 + 0: JS_DECORATOR@18..44 + 0: AT@18..21 "@" [Newline("\n"), Whitespace(" ")] [] + 1: JS_CALL_EXPRESSION@21..44 + 0: JS_IDENTIFIER_EXPRESSION@21..30 + 0: JS_REFERENCE_IDENTIFIER@21..30 + 0: IDENT@21..30 "Decorator" [] [] + 1: (empty) + 2: (empty) + 3: JS_CALL_ARGUMENTS@30..44 + 0: L_PAREN@30..31 "(" [] [] + 1: JS_CALL_ARGUMENT_LIST@31..43 + 0: JS_ARROW_FUNCTION_EXPRESSION@31..43 + 0: (empty) + 1: (empty) + 2: JS_PARAMETERS@31..37 + 0: L_PAREN@31..32 "(" [] [] + 1: JS_PARAMETER_LIST@32..35 + 0: JS_FORMAL_PARAMETER@32..35 + 0: JS_IDENTIFIER_BINDING@32..35 + 0: IDENT@32..35 "val" [] [] + 1: (empty) + 2: (empty) + 3: (empty) + 2: R_PAREN@35..37 ")" [] [Whitespace(" ")] + 3: (empty) + 4: FAT_ARROW@37..40 "=>" [] [Whitespace(" ")] + 5: JS_IDENTIFIER_EXPRESSION@40..43 + 0: JS_REFERENCE_IDENTIFIER@40..43 + 0: IDENT@40..43 "val" [] [] + 2: R_PAREN@43..44 ")" [] [] + 1: JS_LITERAL_MEMBER_NAME@44..54 + 0: IDENT@44..54 "badField" [Newline("\n"), Whitespace(" ")] [] 2: TS_DEFINITE_PROPERTY_ANNOTATION@54..63 0: BANG@54..55 "!" [] [] 1: TS_TYPE_ANNOTATION@55..63 diff --git a/crates/rome_js_syntax/src/generated/nodes.rs b/crates/rome_js_syntax/src/generated/nodes.rs index cc5b11b18ad..7dd2392313e 100644 --- a/crates/rome_js_syntax/src/generated/nodes.rs +++ b/crates/rome_js_syntax/src/generated/nodes.rs @@ -14669,11 +14669,18 @@ impl AnyJsLiteralExpression { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyJsMethodModifier { + JsDecorator(JsDecorator), JsStaticModifier(JsStaticModifier), TsAccessibilityModifier(TsAccessibilityModifier), TsOverrideModifier(TsOverrideModifier), } impl AnyJsMethodModifier { + pub fn as_js_decorator(&self) -> Option<&JsDecorator> { + match &self { + AnyJsMethodModifier::JsDecorator(item) => Some(item), + _ => None, + } + } pub fn as_js_static_modifier(&self) -> Option<&JsStaticModifier> { match &self { AnyJsMethodModifier::JsStaticModifier(item) => Some(item), @@ -14977,6 +14984,7 @@ impl AnyJsParameter { #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyJsPropertyModifier { JsAccessorModifier(JsAccessorModifier), + JsDecorator(JsDecorator), JsStaticModifier(JsStaticModifier), TsAccessibilityModifier(TsAccessibilityModifier), TsOverrideModifier(TsOverrideModifier), @@ -14989,6 +14997,12 @@ impl AnyJsPropertyModifier { _ => None, } } + pub fn as_js_decorator(&self) -> Option<&JsDecorator> { + match &self { + AnyJsPropertyModifier::JsDecorator(item) => Some(item), + _ => None, + } + } pub fn as_js_static_modifier(&self) -> Option<&JsStaticModifier> { match &self { AnyJsPropertyModifier::JsStaticModifier(item) => Some(item), @@ -32631,6 +32645,11 @@ impl From for SyntaxElement { node.into() } } +impl From for AnyJsMethodModifier { + fn from(node: JsDecorator) -> AnyJsMethodModifier { + AnyJsMethodModifier::JsDecorator(node) + } +} impl From for AnyJsMethodModifier { fn from(node: JsStaticModifier) -> AnyJsMethodModifier { AnyJsMethodModifier::JsStaticModifier(node) @@ -32648,17 +32667,19 @@ impl From for AnyJsMethodModifier { } impl AstNode for AnyJsMethodModifier { type Language = Language; - const KIND_SET: SyntaxKindSet = JsStaticModifier::KIND_SET + const KIND_SET: SyntaxKindSet = JsDecorator::KIND_SET + .union(JsStaticModifier::KIND_SET) .union(TsAccessibilityModifier::KIND_SET) .union(TsOverrideModifier::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, - JS_STATIC_MODIFIER | TS_ACCESSIBILITY_MODIFIER | TS_OVERRIDE_MODIFIER + JS_DECORATOR | JS_STATIC_MODIFIER | TS_ACCESSIBILITY_MODIFIER | TS_OVERRIDE_MODIFIER ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { + JS_DECORATOR => AnyJsMethodModifier::JsDecorator(JsDecorator { syntax }), JS_STATIC_MODIFIER => { AnyJsMethodModifier::JsStaticModifier(JsStaticModifier { syntax }) } @@ -32674,6 +32695,7 @@ impl AstNode for AnyJsMethodModifier { } fn syntax(&self) -> &SyntaxNode { match self { + AnyJsMethodModifier::JsDecorator(it) => &it.syntax, AnyJsMethodModifier::JsStaticModifier(it) => &it.syntax, AnyJsMethodModifier::TsAccessibilityModifier(it) => &it.syntax, AnyJsMethodModifier::TsOverrideModifier(it) => &it.syntax, @@ -32681,6 +32703,7 @@ impl AstNode for AnyJsMethodModifier { } fn into_syntax(self) -> SyntaxNode { match self { + AnyJsMethodModifier::JsDecorator(it) => it.syntax, AnyJsMethodModifier::JsStaticModifier(it) => it.syntax, AnyJsMethodModifier::TsAccessibilityModifier(it) => it.syntax, AnyJsMethodModifier::TsOverrideModifier(it) => it.syntax, @@ -32690,6 +32713,7 @@ impl AstNode for AnyJsMethodModifier { impl std::fmt::Debug for AnyJsMethodModifier { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { + AnyJsMethodModifier::JsDecorator(it) => std::fmt::Debug::fmt(it, f), AnyJsMethodModifier::JsStaticModifier(it) => std::fmt::Debug::fmt(it, f), AnyJsMethodModifier::TsAccessibilityModifier(it) => std::fmt::Debug::fmt(it, f), AnyJsMethodModifier::TsOverrideModifier(it) => std::fmt::Debug::fmt(it, f), @@ -32699,6 +32723,7 @@ impl std::fmt::Debug for AnyJsMethodModifier { impl From for SyntaxNode { fn from(n: AnyJsMethodModifier) -> SyntaxNode { match n { + AnyJsMethodModifier::JsDecorator(it) => it.into(), AnyJsMethodModifier::JsStaticModifier(it) => it.into(), AnyJsMethodModifier::TsAccessibilityModifier(it) => it.into(), AnyJsMethodModifier::TsOverrideModifier(it) => it.into(), @@ -33514,6 +33539,11 @@ impl From for AnyJsPropertyModifier { AnyJsPropertyModifier::JsAccessorModifier(node) } } +impl From for AnyJsPropertyModifier { + fn from(node: JsDecorator) -> AnyJsPropertyModifier { + AnyJsPropertyModifier::JsDecorator(node) + } +} impl From for AnyJsPropertyModifier { fn from(node: JsStaticModifier) -> AnyJsPropertyModifier { AnyJsPropertyModifier::JsStaticModifier(node) @@ -33537,6 +33567,7 @@ impl From for AnyJsPropertyModifier { impl AstNode for AnyJsPropertyModifier { type Language = Language; const KIND_SET: SyntaxKindSet = JsAccessorModifier::KIND_SET + .union(JsDecorator::KIND_SET) .union(JsStaticModifier::KIND_SET) .union(TsAccessibilityModifier::KIND_SET) .union(TsOverrideModifier::KIND_SET) @@ -33545,6 +33576,7 @@ impl AstNode for AnyJsPropertyModifier { matches!( kind, JS_ACCESSOR_MODIFIER + | JS_DECORATOR | JS_STATIC_MODIFIER | TS_ACCESSIBILITY_MODIFIER | TS_OVERRIDE_MODIFIER @@ -33556,6 +33588,7 @@ impl AstNode for AnyJsPropertyModifier { JS_ACCESSOR_MODIFIER => { AnyJsPropertyModifier::JsAccessorModifier(JsAccessorModifier { syntax }) } + JS_DECORATOR => AnyJsPropertyModifier::JsDecorator(JsDecorator { syntax }), JS_STATIC_MODIFIER => { AnyJsPropertyModifier::JsStaticModifier(JsStaticModifier { syntax }) } @@ -33575,6 +33608,7 @@ impl AstNode for AnyJsPropertyModifier { fn syntax(&self) -> &SyntaxNode { match self { AnyJsPropertyModifier::JsAccessorModifier(it) => &it.syntax, + AnyJsPropertyModifier::JsDecorator(it) => &it.syntax, AnyJsPropertyModifier::JsStaticModifier(it) => &it.syntax, AnyJsPropertyModifier::TsAccessibilityModifier(it) => &it.syntax, AnyJsPropertyModifier::TsOverrideModifier(it) => &it.syntax, @@ -33584,6 +33618,7 @@ impl AstNode for AnyJsPropertyModifier { fn into_syntax(self) -> SyntaxNode { match self { AnyJsPropertyModifier::JsAccessorModifier(it) => it.syntax, + AnyJsPropertyModifier::JsDecorator(it) => it.syntax, AnyJsPropertyModifier::JsStaticModifier(it) => it.syntax, AnyJsPropertyModifier::TsAccessibilityModifier(it) => it.syntax, AnyJsPropertyModifier::TsOverrideModifier(it) => it.syntax, @@ -33595,6 +33630,7 @@ impl std::fmt::Debug for AnyJsPropertyModifier { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { AnyJsPropertyModifier::JsAccessorModifier(it) => std::fmt::Debug::fmt(it, f), + AnyJsPropertyModifier::JsDecorator(it) => std::fmt::Debug::fmt(it, f), AnyJsPropertyModifier::JsStaticModifier(it) => std::fmt::Debug::fmt(it, f), AnyJsPropertyModifier::TsAccessibilityModifier(it) => std::fmt::Debug::fmt(it, f), AnyJsPropertyModifier::TsOverrideModifier(it) => std::fmt::Debug::fmt(it, f), @@ -33606,6 +33642,7 @@ impl From for SyntaxNode { fn from(n: AnyJsPropertyModifier) -> SyntaxNode { match n { AnyJsPropertyModifier::JsAccessorModifier(it) => it.into(), + AnyJsPropertyModifier::JsDecorator(it) => it.into(), AnyJsPropertyModifier::JsStaticModifier(it) => it.into(), AnyJsPropertyModifier::TsAccessibilityModifier(it) => it.into(), AnyJsPropertyModifier::TsOverrideModifier(it) => it.into(),