Skip to content

Commit

Permalink
fix(codegen): object shorthand with parens ({x: (x)}) -> ({ x }) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jul 21, 2024
1 parent e70c67b commit 44a10c4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_codegen/examples/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() -> std::io::Result<()> {
}
let printed = CodeGenerator::new()
.enable_comment(
&source_text,
&printed,
ret.trivias.clone(),
CommentOptions { preserve_annotate_comments: true },
)
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ObjectProperty<'a> {

let mut shorthand = false;
if let PropertyKey::StaticIdentifier(key) = &self.key {
if let Expression::Identifier(ident) = &self.value {
if let Expression::Identifier(ident) = self.value.without_parenthesized() {
if key.name == p.get_identifier_reference_name(ident) {
shorthand = true;
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fn for_stmt() {
fn shorthand() {
test("let _ = { x }", "let _ = {x};\n");
test("let { x } = y", "let { x } = y;\n");
test("({ x: (x) })", "({x});\n");
test("({ x } = y)", "({x} = y);\n");
}

Expand Down

0 comments on commit 44a10c4

Please sign in to comment.