From 1549db70e60a1ae74f2b7ffc511ef123733f9557 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 16 Oct 2019 12:18:27 +0800 Subject: [PATCH] fix corner case in `ie8` (#3487) fixes #3486 --- lib/scope.js | 8 ++++++-- test/compress/ie8.js | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index b40807fa3f..131235f68c 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -194,7 +194,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { if (node instanceof AST_SymbolCatch) { var scope = node.thedef.defun; if (scope.name instanceof AST_SymbolLambda && scope.name.name == node.name) { - scope = scope.parent_scope; + scope = scope.parent_scope.resolve(); } redefine(node, scope); return true; @@ -202,7 +202,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { if (node instanceof AST_SymbolLambda) { var def = node.thedef; redefine(node, node.scope.parent_scope.resolve()); - if (def.init) node.thedef.init = def.init; + if (typeof node.thedef.init !== "undefined") { + node.thedef.init = false; + } else if (def.init) { + node.thedef.init = def.init; + } return true; } })); diff --git a/test/compress/ie8.js b/test/compress/ie8.js index c6b51d63fb..223da329f0 100644 --- a/test/compress/ie8.js +++ b/test/compress/ie8.js @@ -1841,3 +1841,49 @@ issue_3484_2_ie8_toplevel: { } expect_stdout: "number number" } + +issue_3486: { + options = { + conditionals: true, + ie8: false, + reduce_vars: true, + } + input: { + (function a() { + (function a(a) { + console.log(a ? "FAIL" : "PASS"); + })(); + })(); + } + expect: { + (function a() { + (function a(a) { + console.log(a ? "FAIL" : "PASS"); + })(); + })(); + } + expect_stdout: "PASS" +} + +issue_3486_ie8: { + options = { + conditionals: true, + ie8: true, + reduce_vars: true, + } + input: { + (function a() { + (function a(a) { + console.log(a ? "FAIL" : "PASS"); + })(); + })(); + } + expect: { + (function a() { + (function a(a) { + console.log(a ? "FAIL" : "PASS"); + })(); + })(); + } + expect_stdout: "PASS" +}