diff --git a/crates/rome_js_factory/src/generated/node_factory.rs b/crates/rome_js_factory/src/generated/node_factory.rs index e3ebbe5db45..dfc854747c4 100644 --- a/crates/rome_js_factory/src/generated/node_factory.rs +++ b/crates/rome_js_factory/src/generated/node_factory.rs @@ -6,6 +6,12 @@ use rome_js_syntax::{ JsSyntaxElement as SyntaxElement, JsSyntaxNode as SyntaxNode, JsSyntaxToken as SyntaxToken, *, }; use rome_rowan::AstNode; +pub fn js_accessor_modifier(modifier_token: SyntaxToken) -> JsAccessorModifier { + JsAccessorModifier::unwrap_cast(SyntaxNode::new_detached( + JsSyntaxKind::JS_ACCESSOR_MODIFIER, + [Some(SyntaxElement::Token(modifier_token))], + )) +} pub fn js_array_assignment_pattern( l_brack_token: SyntaxToken, elements: JsArrayAssignmentPatternElementList, diff --git a/crates/rome_js_factory/src/generated/syntax_factory.rs b/crates/rome_js_factory/src/generated/syntax_factory.rs index a1d54778e5f..fc445f48bdc 100644 --- a/crates/rome_js_factory/src/generated/syntax_factory.rs +++ b/crates/rome_js_factory/src/generated/syntax_factory.rs @@ -22,6 +22,25 @@ impl SyntaxFactory for JsSyntaxFactory { | JS_BOGUS_PARAMETER | JS_BOGUS_STATEMENT | TS_BOGUS_TYPE => RawSyntaxNode::new(kind, children.into_iter().map(Some)), + JS_ACCESSOR_MODIFIER => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![accessor] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + JS_ACCESSOR_MODIFIER.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(JS_ACCESSOR_MODIFIER, children) + } JS_ARRAY_ASSIGNMENT_PATTERN => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); diff --git a/crates/rome_js_formatter/src/generated.rs b/crates/rome_js_formatter/src/generated.rs index 9b113fe712b..7afa4e79d3d 100644 --- a/crates/rome_js_formatter/src/generated.rs +++ b/crates/rome_js_formatter/src/generated.rs @@ -4209,6 +4209,44 @@ impl IntoFormat for rome_js_syntax::JsStaticModifier { ) } } +impl FormatRule + for crate::js::auxiliary::accessor_modifier::FormatJsAccessorModifier +{ + type Context = JsFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &rome_js_syntax::JsAccessorModifier, + f: &mut JsFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for rome_js_syntax::JsAccessorModifier { + type Format<'a> = FormatRefWithRule< + 'a, + rome_js_syntax::JsAccessorModifier, + crate::js::auxiliary::accessor_modifier::FormatJsAccessorModifier, + >; + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new( + self, + crate::js::auxiliary::accessor_modifier::FormatJsAccessorModifier::default(), + ) + } +} +impl IntoFormat for rome_js_syntax::JsAccessorModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAccessorModifier, + crate::js::auxiliary::accessor_modifier::FormatJsAccessorModifier, + >; + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new( + self, + crate::js::auxiliary::accessor_modifier::FormatJsAccessorModifier::default(), + ) + } +} impl FormatRule for crate::ts::auxiliary::declare_modifier::FormatTsDeclareModifier { diff --git a/crates/rome_js_formatter/src/js/any/property_modifier.rs b/crates/rome_js_formatter/src/js/any/property_modifier.rs index ddc13213c8c..a2262dd0f2b 100644 --- a/crates/rome_js_formatter/src/js/any/property_modifier.rs +++ b/crates/rome_js_formatter/src/js/any/property_modifier.rs @@ -10,6 +10,7 @@ impl FormatRule for FormatAnyJsPropertyModifier { match node { AnyJsPropertyModifier::TsAccessibilityModifier(node) => node.format().fmt(f), AnyJsPropertyModifier::JsStaticModifier(node) => node.format().fmt(f), + AnyJsPropertyModifier::JsAccessorModifier(node) => node.format().fmt(f), AnyJsPropertyModifier::TsReadonlyModifier(node) => node.format().fmt(f), AnyJsPropertyModifier::TsOverrideModifier(node) => node.format().fmt(f), } diff --git a/crates/rome_js_formatter/src/js/auxiliary/accessor_modifier.rs b/crates/rome_js_formatter/src/js/auxiliary/accessor_modifier.rs new file mode 100644 index 00000000000..e0e5a3498e3 --- /dev/null +++ b/crates/rome_js_formatter/src/js/auxiliary/accessor_modifier.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use rome_formatter::write; +use rome_js_syntax::{JsAccessorModifier, JsAccessorModifierFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatJsAccessorModifier; + +impl FormatNodeRule for FormatJsAccessorModifier { + fn fmt_fields(&self, node: &JsAccessorModifier, f: &mut JsFormatter) -> FormatResult<()> { + let JsAccessorModifierFields { modifier_token } = node.as_fields(); + + write![f, [modifier_token.format()]] + } +} diff --git a/crates/rome_js_formatter/src/js/auxiliary/mod.rs b/crates/rome_js_formatter/src/js/auxiliary/mod.rs index c7e7c2c2f89..369d76b8ed8 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/mod.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/mod.rs @@ -1,5 +1,6 @@ //! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. +pub(crate) mod accessor_modifier; pub(crate) mod array_hole; pub(crate) mod case_clause; pub(crate) mod catch_clause; diff --git a/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs b/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs index eae7230d6f3..16ff793e5ba 100644 --- a/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs +++ b/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs @@ -11,6 +11,7 @@ impl FormatRule for FormatAnyTsPropertySignature AnyTsPropertySignatureModifier::TsDeclareModifier(node) => node.format().fmt(f), AnyTsPropertySignatureModifier::TsAccessibilityModifier(node) => node.format().fmt(f), AnyTsPropertySignatureModifier::JsStaticModifier(node) => node.format().fmt(f), + AnyTsPropertySignatureModifier::JsAccessorModifier(node) => node.format().fmt(f), AnyTsPropertySignatureModifier::TsReadonlyModifier(node) => node.format().fmt(f), AnyTsPropertySignatureModifier::TsOverrideModifier(node) => node.format().fmt(f), AnyTsPropertySignatureModifier::TsAbstractModifier(node) => node.format().fmt(f), diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorator-auto-accessors.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorator-auto-accessors.js.snap deleted file mode 100644 index 88c57dbe033..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorator-auto-accessors.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/babel-plugins/decorator-auto-accessors.js ---- - -# Input - -```js -class C extends HTMLElement { - accessor clicked = false; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class C extends HTMLElement { -- accessor clicked = false; -+ accessor; -+ clicked = false; - } -``` - -# Output - -```js -class C extends HTMLElement { - accessor; - clicked = false; -} -``` - -# Errors -``` -decorator-auto-accessors.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class C extends HTMLElement { - > 2 │ accessor clicked = false; - │ ^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/basic.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/basic.js.snap deleted file mode 100644 index 49bca7c8a8b..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/basic.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/basic.js ---- - -# Input - -```js -class Foo { - accessor bar; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class Foo { -- accessor bar; -+ accessor; -+ bar; - } -``` - -# Output - -```js -class Foo { - accessor; - bar; -} -``` - -# Errors -``` -basic.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class Foo { - > 2 │ accessor bar; - │ ^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/computed.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/computed.js.snap deleted file mode 100644 index 8f7bd687f06..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/computed.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/computed.js ---- - -# Input - -```js -class Foo { - accessor ["bar"]; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class Foo { -- accessor ["bar"]; -+ accessor; -+ ["bar"]; - } -``` - -# Output - -```js -class Foo { - accessor; - ["bar"]; -} -``` - -# Errors -``` -computed.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class Foo { - > 2 │ accessor ["bar"]; - │ ^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/private.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/private.js.snap deleted file mode 100644 index cbf8aa3b35e..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/private.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/private.js ---- - -# Input - -```js -class Foo { - accessor #bar; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class Foo { -- accessor #bar; -+ accessor; -+ #bar; - } -``` - -# Output - -```js -class Foo { - accessor; - #bar; -} -``` - -# Errors -``` -private.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class Foo { - > 2 │ accessor #bar; - │ ^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static-computed.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static-computed.js.snap deleted file mode 100644 index 90c80978608..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static-computed.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/static-computed.js ---- - -# Input - -```js -class Foo { - static accessor ["bar"]; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class Foo { -- static accessor ["bar"]; -+ static accessor; -+ ["bar"]; - } -``` - -# Output - -```js -class Foo { - static accessor; - ["bar"]; -} -``` - -# Errors -``` -static-computed.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class Foo { - > 2 │ static accessor ["bar"]; - │ ^^^^^^^^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static-private.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static-private.js.snap deleted file mode 100644 index 2e8ed4d53ef..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static-private.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/static-private.js ---- - -# Input - -```js -class Foo { - static accessor #bar; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class Foo { -- static accessor #bar; -+ static accessor; -+ #bar; - } -``` - -# Output - -```js -class Foo { - static accessor; - #bar; -} -``` - -# Errors -``` -static-private.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class Foo { - > 2 │ static accessor #bar; - │ ^^^^^^^^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static.js.snap deleted file mode 100644 index af507e79376..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/static.js.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/static.js ---- - -# Input - -```js -class Foo { - static accessor bar; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,3 +1,4 @@ - class Foo { -- static accessor bar; -+ static accessor; -+ bar; - } -``` - -# Output - -```js -class Foo { - static accessor; - bar; -} -``` - -# Errors -``` -static.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class Foo { - > 2 │ static accessor bar; - │ ^^^^^^^^^^^^^^^ - 3 │ } - 4 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/with-semicolon-1.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/with-semicolon-1.js.snap deleted file mode 100644 index ec4092e6eda..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/with-semicolon-1.js.snap +++ /dev/null @@ -1,57 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/with-semicolon-1.js ---- - -# Input - -```js -class C { - accessor clicked = "value"; - [foo]() {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,4 +1,5 @@ - class C { -- accessor clicked = "value"; -+ accessor; -+ clicked = "value"; - [foo]() {} - } -``` - -# Output - -```js -class C { - accessor; - clicked = "value"; - [foo]() {} -} -``` - -# Errors -``` -with-semicolon-1.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class C { - > 2 │ accessor clicked = "value"; - │ ^^^^^^^^ - 3 │ [foo]() {} - 4 │ } - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/with-semicolon-2.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/with-semicolon-2.js.snap deleted file mode 100644 index cd1dbb20bcd..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/with-semicolon-2.js.snap +++ /dev/null @@ -1,57 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: - test_file: js/decorator-auto-accessors/with-semicolon-2.js ---- - -# Input - -```js -class C { - accessor clicked = "value"; - *foo() {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,4 +1,5 @@ - class C { -- accessor clicked = "value"; -+ accessor; -+ clicked = "value"; - *foo() {} - } -``` - -# Output - -```js -class C { - accessor; - clicked = "value"; - *foo() {} -} -``` - -# Errors -``` -with-semicolon-2.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a semicolon to end the class property, but found none - - 1 │ class C { - > 2 │ accessor clicked = "value"; - │ ^^^^^^^^ - 3 │ *foo() {} - 4 │ } - - -``` - - diff --git a/crates/rome_js_parser/src/lexer/mod.rs b/crates/rome_js_parser/src/lexer/mod.rs index d44f2207fb3..c25bcc440b1 100644 --- a/crates/rome_js_parser/src/lexer/mod.rs +++ b/crates/rome_js_parser/src/lexer/mod.rs @@ -1076,6 +1076,7 @@ impl<'src> Lexer<'src> { b"yield" => YIELD_KW, // contextual keywords b"abstract" => ABSTRACT_KW, + b"accessor" => ACCESSOR_KW, b"as" => AS_KW, b"asserts" => ASSERTS_KW, b"assert" => ASSERT_KW, diff --git a/crates/rome_js_parser/src/syntax/class.rs b/crates/rome_js_parser/src/syntax/class.rs index 2b7a29ac10a..4ce22d23118 100644 --- a/crates/rome_js_parser/src/syntax/class.rs +++ b/crates/rome_js_parser/src/syntax/class.rs @@ -452,6 +452,7 @@ impl ParseNodeList for ClassMembersList { T![override], T![declare], T![static], + T![accessor], T![async], T![yield], T!['}'], @@ -1563,6 +1564,7 @@ pub(crate) fn is_nth_at_modifier(p: &mut JsParser, n: usize, constructor_paramet | T![private] | T![override] | T![static] + | T![accessor] | T![readonly] | T![abstract] ) { @@ -1638,6 +1640,7 @@ fn parse_modifier(p: &mut JsParser, constructor_parameter: bool) -> Option ModifierKind::Private, T![override] => ModifierKind::Override, T![static] => ModifierKind::Static, + T![accessor] => ModifierKind::Accessor, T![readonly] => ModifierKind::Readonly, T![abstract] => ModifierKind::Abstract, _ => { @@ -1671,6 +1674,7 @@ bitflags! { const ABSTRACT = 1 << 6; const OVERRIDE = 1 << 7; const PRIVATE_NAME = 1 << 8; + const ACCESSOR = 1 << 9; const ACCESSIBILITY = ModifierFlags::PRIVATE.bits | ModifierFlags::PROTECTED.bits | ModifierFlags::PUBLIC.bits; } @@ -1685,13 +1689,14 @@ enum ModifierKind { Protected, Public, Static, + Accessor, Readonly, Override, } impl ModifierKind { const fn is_ts_modifier(&self) -> bool { - !matches!(self, ModifierKind::Static) + !matches!(self, ModifierKind::Static | ModifierKind::Accessor) } const fn as_syntax_kind(&self) -> JsSyntaxKind { @@ -1702,6 +1707,7 @@ impl ModifierKind { TS_ACCESSIBILITY_MODIFIER } ModifierKind::Static => JS_STATIC_MODIFIER, + ModifierKind::Accessor => JS_ACCESSOR_MODIFIER, ModifierKind::Readonly => TS_READONLY_MODIFIER, ModifierKind::Override => TS_OVERRIDE_MODIFIER, } @@ -1715,6 +1721,7 @@ impl ModifierKind { ModifierKind::Protected => ModifierFlags::PROTECTED, ModifierKind::Public => ModifierFlags::PUBLIC, ModifierKind::Static => ModifierFlags::STATIC, + ModifierKind::Accessor => ModifierFlags::ACCESSOR, ModifierKind::Readonly => ModifierFlags::READONLY, ModifierKind::Override => ModifierFlags::OVERRIDE, } @@ -1884,6 +1891,17 @@ impl ClassMemberModifiers { valid } + // test js_class_property_member_modifiers + // class Test { + // static a = 1; + // accessor b = 1; + // static accessor c = 1; + // } + // class Foo { + // accessor + // foo + // } + // test ts ts_class_property_member_modifiers // class Base { // base1; @@ -1899,6 +1917,8 @@ impl ClassMemberModifiers { // protected readonly abstract i: string; // protected abstract readonly j: string; // protected override readonly base1: string; + // private static accessor readonly k: string; + // protected abstract accessor readonly l: string; // } // test_err ts ts_class_modifier_precedence @@ -1911,7 +1931,11 @@ impl ClassMemberModifiers { // abstract protected d: string; // // Static // readonly static c: string; + // accessor static d: string; // override static base2: string; + // // Accessor + // readonly accessor e: string; + // override accessor f: string; // // abstract // override abstract base3: string; // // override @@ -1937,11 +1961,14 @@ impl ClassMemberModifiers { // abstract async l(); // declare async m(); // declare #l; + // declare accessor p; + // accessor accessor r; // } // test_err class_invalid_modifiers // class A { public foo() {} } // class B { static static foo() {} } + // class C { accessor foo() {} } fn check_class_member_modifier( &self, p: &JsParser, @@ -1978,6 +2005,11 @@ impl ClassMemberModifiers { // abstract class A { // abstract [a: number]: string; // } + + // test_err ts ts_index_signature_class_member_cannot_be_accessor + // abstract class A { + // accessor [a: number]: string; + // } if member_kind == TS_INDEX_SIGNATURE_CLASS_MEMBER && !matches!(modifier.kind, ModifierKind::Static | ModifierKind::Readonly) { @@ -2060,6 +2092,7 @@ impl ClassMemberModifiers { // declare get test() { return "a" } // declare set test(value: string) {} // declare [name: string]: string; + // declare accessor foo: string; // } if preceding_modifiers.contains(ModifierFlags::DECLARE) { return Some(modifier_already_seen( @@ -2067,6 +2100,12 @@ impl ClassMemberModifiers { modifier.as_text_range(), self.get_first_range_unchecked(ModifierKind::Declare), )); + } else if self.flags.contains(ModifierFlags::ACCESSOR) { + return Some(modifier_cannot_be_used_with_modifier( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Accessor), + )); } else if self.flags.contains(ModifierFlags::OVERRIDE) { return Some(modifier_cannot_be_used_with_modifier( p, @@ -2121,6 +2160,14 @@ impl ClassMemberModifiers { modifier.as_text_range(), self.get_first_range_unchecked(ModifierKind::Static), )); + } else if preceding_modifiers.contains(ModifierFlags::ACCESSOR) { + // test_err ts typescript_abstract_classes_abstract_accessor_precedence + // abstract class A { accessor abstract foo: number; } + return Some(modifier_must_precede_modifier( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Accessor), + )); } else if preceding_modifiers.contains(ModifierFlags::OVERRIDE) { return Some(modifier_must_precede_modifier( p, @@ -2163,6 +2210,12 @@ impl ClassMemberModifiers { modifier.as_text_range(), self.get_first_range_unchecked(ModifierKind::Static), )); + } else if preceding_modifiers.contains(ModifierFlags::ACCESSOR) { + return Some(modifier_must_precede_modifier( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Accessor), + )); } else if preceding_modifiers.contains(ModifierFlags::READONLY) { return Some(modifier_must_precede_modifier( p, @@ -2199,12 +2252,21 @@ impl ClassMemberModifiers { modifier.as_text_range(), self.get_first_range_unchecked(ModifierKind::Static), )); - } + // test_err class_member_static_accessor_precedence + // class A { + // accessor static foo = 1; + // } + } else if preceding_modifiers.contains(ModifierFlags::ACCESSOR) { + return Some(modifier_must_precede_modifier( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Accessor), + )); // test_err ts ts_index_signature_class_member_static_readonly_precedence // class A { // readonly static [a: number]: string; // } - else if preceding_modifiers.contains(ModifierFlags::READONLY) { + } else if preceding_modifiers.contains(ModifierFlags::READONLY) { return Some(modifier_must_precede_modifier( p, modifier.as_text_range(), @@ -2218,6 +2280,40 @@ impl ClassMemberModifiers { )); } } + ModifierKind::Accessor => { + if preceding_modifiers.contains(ModifierFlags::ACCESSOR) { + return Some(modifier_already_seen( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Accessor), + )); + } + // test_err ts ts_class_member_accessor_readonly_precedence + // class A { + // readonly accessor foo: number = 1; + // } + else if preceding_modifiers.contains(ModifierFlags::READONLY) { + return Some(modifier_must_precede_modifier( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Readonly), + )); + } else if preceding_modifiers.contains(ModifierFlags::OVERRIDE) { + return Some(modifier_cannot_be_used_with_modifier( + p, + modifier.as_text_range(), + self.get_first_range_unchecked(ModifierKind::Override), + )); + } else if !matches!( + member_kind, + JS_PROPERTY_CLASS_MEMBER | TS_PROPERTY_SIGNATURE_CLASS_MEMBER + ) { + return Some(p.err_builder( + "'accessor' modifier is only allowed on properties.", + modifier.as_text_range(), + )); + } + } ModifierKind::Override => { if preceding_modifiers.contains(ModifierFlags::OVERRIDE) { return Some(modifier_already_seen( diff --git a/crates/rome_js_parser/src/syntax/expr.rs b/crates/rome_js_parser/src/syntax/expr.rs index 682524473a8..efb1e275a42 100644 --- a/crates/rome_js_parser/src/syntax/expr.rs +++ b/crates/rome_js_parser/src/syntax/expr.rs @@ -1449,6 +1449,7 @@ pub(crate) fn is_nth_at_reference_identifier(p: &mut JsParser, n: usize) -> bool // // test identifier // foo; +// let accessor = 5; // // test_err identifier_err // yield; diff --git a/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.js b/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.js index 7e01108b0a1..845f99189f0 100644 --- a/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.js +++ b/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.js @@ -1,2 +1,3 @@ class A { public foo() {} } class B { static static foo() {} } +class C { accessor foo() {} } diff --git a/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.rast b/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.rast index e0fb87e653f..baa2426931e 100644 --- a/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.rast +++ b/crates/rome_js_parser/test_data/inline/err/class_invalid_modifiers.rast @@ -79,14 +79,53 @@ JsModule { ], r_curly_token: R_CURLY@61..62 "}" [] [], }, + JsClassDeclaration { + abstract_token: missing (optional), + class_token: CLASS_KW@62..69 "class" [Newline("\n")] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@69..71 "C" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@71..73 "{" [] [Whitespace(" ")], + members: JsClassMemberList [ + JsBogusMember { + items: [ + JsBogus { + items: [ + JsAccessorModifier { + modifier_token: ACCESSOR_KW@73..82 "accessor" [] [Whitespace(" ")], + }, + ], + }, + JsLiteralMemberName { + value: IDENT@82..85 "foo" [] [], + }, + JsParameters { + l_paren_token: L_PAREN@85..86 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@86..88 ")" [] [Whitespace(" ")], + }, + JsFunctionBody { + l_curly_token: L_CURLY@88..89 "{" [] [], + directives: JsDirectiveList [], + statements: JsStatementList [], + r_curly_token: R_CURLY@89..91 "}" [] [Whitespace(" ")], + }, + ], + }, + ], + r_curly_token: R_CURLY@91..92 "}" [] [], + }, ], - eof_token: EOF@62..63 "" [Newline("\n")] [], + eof_token: EOF@92..93 "" [Newline("\n")] [], } -0: JS_MODULE@0..63 +0: JS_MODULE@0..93 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..62 + 2: JS_MODULE_ITEM_LIST@0..92 0: JS_CLASS_DECLARATION@0..27 0: (empty) 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] @@ -141,7 +180,33 @@ JsModule { 2: JS_STATEMENT_LIST@59..59 3: R_CURLY@59..61 "}" [] [Whitespace(" ")] 8: R_CURLY@61..62 "}" [] [] - 3: EOF@62..63 "" [Newline("\n")] [] + 2: JS_CLASS_DECLARATION@62..92 + 0: (empty) + 1: CLASS_KW@62..69 "class" [Newline("\n")] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@69..71 + 0: IDENT@69..71 "C" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@71..73 "{" [] [Whitespace(" ")] + 7: JS_CLASS_MEMBER_LIST@73..91 + 0: JS_BOGUS_MEMBER@73..91 + 0: JS_BOGUS@73..82 + 0: JS_ACCESSOR_MODIFIER@73..82 + 0: ACCESSOR_KW@73..82 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@82..85 + 0: IDENT@82..85 "foo" [] [] + 2: JS_PARAMETERS@85..88 + 0: L_PAREN@85..86 "(" [] [] + 1: JS_PARAMETER_LIST@86..86 + 2: R_PAREN@86..88 ")" [] [Whitespace(" ")] + 3: JS_FUNCTION_BODY@88..91 + 0: L_CURLY@88..89 "{" [] [] + 1: JS_DIRECTIVE_LIST@89..89 + 2: JS_STATEMENT_LIST@89..89 + 3: R_CURLY@89..91 "}" [] [Whitespace(" ")] + 8: R_CURLY@91..92 "}" [] [] + 3: EOF@92..93 "" [Newline("\n")] [] -- class_invalid_modifiers.js:1:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -150,7 +215,7 @@ class_invalid_modifiers.js:1:11 parse ━━━━━━━━━━━━━━ > 1 │ class A { public foo() {} } │ ^^^^^^ 2 │ class B { static static foo() {} } - 3 │ + 3 │ class C { accessor foo() {} } -- class_invalid_modifiers.js:2:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -160,22 +225,37 @@ class_invalid_modifiers.js:2:18 parse ━━━━━━━━━━━━━━ 1 │ class A { public foo() {} } > 2 │ class B { static static foo() {} } │ ^^^^^^ - 3 │ + 3 │ class C { accessor foo() {} } + 4 │ i duplicate modifier 1 │ class A { public foo() {} } > 2 │ class B { static static foo() {} } │ ^^^^^^ - 3 │ + 3 │ class C { accessor foo() {} } + 4 │ i first seen here 1 │ class A { public foo() {} } > 2 │ class B { static static foo() {} } │ ^^^^^^ - 3 │ + 3 │ class C { accessor foo() {} } + 4 │ + +-- +class_invalid_modifiers.js:3:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'accessor' modifier is only allowed on properties. + + 1 │ class A { public foo() {} } + 2 │ class B { static static foo() {} } + > 3 │ class C { accessor foo() {} } + │ ^^^^^^^^ + 4 │ -- class A { public foo() {} } class B { static static foo() {} } +class C { accessor foo() {} } diff --git a/crates/rome_js_parser/test_data/inline/err/class_member_static_accessor_precedence.js b/crates/rome_js_parser/test_data/inline/err/class_member_static_accessor_precedence.js new file mode 100644 index 00000000000..3e3411429f9 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/class_member_static_accessor_precedence.js @@ -0,0 +1,3 @@ +class A { + accessor static foo = 1; +} diff --git a/crates/rome_js_parser/test_data/inline/err/class_member_static_accessor_precedence.rast b/crates/rome_js_parser/test_data/inline/err/class_member_static_accessor_precedence.rast new file mode 100644 index 00000000000..5e6b2604074 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/class_member_static_accessor_precedence.rast @@ -0,0 +1,104 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsClassDeclaration { + abstract_token: missing (optional), + class_token: CLASS_KW@0..6 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@6..8 "A" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@8..9 "{" [] [], + members: JsClassMemberList [ + JsBogusMember { + items: [ + JsPropertyModifierList [ + JsAccessorModifier { + modifier_token: ACCESSOR_KW@9..23 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsStaticModifier { + modifier_token: STATIC_KW@23..30 "static" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@30..34 "foo" [] [Whitespace(" ")], + }, + JsInitializerClause { + eq_token: EQ@34..36 "=" [] [Whitespace(" ")], + expression: JsNumberLiteralExpression { + value_token: JS_NUMBER_LITERAL@36..37 "1" [] [], + }, + }, + SEMICOLON@37..38 ";" [] [], + ], + }, + ], + r_curly_token: R_CURLY@38..40 "}" [Newline("\n")] [], + }, + ], + eof_token: EOF@40..41 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..41 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..40 + 0: JS_CLASS_DECLARATION@0..40 + 0: (empty) + 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@6..8 + 0: IDENT@6..8 "A" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@8..9 "{" [] [] + 7: JS_CLASS_MEMBER_LIST@9..38 + 0: JS_BOGUS_MEMBER@9..38 + 0: JS_PROPERTY_MODIFIER_LIST@9..30 + 0: JS_ACCESSOR_MODIFIER@9..23 + 0: ACCESSOR_KW@9..23 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_STATIC_MODIFIER@23..30 + 0: STATIC_KW@23..30 "static" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@30..34 + 0: IDENT@30..34 "foo" [] [Whitespace(" ")] + 2: JS_INITIALIZER_CLAUSE@34..37 + 0: EQ@34..36 "=" [] [Whitespace(" ")] + 1: JS_NUMBER_LITERAL_EXPRESSION@36..37 + 0: JS_NUMBER_LITERAL@36..37 "1" [] [] + 3: SEMICOLON@37..38 ";" [] [] + 8: R_CURLY@38..40 "}" [Newline("\n")] [] + 3: EOF@40..41 "" [Newline("\n")] [] +-- +class_member_static_accessor_precedence.js:2:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'static' must precede 'accessor' + + 1 │ class A { + > 2 │ accessor static foo = 1; + │ ^^^^^^ + 3 │ } + 4 │ + + i move this modifier + + 1 │ class A { + > 2 │ accessor static foo = 1; + │ ^^^^^^ + 3 │ } + 4 │ + + i before this modifier + + 1 │ class A { + > 2 │ accessor static foo = 1; + │ ^^^^^^^^ + 3 │ } + 4 │ + +-- +class A { + accessor static foo = 1; +} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.rast b/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.rast index ff17c818cf3..b0f612959f3 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.rast @@ -185,18 +185,40 @@ JsModule { SEMICOLON@204..205 ";" [] [], ], }, + JsBogusMember { + items: [ + TsPropertySignatureModifierList [ + TsDeclareModifier { + modifier_token: DECLARE_KW@205..218 "declare" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@218..227 "accessor" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@227..230 "foo" [] [], + }, + TsTypeAnnotation { + colon_token: COLON@230..232 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@232..238 "string" [] [], + }, + }, + SEMICOLON@238..239 ";" [] [], + ], + }, ], - r_curly_token: R_CURLY@205..207 "}" [Newline("\n")] [], + r_curly_token: R_CURLY@239..241 "}" [Newline("\n")] [], }, ], - eof_token: EOF@207..208 "" [Newline("\n")] [], + eof_token: EOF@241..242 "" [Newline("\n")] [], } -0: JS_MODULE@0..208 +0: JS_MODULE@0..242 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..207 - 0: JS_CLASS_DECLARATION@0..207 + 2: JS_MODULE_ITEM_LIST@0..241 + 0: JS_CLASS_DECLARATION@0..241 0: (empty) 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] 2: JS_IDENTIFIER_BINDING@6..11 @@ -205,7 +227,7 @@ JsModule { 4: (empty) 5: (empty) 6: L_CURLY@11..12 "{" [] [] - 7: JS_CLASS_MEMBER_LIST@12..205 + 7: JS_CLASS_MEMBER_LIST@12..239 0: JS_BOGUS_MEMBER@12..42 0: JS_BOGUS@12..25 0: TS_DECLARE_MODIFIER@12..25 @@ -308,8 +330,21 @@ JsModule { 1: TS_STRING_TYPE@198..204 0: STRING_KW@198..204 "string" [] [] 5: SEMICOLON@204..205 ";" [] [] - 8: R_CURLY@205..207 "}" [Newline("\n")] [] - 3: EOF@207..208 "" [Newline("\n")] [] + 5: JS_BOGUS_MEMBER@205..239 + 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@205..227 + 0: TS_DECLARE_MODIFIER@205..218 + 0: DECLARE_KW@205..218 "declare" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@218..227 + 0: ACCESSOR_KW@218..227 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@227..230 + 0: IDENT@227..230 "foo" [] [] + 2: TS_TYPE_ANNOTATION@230..238 + 0: COLON@230..232 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@232..238 + 0: STRING_KW@232..238 "string" [] [] + 3: SEMICOLON@238..239 ";" [] [] + 8: R_CURLY@239..241 "}" [Newline("\n")] [] + 3: EOF@241..242 "" [Newline("\n")] [] -- ts_class_declare_modifier_error.ts:2:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -367,7 +402,7 @@ ts_class_declare_modifier_error.ts:5:5 parse ━━━━━━━━━━━ > 5 │ declare set test(value: string) {} │ ^^^^^^^ 6 │ declare [name: string]: string; - 7 │ } + 7 │ declare accessor foo: string; -- ts_class_declare_modifier_error.ts:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -378,8 +413,38 @@ ts_class_declare_modifier_error.ts:6:5 parse ━━━━━━━━━━━ 5 │ declare set test(value: string) {} > 6 │ declare [name: string]: string; │ ^^^^^^^ - 7 │ } - 8 │ + 7 │ declare accessor foo: string; + 8 │ } + +-- +ts_class_declare_modifier_error.ts:7:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'declare' cannot be used with 'accessor' modifier. + + 5 │ declare set test(value: string) {} + 6 │ declare [name: string]: string; + > 7 │ declare accessor foo: string; + │ ^^^^^^^ + 8 │ } + 9 │ + + i 'declare' modifier + + 5 │ declare set test(value: string) {} + 6 │ declare [name: string]: string; + > 7 │ declare accessor foo: string; + │ ^^^^^^^ + 8 │ } + 9 │ + + i 'accessor' modifier + + 5 │ declare set test(value: string) {} + 6 │ declare [name: string]: string; + > 7 │ declare accessor foo: string; + │ ^^^^^^^^ + 8 │ } + 9 │ -- class Test { @@ -388,4 +453,5 @@ class Test { declare get test() { return "a" } declare set test(value: string) {} declare [name: string]: string; + declare accessor foo: string; } diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.ts b/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.ts index 095ac03d0e1..06681884f1e 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.ts +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_declare_modifier_error.ts @@ -4,4 +4,5 @@ class Test { declare get test() { return "a" } declare set test(value: string) {} declare [name: string]: string; + declare accessor foo: string; } diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.rast b/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.rast index 77ec3ac02b9..351fe6b39b8 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.rast @@ -314,17 +314,49 @@ JsModule { SEMICOLON@443..444 ";" [] [], ], }, + JsBogusMember { + items: [ + TsPropertySignatureModifierList [ + TsDeclareModifier { + modifier_token: DECLARE_KW@444..457 "declare" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@457..466 "accessor" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@466..467 "p" [] [], + }, + SEMICOLON@467..468 ";" [] [], + ], + }, + JsBogusMember { + items: [ + JsPropertyModifierList [ + JsAccessorModifier { + modifier_token: ACCESSOR_KW@468..482 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@482..491 "accessor" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@491..492 "r" [] [], + }, + SEMICOLON@492..493 ";" [] [], + ], + }, ], - r_curly_token: R_CURLY@444..446 "}" [Newline("\n")] [], + r_curly_token: R_CURLY@493..495 "}" [Newline("\n")] [], }, ], - eof_token: EOF@446..447 "" [Newline("\n")] [], + eof_token: EOF@495..496 "" [Newline("\n")] [], } -0: JS_MODULE@0..447 +0: JS_MODULE@0..496 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..446 + 2: JS_MODULE_ITEM_LIST@0..495 0: JS_CLASS_DECLARATION@0..28 0: (empty) 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] @@ -350,7 +382,7 @@ JsModule { 3: (empty) 4: SEMICOLON@25..27 ";" [] [Whitespace(" ")] 8: R_CURLY@27..28 "}" [] [] - 1: JS_CLASS_DECLARATION@28..446 + 1: JS_CLASS_DECLARATION@28..495 0: ABSTRACT_KW@28..38 "abstract" [Newline("\n")] [Whitespace(" ")] 1: CLASS_KW@38..44 "class" [] [Whitespace(" ")] 2: JS_IDENTIFIER_BINDING@44..49 @@ -364,7 +396,7 @@ JsModule { 2: (empty) 5: (empty) 6: L_CURLY@62..63 "{" [] [] - 7: JS_CLASS_MEMBER_LIST@63..444 + 7: JS_CLASS_MEMBER_LIST@63..493 0: JS_BOGUS_MEMBER@63..92 0: JS_PROPERTY_MODIFIER_LIST@63..86 0: TS_OVERRIDE_MODIFIER@63..77 @@ -514,8 +546,26 @@ JsModule { 0: HASH@441..442 "#" [] [] 1: IDENT@442..443 "l" [] [] 2: SEMICOLON@443..444 ";" [] [] - 8: R_CURLY@444..446 "}" [Newline("\n")] [] - 3: EOF@446..447 "" [Newline("\n")] [] + 16: JS_BOGUS_MEMBER@444..468 + 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@444..466 + 0: TS_DECLARE_MODIFIER@444..457 + 0: DECLARE_KW@444..457 "declare" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@457..466 + 0: ACCESSOR_KW@457..466 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@466..467 + 0: IDENT@466..467 "p" [] [] + 2: SEMICOLON@467..468 ";" [] [] + 17: JS_BOGUS_MEMBER@468..493 + 0: JS_PROPERTY_MODIFIER_LIST@468..491 + 0: JS_ACCESSOR_MODIFIER@468..482 + 0: ACCESSOR_KW@468..482 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@482..491 + 0: ACCESSOR_KW@482..491 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@491..492 + 0: IDENT@491..492 "r" [] [] + 2: SEMICOLON@492..493 ";" [] [] + 8: R_CURLY@493..495 "}" [Newline("\n")] [] + 3: EOF@495..496 "" [Newline("\n")] [] -- ts_class_invalid_modifier_combinations.ts:3:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -940,7 +990,7 @@ ts_class_invalid_modifier_combinations.ts:17:5 parse ━━━━━━━━━ > 17 │ declare async m(); │ ^^^^^^^ 18 │ declare #l; - 19 │ } + 19 │ declare accessor p; -- ts_class_invalid_modifier_combinations.ts:18:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -951,8 +1001,68 @@ ts_class_invalid_modifier_combinations.ts:18:5 parse ━━━━━━━━━ 17 │ declare async m(); > 18 │ declare #l; │ ^^^^^^^ - 19 │ } - 20 │ + 19 │ declare accessor p; + 20 │ accessor accessor r; + +-- +ts_class_invalid_modifier_combinations.ts:19:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'declare' cannot be used with 'accessor' modifier. + + 17 │ declare async m(); + 18 │ declare #l; + > 19 │ declare accessor p; + │ ^^^^^^^ + 20 │ accessor accessor r; + 21 │ } + + i 'declare' modifier + + 17 │ declare async m(); + 18 │ declare #l; + > 19 │ declare accessor p; + │ ^^^^^^^ + 20 │ accessor accessor r; + 21 │ } + + i 'accessor' modifier + + 17 │ declare async m(); + 18 │ declare #l; + > 19 │ declare accessor p; + │ ^^^^^^^^ + 20 │ accessor accessor r; + 21 │ } + +-- +ts_class_invalid_modifier_combinations.ts:20:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'accessor' already seen + + 18 │ declare #l; + 19 │ declare accessor p; + > 20 │ accessor accessor r; + │ ^^^^^^^^ + 21 │ } + 22 │ + + i duplicate modifier + + 18 │ declare #l; + 19 │ declare accessor p; + > 20 │ accessor accessor r; + │ ^^^^^^^^ + 21 │ } + 22 │ + + i first seen here + + 18 │ declare #l; + 19 │ declare accessor p; + > 20 │ accessor accessor r; + │ ^^^^^^^^ + 21 │ } + 22 │ -- class Base { base1; base2; } @@ -973,4 +1083,6 @@ abstract class Test extends Base { abstract async l(); declare async m(); declare #l; + declare accessor p; + accessor accessor r; } diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.ts b/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.ts index fd998ec77c9..be88da23ac2 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.ts +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_invalid_modifier_combinations.ts @@ -16,4 +16,6 @@ abstract class Test extends Base { abstract async l(); declare async m(); declare #l; + declare accessor p; + accessor accessor r; } diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_member_accessor_readonly_precedence.rast b/crates/rome_js_parser/test_data/inline/err/ts_class_member_accessor_readonly_precedence.rast new file mode 100644 index 00000000000..c3fd6e7917b --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_member_accessor_readonly_precedence.rast @@ -0,0 +1,114 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsClassDeclaration { + abstract_token: missing (optional), + class_token: CLASS_KW@0..6 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@6..8 "A" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@8..9 "{" [] [], + members: JsClassMemberList [ + JsBogusMember { + items: [ + JsPropertyModifierList [ + TsReadonlyModifier { + modifier_token: READONLY_KW@9..23 "readonly" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@23..32 "accessor" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@32..35 "foo" [] [], + }, + TsTypeAnnotation { + colon_token: COLON@35..37 ":" [] [Whitespace(" ")], + ty: TsNumberType { + number_token: NUMBER_KW@37..44 "number" [] [Whitespace(" ")], + }, + }, + JsInitializerClause { + eq_token: EQ@44..46 "=" [] [Whitespace(" ")], + expression: JsNumberLiteralExpression { + value_token: JS_NUMBER_LITERAL@46..47 "1" [] [], + }, + }, + SEMICOLON@47..48 ";" [] [], + ], + }, + ], + r_curly_token: R_CURLY@48..50 "}" [Newline("\n")] [], + }, + ], + eof_token: EOF@50..51 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..51 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..50 + 0: JS_CLASS_DECLARATION@0..50 + 0: (empty) + 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@6..8 + 0: IDENT@6..8 "A" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@8..9 "{" [] [] + 7: JS_CLASS_MEMBER_LIST@9..48 + 0: JS_BOGUS_MEMBER@9..48 + 0: JS_PROPERTY_MODIFIER_LIST@9..32 + 0: TS_READONLY_MODIFIER@9..23 + 0: READONLY_KW@9..23 "readonly" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@23..32 + 0: ACCESSOR_KW@23..32 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@32..35 + 0: IDENT@32..35 "foo" [] [] + 2: TS_TYPE_ANNOTATION@35..44 + 0: COLON@35..37 ":" [] [Whitespace(" ")] + 1: TS_NUMBER_TYPE@37..44 + 0: NUMBER_KW@37..44 "number" [] [Whitespace(" ")] + 3: JS_INITIALIZER_CLAUSE@44..47 + 0: EQ@44..46 "=" [] [Whitespace(" ")] + 1: JS_NUMBER_LITERAL_EXPRESSION@46..47 + 0: JS_NUMBER_LITERAL@46..47 "1" [] [] + 4: SEMICOLON@47..48 ";" [] [] + 8: R_CURLY@48..50 "}" [Newline("\n")] [] + 3: EOF@50..51 "" [Newline("\n")] [] +-- +ts_class_member_accessor_readonly_precedence.ts:2:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'accessor' must precede 'readonly' + + 1 │ class A { + > 2 │ readonly accessor foo: number = 1; + │ ^^^^^^^^ + 3 │ } + 4 │ + + i move this modifier + + 1 │ class A { + > 2 │ readonly accessor foo: number = 1; + │ ^^^^^^^^ + 3 │ } + 4 │ + + i before this modifier + + 1 │ class A { + > 2 │ readonly accessor foo: number = 1; + │ ^^^^^^^^ + 3 │ } + 4 │ + +-- +class A { + readonly accessor foo: number = 1; +} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_member_accessor_readonly_precedence.ts b/crates/rome_js_parser/test_data/inline/err/ts_class_member_accessor_readonly_precedence.ts new file mode 100644 index 00000000000..9a5eb7ddd81 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_member_accessor_readonly_precedence.ts @@ -0,0 +1,3 @@ +class A { + readonly accessor foo: number = 1; +} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.rast b/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.rast index 7d6dad74851..2e3c7766ff7 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.rast @@ -178,80 +178,146 @@ JsModule { JsBogusMember { items: [ JsPropertyModifierList [ - TsOverrideModifier { - modifier_token: OVERRIDE_KW@268..282 "override" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + JsAccessorModifier { + modifier_token: ACCESSOR_KW@268..282 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], }, JsStaticModifier { modifier_token: STATIC_KW@282..289 "static" [] [Whitespace(" ")], }, ], JsLiteralMemberName { - value: IDENT@289..294 "base2" [] [], + value: IDENT@289..290 "d" [] [], + }, + TsTypeAnnotation { + colon_token: COLON@290..292 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@292..298 "string" [] [], + }, + }, + SEMICOLON@298..299 ";" [] [], + ], + }, + JsBogusMember { + items: [ + JsPropertyModifierList [ + TsOverrideModifier { + modifier_token: OVERRIDE_KW@299..313 "override" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsStaticModifier { + modifier_token: STATIC_KW@313..320 "static" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@320..325 "base2" [] [], + }, + TsTypeAnnotation { + colon_token: COLON@325..327 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@327..333 "string" [] [], + }, + }, + SEMICOLON@333..334 ";" [] [], + ], + }, + JsBogusMember { + items: [ + JsPropertyModifierList [ + TsReadonlyModifier { + modifier_token: READONLY_KW@334..364 "readonly" [Newline("\n"), Whitespace(" "), Comments("// Accessor"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@364..373 "accessor" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@373..374 "e" [] [], }, TsTypeAnnotation { - colon_token: COLON@294..296 ":" [] [Whitespace(" ")], + colon_token: COLON@374..376 ":" [] [Whitespace(" ")], ty: TsStringType { - string_token: STRING_KW@296..302 "string" [] [], + string_token: STRING_KW@376..382 "string" [] [], }, }, - SEMICOLON@302..303 ";" [] [], + SEMICOLON@382..383 ";" [] [], + ], + }, + JsBogusMember { + items: [ + JsPropertyModifierList [ + TsOverrideModifier { + modifier_token: OVERRIDE_KW@383..397 "override" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@397..406 "accessor" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@406..407 "f" [] [], + }, + TsTypeAnnotation { + colon_token: COLON@407..409 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@409..415 "string" [] [], + }, + }, + SEMICOLON@415..416 ";" [] [], ], }, JsBogusMember { items: [ TsPropertySignatureModifierList [ TsOverrideModifier { - modifier_token: OVERRIDE_KW@303..333 "override" [Newline("\n"), Whitespace(" "), Comments("// abstract"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + modifier_token: OVERRIDE_KW@416..446 "override" [Newline("\n"), Whitespace(" "), Comments("// abstract"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")], }, TsAbstractModifier { - modifier_token: ABSTRACT_KW@333..342 "abstract" [] [Whitespace(" ")], + modifier_token: ABSTRACT_KW@446..455 "abstract" [] [Whitespace(" ")], }, ], JsLiteralMemberName { - value: IDENT@342..347 "base3" [] [], + value: IDENT@455..460 "base3" [] [], }, TsTypeAnnotation { - colon_token: COLON@347..349 ":" [] [Whitespace(" ")], + colon_token: COLON@460..462 ":" [] [Whitespace(" ")], ty: TsStringType { - string_token: STRING_KW@349..355 "string" [] [], + string_token: STRING_KW@462..468 "string" [] [], }, }, - SEMICOLON@355..356 ";" [] [], + SEMICOLON@468..469 ";" [] [], ], }, JsBogusMember { items: [ JsPropertyModifierList [ TsReadonlyModifier { - modifier_token: READONLY_KW@356..386 "readonly" [Newline("\n"), Whitespace(" "), Comments("// override"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + modifier_token: READONLY_KW@469..499 "readonly" [Newline("\n"), Whitespace(" "), Comments("// override"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")], }, TsOverrideModifier { - modifier_token: OVERRIDE_KW@386..395 "override" [] [Whitespace(" ")], + modifier_token: OVERRIDE_KW@499..508 "override" [] [Whitespace(" ")], }, ], JsLiteralMemberName { - value: IDENT@395..400 "base4" [] [], + value: IDENT@508..513 "base4" [] [], }, TsTypeAnnotation { - colon_token: COLON@400..402 ":" [] [Whitespace(" ")], + colon_token: COLON@513..515 ":" [] [Whitespace(" ")], ty: TsStringType { - string_token: STRING_KW@402..408 "string" [] [], + string_token: STRING_KW@515..521 "string" [] [], }, }, - SEMICOLON@408..409 ";" [] [], + SEMICOLON@521..522 ";" [] [], ], }, ], - r_curly_token: R_CURLY@409..411 "}" [Newline("\n")] [], + r_curly_token: R_CURLY@522..524 "}" [Newline("\n")] [], }, ], - eof_token: EOF@411..412 "" [Newline("\n")] [], + eof_token: EOF@524..525 "" [Newline("\n")] [], } -0: JS_MODULE@0..412 +0: JS_MODULE@0..525 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..411 + 2: JS_MODULE_ITEM_LIST@0..524 0: JS_CLASS_DECLARATION@0..41 0: (empty) 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] @@ -291,7 +357,7 @@ JsModule { 3: (empty) 4: SEMICOLON@39..40 ";" [] [] 8: R_CURLY@40..41 "}" [] [] - 1: JS_CLASS_DECLARATION@41..411 + 1: JS_CLASS_DECLARATION@41..524 0: ABSTRACT_KW@41..51 "abstract" [Newline("\n")] [Whitespace(" ")] 1: CLASS_KW@51..57 "class" [] [Whitespace(" ")] 2: JS_IDENTIFIER_BINDING@57..62 @@ -305,7 +371,7 @@ JsModule { 2: (empty) 5: (empty) 6: L_CURLY@75..76 "{" [] [] - 7: JS_CLASS_MEMBER_LIST@76..409 + 7: JS_CLASS_MEMBER_LIST@76..522 0: JS_BOGUS_MEMBER@76..129 0: JS_PROPERTY_MODIFIER_LIST@76..119 0: TS_READONLY_MODIFIER@76..111 @@ -367,47 +433,86 @@ JsModule { 1: TS_STRING_TYPE@261..267 0: STRING_KW@261..267 "string" [] [] 3: SEMICOLON@267..268 ";" [] [] - 5: JS_BOGUS_MEMBER@268..303 + 5: JS_BOGUS_MEMBER@268..299 0: JS_PROPERTY_MODIFIER_LIST@268..289 - 0: TS_OVERRIDE_MODIFIER@268..282 - 0: OVERRIDE_KW@268..282 "override" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 0: JS_ACCESSOR_MODIFIER@268..282 + 0: ACCESSOR_KW@268..282 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] 1: JS_STATIC_MODIFIER@282..289 0: STATIC_KW@282..289 "static" [] [Whitespace(" ")] - 1: JS_LITERAL_MEMBER_NAME@289..294 - 0: IDENT@289..294 "base2" [] [] - 2: TS_TYPE_ANNOTATION@294..302 - 0: COLON@294..296 ":" [] [Whitespace(" ")] - 1: TS_STRING_TYPE@296..302 - 0: STRING_KW@296..302 "string" [] [] - 3: SEMICOLON@302..303 ";" [] [] - 6: JS_BOGUS_MEMBER@303..356 - 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@303..342 - 0: TS_OVERRIDE_MODIFIER@303..333 - 0: OVERRIDE_KW@303..333 "override" [Newline("\n"), Whitespace(" "), Comments("// abstract"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")] - 1: TS_ABSTRACT_MODIFIER@333..342 - 0: ABSTRACT_KW@333..342 "abstract" [] [Whitespace(" ")] - 1: JS_LITERAL_MEMBER_NAME@342..347 - 0: IDENT@342..347 "base3" [] [] - 2: TS_TYPE_ANNOTATION@347..355 - 0: COLON@347..349 ":" [] [Whitespace(" ")] - 1: TS_STRING_TYPE@349..355 - 0: STRING_KW@349..355 "string" [] [] - 3: SEMICOLON@355..356 ";" [] [] - 7: JS_BOGUS_MEMBER@356..409 - 0: JS_PROPERTY_MODIFIER_LIST@356..395 - 0: TS_READONLY_MODIFIER@356..386 - 0: READONLY_KW@356..386 "readonly" [Newline("\n"), Whitespace(" "), Comments("// override"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")] - 1: TS_OVERRIDE_MODIFIER@386..395 - 0: OVERRIDE_KW@386..395 "override" [] [Whitespace(" ")] - 1: JS_LITERAL_MEMBER_NAME@395..400 - 0: IDENT@395..400 "base4" [] [] - 2: TS_TYPE_ANNOTATION@400..408 - 0: COLON@400..402 ":" [] [Whitespace(" ")] - 1: TS_STRING_TYPE@402..408 - 0: STRING_KW@402..408 "string" [] [] - 3: SEMICOLON@408..409 ";" [] [] - 8: R_CURLY@409..411 "}" [Newline("\n")] [] - 3: EOF@411..412 "" [Newline("\n")] [] + 1: JS_LITERAL_MEMBER_NAME@289..290 + 0: IDENT@289..290 "d" [] [] + 2: TS_TYPE_ANNOTATION@290..298 + 0: COLON@290..292 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@292..298 + 0: STRING_KW@292..298 "string" [] [] + 3: SEMICOLON@298..299 ";" [] [] + 6: JS_BOGUS_MEMBER@299..334 + 0: JS_PROPERTY_MODIFIER_LIST@299..320 + 0: TS_OVERRIDE_MODIFIER@299..313 + 0: OVERRIDE_KW@299..313 "override" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_STATIC_MODIFIER@313..320 + 0: STATIC_KW@313..320 "static" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@320..325 + 0: IDENT@320..325 "base2" [] [] + 2: TS_TYPE_ANNOTATION@325..333 + 0: COLON@325..327 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@327..333 + 0: STRING_KW@327..333 "string" [] [] + 3: SEMICOLON@333..334 ";" [] [] + 7: JS_BOGUS_MEMBER@334..383 + 0: JS_PROPERTY_MODIFIER_LIST@334..373 + 0: TS_READONLY_MODIFIER@334..364 + 0: READONLY_KW@334..364 "readonly" [Newline("\n"), Whitespace(" "), Comments("// Accessor"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@364..373 + 0: ACCESSOR_KW@364..373 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@373..374 + 0: IDENT@373..374 "e" [] [] + 2: TS_TYPE_ANNOTATION@374..382 + 0: COLON@374..376 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@376..382 + 0: STRING_KW@376..382 "string" [] [] + 3: SEMICOLON@382..383 ";" [] [] + 8: JS_BOGUS_MEMBER@383..416 + 0: JS_PROPERTY_MODIFIER_LIST@383..406 + 0: TS_OVERRIDE_MODIFIER@383..397 + 0: OVERRIDE_KW@383..397 "override" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@397..406 + 0: ACCESSOR_KW@397..406 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@406..407 + 0: IDENT@406..407 "f" [] [] + 2: TS_TYPE_ANNOTATION@407..415 + 0: COLON@407..409 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@409..415 + 0: STRING_KW@409..415 "string" [] [] + 3: SEMICOLON@415..416 ";" [] [] + 9: JS_BOGUS_MEMBER@416..469 + 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@416..455 + 0: TS_OVERRIDE_MODIFIER@416..446 + 0: OVERRIDE_KW@416..446 "override" [Newline("\n"), Whitespace(" "), Comments("// abstract"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: TS_ABSTRACT_MODIFIER@446..455 + 0: ABSTRACT_KW@446..455 "abstract" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@455..460 + 0: IDENT@455..460 "base3" [] [] + 2: TS_TYPE_ANNOTATION@460..468 + 0: COLON@460..462 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@462..468 + 0: STRING_KW@462..468 "string" [] [] + 3: SEMICOLON@468..469 ";" [] [] + 10: JS_BOGUS_MEMBER@469..522 + 0: JS_PROPERTY_MODIFIER_LIST@469..508 + 0: TS_READONLY_MODIFIER@469..499 + 0: READONLY_KW@469..499 "readonly" [Newline("\n"), Whitespace(" "), Comments("// override"), Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: TS_OVERRIDE_MODIFIER@499..508 + 0: OVERRIDE_KW@499..508 "override" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@508..513 + 0: IDENT@508..513 "base4" [] [] + 2: TS_TYPE_ANNOTATION@513..521 + 0: COLON@513..515 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@515..521 + 0: STRING_KW@515..521 "string" [] [] + 3: SEMICOLON@521..522 ";" [] [] + 8: R_CURLY@522..524 "}" [Newline("\n")] [] + 3: EOF@524..525 "" [Newline("\n")] [] -- ts_class_modifier_precedence.ts:4:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -537,8 +642,8 @@ ts_class_modifier_precedence.ts:9:14 parse ━━━━━━━━━━━━ 8 │ // Static > 9 │ readonly static c: string; │ ^^^^^^ - 10 │ override static base2: string; - 11 │ // abstract + 10 │ accessor static d: string; + 11 │ override static base2: string; i move this modifier @@ -546,8 +651,8 @@ ts_class_modifier_precedence.ts:9:14 parse ━━━━━━━━━━━━ 8 │ // Static > 9 │ readonly static c: string; │ ^^^^^^ - 10 │ override static base2: string; - 11 │ // abstract + 10 │ accessor static d: string; + 11 │ override static base2: string; i before this modifier @@ -555,98 +660,188 @@ ts_class_modifier_precedence.ts:9:14 parse ━━━━━━━━━━━━ 8 │ // Static > 9 │ readonly static c: string; │ ^^^^^^^^ - 10 │ override static base2: string; - 11 │ // abstract + 10 │ accessor static d: string; + 11 │ override static base2: string; -- ts_class_modifier_precedence.ts:10:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × 'static' must precede 'override' + × 'static' must precede 'accessor' 8 │ // Static 9 │ readonly static c: string; - > 10 │ override static base2: string; + > 10 │ accessor static d: string; │ ^^^^^^ - 11 │ // abstract - 12 │ override abstract base3: string; + 11 │ override static base2: string; + 12 │ // Accessor i move this modifier 8 │ // Static 9 │ readonly static c: string; - > 10 │ override static base2: string; + > 10 │ accessor static d: string; │ ^^^^^^ - 11 │ // abstract - 12 │ override abstract base3: string; + 11 │ override static base2: string; + 12 │ // Accessor i before this modifier 8 │ // Static 9 │ readonly static c: string; - > 10 │ override static base2: string; + > 10 │ accessor static d: string; │ ^^^^^^^^ - 11 │ // abstract - 12 │ override abstract base3: string; + 11 │ override static base2: string; + 12 │ // Accessor -- -ts_class_modifier_precedence.ts:12:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +ts_class_modifier_precedence.ts:11:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × 'abstract' must precede 'override' + × 'static' must precede 'override' + + 9 │ readonly static c: string; + 10 │ accessor static d: string; + > 11 │ override static base2: string; + │ ^^^^^^ + 12 │ // Accessor + 13 │ readonly accessor e: string; + + i move this modifier + + 9 │ readonly static c: string; + 10 │ accessor static d: string; + > 11 │ override static base2: string; + │ ^^^^^^ + 12 │ // Accessor + 13 │ readonly accessor e: string; - 10 │ override static base2: string; - 11 │ // abstract - > 12 │ override abstract base3: string; + i before this modifier + + 9 │ readonly static c: string; + 10 │ accessor static d: string; + > 11 │ override static base2: string; + │ ^^^^^^^^ + 12 │ // Accessor + 13 │ readonly accessor e: string; + +-- +ts_class_modifier_precedence.ts:13:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'accessor' must precede 'readonly' + + 11 │ override static base2: string; + 12 │ // Accessor + > 13 │ readonly accessor e: string; │ ^^^^^^^^ - 13 │ // override - 14 │ readonly override base4: string; + 14 │ override accessor f: string; + 15 │ // abstract i move this modifier - 10 │ override static base2: string; - 11 │ // abstract - > 12 │ override abstract base3: string; + 11 │ override static base2: string; + 12 │ // Accessor + > 13 │ readonly accessor e: string; │ ^^^^^^^^ - 13 │ // override - 14 │ readonly override base4: string; + 14 │ override accessor f: string; + 15 │ // abstract i before this modifier - 10 │ override static base2: string; - 11 │ // abstract - > 12 │ override abstract base3: string; + 11 │ override static base2: string; + 12 │ // Accessor + > 13 │ readonly accessor e: string; │ ^^^^^^^^ - 13 │ // override - 14 │ readonly override base4: string; + 14 │ override accessor f: string; + 15 │ // abstract -- ts_class_modifier_precedence.ts:14:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + × 'accessor' cannot be used with 'override' modifier. + + 12 │ // Accessor + 13 │ readonly accessor e: string; + > 14 │ override accessor f: string; + │ ^^^^^^^^ + 15 │ // abstract + 16 │ override abstract base3: string; + + i 'accessor' modifier + + 12 │ // Accessor + 13 │ readonly accessor e: string; + > 14 │ override accessor f: string; + │ ^^^^^^^^ + 15 │ // abstract + 16 │ override abstract base3: string; + + i 'override' modifier + + 12 │ // Accessor + 13 │ readonly accessor e: string; + > 14 │ override accessor f: string; + │ ^^^^^^^^ + 15 │ // abstract + 16 │ override abstract base3: string; + +-- +ts_class_modifier_precedence.ts:16:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'abstract' must precede 'override' + + 14 │ override accessor f: string; + 15 │ // abstract + > 16 │ override abstract base3: string; + │ ^^^^^^^^ + 17 │ // override + 18 │ readonly override base4: string; + + i move this modifier + + 14 │ override accessor f: string; + 15 │ // abstract + > 16 │ override abstract base3: string; + │ ^^^^^^^^ + 17 │ // override + 18 │ readonly override base4: string; + + i before this modifier + + 14 │ override accessor f: string; + 15 │ // abstract + > 16 │ override abstract base3: string; + │ ^^^^^^^^ + 17 │ // override + 18 │ readonly override base4: string; + +-- +ts_class_modifier_precedence.ts:18:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + × 'override' must precede 'readonly' - 12 │ override abstract base3: string; - 13 │ // override - > 14 │ readonly override base4: string; + 16 │ override abstract base3: string; + 17 │ // override + > 18 │ readonly override base4: string; │ ^^^^^^^^ - 15 │ } - 16 │ + 19 │ } + 20 │ i move this modifier - 12 │ override abstract base3: string; - 13 │ // override - > 14 │ readonly override base4: string; + 16 │ override abstract base3: string; + 17 │ // override + > 18 │ readonly override base4: string; │ ^^^^^^^^ - 15 │ } - 16 │ + 19 │ } + 20 │ i before this modifier - 12 │ override abstract base3: string; - 13 │ // override - > 14 │ readonly override base4: string; + 16 │ override abstract base3: string; + 17 │ // override + > 18 │ readonly override base4: string; │ ^^^^^^^^ - 15 │ } - 16 │ + 19 │ } + 20 │ -- class Base { base1; base2; base3; base4;} @@ -658,7 +853,11 @@ abstract class Test extends Base { abstract protected d: string; // Static readonly static c: string; + accessor static d: string; override static base2: string; + // Accessor + readonly accessor e: string; + override accessor f: string; // abstract override abstract base3: string; // override diff --git a/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.ts b/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.ts index 7560c5c3569..60bf6c26e2d 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.ts +++ b/crates/rome_js_parser/test_data/inline/err/ts_class_modifier_precedence.ts @@ -7,7 +7,11 @@ abstract class Test extends Base { abstract protected d: string; // Static readonly static c: string; + accessor static d: string; override static base2: string; + // Accessor + readonly accessor e: string; + override accessor f: string; // abstract override abstract base3: string; // override diff --git a/crates/rome_js_parser/test_data/inline/err/ts_index_signature_class_member_cannot_be_accessor.rast b/crates/rome_js_parser/test_data/inline/err/ts_index_signature_class_member_cannot_be_accessor.rast new file mode 100644 index 00000000000..a060086c0d4 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/ts_index_signature_class_member_cannot_be_accessor.rast @@ -0,0 +1,102 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsClassDeclaration { + abstract_token: ABSTRACT_KW@0..9 "abstract" [] [Whitespace(" ")], + class_token: CLASS_KW@9..15 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@15..17 "A" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@17..18 "{" [] [], + members: JsClassMemberList [ + JsBogusMember { + items: [ + JsBogus { + items: [ + JsAccessorModifier { + modifier_token: ACCESSOR_KW@18..32 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + ], + }, + L_BRACK@32..33 "[" [] [], + TsIndexSignatureParameter { + binding: JsIdentifierBinding { + name_token: IDENT@33..34 "a" [] [], + }, + type_annotation: TsTypeAnnotation { + colon_token: COLON@34..36 ":" [] [Whitespace(" ")], + ty: TsNumberType { + number_token: NUMBER_KW@36..42 "number" [] [], + }, + }, + }, + R_BRACK@42..43 "]" [] [], + TsTypeAnnotation { + colon_token: COLON@43..45 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@45..51 "string" [] [], + }, + }, + SEMICOLON@51..52 ";" [] [], + ], + }, + ], + r_curly_token: R_CURLY@52..54 "}" [Newline("\n")] [], + }, + ], + eof_token: EOF@54..55 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..55 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..54 + 0: JS_CLASS_DECLARATION@0..54 + 0: ABSTRACT_KW@0..9 "abstract" [] [Whitespace(" ")] + 1: CLASS_KW@9..15 "class" [] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@15..17 + 0: IDENT@15..17 "A" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@17..18 "{" [] [] + 7: JS_CLASS_MEMBER_LIST@18..52 + 0: JS_BOGUS_MEMBER@18..52 + 0: JS_BOGUS@18..32 + 0: JS_ACCESSOR_MODIFIER@18..32 + 0: ACCESSOR_KW@18..32 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: L_BRACK@32..33 "[" [] [] + 2: TS_INDEX_SIGNATURE_PARAMETER@33..42 + 0: JS_IDENTIFIER_BINDING@33..34 + 0: IDENT@33..34 "a" [] [] + 1: TS_TYPE_ANNOTATION@34..42 + 0: COLON@34..36 ":" [] [Whitespace(" ")] + 1: TS_NUMBER_TYPE@36..42 + 0: NUMBER_KW@36..42 "number" [] [] + 3: R_BRACK@42..43 "]" [] [] + 4: TS_TYPE_ANNOTATION@43..51 + 0: COLON@43..45 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@45..51 + 0: STRING_KW@45..51 "string" [] [] + 5: SEMICOLON@51..52 ";" [] [] + 8: R_CURLY@52..54 "}" [Newline("\n")] [] + 3: EOF@54..55 "" [Newline("\n")] [] +-- +ts_index_signature_class_member_cannot_be_accessor.ts:2:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'accessor' modifier cannot appear on an index signature. + + 1 │ abstract class A { + > 2 │ accessor [a: number]: string; + │ ^^^^^^^^ + 3 │ } + 4 │ + +-- +abstract class A { + accessor [a: number]: string; +} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_index_signature_class_member_cannot_be_accessor.ts b/crates/rome_js_parser/test_data/inline/err/ts_index_signature_class_member_cannot_be_accessor.ts new file mode 100644 index 00000000000..875ebf1b91b --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/ts_index_signature_class_member_cannot_be_accessor.ts @@ -0,0 +1,3 @@ +abstract class A { + accessor [a: number]: string; +} diff --git a/crates/rome_js_parser/test_data/inline/err/typescript_abstract_classes_abstract_accessor_precedence.rast b/crates/rome_js_parser/test_data/inline/err/typescript_abstract_classes_abstract_accessor_precedence.rast new file mode 100644 index 00000000000..c8b96d65b60 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/typescript_abstract_classes_abstract_accessor_precedence.rast @@ -0,0 +1,96 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsClassDeclaration { + abstract_token: ABSTRACT_KW@0..9 "abstract" [] [Whitespace(" ")], + class_token: CLASS_KW@9..15 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@15..17 "A" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@17..19 "{" [] [Whitespace(" ")], + members: JsClassMemberList [ + JsBogusMember { + items: [ + TsPropertySignatureModifierList [ + JsAccessorModifier { + modifier_token: ACCESSOR_KW@19..28 "accessor" [] [Whitespace(" ")], + }, + TsAbstractModifier { + modifier_token: ABSTRACT_KW@28..37 "abstract" [] [Whitespace(" ")], + }, + ], + JsLiteralMemberName { + value: IDENT@37..40 "foo" [] [], + }, + TsTypeAnnotation { + colon_token: COLON@40..42 ":" [] [Whitespace(" ")], + ty: TsNumberType { + number_token: NUMBER_KW@42..48 "number" [] [], + }, + }, + SEMICOLON@48..50 ";" [] [Whitespace(" ")], + ], + }, + ], + r_curly_token: R_CURLY@50..51 "}" [] [], + }, + ], + eof_token: EOF@51..52 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..52 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..51 + 0: JS_CLASS_DECLARATION@0..51 + 0: ABSTRACT_KW@0..9 "abstract" [] [Whitespace(" ")] + 1: CLASS_KW@9..15 "class" [] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@15..17 + 0: IDENT@15..17 "A" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@17..19 "{" [] [Whitespace(" ")] + 7: JS_CLASS_MEMBER_LIST@19..50 + 0: JS_BOGUS_MEMBER@19..50 + 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@19..37 + 0: JS_ACCESSOR_MODIFIER@19..28 + 0: ACCESSOR_KW@19..28 "accessor" [] [Whitespace(" ")] + 1: TS_ABSTRACT_MODIFIER@28..37 + 0: ABSTRACT_KW@28..37 "abstract" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@37..40 + 0: IDENT@37..40 "foo" [] [] + 2: TS_TYPE_ANNOTATION@40..48 + 0: COLON@40..42 ":" [] [Whitespace(" ")] + 1: TS_NUMBER_TYPE@42..48 + 0: NUMBER_KW@42..48 "number" [] [] + 3: SEMICOLON@48..50 ";" [] [Whitespace(" ")] + 8: R_CURLY@50..51 "}" [] [] + 3: EOF@51..52 "" [Newline("\n")] [] +-- +typescript_abstract_classes_abstract_accessor_precedence.ts:1:29 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'abstract' must precede 'accessor' + + > 1 │ abstract class A { accessor abstract foo: number; } + │ ^^^^^^^^ + 2 │ + + i move this modifier + + > 1 │ abstract class A { accessor abstract foo: number; } + │ ^^^^^^^^ + 2 │ + + i before this modifier + + > 1 │ abstract class A { accessor abstract foo: number; } + │ ^^^^^^^^ + 2 │ + +-- +abstract class A { accessor abstract foo: number; } diff --git a/crates/rome_js_parser/test_data/inline/err/typescript_abstract_classes_abstract_accessor_precedence.ts b/crates/rome_js_parser/test_data/inline/err/typescript_abstract_classes_abstract_accessor_precedence.ts new file mode 100644 index 00000000000..f4525039f6e --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/err/typescript_abstract_classes_abstract_accessor_precedence.ts @@ -0,0 +1 @@ +abstract class A { accessor abstract foo: number; } diff --git a/crates/rome_js_parser/test_data/inline/ok/identifier.js b/crates/rome_js_parser/test_data/inline/ok/identifier.js index e901f01b487..128eacb2b28 100644 --- a/crates/rome_js_parser/test_data/inline/ok/identifier.js +++ b/crates/rome_js_parser/test_data/inline/ok/identifier.js @@ -1 +1,2 @@ foo; +let accessor = 5; diff --git a/crates/rome_js_parser/test_data/inline/ok/identifier.rast b/crates/rome_js_parser/test_data/inline/ok/identifier.rast index 133cc98597e..d606e306005 100644 --- a/crates/rome_js_parser/test_data/inline/ok/identifier.rast +++ b/crates/rome_js_parser/test_data/inline/ok/identifier.rast @@ -10,17 +10,50 @@ JsModule { }, semicolon_token: SEMICOLON@3..4 ";" [] [], }, + JsVariableStatement { + declaration: JsVariableDeclaration { + kind: LET_KW@4..9 "let" [Newline("\n")] [Whitespace(" ")], + declarators: JsVariableDeclaratorList [ + JsVariableDeclarator { + id: JsIdentifierBinding { + name_token: IDENT@9..18 "accessor" [] [Whitespace(" ")], + }, + variable_annotation: missing (optional), + initializer: JsInitializerClause { + eq_token: EQ@18..20 "=" [] [Whitespace(" ")], + expression: JsNumberLiteralExpression { + value_token: JS_NUMBER_LITERAL@20..21 "5" [] [], + }, + }, + }, + ], + }, + semicolon_token: SEMICOLON@21..22 ";" [] [], + }, ], - eof_token: EOF@4..5 "" [Newline("\n")] [], + eof_token: EOF@22..23 "" [Newline("\n")] [], } -0: JS_MODULE@0..5 +0: JS_MODULE@0..23 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..4 + 2: JS_MODULE_ITEM_LIST@0..22 0: JS_EXPRESSION_STATEMENT@0..4 0: JS_IDENTIFIER_EXPRESSION@0..3 0: JS_REFERENCE_IDENTIFIER@0..3 0: IDENT@0..3 "foo" [] [] 1: SEMICOLON@3..4 ";" [] [] - 3: EOF@4..5 "" [Newline("\n")] [] + 1: JS_VARIABLE_STATEMENT@4..22 + 0: JS_VARIABLE_DECLARATION@4..21 + 0: LET_KW@4..9 "let" [Newline("\n")] [Whitespace(" ")] + 1: JS_VARIABLE_DECLARATOR_LIST@9..21 + 0: JS_VARIABLE_DECLARATOR@9..21 + 0: JS_IDENTIFIER_BINDING@9..18 + 0: IDENT@9..18 "accessor" [] [Whitespace(" ")] + 1: (empty) + 2: JS_INITIALIZER_CLAUSE@18..21 + 0: EQ@18..20 "=" [] [Whitespace(" ")] + 1: JS_NUMBER_LITERAL_EXPRESSION@20..21 + 0: JS_NUMBER_LITERAL@20..21 "5" [] [] + 1: SEMICOLON@21..22 ";" [] [] + 3: EOF@22..23 "" [Newline("\n")] [] diff --git a/crates/rome_js_parser/test_data/inline/ok/js_class_property_member_modifiers.js b/crates/rome_js_parser/test_data/inline/ok/js_class_property_member_modifiers.js new file mode 100644 index 00000000000..375cbb72d90 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/ok/js_class_property_member_modifiers.js @@ -0,0 +1,9 @@ +class Test { + static a = 1; + accessor b = 1; + static accessor c = 1; +} +class Foo { + accessor + foo +} diff --git a/crates/rome_js_parser/test_data/inline/ok/js_class_property_member_modifiers.rast b/crates/rome_js_parser/test_data/inline/ok/js_class_property_member_modifiers.rast new file mode 100644 index 00000000000..8a9e1382ca7 --- /dev/null +++ b/crates/rome_js_parser/test_data/inline/ok/js_class_property_member_modifiers.rast @@ -0,0 +1,190 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsClassDeclaration { + abstract_token: missing (optional), + class_token: CLASS_KW@0..6 "class" [] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@6..11 "Test" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@11..12 "{" [] [], + members: JsClassMemberList [ + JsPropertyClassMember { + modifiers: JsPropertyModifierList [ + JsStaticModifier { + modifier_token: STATIC_KW@12..24 "static" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + ], + name: JsLiteralMemberName { + value: IDENT@24..26 "a" [] [Whitespace(" ")], + }, + property_annotation: missing (optional), + value: JsInitializerClause { + eq_token: EQ@26..28 "=" [] [Whitespace(" ")], + expression: JsNumberLiteralExpression { + value_token: JS_NUMBER_LITERAL@28..29 "1" [] [], + }, + }, + semicolon_token: SEMICOLON@29..30 ";" [] [], + }, + JsPropertyClassMember { + modifiers: JsPropertyModifierList [ + JsAccessorModifier { + modifier_token: ACCESSOR_KW@30..44 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + ], + name: JsLiteralMemberName { + value: IDENT@44..46 "b" [] [Whitespace(" ")], + }, + property_annotation: missing (optional), + value: JsInitializerClause { + eq_token: EQ@46..48 "=" [] [Whitespace(" ")], + expression: JsNumberLiteralExpression { + value_token: JS_NUMBER_LITERAL@48..49 "1" [] [], + }, + }, + semicolon_token: SEMICOLON@49..50 ";" [] [], + }, + JsPropertyClassMember { + modifiers: JsPropertyModifierList [ + JsStaticModifier { + modifier_token: STATIC_KW@50..62 "static" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@62..71 "accessor" [] [Whitespace(" ")], + }, + ], + name: JsLiteralMemberName { + value: IDENT@71..73 "c" [] [Whitespace(" ")], + }, + property_annotation: missing (optional), + value: JsInitializerClause { + eq_token: EQ@73..75 "=" [] [Whitespace(" ")], + expression: JsNumberLiteralExpression { + value_token: JS_NUMBER_LITERAL@75..76 "1" [] [], + }, + }, + semicolon_token: SEMICOLON@76..77 ";" [] [], + }, + ], + r_curly_token: R_CURLY@77..79 "}" [Newline("\n")] [], + }, + JsClassDeclaration { + abstract_token: missing (optional), + class_token: CLASS_KW@79..86 "class" [Newline("\n")] [Whitespace(" ")], + id: JsIdentifierBinding { + name_token: IDENT@86..90 "Foo" [] [Whitespace(" ")], + }, + type_parameters: missing (optional), + extends_clause: missing (optional), + implements_clause: missing (optional), + l_curly_token: L_CURLY@90..91 "{" [] [], + members: JsClassMemberList [ + JsPropertyClassMember { + modifiers: JsPropertyModifierList [], + name: JsLiteralMemberName { + value: IDENT@91..104 "accessor" [Newline("\n"), Whitespace(" ")] [], + }, + property_annotation: missing (optional), + value: missing (optional), + semicolon_token: missing (optional), + }, + JsPropertyClassMember { + modifiers: JsPropertyModifierList [], + name: JsLiteralMemberName { + value: IDENT@104..112 "foo" [Newline("\n"), Whitespace(" ")] [], + }, + property_annotation: missing (optional), + value: missing (optional), + semicolon_token: missing (optional), + }, + ], + r_curly_token: R_CURLY@112..114 "}" [Newline("\n")] [], + }, + ], + eof_token: EOF@114..115 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..115 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..114 + 0: JS_CLASS_DECLARATION@0..79 + 0: (empty) + 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@6..11 + 0: IDENT@6..11 "Test" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@11..12 "{" [] [] + 7: JS_CLASS_MEMBER_LIST@12..77 + 0: JS_PROPERTY_CLASS_MEMBER@12..30 + 0: JS_PROPERTY_MODIFIER_LIST@12..24 + 0: JS_STATIC_MODIFIER@12..24 + 0: STATIC_KW@12..24 "static" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@24..26 + 0: IDENT@24..26 "a" [] [Whitespace(" ")] + 2: (empty) + 3: JS_INITIALIZER_CLAUSE@26..29 + 0: EQ@26..28 "=" [] [Whitespace(" ")] + 1: JS_NUMBER_LITERAL_EXPRESSION@28..29 + 0: JS_NUMBER_LITERAL@28..29 "1" [] [] + 4: SEMICOLON@29..30 ";" [] [] + 1: JS_PROPERTY_CLASS_MEMBER@30..50 + 0: JS_PROPERTY_MODIFIER_LIST@30..44 + 0: JS_ACCESSOR_MODIFIER@30..44 + 0: ACCESSOR_KW@30..44 "accessor" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@44..46 + 0: IDENT@44..46 "b" [] [Whitespace(" ")] + 2: (empty) + 3: JS_INITIALIZER_CLAUSE@46..49 + 0: EQ@46..48 "=" [] [Whitespace(" ")] + 1: JS_NUMBER_LITERAL_EXPRESSION@48..49 + 0: JS_NUMBER_LITERAL@48..49 "1" [] [] + 4: SEMICOLON@49..50 ";" [] [] + 2: JS_PROPERTY_CLASS_MEMBER@50..77 + 0: JS_PROPERTY_MODIFIER_LIST@50..71 + 0: JS_STATIC_MODIFIER@50..62 + 0: STATIC_KW@50..62 "static" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_ACCESSOR_MODIFIER@62..71 + 0: ACCESSOR_KW@62..71 "accessor" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@71..73 + 0: IDENT@71..73 "c" [] [Whitespace(" ")] + 2: (empty) + 3: JS_INITIALIZER_CLAUSE@73..76 + 0: EQ@73..75 "=" [] [Whitespace(" ")] + 1: JS_NUMBER_LITERAL_EXPRESSION@75..76 + 0: JS_NUMBER_LITERAL@75..76 "1" [] [] + 4: SEMICOLON@76..77 ";" [] [] + 8: R_CURLY@77..79 "}" [Newline("\n")] [] + 1: JS_CLASS_DECLARATION@79..114 + 0: (empty) + 1: CLASS_KW@79..86 "class" [Newline("\n")] [Whitespace(" ")] + 2: JS_IDENTIFIER_BINDING@86..90 + 0: IDENT@86..90 "Foo" [] [Whitespace(" ")] + 3: (empty) + 4: (empty) + 5: (empty) + 6: L_CURLY@90..91 "{" [] [] + 7: JS_CLASS_MEMBER_LIST@91..112 + 0: JS_PROPERTY_CLASS_MEMBER@91..104 + 0: JS_PROPERTY_MODIFIER_LIST@91..91 + 1: JS_LITERAL_MEMBER_NAME@91..104 + 0: IDENT@91..104 "accessor" [Newline("\n"), Whitespace(" ")] [] + 2: (empty) + 3: (empty) + 4: (empty) + 1: JS_PROPERTY_CLASS_MEMBER@104..112 + 0: JS_PROPERTY_MODIFIER_LIST@104..104 + 1: JS_LITERAL_MEMBER_NAME@104..112 + 0: IDENT@104..112 "foo" [Newline("\n"), Whitespace(" ")] [] + 2: (empty) + 3: (empty) + 4: (empty) + 8: R_CURLY@112..114 "}" [Newline("\n")] [] + 3: EOF@114..115 "" [Newline("\n")] [] diff --git a/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.rast b/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.rast index 6840483ba8c..7e23e531eb8 100644 --- a/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.rast +++ b/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.rast @@ -269,17 +269,70 @@ JsModule { value: missing (optional), semicolon_token: SEMICOLON@449..450 ";" [] [], }, + JsPropertyClassMember { + modifiers: JsPropertyModifierList [ + TsAccessibilityModifier { + modifier_token: PRIVATE_KW@450..463 "private" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + JsStaticModifier { + modifier_token: STATIC_KW@463..470 "static" [] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@470..479 "accessor" [] [Whitespace(" ")], + }, + TsReadonlyModifier { + modifier_token: READONLY_KW@479..488 "readonly" [] [Whitespace(" ")], + }, + ], + name: JsLiteralMemberName { + value: IDENT@488..489 "k" [] [], + }, + property_annotation: TsTypeAnnotation { + colon_token: COLON@489..491 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@491..497 "string" [] [], + }, + }, + value: missing (optional), + semicolon_token: SEMICOLON@497..498 ";" [] [], + }, + TsPropertySignatureClassMember { + modifiers: TsPropertySignatureModifierList [ + TsAccessibilityModifier { + modifier_token: PROTECTED_KW@498..513 "protected" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + TsAbstractModifier { + modifier_token: ABSTRACT_KW@513..522 "abstract" [] [Whitespace(" ")], + }, + JsAccessorModifier { + modifier_token: ACCESSOR_KW@522..531 "accessor" [] [Whitespace(" ")], + }, + TsReadonlyModifier { + modifier_token: READONLY_KW@531..540 "readonly" [] [Whitespace(" ")], + }, + ], + name: JsLiteralMemberName { + value: IDENT@540..541 "l" [] [], + }, + property_annotation: TsTypeAnnotation { + colon_token: COLON@541..543 ":" [] [Whitespace(" ")], + ty: TsStringType { + string_token: STRING_KW@543..549 "string" [] [], + }, + }, + semicolon_token: SEMICOLON@549..550 ";" [] [], + }, ], - r_curly_token: R_CURLY@450..452 "}" [Newline("\n")] [], + r_curly_token: R_CURLY@550..552 "}" [Newline("\n")] [], }, ], - eof_token: EOF@452..453 "" [Newline("\n")] [], + eof_token: EOF@552..553 "" [Newline("\n")] [], } -0: JS_MODULE@0..453 +0: JS_MODULE@0..553 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..452 + 2: JS_MODULE_ITEM_LIST@0..552 0: JS_CLASS_DECLARATION@0..23 0: (empty) 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")] @@ -298,7 +351,7 @@ JsModule { 3: (empty) 4: SEMICOLON@20..21 ";" [] [] 8: R_CURLY@21..23 "}" [Newline("\n")] [] - 1: JS_CLASS_DECLARATION@23..452 + 1: JS_CLASS_DECLARATION@23..552 0: ABSTRACT_KW@23..33 "abstract" [Newline("\n")] [Whitespace(" ")] 1: CLASS_KW@33..39 "class" [] [Whitespace(" ")] 2: JS_IDENTIFIER_BINDING@39..44 @@ -312,7 +365,7 @@ JsModule { 2: (empty) 5: (empty) 6: L_CURLY@57..58 "{" [] [] - 7: JS_CLASS_MEMBER_LIST@58..450 + 7: JS_CLASS_MEMBER_LIST@58..550 0: TS_PROPERTY_SIGNATURE_CLASS_MEMBER@58..81 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@58..71 0: TS_DECLARE_MODIFIER@58..71 @@ -460,5 +513,40 @@ JsModule { 0: STRING_KW@443..449 "string" [] [] 3: (empty) 4: SEMICOLON@449..450 ";" [] [] - 8: R_CURLY@450..452 "}" [Newline("\n")] [] - 3: EOF@452..453 "" [Newline("\n")] [] + 10: JS_PROPERTY_CLASS_MEMBER@450..498 + 0: JS_PROPERTY_MODIFIER_LIST@450..488 + 0: TS_ACCESSIBILITY_MODIFIER@450..463 + 0: PRIVATE_KW@450..463 "private" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: JS_STATIC_MODIFIER@463..470 + 0: STATIC_KW@463..470 "static" [] [Whitespace(" ")] + 2: JS_ACCESSOR_MODIFIER@470..479 + 0: ACCESSOR_KW@470..479 "accessor" [] [Whitespace(" ")] + 3: TS_READONLY_MODIFIER@479..488 + 0: READONLY_KW@479..488 "readonly" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@488..489 + 0: IDENT@488..489 "k" [] [] + 2: TS_TYPE_ANNOTATION@489..497 + 0: COLON@489..491 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@491..497 + 0: STRING_KW@491..497 "string" [] [] + 3: (empty) + 4: SEMICOLON@497..498 ";" [] [] + 11: TS_PROPERTY_SIGNATURE_CLASS_MEMBER@498..550 + 0: TS_PROPERTY_SIGNATURE_MODIFIER_LIST@498..540 + 0: TS_ACCESSIBILITY_MODIFIER@498..513 + 0: PROTECTED_KW@498..513 "protected" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: TS_ABSTRACT_MODIFIER@513..522 + 0: ABSTRACT_KW@513..522 "abstract" [] [Whitespace(" ")] + 2: JS_ACCESSOR_MODIFIER@522..531 + 0: ACCESSOR_KW@522..531 "accessor" [] [Whitespace(" ")] + 3: TS_READONLY_MODIFIER@531..540 + 0: READONLY_KW@531..540 "readonly" [] [Whitespace(" ")] + 1: JS_LITERAL_MEMBER_NAME@540..541 + 0: IDENT@540..541 "l" [] [] + 2: TS_TYPE_ANNOTATION@541..549 + 0: COLON@541..543 ":" [] [Whitespace(" ")] + 1: TS_STRING_TYPE@543..549 + 0: STRING_KW@543..549 "string" [] [] + 3: SEMICOLON@549..550 ";" [] [] + 8: R_CURLY@550..552 "}" [Newline("\n")] [] + 3: EOF@552..553 "" [Newline("\n")] [] diff --git a/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.ts b/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.ts index 5a771441826..31286e5c49c 100644 --- a/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.ts +++ b/crates/rome_js_parser/test_data/inline/ok/ts_class_property_member_modifiers.ts @@ -12,4 +12,6 @@ abstract class Test extends Base { protected readonly abstract i: string; protected abstract readonly j: string; protected override readonly base1: string; + private static accessor readonly k: string; + protected abstract accessor readonly l: string; } diff --git a/crates/rome_js_syntax/src/generated/kind.rs b/crates/rome_js_syntax/src/generated/kind.rs index a57b77e629c..2a4a23354ae 100644 --- a/crates/rome_js_syntax/src/generated/kind.rs +++ b/crates/rome_js_syntax/src/generated/kind.rs @@ -115,6 +115,7 @@ pub enum JsSyntaxKind { STATIC_KW, YIELD_KW, ABSTRACT_KW, + ACCESSOR_KW, AS_KW, SATISFIES_KW, ASSERTS_KW, @@ -286,6 +287,7 @@ pub enum JsSyntaxKind { JS_CLASS_EXPRESSION, JS_CLASS_MEMBER_LIST, JS_STATIC_MODIFIER, + JS_ACCESSOR_MODIFIER, TS_DECLARE_MODIFIER, TS_READONLY_MODIFIER, TS_ABSTRACT_MODIFIER, @@ -609,6 +611,7 @@ impl JsSyntaxKind { "static" => STATIC_KW, "yield" => YIELD_KW, "abstract" => ABSTRACT_KW, + "accessor" => ACCESSOR_KW, "as" => AS_KW, "satisfies" => SATISFIES_KW, "asserts" => ASSERTS_KW, @@ -753,6 +756,7 @@ impl JsSyntaxKind { STATIC_KW => "static", YIELD_KW => "yield", ABSTRACT_KW => "abstract", + ACCESSOR_KW => "accessor", AS_KW => "as", SATISFIES_KW => "satisfies", ASSERTS_KW => "asserts", @@ -794,4 +798,4 @@ impl JsSyntaxKind { } #[doc = r" Utility macro for creating a SyntaxKind through simple macro syntax"] #[macro_export] -macro_rules ! T { [;] => { $ crate :: JsSyntaxKind :: SEMICOLON } ; [,] => { $ crate :: JsSyntaxKind :: COMMA } ; ['('] => { $ crate :: JsSyntaxKind :: L_PAREN } ; [')'] => { $ crate :: JsSyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: JsSyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: JsSyntaxKind :: R_CURLY } ; ['['] => { $ crate :: JsSyntaxKind :: L_BRACK } ; [']'] => { $ crate :: JsSyntaxKind :: R_BRACK } ; [<] => { $ crate :: JsSyntaxKind :: L_ANGLE } ; [>] => { $ crate :: JsSyntaxKind :: R_ANGLE } ; [~] => { $ crate :: JsSyntaxKind :: TILDE } ; [?] => { $ crate :: JsSyntaxKind :: QUESTION } ; [??] => { $ crate :: JsSyntaxKind :: QUESTION2 } ; [?.] => { $ crate :: JsSyntaxKind :: QUESTIONDOT } ; [&] => { $ crate :: JsSyntaxKind :: AMP } ; [|] => { $ crate :: JsSyntaxKind :: PIPE } ; [+] => { $ crate :: JsSyntaxKind :: PLUS } ; [++] => { $ crate :: JsSyntaxKind :: PLUS2 } ; [*] => { $ crate :: JsSyntaxKind :: STAR } ; [**] => { $ crate :: JsSyntaxKind :: STAR2 } ; [/] => { $ crate :: JsSyntaxKind :: SLASH } ; [^] => { $ crate :: JsSyntaxKind :: CARET } ; [%] => { $ crate :: JsSyntaxKind :: PERCENT } ; [.] => { $ crate :: JsSyntaxKind :: DOT } ; [...] => { $ crate :: JsSyntaxKind :: DOT3 } ; [:] => { $ crate :: JsSyntaxKind :: COLON } ; [=] => { $ crate :: JsSyntaxKind :: EQ } ; [==] => { $ crate :: JsSyntaxKind :: EQ2 } ; [===] => { $ crate :: JsSyntaxKind :: EQ3 } ; [=>] => { $ crate :: JsSyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: JsSyntaxKind :: BANG } ; [!=] => { $ crate :: JsSyntaxKind :: NEQ } ; [!==] => { $ crate :: JsSyntaxKind :: NEQ2 } ; [-] => { $ crate :: JsSyntaxKind :: MINUS } ; [--] => { $ crate :: JsSyntaxKind :: MINUS2 } ; [<=] => { $ crate :: JsSyntaxKind :: LTEQ } ; [>=] => { $ crate :: JsSyntaxKind :: GTEQ } ; [+=] => { $ crate :: JsSyntaxKind :: PLUSEQ } ; [-=] => { $ crate :: JsSyntaxKind :: MINUSEQ } ; [|=] => { $ crate :: JsSyntaxKind :: PIPEEQ } ; [&=] => { $ crate :: JsSyntaxKind :: AMPEQ } ; [^=] => { $ crate :: JsSyntaxKind :: CARETEQ } ; [/=] => { $ crate :: JsSyntaxKind :: SLASHEQ } ; [*=] => { $ crate :: JsSyntaxKind :: STAREQ } ; [%=] => { $ crate :: JsSyntaxKind :: PERCENTEQ } ; [&&] => { $ crate :: JsSyntaxKind :: AMP2 } ; [||] => { $ crate :: JsSyntaxKind :: PIPE2 } ; [<<] => { $ crate :: JsSyntaxKind :: SHL } ; [>>] => { $ crate :: JsSyntaxKind :: SHR } ; [>>>] => { $ crate :: JsSyntaxKind :: USHR } ; [<<=] => { $ crate :: JsSyntaxKind :: SHLEQ } ; [>>=] => { $ crate :: JsSyntaxKind :: SHREQ } ; [>>>=] => { $ crate :: JsSyntaxKind :: USHREQ } ; [&&=] => { $ crate :: JsSyntaxKind :: AMP2EQ } ; [||=] => { $ crate :: JsSyntaxKind :: PIPE2EQ } ; [**=] => { $ crate :: JsSyntaxKind :: STAR2EQ } ; [??=] => { $ crate :: JsSyntaxKind :: QUESTION2EQ } ; [@] => { $ crate :: JsSyntaxKind :: AT } ; ['`'] => { $ crate :: JsSyntaxKind :: BACKTICK } ; [break] => { $ crate :: JsSyntaxKind :: BREAK_KW } ; [case] => { $ crate :: JsSyntaxKind :: CASE_KW } ; [catch] => { $ crate :: JsSyntaxKind :: CATCH_KW } ; [class] => { $ crate :: JsSyntaxKind :: CLASS_KW } ; [const] => { $ crate :: JsSyntaxKind :: CONST_KW } ; [continue] => { $ crate :: JsSyntaxKind :: CONTINUE_KW } ; [debugger] => { $ crate :: JsSyntaxKind :: DEBUGGER_KW } ; [default] => { $ crate :: JsSyntaxKind :: DEFAULT_KW } ; [delete] => { $ crate :: JsSyntaxKind :: DELETE_KW } ; [do] => { $ crate :: JsSyntaxKind :: DO_KW } ; [else] => { $ crate :: JsSyntaxKind :: ELSE_KW } ; [enum] => { $ crate :: JsSyntaxKind :: ENUM_KW } ; [export] => { $ crate :: JsSyntaxKind :: EXPORT_KW } ; [extends] => { $ crate :: JsSyntaxKind :: EXTENDS_KW } ; [false] => { $ crate :: JsSyntaxKind :: FALSE_KW } ; [finally] => { $ crate :: JsSyntaxKind :: FINALLY_KW } ; [for] => { $ crate :: JsSyntaxKind :: FOR_KW } ; [function] => { $ crate :: JsSyntaxKind :: FUNCTION_KW } ; [if] => { $ crate :: JsSyntaxKind :: IF_KW } ; [in] => { $ crate :: JsSyntaxKind :: IN_KW } ; [instanceof] => { $ crate :: JsSyntaxKind :: INSTANCEOF_KW } ; [import] => { $ crate :: JsSyntaxKind :: IMPORT_KW } ; [new] => { $ crate :: JsSyntaxKind :: NEW_KW } ; [null] => { $ crate :: JsSyntaxKind :: NULL_KW } ; [return] => { $ crate :: JsSyntaxKind :: RETURN_KW } ; [super] => { $ crate :: JsSyntaxKind :: SUPER_KW } ; [switch] => { $ crate :: JsSyntaxKind :: SWITCH_KW } ; [this] => { $ crate :: JsSyntaxKind :: THIS_KW } ; [throw] => { $ crate :: JsSyntaxKind :: THROW_KW } ; [try] => { $ crate :: JsSyntaxKind :: TRY_KW } ; [true] => { $ crate :: JsSyntaxKind :: TRUE_KW } ; [typeof] => { $ crate :: JsSyntaxKind :: TYPEOF_KW } ; [var] => { $ crate :: JsSyntaxKind :: VAR_KW } ; [void] => { $ crate :: JsSyntaxKind :: VOID_KW } ; [while] => { $ crate :: JsSyntaxKind :: WHILE_KW } ; [with] => { $ crate :: JsSyntaxKind :: WITH_KW } ; [implements] => { $ crate :: JsSyntaxKind :: IMPLEMENTS_KW } ; [interface] => { $ crate :: JsSyntaxKind :: INTERFACE_KW } ; [let] => { $ crate :: JsSyntaxKind :: LET_KW } ; [package] => { $ crate :: JsSyntaxKind :: PACKAGE_KW } ; [private] => { $ crate :: JsSyntaxKind :: PRIVATE_KW } ; [protected] => { $ crate :: JsSyntaxKind :: PROTECTED_KW } ; [public] => { $ crate :: JsSyntaxKind :: PUBLIC_KW } ; [static] => { $ crate :: JsSyntaxKind :: STATIC_KW } ; [yield] => { $ crate :: JsSyntaxKind :: YIELD_KW } ; [abstract] => { $ crate :: JsSyntaxKind :: ABSTRACT_KW } ; [as] => { $ crate :: JsSyntaxKind :: AS_KW } ; [satisfies] => { $ crate :: JsSyntaxKind :: SATISFIES_KW } ; [asserts] => { $ crate :: JsSyntaxKind :: ASSERTS_KW } ; [assert] => { $ crate :: JsSyntaxKind :: ASSERT_KW } ; [any] => { $ crate :: JsSyntaxKind :: ANY_KW } ; [async] => { $ crate :: JsSyntaxKind :: ASYNC_KW } ; [await] => { $ crate :: JsSyntaxKind :: AWAIT_KW } ; [boolean] => { $ crate :: JsSyntaxKind :: BOOLEAN_KW } ; [constructor] => { $ crate :: JsSyntaxKind :: CONSTRUCTOR_KW } ; [declare] => { $ crate :: JsSyntaxKind :: DECLARE_KW } ; [get] => { $ crate :: JsSyntaxKind :: GET_KW } ; [infer] => { $ crate :: JsSyntaxKind :: INFER_KW } ; [is] => { $ crate :: JsSyntaxKind :: IS_KW } ; [keyof] => { $ crate :: JsSyntaxKind :: KEYOF_KW } ; [module] => { $ crate :: JsSyntaxKind :: MODULE_KW } ; [namespace] => { $ crate :: JsSyntaxKind :: NAMESPACE_KW } ; [never] => { $ crate :: JsSyntaxKind :: NEVER_KW } ; [readonly] => { $ crate :: JsSyntaxKind :: READONLY_KW } ; [require] => { $ crate :: JsSyntaxKind :: REQUIRE_KW } ; [number] => { $ crate :: JsSyntaxKind :: NUMBER_KW } ; [object] => { $ crate :: JsSyntaxKind :: OBJECT_KW } ; [set] => { $ crate :: JsSyntaxKind :: SET_KW } ; [string] => { $ crate :: JsSyntaxKind :: STRING_KW } ; [symbol] => { $ crate :: JsSyntaxKind :: SYMBOL_KW } ; [type] => { $ crate :: JsSyntaxKind :: TYPE_KW } ; [undefined] => { $ crate :: JsSyntaxKind :: UNDEFINED_KW } ; [unique] => { $ crate :: JsSyntaxKind :: UNIQUE_KW } ; [unknown] => { $ crate :: JsSyntaxKind :: UNKNOWN_KW } ; [from] => { $ crate :: JsSyntaxKind :: FROM_KW } ; [global] => { $ crate :: JsSyntaxKind :: GLOBAL_KW } ; [bigint] => { $ crate :: JsSyntaxKind :: BIGINT_KW } ; [override] => { $ crate :: JsSyntaxKind :: OVERRIDE_KW } ; [of] => { $ crate :: JsSyntaxKind :: OF_KW } ; [ident] => { $ crate :: JsSyntaxKind :: IDENT } ; [EOF] => { $ crate :: JsSyntaxKind :: EOF } ; [#] => { $ crate :: JsSyntaxKind :: HASH } ; } +macro_rules ! T { [;] => { $ crate :: JsSyntaxKind :: SEMICOLON } ; [,] => { $ crate :: JsSyntaxKind :: COMMA } ; ['('] => { $ crate :: JsSyntaxKind :: L_PAREN } ; [')'] => { $ crate :: JsSyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: JsSyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: JsSyntaxKind :: R_CURLY } ; ['['] => { $ crate :: JsSyntaxKind :: L_BRACK } ; [']'] => { $ crate :: JsSyntaxKind :: R_BRACK } ; [<] => { $ crate :: JsSyntaxKind :: L_ANGLE } ; [>] => { $ crate :: JsSyntaxKind :: R_ANGLE } ; [~] => { $ crate :: JsSyntaxKind :: TILDE } ; [?] => { $ crate :: JsSyntaxKind :: QUESTION } ; [??] => { $ crate :: JsSyntaxKind :: QUESTION2 } ; [?.] => { $ crate :: JsSyntaxKind :: QUESTIONDOT } ; [&] => { $ crate :: JsSyntaxKind :: AMP } ; [|] => { $ crate :: JsSyntaxKind :: PIPE } ; [+] => { $ crate :: JsSyntaxKind :: PLUS } ; [++] => { $ crate :: JsSyntaxKind :: PLUS2 } ; [*] => { $ crate :: JsSyntaxKind :: STAR } ; [**] => { $ crate :: JsSyntaxKind :: STAR2 } ; [/] => { $ crate :: JsSyntaxKind :: SLASH } ; [^] => { $ crate :: JsSyntaxKind :: CARET } ; [%] => { $ crate :: JsSyntaxKind :: PERCENT } ; [.] => { $ crate :: JsSyntaxKind :: DOT } ; [...] => { $ crate :: JsSyntaxKind :: DOT3 } ; [:] => { $ crate :: JsSyntaxKind :: COLON } ; [=] => { $ crate :: JsSyntaxKind :: EQ } ; [==] => { $ crate :: JsSyntaxKind :: EQ2 } ; [===] => { $ crate :: JsSyntaxKind :: EQ3 } ; [=>] => { $ crate :: JsSyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: JsSyntaxKind :: BANG } ; [!=] => { $ crate :: JsSyntaxKind :: NEQ } ; [!==] => { $ crate :: JsSyntaxKind :: NEQ2 } ; [-] => { $ crate :: JsSyntaxKind :: MINUS } ; [--] => { $ crate :: JsSyntaxKind :: MINUS2 } ; [<=] => { $ crate :: JsSyntaxKind :: LTEQ } ; [>=] => { $ crate :: JsSyntaxKind :: GTEQ } ; [+=] => { $ crate :: JsSyntaxKind :: PLUSEQ } ; [-=] => { $ crate :: JsSyntaxKind :: MINUSEQ } ; [|=] => { $ crate :: JsSyntaxKind :: PIPEEQ } ; [&=] => { $ crate :: JsSyntaxKind :: AMPEQ } ; [^=] => { $ crate :: JsSyntaxKind :: CARETEQ } ; [/=] => { $ crate :: JsSyntaxKind :: SLASHEQ } ; [*=] => { $ crate :: JsSyntaxKind :: STAREQ } ; [%=] => { $ crate :: JsSyntaxKind :: PERCENTEQ } ; [&&] => { $ crate :: JsSyntaxKind :: AMP2 } ; [||] => { $ crate :: JsSyntaxKind :: PIPE2 } ; [<<] => { $ crate :: JsSyntaxKind :: SHL } ; [>>] => { $ crate :: JsSyntaxKind :: SHR } ; [>>>] => { $ crate :: JsSyntaxKind :: USHR } ; [<<=] => { $ crate :: JsSyntaxKind :: SHLEQ } ; [>>=] => { $ crate :: JsSyntaxKind :: SHREQ } ; [>>>=] => { $ crate :: JsSyntaxKind :: USHREQ } ; [&&=] => { $ crate :: JsSyntaxKind :: AMP2EQ } ; [||=] => { $ crate :: JsSyntaxKind :: PIPE2EQ } ; [**=] => { $ crate :: JsSyntaxKind :: STAR2EQ } ; [??=] => { $ crate :: JsSyntaxKind :: QUESTION2EQ } ; [@] => { $ crate :: JsSyntaxKind :: AT } ; ['`'] => { $ crate :: JsSyntaxKind :: BACKTICK } ; [break] => { $ crate :: JsSyntaxKind :: BREAK_KW } ; [case] => { $ crate :: JsSyntaxKind :: CASE_KW } ; [catch] => { $ crate :: JsSyntaxKind :: CATCH_KW } ; [class] => { $ crate :: JsSyntaxKind :: CLASS_KW } ; [const] => { $ crate :: JsSyntaxKind :: CONST_KW } ; [continue] => { $ crate :: JsSyntaxKind :: CONTINUE_KW } ; [debugger] => { $ crate :: JsSyntaxKind :: DEBUGGER_KW } ; [default] => { $ crate :: JsSyntaxKind :: DEFAULT_KW } ; [delete] => { $ crate :: JsSyntaxKind :: DELETE_KW } ; [do] => { $ crate :: JsSyntaxKind :: DO_KW } ; [else] => { $ crate :: JsSyntaxKind :: ELSE_KW } ; [enum] => { $ crate :: JsSyntaxKind :: ENUM_KW } ; [export] => { $ crate :: JsSyntaxKind :: EXPORT_KW } ; [extends] => { $ crate :: JsSyntaxKind :: EXTENDS_KW } ; [false] => { $ crate :: JsSyntaxKind :: FALSE_KW } ; [finally] => { $ crate :: JsSyntaxKind :: FINALLY_KW } ; [for] => { $ crate :: JsSyntaxKind :: FOR_KW } ; [function] => { $ crate :: JsSyntaxKind :: FUNCTION_KW } ; [if] => { $ crate :: JsSyntaxKind :: IF_KW } ; [in] => { $ crate :: JsSyntaxKind :: IN_KW } ; [instanceof] => { $ crate :: JsSyntaxKind :: INSTANCEOF_KW } ; [import] => { $ crate :: JsSyntaxKind :: IMPORT_KW } ; [new] => { $ crate :: JsSyntaxKind :: NEW_KW } ; [null] => { $ crate :: JsSyntaxKind :: NULL_KW } ; [return] => { $ crate :: JsSyntaxKind :: RETURN_KW } ; [super] => { $ crate :: JsSyntaxKind :: SUPER_KW } ; [switch] => { $ crate :: JsSyntaxKind :: SWITCH_KW } ; [this] => { $ crate :: JsSyntaxKind :: THIS_KW } ; [throw] => { $ crate :: JsSyntaxKind :: THROW_KW } ; [try] => { $ crate :: JsSyntaxKind :: TRY_KW } ; [true] => { $ crate :: JsSyntaxKind :: TRUE_KW } ; [typeof] => { $ crate :: JsSyntaxKind :: TYPEOF_KW } ; [var] => { $ crate :: JsSyntaxKind :: VAR_KW } ; [void] => { $ crate :: JsSyntaxKind :: VOID_KW } ; [while] => { $ crate :: JsSyntaxKind :: WHILE_KW } ; [with] => { $ crate :: JsSyntaxKind :: WITH_KW } ; [implements] => { $ crate :: JsSyntaxKind :: IMPLEMENTS_KW } ; [interface] => { $ crate :: JsSyntaxKind :: INTERFACE_KW } ; [let] => { $ crate :: JsSyntaxKind :: LET_KW } ; [package] => { $ crate :: JsSyntaxKind :: PACKAGE_KW } ; [private] => { $ crate :: JsSyntaxKind :: PRIVATE_KW } ; [protected] => { $ crate :: JsSyntaxKind :: PROTECTED_KW } ; [public] => { $ crate :: JsSyntaxKind :: PUBLIC_KW } ; [static] => { $ crate :: JsSyntaxKind :: STATIC_KW } ; [yield] => { $ crate :: JsSyntaxKind :: YIELD_KW } ; [abstract] => { $ crate :: JsSyntaxKind :: ABSTRACT_KW } ; [accessor] => { $ crate :: JsSyntaxKind :: ACCESSOR_KW } ; [as] => { $ crate :: JsSyntaxKind :: AS_KW } ; [satisfies] => { $ crate :: JsSyntaxKind :: SATISFIES_KW } ; [asserts] => { $ crate :: JsSyntaxKind :: ASSERTS_KW } ; [assert] => { $ crate :: JsSyntaxKind :: ASSERT_KW } ; [any] => { $ crate :: JsSyntaxKind :: ANY_KW } ; [async] => { $ crate :: JsSyntaxKind :: ASYNC_KW } ; [await] => { $ crate :: JsSyntaxKind :: AWAIT_KW } ; [boolean] => { $ crate :: JsSyntaxKind :: BOOLEAN_KW } ; [constructor] => { $ crate :: JsSyntaxKind :: CONSTRUCTOR_KW } ; [declare] => { $ crate :: JsSyntaxKind :: DECLARE_KW } ; [get] => { $ crate :: JsSyntaxKind :: GET_KW } ; [infer] => { $ crate :: JsSyntaxKind :: INFER_KW } ; [is] => { $ crate :: JsSyntaxKind :: IS_KW } ; [keyof] => { $ crate :: JsSyntaxKind :: KEYOF_KW } ; [module] => { $ crate :: JsSyntaxKind :: MODULE_KW } ; [namespace] => { $ crate :: JsSyntaxKind :: NAMESPACE_KW } ; [never] => { $ crate :: JsSyntaxKind :: NEVER_KW } ; [readonly] => { $ crate :: JsSyntaxKind :: READONLY_KW } ; [require] => { $ crate :: JsSyntaxKind :: REQUIRE_KW } ; [number] => { $ crate :: JsSyntaxKind :: NUMBER_KW } ; [object] => { $ crate :: JsSyntaxKind :: OBJECT_KW } ; [set] => { $ crate :: JsSyntaxKind :: SET_KW } ; [string] => { $ crate :: JsSyntaxKind :: STRING_KW } ; [symbol] => { $ crate :: JsSyntaxKind :: SYMBOL_KW } ; [type] => { $ crate :: JsSyntaxKind :: TYPE_KW } ; [undefined] => { $ crate :: JsSyntaxKind :: UNDEFINED_KW } ; [unique] => { $ crate :: JsSyntaxKind :: UNIQUE_KW } ; [unknown] => { $ crate :: JsSyntaxKind :: UNKNOWN_KW } ; [from] => { $ crate :: JsSyntaxKind :: FROM_KW } ; [global] => { $ crate :: JsSyntaxKind :: GLOBAL_KW } ; [bigint] => { $ crate :: JsSyntaxKind :: BIGINT_KW } ; [override] => { $ crate :: JsSyntaxKind :: OVERRIDE_KW } ; [of] => { $ crate :: JsSyntaxKind :: OF_KW } ; [ident] => { $ crate :: JsSyntaxKind :: IDENT } ; [EOF] => { $ crate :: JsSyntaxKind :: EOF } ; [#] => { $ crate :: JsSyntaxKind :: HASH } ; } diff --git a/crates/rome_js_syntax/src/generated/macros.rs b/crates/rome_js_syntax/src/generated/macros.rs index 02e38ab201c..d21ec3f1a2e 100644 --- a/crates/rome_js_syntax/src/generated/macros.rs +++ b/crates/rome_js_syntax/src/generated/macros.rs @@ -16,6 +16,10 @@ macro_rules! map_syntax_node { ($ node : expr , $ pattern : pat => $ body : expr) => { match $node { node => match $crate::JsSyntaxNode::kind(&node) { + $crate::JsSyntaxKind::JS_ACCESSOR_MODIFIER => { + let $pattern = unsafe { $crate::JsAccessorModifier::new_unchecked(node) }; + $body + } $crate::JsSyntaxKind::JS_ARRAY_ASSIGNMENT_PATTERN => { let $pattern = unsafe { $crate::JsArrayAssignmentPattern::new_unchecked(node) }; $body diff --git a/crates/rome_js_syntax/src/generated/nodes.rs b/crates/rome_js_syntax/src/generated/nodes.rs index 94b8ff1e1d7..908c726cc8e 100644 --- a/crates/rome_js_syntax/src/generated/nodes.rs +++ b/crates/rome_js_syntax/src/generated/nodes.rs @@ -20,6 +20,40 @@ use serde::ser::SerializeSeq; use serde::{Serialize, Serializer}; use std::fmt::{Debug, Formatter}; #[derive(Clone, PartialEq, Eq, Hash)] +pub struct JsAccessorModifier { + pub(crate) syntax: SyntaxNode, +} +impl JsAccessorModifier { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } + pub fn as_fields(&self) -> JsAccessorModifierFields { + JsAccessorModifierFields { + modifier_token: self.modifier_token(), + } + } + pub fn modifier_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for JsAccessorModifier { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct JsAccessorModifierFields { + pub modifier_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] pub struct JsArrayAssignmentPattern { pub(crate) syntax: SyntaxNode, } @@ -13646,12 +13680,19 @@ impl AnyJsParameter { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyJsPropertyModifier { + JsAccessorModifier(JsAccessorModifier), JsStaticModifier(JsStaticModifier), TsAccessibilityModifier(TsAccessibilityModifier), TsOverrideModifier(TsOverrideModifier), TsReadonlyModifier(TsReadonlyModifier), } impl AnyJsPropertyModifier { + pub fn as_js_accessor_modifier(&self) -> Option<&JsAccessorModifier> { + match &self { + AnyJsPropertyModifier::JsAccessorModifier(item) => Some(item), + _ => None, + } + } pub fn as_js_static_modifier(&self) -> Option<&JsStaticModifier> { match &self { AnyJsPropertyModifier::JsStaticModifier(item) => Some(item), @@ -14412,6 +14453,7 @@ impl AnyTsPropertySignatureAnnotation { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyTsPropertySignatureModifier { + JsAccessorModifier(JsAccessorModifier), JsStaticModifier(JsStaticModifier), TsAbstractModifier(TsAbstractModifier), TsAccessibilityModifier(TsAccessibilityModifier), @@ -14420,6 +14462,12 @@ pub enum AnyTsPropertySignatureModifier { TsReadonlyModifier(TsReadonlyModifier), } impl AnyTsPropertySignatureModifier { + pub fn as_js_accessor_modifier(&self) -> Option<&JsAccessorModifier> { + match &self { + AnyTsPropertySignatureModifier::JsAccessorModifier(item) => Some(item), + _ => None, + } + } pub fn as_js_static_modifier(&self) -> Option<&JsStaticModifier> { match &self { AnyTsPropertySignatureModifier::JsStaticModifier(item) => Some(item), @@ -14891,6 +14939,37 @@ impl AnyTsVariableAnnotation { } } } +impl AstNode for JsAccessorModifier { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(JS_ACCESSOR_MODIFIER as u16)); + fn can_cast(kind: SyntaxKind) -> bool { kind == JS_ACCESSOR_MODIFIER } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } + fn into_syntax(self) -> SyntaxNode { self.syntax } +} +impl std::fmt::Debug for JsAccessorModifier { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("JsAccessorModifier") + .field( + "modifier_token", + &support::DebugSyntaxResult(self.modifier_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: JsAccessorModifier) -> SyntaxNode { n.syntax } +} +impl From for SyntaxElement { + fn from(n: JsAccessorModifier) -> SyntaxElement { n.syntax.into() } +} impl AstNode for JsArrayAssignmentPattern { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -28909,6 +28988,11 @@ impl From for SyntaxElement { node.into() } } +impl From for AnyJsPropertyModifier { + fn from(node: JsAccessorModifier) -> AnyJsPropertyModifier { + AnyJsPropertyModifier::JsAccessorModifier(node) + } +} impl From for AnyJsPropertyModifier { fn from(node: JsStaticModifier) -> AnyJsPropertyModifier { AnyJsPropertyModifier::JsStaticModifier(node) @@ -28931,14 +29015,16 @@ impl From for AnyJsPropertyModifier { } impl AstNode for AnyJsPropertyModifier { type Language = Language; - const KIND_SET: SyntaxKindSet = JsStaticModifier::KIND_SET + const KIND_SET: SyntaxKindSet = JsAccessorModifier::KIND_SET + .union(JsStaticModifier::KIND_SET) .union(TsAccessibilityModifier::KIND_SET) .union(TsOverrideModifier::KIND_SET) .union(TsReadonlyModifier::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, - JS_STATIC_MODIFIER + JS_ACCESSOR_MODIFIER + | JS_STATIC_MODIFIER | TS_ACCESSIBILITY_MODIFIER | TS_OVERRIDE_MODIFIER | TS_READONLY_MODIFIER @@ -28946,6 +29032,9 @@ impl AstNode for AnyJsPropertyModifier { } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { + JS_ACCESSOR_MODIFIER => { + AnyJsPropertyModifier::JsAccessorModifier(JsAccessorModifier { syntax }) + } JS_STATIC_MODIFIER => { AnyJsPropertyModifier::JsStaticModifier(JsStaticModifier { syntax }) } @@ -28964,6 +29053,7 @@ impl AstNode for AnyJsPropertyModifier { } fn syntax(&self) -> &SyntaxNode { match self { + AnyJsPropertyModifier::JsAccessorModifier(it) => &it.syntax, AnyJsPropertyModifier::JsStaticModifier(it) => &it.syntax, AnyJsPropertyModifier::TsAccessibilityModifier(it) => &it.syntax, AnyJsPropertyModifier::TsOverrideModifier(it) => &it.syntax, @@ -28972,6 +29062,7 @@ impl AstNode for AnyJsPropertyModifier { } fn into_syntax(self) -> SyntaxNode { match self { + AnyJsPropertyModifier::JsAccessorModifier(it) => it.syntax, AnyJsPropertyModifier::JsStaticModifier(it) => it.syntax, AnyJsPropertyModifier::TsAccessibilityModifier(it) => it.syntax, AnyJsPropertyModifier::TsOverrideModifier(it) => it.syntax, @@ -28982,6 +29073,7 @@ impl AstNode for AnyJsPropertyModifier { 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::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), @@ -28992,6 +29084,7 @@ impl std::fmt::Debug for AnyJsPropertyModifier { impl From for SyntaxNode { fn from(n: AnyJsPropertyModifier) -> SyntaxNode { match n { + AnyJsPropertyModifier::JsAccessorModifier(it) => it.into(), AnyJsPropertyModifier::JsStaticModifier(it) => it.into(), AnyJsPropertyModifier::TsAccessibilityModifier(it) => it.into(), AnyJsPropertyModifier::TsOverrideModifier(it) => it.into(), @@ -30848,6 +30941,11 @@ impl From for SyntaxElement { node.into() } } +impl From for AnyTsPropertySignatureModifier { + fn from(node: JsAccessorModifier) -> AnyTsPropertySignatureModifier { + AnyTsPropertySignatureModifier::JsAccessorModifier(node) + } +} impl From for AnyTsPropertySignatureModifier { fn from(node: JsStaticModifier) -> AnyTsPropertySignatureModifier { AnyTsPropertySignatureModifier::JsStaticModifier(node) @@ -30880,7 +30978,8 @@ impl From for AnyTsPropertySignatureModifier { } impl AstNode for AnyTsPropertySignatureModifier { type Language = Language; - const KIND_SET: SyntaxKindSet = JsStaticModifier::KIND_SET + const KIND_SET: SyntaxKindSet = JsAccessorModifier::KIND_SET + .union(JsStaticModifier::KIND_SET) .union(TsAbstractModifier::KIND_SET) .union(TsAccessibilityModifier::KIND_SET) .union(TsDeclareModifier::KIND_SET) @@ -30889,7 +30988,8 @@ impl AstNode for AnyTsPropertySignatureModifier { fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, - JS_STATIC_MODIFIER + JS_ACCESSOR_MODIFIER + | JS_STATIC_MODIFIER | TS_ABSTRACT_MODIFIER | TS_ACCESSIBILITY_MODIFIER | TS_DECLARE_MODIFIER @@ -30899,6 +30999,9 @@ impl AstNode for AnyTsPropertySignatureModifier { } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { + JS_ACCESSOR_MODIFIER => { + AnyTsPropertySignatureModifier::JsAccessorModifier(JsAccessorModifier { syntax }) + } JS_STATIC_MODIFIER => { AnyTsPropertySignatureModifier::JsStaticModifier(JsStaticModifier { syntax }) } @@ -30925,6 +31028,7 @@ impl AstNode for AnyTsPropertySignatureModifier { } fn syntax(&self) -> &SyntaxNode { match self { + AnyTsPropertySignatureModifier::JsAccessorModifier(it) => &it.syntax, AnyTsPropertySignatureModifier::JsStaticModifier(it) => &it.syntax, AnyTsPropertySignatureModifier::TsAbstractModifier(it) => &it.syntax, AnyTsPropertySignatureModifier::TsAccessibilityModifier(it) => &it.syntax, @@ -30935,6 +31039,7 @@ impl AstNode for AnyTsPropertySignatureModifier { } fn into_syntax(self) -> SyntaxNode { match self { + AnyTsPropertySignatureModifier::JsAccessorModifier(it) => it.syntax, AnyTsPropertySignatureModifier::JsStaticModifier(it) => it.syntax, AnyTsPropertySignatureModifier::TsAbstractModifier(it) => it.syntax, AnyTsPropertySignatureModifier::TsAccessibilityModifier(it) => it.syntax, @@ -30947,6 +31052,7 @@ impl AstNode for AnyTsPropertySignatureModifier { impl std::fmt::Debug for AnyTsPropertySignatureModifier { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { + AnyTsPropertySignatureModifier::JsAccessorModifier(it) => std::fmt::Debug::fmt(it, f), AnyTsPropertySignatureModifier::JsStaticModifier(it) => std::fmt::Debug::fmt(it, f), AnyTsPropertySignatureModifier::TsAbstractModifier(it) => std::fmt::Debug::fmt(it, f), AnyTsPropertySignatureModifier::TsAccessibilityModifier(it) => { @@ -30961,6 +31067,7 @@ impl std::fmt::Debug for AnyTsPropertySignatureModifier { impl From for SyntaxNode { fn from(n: AnyTsPropertySignatureModifier) -> SyntaxNode { match n { + AnyTsPropertySignatureModifier::JsAccessorModifier(it) => it.into(), AnyTsPropertySignatureModifier::JsStaticModifier(it) => it.into(), AnyTsPropertySignatureModifier::TsAbstractModifier(it) => it.into(), AnyTsPropertySignatureModifier::TsAccessibilityModifier(it) => it.into(), @@ -32239,6 +32346,11 @@ impl std::fmt::Display for AnyTsVariableAnnotation { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for JsAccessorModifier { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for JsArrayAssignmentPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/rome_js_syntax/src/generated/nodes_mut.rs b/crates/rome_js_syntax/src/generated/nodes_mut.rs index 3d29fcbbedf..671ec142ee1 100644 --- a/crates/rome_js_syntax/src/generated/nodes_mut.rs +++ b/crates/rome_js_syntax/src/generated/nodes_mut.rs @@ -3,6 +3,14 @@ use crate::{generated::nodes::*, JsSyntaxToken as SyntaxToken}; use rome_rowan::AstNode; use std::iter::once; +impl JsAccessorModifier { + pub fn with_modifier_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} impl JsArrayAssignmentPattern { pub fn with_l_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( diff --git a/crates/rome_js_syntax/src/modifier_ext.rs b/crates/rome_js_syntax/src/modifier_ext.rs index 7bc68418d36..a23d0a1ddd3 100644 --- a/crates/rome_js_syntax/src/modifier_ext.rs +++ b/crates/rome_js_syntax/src/modifier_ext.rs @@ -10,6 +10,7 @@ pub enum Modifiers { Accessibility, Declare, Static, + Accessor, Abstract, Override, Readonly, @@ -49,6 +50,7 @@ impl From<&AnyJsPropertyModifier> for Modifiers { fn from(modifier: &AnyJsPropertyModifier) -> Self { match modifier { AnyJsPropertyModifier::JsStaticModifier(_) => Modifiers::Static, + AnyJsPropertyModifier::JsAccessorModifier(_) => Modifiers::Accessor, AnyJsPropertyModifier::TsAccessibilityModifier(_) => Modifiers::Accessibility, AnyJsPropertyModifier::TsOverrideModifier(_) => Modifiers::Override, AnyJsPropertyModifier::TsReadonlyModifier(_) => Modifiers::Readonly, @@ -72,6 +74,7 @@ impl From<&AnyTsPropertySignatureModifier> for Modifiers { AnyTsPropertySignatureModifier::TsAccessibilityModifier(_) => Modifiers::Accessibility, AnyTsPropertySignatureModifier::TsDeclareModifier(_) => Modifiers::Declare, AnyTsPropertySignatureModifier::JsStaticModifier(_) => Modifiers::Static, + AnyTsPropertySignatureModifier::JsAccessorModifier(_) => Modifiers::Accessor, AnyTsPropertySignatureModifier::TsAbstractModifier(_) => Modifiers::Abstract, AnyTsPropertySignatureModifier::TsOverrideModifier(_) => Modifiers::Override, AnyTsPropertySignatureModifier::TsReadonlyModifier(_) => Modifiers::Readonly, diff --git a/xtask/codegen/js.ungram b/xtask/codegen/js.ungram index 78e7cbb8219..ffbfe09b12c 100644 --- a/xtask/codegen/js.ungram +++ b/xtask/codegen/js.ungram @@ -642,6 +642,7 @@ AnyJsClassMember = | JsBogusMember JsStaticModifier = modifier: 'static' +JsAccessorModifier = modifier: 'accessor' TsDeclareModifier = modifier: 'declare' TsReadonlyModifier = modifier: 'readonly' TsAbstractModifier = modifier: 'abstract' @@ -712,6 +713,7 @@ JsPropertyClassMember = AnyJsPropertyModifier = TsAccessibilityModifier | JsStaticModifier + | JsAccessorModifier | TsReadonlyModifier | TsOverrideModifier @@ -729,6 +731,7 @@ AnyTsPropertySignatureModifier = TsDeclareModifier | TsAccessibilityModifier | JsStaticModifier + | JsAccessorModifier | TsReadonlyModifier | TsOverrideModifier | TsAbstractModifier diff --git a/xtask/codegen/src/kinds_src.rs b/xtask/codegen/src/kinds_src.rs index 0dc45ce8deb..3a7bec7e2ee 100644 --- a/xtask/codegen/src/kinds_src.rs +++ b/xtask/codegen/src/kinds_src.rs @@ -128,6 +128,7 @@ pub const JS_KINDS_SRC: KindsSrc = KindsSrc { "yield", // contextual keywords "abstract", + "accessor", "as", "satisfies", "asserts", @@ -305,6 +306,7 @@ pub const JS_KINDS_SRC: KindsSrc = KindsSrc { "JS_CLASS_EXPRESSION", "JS_CLASS_MEMBER_LIST", "JS_STATIC_MODIFIER", + "JS_ACCESSOR_MODIFIER", "TS_DECLARE_MODIFIER", "TS_READONLY_MODIFIER", "TS_ABSTRACT_MODIFIER",