fix(codegen): object shorthand with parens ({x: (x)}) -> ({ x }) (#4391)

This commit is contained in:
Boshen 2024-07-21 14:04:17 +00:00
parent e70c67b2e2
commit 44a10c4b91
3 changed files with 3 additions and 2 deletions

View file

@ -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 },
)

View file

@ -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;
}

View file

@ -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");
}