From 68cc14f84678bf7777f777b668d6c006e65250d3 Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Mon, 18 Apr 2016 15:51:32 +0200 Subject: [PATCH] Fixups after merge --- lib/ast.js | 7 +++++++ lib/compress.js | 2 +- test/compress/block-scope.js | 8 ++++---- test/compress/harmony.js | 24 ++++++++++++------------ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index a0d2aac1..b89a00d2 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -294,6 +294,13 @@ var AST_Scope = DEFNODE("Scope", "is_block_scope directives variables functions parent_scope: "[AST_Scope?/S] link to the parent scope", enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes", cname: "[integer/S] current index for mangling variables (used internally by the mangler)", + }, + get_defun_scope: function () { + var self = this; + while (self.is_block_scope && self.parent_scope) { + self = self.parent_scope; + } + return self; } }, AST_Block); diff --git a/lib/compress.js b/lib/compress.js index 699a95b6..fdb06839 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -323,7 +323,7 @@ merge(Compressor.prototype, { if (side_effects_encountered |= lvalues_encountered) continue; // Non-constant single use vars can only be replaced in same scope. - if (ref.scope !== self) { + if (ref.scope.get_defun_scope() !== self) { side_effects_encountered |= var_decl.value.has_side_effects(compressor); continue; } diff --git a/test/compress/block-scope.js b/test/compress/block-scope.js index 4c8ca796..dd243009 100644 --- a/test/compress/block-scope.js +++ b/test/compress/block-scope.js @@ -117,13 +117,13 @@ regression_block_scope_resolves: { expect: { (function () { if (1) { - let a; - const b; + let o; + const n; class c {}; } if (1) { - let a; - const b; + let o; + const n; class c {}; } console.log(x, y, Zee, ex, why, Zi); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 84aba4bb..b4abb470 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -62,9 +62,9 @@ shorthand_properties: { return value; })(); expect: (function() { - var a = 1; - const b = {prop:a}; - return b; + var n = 1; + const r = {prop:n}; + return r; })(); } @@ -271,8 +271,8 @@ class_name_can_be_mangled: { expect: { function x() { class a { } - var b = a - var c = class a {} + var n = a + var r = class a {} } } } @@ -354,13 +354,13 @@ import_statement_mangling: { Whatever(); } expect: { - import a from "foo"; - import b, {Food as c} from "lel"; - import {What as d} from "lel"; - a(); - b(); - c(); - d(); + import l from "foo"; + import e, {Food as o} from "lel"; + import {What as f} from "lel"; + l(); + e(); + o(); + f(); } }