diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-01 04:56:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-01 12:56:13 +0800 |
commit | 2dbafbb4ee9c5cb82665299ee9343c80e96daad4 (patch) | |
tree | 5b66f7838396dc84fd73c18fdfea66f41b9a921a /test | |
parent | 311c074622e0aabbd79b0d701c19f21b8b093b77 (diff) | |
download | tracifyjs-2dbafbb4ee9c5cb82665299ee9343c80e96daad4.tar.gz tracifyjs-2dbafbb4ee9c5cb82665299ee9343c80e96daad4.zip |
fix corner case in `reduce_vars` (#4490)
fixes #4489
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/hoist_vars.js | 19 | ||||
-rw-r--r-- | test/reduce.js | 16 |
2 files changed, 29 insertions, 6 deletions
diff --git a/test/compress/hoist_vars.js b/test/compress/hoist_vars.js index 173aaeaf..82f8ede6 100644 --- a/test/compress/hoist_vars.js +++ b/test/compress/hoist_vars.js @@ -158,3 +158,22 @@ issue_4487: { } expect_stdout: "undefined" } + +issue_4489: { + options = { + collapse_vars: true, + evaluate: true, + hoist_vars: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + A = 0; + var o = !0 || null; + for (var k in o); + } + expect: { + for (var k in !(A = 0)); + } +} diff --git a/test/reduce.js b/test/reduce.js index 120868fe..e45cfa5d 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -322,7 +322,16 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) } else if (node instanceof U.AST_Object) { // first property's value - var expr = node.properties[0] instanceof U.AST_ObjectKeyVal && node.properties[0].value; + var expr = node.properties[0]; + if (expr instanceof U.AST_ObjectKeyVal) { + expr = expr.value; + } else if (expr instanceof U.AST_Spread) { + expr = expr.expression; + } else if (expr && expr.key instanceof U.AST_Node) { + expr = expr.key; + } else { + expr = null; + } if (expr) { node.start._permute++; CHANGED = true; @@ -351,11 +360,6 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) } } } - else if (node instanceof U.AST_Spread) { - node.start._permute++; - CHANGED = true; - return node.expression; - } else if (node instanceof U.AST_Switch) { var expr = [ node.expression, // switch expression |