From 44dfa5a318d6df8eff4741a351f24667708a9cab Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 16 Apr 2017 17:25:39 +0800 Subject: fix variable substitution (#1816) - let `collapse_vars` take care of value containing any symbols - improve overhead accounting --- test/compress/issue-1656.js | 6 ++--- test/compress/reduce_vars.js | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/compress/issue-1656.js b/test/compress/issue-1656.js index 8b683a28..c4c8f863 100644 --- a/test/compress/issue-1656.js +++ b/test/compress/issue-1656.js @@ -35,11 +35,11 @@ f7: { console.log(a, b); } expect_exact: [ - "var a = 100, b = 10;", + "var b = 10;", "", "!function() {", - " for (;b = a, !1; ) ;", - "}(), console.log(a, b);", + " for (;b = 100, !1; ) ;", + "}(), console.log(100, b);", ] expect_stdout: true } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index b6f711ad..7621dd4a 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -1995,3 +1995,55 @@ catch_var: { } expect_stdout: "true" } + +issue_1814_1: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + const a = 42; + !function() { + var b = a; + !function(a) { + console.log(a++, b); + }(0); + }(); + } + expect: { + const a = 42; + !function() { + !function(a) { + console.log(a++, 42); + }(0); + }(); + } + expect_stdout: "0 42" +} + +issue_1814_2: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + const a = "32"; + !function() { + var b = a + 1; + !function(a) { + console.log(a++, b); + }(0); + }(); + } + expect: { + const a = "32"; + !function() { + !function(a) { + console.log(a++, "321"); + }(0); + }(); + } + expect_stdout: "0 '321'" +} -- cgit v1.2.3