diff --git a/lib/output.js b/lib/output.js index 415437bd..9d7a7e1b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -805,17 +805,15 @@ function OutputStream(options) { DEFPRINT(AST_Destructuring, function (self, output) { output.print(self.is_array ? "[" : "{"); - var first = true; var len = self.names.length; self.names.forEach(function (name, i) { - if (first) first = false; else { output.comma(); output.space(); } + if (i > 0) output.comma(); name.print(output); // If the final element is a hole, we need to make sure it // doesn't look like a trailing comma, by inserting an actual // trailing comma. - if (i === len - 1 && name instanceof AST_Hole) - output.comma(); - }) + if (i == len - 1 && name instanceof AST_Hole) output.comma(); + }); output.print(self.is_array ? "]" : "}"); }); @@ -1577,7 +1575,9 @@ function OutputStream(options) { get_name(self.value.left) === self.key ) { print_property_name(self.key, self.quote, output); + output.space(); output.print("="); + output.space(); self.value.right.print(output); } else { if (!(self.key instanceof AST_Node)) { diff --git a/test/compress/destructuring.js b/test/compress/destructuring.js index 84c1920e..99b5842b 100644 --- a/test/compress/destructuring.js +++ b/test/compress/destructuring.js @@ -595,3 +595,47 @@ arrow_func_with_destructuring_args: { expect_stdout: "1 5 3 6" node_version: ">=6" } + +issue_2044_ecma_5: { + beautify = { + beautify: false, + ecma: 5, + } + input: { + ({x : a = 1, y = 2 + b, z = 3 - c} = obj); + } + expect_exact: "({x:a=1,y:y=2+b,z:z=3-c}=obj);" +} + +issue_2044_ecma_6: { + beautify = { + beautify: false, + ecma: 6, + } + input: { + ({x : a = 1, y = 2 + b, z = 3 - c} = obj); + } + expect_exact: "({x:a=1,y=2+b,z=3-c}=obj);" +} + +issue_2044_ecma_5_beautify: { + beautify = { + beautify: true, + ecma: 5, + } + input: { + ({x : a = 1, y = 2 + b, z = 3 - c} = obj); + } + expect_exact: "({x: a = 1, y: y = 2 + b, z: z = 3 - c} = obj);" +} + +issue_2044_ecma_6_beautify: { + beautify = { + beautify: true, + ecma: 6, + } + input: { + ({x : a = 1, y = 2 + b, z = 3 - c} = obj); + } + expect_exact: "({x: a = 1, y = 2 + b, z = 3 - c} = obj);" +}