diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 0dcc8a590a44d..4f11d22fce27e 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2413,6 +2413,9 @@ impl<'a, const MINIFY: bool> Gen for MethodDefinition<'a> { if self.computed { p.print(b']'); } + if self.optional { + p.print(b'?'); + } if let Some(type_parameters) = self.value.type_parameters.as_ref() { type_parameters.gen(p, ctx); } diff --git a/crates/oxc_codegen/tests/mod.rs b/crates/oxc_codegen/tests/mod.rs index f834ac8e8d22d..0189aca934055 100644 --- a/crates/oxc_codegen/tests/mod.rs +++ b/crates/oxc_codegen/tests/mod.rs @@ -201,6 +201,7 @@ 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); } fn test_comment_helper(source_text: &str, expected: &str) {