diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index fc079010e9930..d3daf9bbd5716 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -1640,6 +1640,13 @@ impl Gen for ObjectProperty<'_> { type_parameters.print(p, ctx); } p.print_ascii_byte(b'('); + if let Some(this_param) = &func.this_param { + this_param.print(p, ctx); + if !func.params.is_empty() || func.params.rest.is_some() { + p.print_ascii_byte(b','); + p.print_soft_space(); + } + } func.params.print(p, ctx); p.print_ascii_byte(b')'); if let Some(return_type) = &func.return_type { diff --git a/crates/oxc_codegen/tests/integration/ts.rs b/crates/oxc_codegen/tests/integration/ts.rs index 1792e8e9aae40..97fb0d7599bda 100644 --- a/crates/oxc_codegen/tests/integration/ts.rs +++ b/crates/oxc_codegen/tests/integration/ts.rs @@ -8,6 +8,8 @@ use crate::{ #[test] fn cases() { test_same("({ foo(): string {} });\n"); + test_same("({ method(this: Foo): void {} });\n"); + test_same("({ methodWithParam(this: Foo, bar: string): void {} });\n"); test_same("interface I {}\n"); test_same("function F() {}\n"); test_same("class C {\n\tp = await(0);\n}\n");