From 2f0da2ff054491144ffcc77ac2d03389fda45af0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 2 Sep 2020 01:51:43 +0100 Subject: [PATCH] reduce `AST_ForIn` gracefully (#4087) --- test/reduce.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) 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 -- 2.34.1