Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,9 @@ impl Gen for ArrayAssignmentTarget<'_> {
}
}
if let Some(target) = &self.rest {
p.print_soft_space();
if !self.elements.is_empty() {
p.print_soft_space();
}
p.add_source_mapping(self.span);
target.print(p, ctx);
}
Expand All @@ -1961,6 +1963,7 @@ impl Gen for ObjectAssignmentTarget<'_> {
if let Some(target) = &self.rest {
if !self.properties.is_empty() {
p.print_comma();
p.print_soft_space();
}
p.add_source_mapping(self.span);
target.print(p, ctx);
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ fn comma() {
#[test]
fn assignment() {
test("(let[0] = 100);", "(let)[0] = 100;\n");
test("[a, ...rest] = arr;", "[a, ...rest] = arr;\n");
test("[...rest] = arr;", "[...rest] = arr;\n");
test("({a, ...rest} = obj);", "({a, ...rest} = obj);\n");
test("({...rest} = obj);", "({...rest} = obj);\n");
test_minify("a = b ? c : d", "a=b?c:d;");
test_minify("[a,b] = (1, 2)", "[a,b]=(1,2);");
// `{a,b}` is a block, must wrap the whole expression to be an assignment expression
Expand Down
Loading