[Pkg-javascript-commits] [uglifyjs] 263/491: inline single-use functions that are not constant expressions (#2434)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:42 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 2c2fd89e343626f8d7dc83812a6476b0ab99b784
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Nov 5 22:14:11 2017 +0800

    inline single-use functions that are not constant expressions (#2434)
    
    fixes #2428
---
 lib/compress.js            | 20 +++-----------------
 lib/minify.js              | 10 ++++------
 test/compress/functions.js | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 454c166..ba7c10f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -150,7 +150,9 @@ merge(Compressor.prototype, {
         }
         var passes = +this.options.passes || 1;
         var last_count = 1 / 0;
+        var mangle = { ie8: this.option("ie8") };
         for (var pass = 0; pass < passes; pass++) {
+            node.figure_out_scope(mangle);
             if (pass > 0 || this.option("reduce_vars"))
                 node.reset_opt_flags(this);
             node = node.transform(this);
@@ -3528,6 +3530,7 @@ merge(Compressor.prototype, {
                 && !exp.uses_arguments
                 && !exp.uses_eval
                 && exp.body.length == 1
+                && !exp.contains_this()
                 && all(exp.argnames, function(arg) {
                     return arg.__unused;
                 })
@@ -3542,23 +3545,6 @@ merge(Compressor.prototype, {
                     });
                 }
                 if (value) {
-                    var tw = new TreeWalker(function(node) {
-                        if (!value) return true;
-                        if (node instanceof AST_SymbolRef) {
-                            var ref = node.scope.find_variable(node);
-                            if (ref && ref.scope.parent_scope === fn.parent_scope) {
-                                value = null;
-                                return true;
-                            }
-                        }
-                        if (node instanceof AST_This && !tw.find_parent(AST_Scope)) {
-                            value = null;
-                            return true;
-                        }
-                    });
-                    value.walk(tw);
-                }
-                if (value) {
                     var args = self.args.concat(value);
                     return make_sequence(self, args).optimize(compressor);
                 }
diff --git a/lib/minify.js b/lib/minify.js
index 773e953..f9d726b 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -137,11 +137,9 @@ function minify(files, options) {
         if (options.wrap) {
             toplevel = toplevel.wrap_commonjs(options.wrap);
         }
-        if (timings) timings.scope1 = Date.now();
-        if (options.compress) toplevel.figure_out_scope(options.mangle);
         if (timings) timings.compress = Date.now();
         if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
-        if (timings) timings.scope2 = Date.now();
+        if (timings) timings.scope = Date.now();
         if (options.mangle) toplevel.figure_out_scope(options.mangle);
         if (timings) timings.mangle = Date.now();
         if (options.mangle) {
@@ -199,9 +197,9 @@ function minify(files, options) {
         if (timings) {
             timings.end = Date.now();
             result.timings = {
-                parse: 1e-3 * (timings.scope1 - timings.parse),
-                scope: 1e-3 * (timings.compress - timings.scope1 + timings.mangle - timings.scope2),
-                compress: 1e-3 * (timings.scope2 - timings.compress),
+                parse: 1e-3 * (timings.compress - timings.parse),
+                compress: 1e-3 * (timings.scope - timings.compress),
+                scope: 1e-3 * (timings.mangle - timings.scope),
                 mangle: 1e-3 * (timings.properties - timings.mangle),
                 properties: 1e-3 * (timings.output - timings.properties),
                 output: 1e-3 * (timings.end - timings.output),
diff --git a/test/compress/functions.js b/test/compress/functions.js
index febf81c..3c2ccce 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -508,3 +508,41 @@ issue_2114_2: {
     }
     expect_stdout: "2"
 }
+
+issue_2428: {
+    options = {
+        collapse_vars: true,
+        inline: true,
+        passes: 2,
+        pure_getters: "strict",
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unsafe: true,
+        unused: true,
+    }
+    input: {
+        function bar(k) {
+            console.log(k);
+        }
+        function foo(x) {
+            return bar(x);
+        }
+        function baz(a) {
+            foo(a);
+        }
+        baz(42);
+        baz("PASS");
+    }
+    expect: {
+        function baz(a) {
+            console.log(a);
+        }
+        baz(42);
+        baz("PASS");
+    }
+    expect_stdout: [
+        "42",
+        "PASS",
+    ]
+}

-- 
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