[Pkg-javascript-commits] [uglifyjs] 127/228: introduce compressor.info() (#1633)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:23 UTC 2017


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

js pushed a commit to branch master
in repository uglifyjs.

commit c0f3feae9f251abbea5ae1198e1a6784dd3261f7
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Mar 23 06:49:49 2017 +0800

    introduce compressor.info() (#1633)
    
    report the following only when `options.warnings = "verbose"`
    - unused elements due to inlining
    - collpased variables
---
 lib/compress.js             | 13 +++++++++----
 test/compress/issue-1034.js |  7 ++-----
 test/run-tests.js           |  2 +-
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 41612ad..a8fbb8b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -131,6 +131,11 @@ merge(Compressor.prototype, {
         }
         return node;
     },
+    info: function() {
+        if (this.options.warnings == "verbose") {
+            AST_Node.warn.apply(AST_Node, arguments);
+        }
+    },
     warn: function(text, props) {
         if (this.options.warnings) {
             // only emit unique warnings
@@ -664,7 +669,7 @@ merge(Compressor.prototype, {
                 // Further optimize statement after substitution.
                 stat.reset_opt_flags(compressor);
 
-                compressor.warn("Collapsing " + (is_constant ? "constant" : "variable") +
+                compressor.info("Collapsing " + (is_constant ? "constant" : "variable") +
                     " " + var_name + " [{file}:{line},{col}]", node.start);
                 CHANGED = true;
                 return value;
@@ -1828,7 +1833,7 @@ merge(Compressor.prototype, {
                                 sym.__unused = true;
                                 if (trim) {
                                     a.pop();
-                                    compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
+                                    compressor[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", {
                                         name : sym.name,
                                         file : sym.start.file,
                                         line : sym.start.line,
@@ -1843,7 +1848,7 @@ merge(Compressor.prototype, {
                     }
                     if (drop_funcs && node instanceof AST_Defun && node !== self) {
                         if (!(node.name.definition().id in in_use_ids)) {
-                            compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
+                            compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", {
                                 name : node.name.name,
                                 file : node.name.start.file,
                                 line : node.name.start.line,
@@ -1867,7 +1872,7 @@ merge(Compressor.prototype, {
                                 compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", w);
                                 return true;
                             }
-                            compressor.warn("Dropping unused variable {name} [{file}:{line},{col}]", w);
+                            compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", w);
                             return false;
                         });
                         // place uninitialized names at the start
diff --git a/test/compress/issue-1034.js b/test/compress/issue-1034.js
index b91eace..57c584a 100644
--- a/test/compress/issue-1034.js
+++ b/test/compress/issue-1034.js
@@ -39,7 +39,7 @@ non_hoisted_function_after_return_2a: {
         hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
         evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
         if_return: true, join_vars: true, cascade: true, side_effects: true,
-        collapse_vars: false, passes: 2
+        collapse_vars: false, passes: 2, warnings: "verbose"
     }
     input: {
         function foo(x) {
@@ -75,7 +75,7 @@ non_hoisted_function_after_return_2a: {
         "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
         "WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
         "WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
-        "WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]"
+        "WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
     ]
 }
 
@@ -114,8 +114,5 @@ non_hoisted_function_after_return_2b: {
         "WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
         "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
         "WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
-        "WARN: Dropping unused variable b [test/compress/issue-1034.js:95,20]",
-        "WARN: Dropping unused variable c [test/compress/issue-1034.js:97,16]"
     ]
 }
-
diff --git a/test/run-tests.js b/test/run-tests.js
index a3184d7..09e7002 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -114,7 +114,7 @@ function run_compress_tests() {
                 U.AST_Node.warn_function = function(text) {
                     warnings_emitted.push("WARN: " + text);
                 };
-                options.warnings = true;
+                if (!options.warnings) options.warnings = true;
             }
             var cmp = new U.Compressor(options, true);
             var output_options = test.beautify || {};

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