diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 4f11d22fce27..b9bccc9e3cd1 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -682,12 +682,12 @@ impl<'a, const MINIFY: bool> Gen for FunctionBody<'a> { impl<'a, const MINIFY: bool> Gen for FormalParameter<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { self.decorators.gen(p, ctx); - if self.readonly { - p.print_str(b"readonly "); - } if let Some(accessibility) = self.accessibility { accessibility.gen(p, ctx); } + if self.readonly { + p.print_str(b"readonly "); + } self.pattern.gen(p, ctx); } } @@ -2378,12 +2378,12 @@ impl<'a, const MINIFY: bool> Gen for MethodDefinition<'a> { p.add_source_mapping(self.span.start); self.decorators.gen(p, ctx); - if self.r#type == MethodDefinitionType::TSAbstractMethodDefinition { - p.print_str(b"abstract "); - } if let Some(accessibility) = &self.accessibility { accessibility.gen(p, ctx); } + if self.r#type == MethodDefinitionType::TSAbstractMethodDefinition { + p.print_str(b"abstract "); + } if self.r#static { p.print_str(b"static "); } @@ -2440,13 +2440,12 @@ impl<'a, const MINIFY: bool> Gen for PropertyDefinition<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { p.add_source_mapping(self.span.start); self.decorators.gen(p, ctx); - if self.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition { - p.print_str(b"abstract "); - } if let Some(accessibility) = &self.accessibility { accessibility.gen(p, ctx); } - + if self.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition { + p.print_str(b"abstract "); + } if self.r#static { p.print_str(b"static "); } diff --git a/crates/oxc_codegen/tests/mod.rs b/crates/oxc_codegen/tests/mod.rs index 0189aca93405..7389fbd47068 100644 --- a/crates/oxc_codegen/tests/mod.rs +++ b/crates/oxc_codegen/tests/mod.rs @@ -202,6 +202,9 @@ fn typescript() { test_ts("let foo: { (t: T): void }", "let foo: {(t: T): void};\n", false); test_ts("function (){}", "function() {}\n", false); test_ts("class A {m?(): void}", "class A {\n\tm?(): void;\n}\n", false); + test_ts("class A {constructor(public readonly a: number) {}}", "class A {\n\tconstructor(public readonly a: number) {}\n}\n", false); + test_ts("abstract class A {private abstract static m() {}}", "abstract class A {\n\tprivate abstract static m() {}\n}\n", false); + test_ts("abstract class A {private abstract static readonly prop: string}", "abstract class A {\n\tprivate abstract static readonly prop: string;\n}\n", false) } fn test_comment_helper(source_text: &str, expected: &str) {