From 1c117eb20df5c130f1d732f8a49122cfe84f2649 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Thu, 11 Jul 2024 20:16:02 +0800 Subject: [PATCH] fix: avoid print extra semicolon after accessor property (#4199) ## Before ```js export default class Foo { @x @y accessor #aDef = 1 } ``` **output** ```bash Original: export default class Foo { @x @y accessor #aDef = 1 } Printed: export default class Foo { accessor #aDef=1;; } ``` --- crates/oxc_codegen/src/gen.rs | 1 - crates/oxc_codegen/tests/mod.rs | 8 ++++++++ tasks/coverage/codegen_sourcemap.snap | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 96f239ef238b5..00c5590511433 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2491,7 +2491,6 @@ impl<'a, const MINIFY: bool> Gen for AccessorProperty<'a> { p.print_equal(); value.gen_expr(p, Precedence::Assign, Context::default()); } - p.print_semicolon(); } } diff --git a/crates/oxc_codegen/tests/mod.rs b/crates/oxc_codegen/tests/mod.rs index 314a70a12511e..b92a852333297 100644 --- a/crates/oxc_codegen/tests/mod.rs +++ b/crates/oxc_codegen/tests/mod.rs @@ -124,6 +124,14 @@ fn new_expr() { test("new (foo()).bar();", "new (foo()).bar();\n"); } +#[test] +fn access_property() { + test( + "export default class Foo { @x @y accessor #aDef = 1 }", + "export default class Foo {\n\taccessor #aDef=1;\n}\n", + ); +} + #[test] fn for_stmt() { test("for (let x = 0; x < 10; x++) {}", "for (let x = 0; x < 10; x++) {}\n"); diff --git a/tasks/coverage/codegen_sourcemap.snap b/tasks/coverage/codegen_sourcemap.snap index 663133b3f054c..6a6ad154e3694 100644 --- a/tasks/coverage/codegen_sourcemap.snap +++ b/tasks/coverage/codegen_sourcemap.snap @@ -275,7 +275,7 @@ Unexpected token (29:11-29:15) " y =" --> (25:10-25:12) " y" (29:15-29:26) " function()" --> (25:12-25:23) "=function()" (29:26-29:28) " {" --> (25:23-25:24) " " -(29:28-30:1) "}\n" --> (25:24-26:0) "{};;" +(29:28-30:1) "}\n" --> (25:24-26:0) "{};" (30:1-32:0) "}\n" --> (26:0-27:0) "\n}" (32:0-32:4) "\nvar" --> (27:0-27:4) "\nvar" (32:4-32:9) " aa =" --> (27:4-27:9) " aa ="