From 7f396ec31151ffac5d672e16bc8d62e8ad3591ae Mon Sep 17 00:00:00 2001 From: magic-akari Date: Thu, 29 May 2025 17:54:22 +0800 Subject: [PATCH 1/3] fix(parser): correctly parse decorators of property declaration --- .../tests/fixtures/class-decorator.ts | 17 +++++++++++++++++ .../tests/snapshots/class-decorator.snap | 19 +++++++++++++++++++ crates/oxc_parser/src/js/class.rs | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts create mode 100644 crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap diff --git a/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts b/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts new file mode 100644 index 0000000000000..670f227054a45 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts @@ -0,0 +1,17 @@ +declare const decorator: any; + +export class Test1 { + /** + * This methond will trigger the feature highlight dialog load/show based on dialogId and analyticsId + */ + @decorator + property: (() => any) | undefined; +} + +export class Test2 { + /** + * This methond will trigger the feature highlight dialog load/show based on dialogId and analyticsId + */ + @decorator + property: ((arg: any) => any) | undefined; +} diff --git a/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap b/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap new file mode 100644 index 0000000000000..e1c92a42e2c42 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap @@ -0,0 +1,19 @@ +--- +source: crates/oxc_isolated_declarations/tests/mod.rs +input_file: crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts +--- +``` +==================== .D.TS ==================== + +export declare class Test1 { + /** + * This methond will trigger the feature highlight dialog load/show based on dialogId and analyticsId + */ + property: (() => any) | undefined; +} +export declare class Test2 { + /** + * This methond will trigger the feature highlight dialog load/show based on dialogId and analyticsId + */ + property: ((arg: any) => any) | undefined; +} diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index 9e8d95f7f089e..d73f36ba2ef32 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -516,8 +516,8 @@ impl<'a> ParserImpl<'a> { definite: bool, modifiers: &Modifiers, ) -> ClassElement<'a> { - let type_annotation = if self.is_ts { self.parse_ts_type_annotation() } else { None }; let decorators = self.consume_decorators(); + let type_annotation = if self.is_ts { self.parse_ts_type_annotation() } else { None }; // Initializer[+In, ?Yield, ?Await]opt let initializer = self .eat(Kind::Eq) From 0feb6009f5fc3be3aac3cc81bf0d957eb64f693a Mon Sep 17 00:00:00 2001 From: magic-akari Date: Thu, 29 May 2025 19:18:44 +0800 Subject: [PATCH 2/3] chore: update test cases --- .../tests/fixtures/class-decorator.ts | 7 +++++++ .../tests/snapshots/class-decorator.snap | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts b/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts index 670f227054a45..fae0516694f87 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts @@ -15,3 +15,10 @@ export class Test2 { @decorator property: ((arg: any) => any) | undefined; } + +export class Test3 { + @decorator + property?: { + property?: (arg: any) => any; + }; +} diff --git a/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap b/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap index e1c92a42e2c42..1480457e7c238 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap @@ -17,3 +17,8 @@ export declare class Test2 { */ property: ((arg: any) => any) | undefined; } +export declare class Test3 { + property?: { + property?: (arg: any) => any + }; +} From 405209b82e32179350221ac90bffc581d0ffaa16 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Thu, 29 May 2025 22:44:19 +0800 Subject: [PATCH 3/3] chore: update test cases --- crates/oxc_codegen/tests/integration/unit.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 3dc78c249b4ac..fa8cd07122c48 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -74,6 +74,10 @@ fn class() { "export default class Foo { @x @y accessor #aDef = 1 }", "export default class Foo {\n\t@x @y accessor #aDef = 1;\n}\n", ); + test( + "export class Test2 {\n@decorator\nproperty: ((arg: any) => any) | undefined;\n}", + "export class Test2 {\n\t@decorator property: ((arg: any) => any) | undefined;\n}\n", + ); test_minify("class { static [computed] }", "class{static[computed]}"); }