From: Alex Lam S.L Date: Wed, 2 Sep 2020 00:51:43 +0000 (+0100) Subject: reduce `AST_ForIn` gracefully (#4087) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2f0da2ff054491144ffcc77ac2d03389fda45af0;p=UglifyJS.git reduce `AST_ForIn` gracefully (#4087) --- diff --git a/test/reduce.js b/test/reduce.js index a380b390..95688358 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -112,19 +112,18 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) // no structural AST changes before this point. if (node.start._permute >= REPLACEMENTS.length) return; - if (parent instanceof U.AST_Assign - && parent.left === node - || parent instanceof U.AST_Unary - && parent.expression === node - && ["++", "--", "delete"].indexOf(parent.operator) >= 0) { - // ignore lvalues + // ignore lvalues + if (parent instanceof U.AST_Assign && parent.left === node) return; + if (parent instanceof U.AST_Unary && parent.expression === node) switch (parent.operator) { + case "++": + case "--": + case "delete": return; } - if ((parent instanceof U.AST_For || parent instanceof U.AST_ForIn) - && parent.init === node && node instanceof U.AST_Var) { - // preserve for (var ...) - return node; - } + // preserve for (var xxx; ...) + if (parent instanceof U.AST_For && parent.init === node && node instanceof U.AST_Var) return node; + // preserve for (xxx in ...) + if (parent instanceof U.AST_ForIn && parent.init === node) return node; // node specific permutations with no parent logic