From 5d12abc41b9cb4890b937599fa588a53fdb2996b Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 30 Oct 2020 02:04:23 +0000 Subject: fix corner cases in `collapse_vars` (#4249) fixes #4248 --- test/compress/collapse_vars.js | 25 +++++++++++++++++++++++++ test/compress/const.js | 31 +++++++++++++++++++++++++++++++ test/compress/let.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) (limited to 'test') diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index dea01b60..edf4795a 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8577,3 +8577,28 @@ issue_4242: { } expect_stdout: "undefined" } + +issue_4248: { + options = { + collapse_vars: true, + } + input: { + var a = 0; + try { + a = 1; + b[1]; + } catch (e) { + console.log(a); + } + } + expect: { + var a = 0; + try { + a = 1; + b[1]; + } catch (e) { + console.log(a); + } + } + expect_stdout: "1" +} diff --git a/test/compress/const.js b/test/compress/const.js index 2f88975e..896e8c38 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1104,3 +1104,34 @@ issue_4245: { } expect_stdout: true } + +issue_4248: { + options = { + collapse_vars: true, + } + input: { + var a = "FAIL"; + try { + (function() { + a = "PASS"; + b[a]; + const b = 0; + })(); + } catch (e) { + console.log(a); + } + } + expect: { + var a = "FAIL"; + try { + (function() { + a = "PASS"; + b[a]; + const b = 0; + })(); + } catch (e) { + console.log(a); + } + } + expect_stdout: "PASS" +} diff --git a/test/compress/let.js b/test/compress/let.js index deb48120..9a6fc944 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -916,3 +916,37 @@ issue_4245: { expect_stdout: ReferenceError("a is not defined") node_version: ">=4" } + +issue_4248: { + options = { + collapse_vars: true, + } + input: { + var a = "FAIL"; + try { + (function() { + "use strict"; + a = "PASS"; + b[a]; + let b; + })(); + } catch (e) { + console.log(a); + } + } + expect: { + var a = "FAIL"; + try { + (function() { + "use strict"; + a = "PASS"; + b[a]; + let b; + })(); + } catch (e) { + console.log(a); + } + } + expect_stdout: "PASS" + node_version: ">=4" +} -- cgit v1.2.3