Skip to content

Commit

Permalink
fix: avoid print extra semicolon after accessor property (#4199)
Browse files Browse the repository at this point in the history
## 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;;
}

```
  • Loading branch information
IWANABETHATGUY authored Jul 11, 2024
1 parent e3e663b commit 1c117eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 0 additions & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,6 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for AccessorProperty<'a> {
p.print_equal();
value.gen_expr(p, Precedence::Assign, Context::default());
}
p.print_semicolon();
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_codegen/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tasks/coverage/codegen_sourcemap.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 ="
Expand Down

0 comments on commit 1c117eb

Please sign in to comment.