diff --git a/lib/compress.js b/lib/compress.js index 3309d7fa61..57072615a2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1400,22 +1400,23 @@ Compressor.prototype.compress = function(node) { pop_scope(tw, fn); return true; }); - def(AST_Sub, function(tw, descend) { + def(AST_Sub, function(tw) { var node = this; var expr = node.expression; + var prop = node.property; + expr.walk(tw); if (node.optional) { - expr.walk(tw); push(tw, true, true); - node.property.walk(tw); + prop.walk(tw); pop(tw); } else { - descend(); while (expr instanceof AST_Assign && expr.operator == "=") { var lhs = expr.left; if (lhs instanceof AST_SymbolRef) access(tw, lhs.definition()); expr = expr.right; } if (expr instanceof AST_SymbolRef) access(tw, expr.definition()); + prop.walk(tw); } return true; }); diff --git a/test/compress/properties.js b/test/compress/properties.js index 5a9117dc97..618ec3146e 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -1992,3 +1992,57 @@ issue_5927: { } expect_stdout: "PASS" } + +issue_5949_1: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + } + input: { + var a = 42; + a[a = null]; + try { + a.p; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect: { + var a = 42; + a[a = null]; + try { + a.p; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" +} + +issue_5949_2: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + } + input: { + try { + a[42]; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect: { + try { + a[42]; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" +}