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]}"); } 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..fae0516694f87 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/class-decorator.ts @@ -0,0 +1,24 @@ +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; +} + +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 new file mode 100644 index 0000000000000..1480457e7c238 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/class-decorator.snap @@ -0,0 +1,24 @@ +--- +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; +} +export declare class Test3 { + property?: { + property?: (arg: any) => any + }; +} 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)