[Pkg-javascript-commits] [uglifyjs] 276/491: fix `top_retain` on `hoist_props` (#2474)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:44 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 2ac5086831f17ae93f1cfec9b7375b8ae19915ca
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon Nov 13 00:59:41 2017 +0800

    fix `top_retain` on `hoist_props` (#2474)
    
    fixes #2473
---
 lib/compress.js              |  2 +
 test/compress/hoist_props.js | 89 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index 54ac3d7..0635c41 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2769,6 +2769,7 @@ merge(Compressor.prototype, {
     AST_Scope.DEFMETHOD("hoist_properties", function(compressor){
         var self = this;
         if (!compressor.option("hoist_props") || compressor.has_directive("use asm")) return self;
+        var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
         var defs_by_id = Object.create(null);
         var var_names = Object.create(null);
         self.enclosed.forEach(function(def) {
@@ -2784,6 +2785,7 @@ merge(Compressor.prototype, {
                     && !(def = sym.definition()).escaped
                     && !def.single_use
                     && !def.direct_access
+                    && !top_retain(def)
                     && (value = sym.fixed_value()) === node.value
                     && value instanceof AST_Object) {
                     var defs = new Dictionary();
diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js
index 1fa321c..40d36ac 100644
--- a/test/compress/hoist_props.js
+++ b/test/compress/hoist_props.js
@@ -411,3 +411,92 @@ new_this: {
     }
     expect_stdout: "1 2"
 }
+
+issue_2473_1: {
+    options = {
+        hoist_props: false,
+        reduce_vars: true,
+        top_retain: [ "x", "y" ],
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var x = {};
+        var y = [];
+        var z = {};
+    }
+    expect: {
+        var x = {};
+        var y = [];
+    }
+}
+
+issue_2473_2: {
+    options = {
+        hoist_props: true,
+        reduce_vars: true,
+        top_retain: [ "x", "y" ],
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var x = {};
+        var y = [];
+        var z = {};
+    }
+    expect: {
+        var x = {};
+        var y = [];
+    }
+}
+
+issue_2473_3: {
+    options = {
+        hoist_props: true,
+        reduce_vars: true,
+        top_retain: "o",
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var o = {
+            a: 1,
+            b: 2,
+        };
+        console.log(o.a, o.b);
+    }
+    expect: {
+        var o = {
+            a: 1,
+            b: 2,
+        };
+        console.log(o.a, o.b);
+    }
+    expect_stdout: "1 2"
+}
+
+issue_2473_4: {
+    options = {
+        hoist_props: true,
+        reduce_vars: true,
+        top_retain: "o",
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        (function() {
+            var o = {
+                a: 1,
+                b: 2,
+            };
+            console.log(o.a, o.b);
+        })();
+    }
+    expect: {
+        (function() {
+            var o_a = 1, o_b = 2;
+            console.log(o_a, o_b);
+        })();
+    }
+    expect_stdout: "1 2"
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list