Skip to content

Commit bf4a1ae

Browse files
Dunqingclaude
andcommitted
fix(codegen): print override keyword for method and property definitions
The codegen was missing the `override` keyword when printing `MethodDefinition` and `PropertyDefinition` nodes, causing `override` class members to lose the modifier during code generation. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 5a7568d commit bf4a1ae

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

crates/oxc_codegen/src/gen.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,11 @@ impl Gen for MethodDefinition<'_> {
26662666
p.print_str("static");
26672667
p.print_soft_space();
26682668
}
2669+
if self.r#override {
2670+
p.print_space_before_identifier();
2671+
p.print_str("override");
2672+
p.print_soft_space();
2673+
}
26692674
match &self.kind {
26702675
MethodDefinitionKind::Constructor | MethodDefinitionKind::Method => {}
26712676
MethodDefinitionKind::Get => {
@@ -2748,6 +2753,11 @@ impl Gen for PropertyDefinition<'_> {
27482753
p.print_str("static");
27492754
p.print_soft_space();
27502755
}
2756+
if self.r#override {
2757+
p.print_space_before_identifier();
2758+
p.print_str("override");
2759+
p.print_soft_space();
2760+
}
27512761
if self.readonly {
27522762
p.print_space_before_identifier();
27532763
p.print_str("readonly");

crates/oxc_codegen/tests/integration/ts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ fn cases() {
1515
"class Foo {\n\t#name: string;\n\tf() {\n\t\t#name in other && this.#name === other.#name;\n\t}\n}\n",
1616
);
1717
test_same("class B {\n\tconstructor(override readonly a: number) {}\n}\n");
18+
test_same("class C extends B {\n\toverride show(): void;\n\toverride hide(): void;\n}\n");
19+
test_same("class D extends B {\n\toverride readonly x: number;\n}\n");
1820
test_same("export { type as as };\n");
1921
}
2022

0 commit comments

Comments
 (0)