diff --git a/lib/compress.js b/lib/compress.js index 6f9d460c..7f0cefcc 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5032,10 +5032,8 @@ merge(Compressor.prototype, { var init; if (fixed instanceof AST_This) { if (!(d.orig[0] instanceof AST_SymbolFunarg) - && all(d.references, d.scope.is_block_scope() ? function(ref) { + && all(d.references, function(ref) { return d.scope === ref.scope; - } : function(ref) { - return d.scope === ref.scope.get_defun_scope(); })) { init = fixed; } diff --git a/lib/scope.js b/lib/scope.js index 745d5e35..1a3d39f9 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -284,6 +284,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ } node.thedef = sym; node.reference(options); + if (node.scope.is_block_scope() + && !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) { + node.scope = node.scope.get_defun_scope(); + } return true; } // ensure mangling works if catch reuses a scope variable diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index b99cc261..f92f40ca 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -1555,10 +1555,10 @@ defun_label: { !function() { console.log(function(a) { L: { - if (a) break L; + if (2) break L; return 1; } - }(2)); + }()); }(); } expect_stdout: true @@ -3366,9 +3366,7 @@ obj_for_1: { console.log(i); } expect: { - // TODO make this work on harmony - var o = { a: 1 }; - for (var i = o.a--; i; i--) + for (var i = { a: 1 }.a--; i; i--) console.log(i); } expect_stdout: "1" @@ -3407,9 +3405,7 @@ array_forin_1: { console.log(b); } expect: { - // TODO make this work on harmony - var a = [ 1, 2, 3 ]; - for (var b in a) + for (var b in [ 1, 2, 3 ]) console.log(b); } expect_stdout: [ @@ -3454,9 +3450,7 @@ array_forof_1: { console.log(b); } expect: { - // TODO make this work on harmony - var a = [ 1, 2, 3 ]; - for (var b of a) + for (var b of [ 1, 2, 3 ]) console.log(b); } expect_stdout: [ @@ -5160,10 +5154,8 @@ escape_local_throw: { } expect: { function baz() { - // TODO: improve to match `master` - function foo() {} try { - throw foo; + throw function() {}; } catch (bar) { return bar; }