From de9e74b0a7312c797db8c60ef36a100ebde8de35 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Wed, 10 Sep 2025 10:43:41 +0700 Subject: [PATCH] fix(codegen): use backticks for computed object property keys in destructuring assignments --- crates/oxc_codegen/src/gen.rs | 8 +------- crates/oxc_codegen/tests/integration/js.rs | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index db0255d5b8e9c..078a9cc3600b8 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -1996,14 +1996,8 @@ impl Gen for AssignmentTargetPropertyProperty<'_> { PropertyKey::PrivateIdentifier(ident) => { ident.print(p, ctx); } - PropertyKey::StringLiteral(s) => { - if self.computed { - p.print_ascii_byte(b'['); - } + PropertyKey::StringLiteral(s) if !self.computed => { p.print_string_literal(s, /* allow_backtick */ false); - if self.computed { - p.print_ascii_byte(b']'); - } } key => { if self.computed { diff --git a/crates/oxc_codegen/tests/integration/js.rs b/crates/oxc_codegen/tests/integration/js.rs index 3b02879a686d9..154cb2431ecd1 100644 --- a/crates/oxc_codegen/tests/integration/js.rs +++ b/crates/oxc_codegen/tests/integration/js.rs @@ -229,7 +229,7 @@ fn assignment() { test_minify(r#"({"my-key": value} = obj);"#, r#"({"my-key":value}=obj);"#); test_minify( r#"({["computed"]: a, "literal": b} = obj);"#, - r#"({["computed"]:a,"literal":b}=obj);"#, + r#"({[`computed`]:a,"literal":b}=obj);"#, ); test_minify(r#"let {"test-key": testKey} = obj;"#, r#"let{"test-key":testKey}=obj;"#);