Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codegen): print missing fields for AccessorProperty #5291

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
}
Expand All @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
}

Expand Down
8 changes: 4 additions & 4 deletions tasks/coverage/codegen_sourcemap.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 ="
Expand Down