diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-18 17:01:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 01:01:49 +0800 |
commit | 7d9dad02899fdc0a46ab030f9663e7f5bec2003b (patch) | |
tree | 50995d3865ef679c07ead586a1ac2beffb98b3ef | |
parent | 44e494f16f5ce7fc1272e6ca6ae227f77623c2f9 (diff) | |
download | tracifyjs-7d9dad02899fdc0a46ab030f9663e7f5bec2003b.tar.gz tracifyjs-7d9dad02899fdc0a46ab030f9663e7f5bec2003b.zip |
fix corner case with parentheses (#4409)
fixes #4408
-rw-r--r-- | lib/output.js | 8 | ||||
-rw-r--r-- | test/compress/arrows.js | 76 |
2 files changed, 79 insertions, 5 deletions
diff --git a/lib/output.js b/lib/output.js index 7bb27d9b..3d8d74c9 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1198,11 +1198,9 @@ function OutputStream(options) { // need to take some precautions here: // https://github.com/mishoo/UglifyJS/issues/60 if (noin) node.walk(new TreeWalker(function(node) { - if (parens || node instanceof AST_Scope) return true; - if (node instanceof AST_Binary && node.operator == "in") { - parens = true; - return true; - } + if (parens) return true; + if (node instanceof AST_Binary && node.operator == "in") return parens = true; + if (node instanceof AST_Scope && !(node instanceof AST_Arrow && node.value)) return true; })); node.print(output, parens); } diff --git a/test/compress/arrows.js b/test/compress/arrows.js index 0088392c..7245c134 100644 --- a/test/compress/arrows.js +++ b/test/compress/arrows.js @@ -43,6 +43,82 @@ await_parenthesis: { expect_exact: "async function f(){await(a=>a)}" } +for_parenthesis_init: { + input: { + for (a => (a in a); console.log(42);); + } + expect_exact: "for((a=>a in a);console.log(42););" + expect_stdout: "42" + node_version: ">=4" +} + +for_parenthesis_condition: { + input: { + for (console.log(42); a => (a in a);) + break; + } + expect_exact: "for(console.log(42);a=>a in a;)break;" + expect_stdout: "42" + node_version: ">=4" +} + +for_parenthesis_step: { + input: { + for (; console.log(42); a => (a in a)); + } + expect_exact: "for(;console.log(42);a=>a in a);" + expect_stdout: "42" + node_version: ">=4" +} + +for_assign_parenthesis_init: { + input: { + for (f = a => (a in a); console.log(42);); + } + expect_exact: "for((f=a=>a in a);console.log(42););" + expect_stdout: "42" + node_version: ">=4" +} + +for_assign_parenthesis_condition: { + input: { + for (console.log(42); f = a => (a in a);) + break; + } + expect_exact: "for(console.log(42);f=a=>a in a;)break;" + expect_stdout: "42" + node_version: ">=4" +} + +for_assign_parenthesis_step: { + input: { + for (; console.log(42); f = a => (a in a)); + } + expect_exact: "for(;console.log(42);f=a=>a in a);" + expect_stdout: "42" + node_version: ">=4" +} + +for_declaration_parenthesis_init: { + input: { + for (var f = a => (a in a); console.log(42);); + } + expect_exact: "for(var f=(a=>a in a);console.log(42););" + expect_stdout: "42" + node_version: ">=4" +} + +for_statement_parenthesis_init: { + input: { + for (a => { + a in a; + }; console.log(42);); + } + expect_exact: "for(a=>{a in a};console.log(42););" + expect_stdout: "42" + node_version: ">=4" +} + body_call: { input: { (() => { |