From 1710f563608f529adfe7b827b972277a5b745d52 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:24:26 +0000 Subject: [PATCH] fix(codegen): remove double indentation for enum inside namespace (#19775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - `TSEnumDeclaration::gen()` called `p.print_indent()`, but the `Statement` handler already calls `print_indent()` before dispatching — causing enums inside namespaces to get double indentation (e.g. 4 spaces instead of 2). - No other declaration type (`Class`, `TSModuleDeclaration`, `TSInterfaceDeclaration`, `TSTypeAliasDeclaration`) has this issue. **Before:** ```ts declare namespace ns { class Foo {} enum Bar {} type Baz = undefined; } ``` **After:** ```ts declare namespace ns { class Foo {} enum Bar {} type Baz = undefined; } ``` ## Test plan - [x] Added `test_same` case for `declare namespace` with class, enum, and type alias - [x] Verified test fails without the fix, passes with it - [x] All 92 `oxc_codegen` tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- crates/oxc_codegen/src/gen.rs | 1 - crates/oxc_codegen/tests/integration/ts.rs | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 1bd6195726da5..84ca3f3474766 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -3825,7 +3825,6 @@ impl Gen for TSInterfaceHeritage<'_> { impl Gen for TSEnumDeclaration<'_> { fn r#gen(&self, p: &mut Codegen, ctx: Context) { - p.print_indent(); if self.declare { p.print_str("declare "); } diff --git a/crates/oxc_codegen/tests/integration/ts.rs b/crates/oxc_codegen/tests/integration/ts.rs index 70b03c06951a9..b7dc2880ba769 100644 --- a/crates/oxc_codegen/tests/integration/ts.rs +++ b/crates/oxc_codegen/tests/integration/ts.rs @@ -33,6 +33,9 @@ fn cases() { test_same("class B {\n\tconstructor(override readonly a: number) {}\n}\n"); test_same("class C extends B {\n\toverride show(): void;\n\toverride hide(): void;\n}\n"); test_same("class D extends B {\n\toverride readonly x: number;\n}\n"); + test_same( + "declare namespace ns {\n\tclass Foo {}\n\tenum Bar {}\n\ttype Baz = undefined;\n}\n", + ); test_same("class E {\n\tsubscribe!: string;\n}\n"); test_same("class F {\n\taccessor value!: string;\n}\n"); test_same("export { type as as };\n");