diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-11-17 02:36:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-17 02:36:42 +0800 |
commit | a6a0319f1c758013e8f1be9632fa30b031144835 (patch) | |
tree | b5f4463a45cc39063215ae181b5c8ebc50df3096 /test/compress/loops.js | |
parent | d1b2ecec27ea17e42d504503c6d760ff3c67b9ad (diff) | |
download | tracifyjs-a6a0319f1c758013e8f1be9632fa30b031144835.tar.gz tracifyjs-a6a0319f1c758013e8f1be9632fa30b031144835.zip |
compress empty for-in loops (#3590)
Diffstat (limited to 'test/compress/loops.js')
-rw-r--r-- | test/compress/loops.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/compress/loops.js b/test/compress/loops.js index d835080d..7b6002a2 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -689,3 +689,67 @@ step: { } expect_stdout: "42" } + +empty_for_in: { + options = { + loops: true, + toplevel: true, + unused: true, + } + input: { + for (var a in [ 1, 2, 3 ]) { + var b = a + 1; + } + } + expect: {} + expect_warnings: [ + "WARN: Dropping unused variable b [test/compress/loops.js:2,16]", + "INFO: Dropping unused loop variable a [test/compress/loops.js:1,17]", + ] +} + +empty_for_in_used: { + options = { + loops: true, + toplevel: true, + unused: true, + } + input: { + for (var a in [ 1, 2, 3 ]) { + var b = a + 1; + } + console.log(a); + } + expect: { + for (var a in [ 1, 2, 3 ]); + console.log(a); + } + expect_stdout: "2" + expect_warnings: [ + "WARN: Dropping unused variable b [test/compress/loops.js:2,16]", + ] +} + +empty_for_in_side_effects: { + options = { + loops: true, + toplevel: true, + unused: true, + } + input: { + for (var a in { + foo: console.log("PASS") + }) { + var b = a + "bar"; + } + } + expect: { + console.log("PASS"); + } + expect_stdout: "PASS" + expect_warnings: [ + "WARN: Dropping unused variable b [test/compress/loops.js:4,16]", + "INFO: Dropping unused loop variable a [test/compress/loops.js:1,17]", + "WARN: Side effects in object of for-in loop [test/compress/loops.js:1,17]", + ] +} |