diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-14 00:18:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-14 07:18:26 +0800 |
commit | 9f8106e1d845f66033c3c73e2e3844cf32fd4bb2 (patch) | |
tree | 57013216b12a1220b4904d829cfa33f8bc80093c | |
parent | b7b8435721a07bebec9fca513700cc2af31ed175 (diff) | |
download | tracifyjs-9f8106e1d845f66033c3c73e2e3844cf32fd4bb2.tar.gz tracifyjs-9f8106e1d845f66033c3c73e2e3844cf32fd4bb2.zip |
fix corner case in `collapse_vars` (#4217)
fixes #4216
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | lib/output.js | 2 | ||||
-rw-r--r-- | test/compress/const.js | 23 |
3 files changed, 25 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js index baa501ff..b2ed17cf 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1501,9 +1501,9 @@ merge(Compressor.prototype, { // Skip (non-executed) functions if (node instanceof AST_Scope) return node; // Stop upon collision with block-scoped variables - if (node.variables && !node.variables.all(function(def) { + if (!(node.variables && node.variables.all(function(def) { return !lvalues.has(def.name); - })) { + }))) { abort = true; return node; } diff --git a/lib/output.js b/lib/output.js index 05baa239..7077d6dd 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1385,8 +1385,6 @@ function OutputStream(options) { make_block(stat, output); } else if (!stat || stat instanceof AST_EmptyStatement) { output.force_semicolon(); - } else if (stat instanceof AST_Const) { - make_block(stat, output); } else { stat.print(output); } diff --git a/test/compress/const.js b/test/compress/const.js index 4411cbf8..27c55ddb 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1009,3 +1009,26 @@ issue_4212_2: { } expect_stdout: true } + +issue_4216: { + options = { + collapse_vars: true, + conditionals: true, + dead_code: true, + evaluate: true, + } + input: { + if (a = 0) { + const a = 0; + } + console.log(typeof a); + } + expect: { + a = 0; + { + const a = void 0; + } + console.log(typeof a); + } + expect_stdout: true +} |