[Pkg-javascript-commits] [uglifyjs] 360/491: fix infinite loop during `inline` (#2645)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:52 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 cb6a92892f9a5d66d36c766213c19e274efb9796
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon Dec 25 01:57:11 2017 +0800

    fix infinite loop during `inline` (#2645)
    
    fixes #2644
---
 lib/compress.js            | 14 ++++++--------
 test/compress/functions.js | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 315a18c..cc36095 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3934,7 +3934,7 @@ merge(Compressor.prototype, {
             }
         }
         if (fn instanceof AST_Function) {
-            var def, scope, value;
+            var def, value, scope, level = -1;
             if (compressor.option("inline")
                 && !fn.uses_arguments
                 && !fn.uses_eval
@@ -3946,7 +3946,7 @@ merge(Compressor.prototype, {
                         && fn.is_constant_expression(exp.scope))
                 && !self.pure
                 && !fn.contains_this()
-                && (scope = can_flatten_args(fn))
+                && can_flatten_args(fn)
                 && (value = flatten_body(stat))) {
                 var expressions = flatten_args(fn, scope);
                 expressions.push(value.clone(true));
@@ -3981,10 +3981,9 @@ merge(Compressor.prototype, {
         return self;
 
         function can_flatten_args(fn) {
-            var scope, level = 0;
             var catches = Object.create(null);
             do {
-                scope = compressor.parent(level++);
+                scope = compressor.parent(++level);
                 if (scope instanceof AST_SymbolRef) {
                     scope = scope.fixed_value();
                 } else if (scope instanceof AST_Catch) {
@@ -3998,10 +3997,10 @@ merge(Compressor.prototype, {
                         && !catches[arg.name]
                         && !identifier_atom(arg.name)
                         && !scope.var_names()[arg.name];
-            }) && scope;
+            });
         }
 
-        function flatten_args(fn, scope) {
+        function flatten_args(fn) {
             var decls = [];
             var expressions = [];
             for (var len = fn.argnames.length, i = len; --i >= 0;) {
@@ -4035,8 +4034,7 @@ merge(Compressor.prototype, {
                 expressions.push(self.args[i]);
             }
             if (decls.length) {
-                for (i = 0; compressor.parent(i) !== scope;) i++;
-                i = scope.body.indexOf(compressor.parent(i - 1)) + 1;
+                i = scope.body.indexOf(compressor.parent(level - 1)) + 1;
                 scope.body.splice(i, 0, make_node(AST_Var, fn, {
                     definitions: decls
                 }));
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 0714766..02b4ab3 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -1423,3 +1423,27 @@ issue_2630_5: {
     }
     expect_stdout: "155"
 }
+
+recursive_inline: {
+    options = {
+        inline: true,
+        reduce_funcs: true,
+        reduce_vars: true,
+        sequences: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            h();
+        }
+        function g(a) {
+            a();
+        }
+        function h(b) {
+            g();
+            if (b) x();
+        }
+    }
+    expect: {}
+}

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