From c289ba1139781f5619ec92136c2ceaac7d745ba7 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 19 Nov 2019 02:30:52 +0800 Subject: fix corner case in `collapse_vars` (#3597) fixes #3596 --- lib/output.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'lib/output.js') diff --git a/lib/output.js b/lib/output.js index d59176c3..0f8ef1cd 100644 --- a/lib/output.js +++ b/lib/output.js @@ -711,16 +711,23 @@ function OutputStream(options) { PARENS(AST_Sequence, function(output) { var p = output.parent(); - return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4) - || p instanceof AST_Unary // !(foo, bar, baz) - || p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8 - || p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4 - || p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2 - || p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ] - || p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2 - || p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30) - * ==> 20 (side effect, set a := 10 and b := 20) */ - ; + // (foo, bar)() or foo(1, (2, 3), 4) + return p instanceof AST_Call + // !(foo, bar, baz) + || p instanceof AST_Unary + // 1 + (2, 3) + 4 ==> 8 + || p instanceof AST_Binary + // var a = (1, 2), b = a + a; ==> b == 4 + || p instanceof AST_VarDef + // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2 + || p instanceof AST_PropAccess && p.expression === this + // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ] + || p instanceof AST_Array + // { foo: (1, 2) }.foo ==> 2 + || p instanceof AST_ObjectProperty + // (false, true) ? (a = 10, b = 20) : (c = 30) + // ==> 20 (side effect, set a := 10 and b := 20) + || p instanceof AST_Conditional; }); PARENS(AST_Binary, function(output) { -- cgit v1.2.3