diff options
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/functions.js | 52 |
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 5a8f23bf..0f4dd255 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1970,7 +1970,7 @@ merge(Compressor.prototype, { } return node; } - if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn)) { + if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn && tt.parent().init === node)) { // place uninitialized names at the start var body = [], head = [], tail = []; // for unused names whose initialization has diff --git a/test/compress/functions.js b/test/compress/functions.js index dca40623..2a2d0965 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -93,3 +93,55 @@ issue_485_crashing_1530: { this, void 0; } } + +issue_1841_1: { + options = { + keep_fargs: false, + pure_getters: "strict", + reduce_vars: true, + unused: true, + } + input: { + var b = 10; + !function(arg) { + for (var key in "hi") + var n = arg.baz, n = [ b = 42 ]; + }(--b); + console.log(b); + } + expect: { + var b = 10; + !function() { + for (var key in "hi") + b = 42; + }(--b); + console.log(b); + } + expect_exact: "42" +} + +issue_1841_2: { + options = { + keep_fargs: false, + pure_getters: false, + reduce_vars: true, + unused: true, + } + input: { + var b = 10; + !function(arg) { + for (var key in "hi") + var n = arg.baz, n = [ b = 42 ]; + }(--b); + console.log(b); + } + expect: { + var b = 10; + !function(arg) { + for (var key in "hi") + arg.baz, b = 42; + }(--b); + console.log(b); + } + expect_exact: "42" +} |