diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-11-19 02:30:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-19 02:30:52 +0800 |
commit | c289ba1139781f5619ec92136c2ceaac7d745ba7 (patch) | |
tree | f7731128d509e33ea793a902afe1f4f92b818ee0 /lib/output.js | |
parent | 02cc4a0d0370a79cb868199c58a03cfcd0e4d299 (diff) | |
download | tracifyjs-c289ba1139781f5619ec92136c2ceaac7d745ba7.tar.gz tracifyjs-c289ba1139781f5619ec92136c2ceaac7d745ba7.zip |
fix corner case in `collapse_vars` (#3597)
fixes #3596
Diffstat (limited to 'lib/output.js')
-rw-r--r-- | lib/output.js | 27 |
1 files changed, 17 insertions, 10 deletions
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) { |