From: Alex Lam S.L Date: Fri, 18 Dec 2020 17:01:49 +0000 (+0000) Subject: fix corner case with parentheses (#4409) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7d9dad02899fdc0a46ab030f9663e7f5bec2003b;p=UglifyJS.git fix corner case with parentheses (#4409) fixes #4408 --- 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: { (() => {