From 292d162b23462eec7d78c34e309e0422d8fe5dac Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Wed, 28 Aug 2024 08:42:38 +0000 Subject: [PATCH] feat(codegen): print missing fields for `AccessorProperty` (#5291) Found in https://github.com/oxc-project/monitor-oxc/actions/runs/10592050362/job/29350666018 --- crates/oxc_codegen/src/gen.rs | 8 ++++++++ crates/oxc_codegen/tests/integration/unit.rs | 2 +- tasks/coverage/codegen_sourcemap.snap | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index d6c580e2e..03f390a9e 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2567,6 +2567,7 @@ impl<'a> Gen for PropertyDefinition<'a> { impl<'a> Gen for AccessorProperty<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); + self.decorators.gen(p, ctx); if self.r#type.is_abstract() { p.print_str("abstract "); } @@ -2587,8 +2588,15 @@ impl<'a> Gen for AccessorProperty<'a> { if self.computed { p.print_char(b']'); } + if let Some(type_annotation) = &self.type_annotation { + p.print_colon(); + p.print_soft_space(); + type_annotation.gen(p, ctx); + } if let Some(value) = &self.value { + p.print_soft_space(); p.print_equal(); + p.print_soft_space(); value.gen_expr(p, Precedence::Comma, Context::empty()); } } diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 0a048ceb8..8c559c66b 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -27,7 +27,7 @@ fn expr() { fn access_property() { test( "export default class Foo { @x @y accessor #aDef = 1 }", - "export default class Foo {\n\taccessor #aDef=1;\n}\n", + "export default class Foo {\n\t@x @y accessor #aDef = 1;\n}\n", ); } diff --git a/tasks/coverage/codegen_sourcemap.snap b/tasks/coverage/codegen_sourcemap.snap index 77b52897b..2654e3c2b 100644 --- a/tasks/coverage/codegen_sourcemap.snap +++ b/tasks/coverage/codegen_sourcemap.snap @@ -264,10 +264,10 @@ Unexpected token (28:18-28:20) " {" --> (25:17-25:18) " " (28:20-29:2) "};\n " --> (25:18-26:1) "{};\n" (29:2-29:11) " accessor" --> (26:1-26:10) "\taccessor" -(29:11-29:15) " y =" --> (26:10-26:12) " y" -(29:15-29:26) " function()" --> (26:12-26:23) "=function()" -(29:26-29:28) " {" --> (26:23-26:24) " " -(29:28-30:1) "}\n" --> (26:24-27:0) "{};" +(29:11-29:15) " y =" --> (26:10-26:14) " y =" +(29:15-29:26) " function()" --> (26:14-26:25) " function()" +(29:26-29:28) " {" --> (26:25-26:26) " " +(29:28-30:1) "}\n" --> (26:26-27:0) "{};" (30:1-32:0) "}\n" --> (27:0-28:0) "\n}" (32:0-32:4) "\nvar" --> (28:0-28:4) "\nvar" (32:4-32:9) " aa =" --> (28:4-28:9) " aa ="