aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-09-02 01:51:43 +0100
committerGitHub <noreply@github.com>2020-09-02 08:51:43 +0800
commit2f0da2ff054491144ffcc77ac2d03389fda45af0 (patch)
tree70740f6bc3cf9b2df82e6c0b5959420846ec32ac
parent83a3cbf1514e81292b749655f2f712e82a5a2ba8 (diff)
downloadtracifyjs-2f0da2ff054491144ffcc77ac2d03389fda45af0.tar.gz
tracifyjs-2f0da2ff054491144ffcc77ac2d03389fda45af0.zip
reduce `AST_ForIn` gracefully (#4087)
-rw-r--r--test/reduce.js21
1 files 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