fix corner case in `reduce_vars` (#4665)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 18 Feb 2021 18:04:33 +0000 (18:04 +0000)
committerGitHub <noreply@github.com>
Thu, 18 Feb 2021 18:04:33 +0000 (02:04 +0800)
fixes #4664

bin/uglifyjs
lib/compress.js
test/compress/exponentiation.js

index c2576ba..6033542 100755 (executable)
@@ -10,7 +10,7 @@ var info = require("../package.json");
 var path = require("path");
 var UglifyJS = require("../tools/node");
 
-var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
+var skip_keys = [ "cname", "fixed", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
 var files = {};
 var options = {};
 var short_forms = {
@@ -360,14 +360,14 @@ function run() {
         }
         print(JSON.stringify(result.ast, function(key, value) {
             if (value) switch (key) {
-              case "thedef":
-                return symdef(value);
               case "enclosed":
                 return value.length ? value.map(symdef) : undefined;
-              case "variables":
               case "functions":
               case "globals":
+              case "variables":
                 return value.size() ? value.map(symdef) : undefined;
+              case "thedef":
+                return symdef(value);
             }
             if (skip_key(key)) return;
             if (value instanceof UglifyJS.AST_Token) return;
index a58e281..325c0cd 100644 (file)
@@ -757,7 +757,9 @@ merge(Compressor.prototype, {
                 var value = iife.args[i];
                 scan_declaration(tw, compressor, arg, function() {
                     var j = fn.argnames.indexOf(arg);
-                    return (j < 0 ? value : iife.args[j]) || make_node(AST_Undefined, iife);
+                    var arg = j < 0 ? value : iife.args[j];
+                    if (arg instanceof AST_Sequence && arg.expressions.length < 2) arg = arg.expressions[0];
+                    return arg || make_node(AST_Undefined, iife);
                 }, visit);
             });
             if (fn.rest) scan_declaration(tw, compressor, fn.rest, compressor.option("rests") && function() {
@@ -3644,7 +3646,7 @@ merge(Compressor.prototype, {
     // methods to determine if an expression has a numeric result type
     (function(def) {
         def(AST_Node, return_false);
-        var binary = makePredicate("- * / % & | ^ << >> >>>");
+        var binary = makePredicate("- * / % ** & | ^ << >> >>>");
         def(AST_Assign, function(compressor) {
             return binary[this.operator.slice(0, -1)]
                 || this.operator == "=" && this.right.is_number(compressor);
index 008d587..b6cfde5 100644 (file)
@@ -56,3 +56,31 @@ evaluate: {
     expect_stdout: "5"
     node_version: ">=8"
 }
+
+issue_4664: {
+    options = {
+        collapse_vars: true,
+        evaluate: true,
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            new function(a) {
+                console.log(typeof f, a, typeof this);
+            }((A = 0, (NaN ^ 1) * 2 ** 30), 0);
+        }
+        f();
+    }
+    expect: {
+        (function f() {
+            new function(a) {
+                console.log(typeof f, 2 ** 30, typeof this);
+            }(0, A = 0);
+        })();
+    }
+    expect_stdout: "function 1073741824 object"
+    node_version: ">=8"
+}