diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 84f9236c6ea12..db0255d5b8e9c 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -1996,6 +1996,15 @@ impl Gen for AssignmentTargetPropertyProperty<'_> { PropertyKey::PrivateIdentifier(ident) => { ident.print(p, ctx); } + PropertyKey::StringLiteral(s) => { + if self.computed { + p.print_ascii_byte(b'['); + } + p.print_string_literal(s, /* allow_backtick */ false); + if self.computed { + p.print_ascii_byte(b']'); + } + } key => { if self.computed { p.print_ascii_byte(b'['); diff --git a/crates/oxc_codegen/tests/integration/js.rs b/crates/oxc_codegen/tests/integration/js.rs index cc55b3cc90119..3b02879a686d9 100644 --- a/crates/oxc_codegen/tests/integration/js.rs +++ b/crates/oxc_codegen/tests/integration/js.rs @@ -225,6 +225,16 @@ fn assignment() { test_minify("({ [0]: x } = foo);", "({[0]:x}=foo);"); test_minify("({ a: x } = foo);", "({a:x}=foo);"); test_minify("({ [a.b]: x } = foo);", "({[a.b]:x}=foo);"); + + 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);"#, + ); + test_minify(r#"let {"test-key": testKey} = obj;"#, r#"let{"test-key":testKey}=obj;"#); + + test_minify(r#"({ "test-key": key });"#, r#"({"test-key":key});"#); + test_minify(r#"(class { "test-key" = key });"#, r#"(class{"test-key"=key});"#); } #[test]