Skip to content

Commit 1710f56

Browse files
committed
fix(codegen): remove double indentation for enum inside namespace (oxc-project#19775)
## 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)
1 parent 805ee60 commit 1710f56

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

crates/oxc_codegen/src/gen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3825,7 +3825,6 @@ impl Gen for TSInterfaceHeritage<'_> {
38253825

38263826
impl Gen for TSEnumDeclaration<'_> {
38273827
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
3828-
p.print_indent();
38293828
if self.declare {
38303829
p.print_str("declare ");
38313830
}

crates/oxc_codegen/tests/integration/ts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ fn cases() {
3333
test_same("class B {\n\tconstructor(override readonly a: number) {}\n}\n");
3434
test_same("class C extends B {\n\toverride show(): void;\n\toverride hide(): void;\n}\n");
3535
test_same("class D extends B {\n\toverride readonly x: number;\n}\n");
36+
test_same(
37+
"declare namespace ns {\n\tclass Foo {}\n\tenum Bar {}\n\ttype Baz = undefined;\n}\n",
38+
);
3639
test_same("class E {\n\tsubscribe!: string;\n}\n");
3740
test_same("class F {\n\taccessor value!: string;\n}\n");
3841
test_same("export { type as as };\n");

0 commit comments

Comments
 (0)