From 32561c15174ba5769c0ce615a3662ce6f764706c Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Sat, 15 Apr 2017 00:26:49 +0800 Subject: [PATCH] suppress warnings by default --- README.md | 6 ++---- bin/uglifyjs | 5 ++++- lib/compress.js | 2 +- lib/minify.js | 4 ++-- test/benchmark.js | 2 +- test/jetstream.js | 2 +- test/mocha/release.js | 4 ++-- test/ufuzz.json | 15 +++------------ 8 files changed, 16 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 7df55e70..8000088c 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,8 @@ The available options are: `//# sourceMappingURL`. --stats Display operations run time on STDERR. --toplevel Compress and/or mangle variables in toplevel scope. - --verbose Print informational/diagnostic messages. + --verbose Print diagnostic messages. + --warn Print warning messages. --wrap Embed everything in a big function, making the “exports” and “global” variables available. You need to pass an argument to this option to @@ -743,9 +744,6 @@ Other options: - `warnings` (default `false`) — pass `true` to display compressor warnings. -- `fromString` (default `false`) — if you pass `true` then you can pass - JavaScript source code, rather than file names. - - `mangle` (default `true`) — pass `false` to skip mangling names, or pass an object to specify mangling options (see below). diff --git a/bin/uglifyjs b/bin/uglifyjs index f451790b..1b12d837 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -33,7 +33,8 @@ program.option("--self", "Build UglifyJS2 as a library (implies --wrap UglifyJS) program.option("--source-map [options]", "Enable source map/specify source map options.", parseSourceMap()); program.option("--stats", "Display operations run time on STDERR.") program.option("--toplevel", "Compress and/or mangle variables in toplevel scope."); -program.option("--verbose", "Print informational/diagnostic messages."); +program.option("--verbose", "Print diagnostic messages."); +program.option("--warn", "Print warning messages."); program.option("--wrap ", "Embed everything as a function with “exports” corresponding to “name” globally."); program.arguments("[files...]").parseArgv(process.argv); if (program.configFile) { @@ -99,6 +100,8 @@ if (program.sourceMap && "base" in program.sourceMap) { } if (program.verbose) { options.warnings = "verbose"; +} else if (program.warn) { + options.warnings = true; } if (program.self) { if (program.args.length) { diff --git a/lib/compress.js b/lib/compress.js index d4983d0e..cb44e095 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -85,7 +85,7 @@ function Compressor(options, false_by_default) { unsafe_math : false, unsafe_proto : false, unused : !false_by_default, - warnings : true, + warnings : false, }, true); var pure_funcs = this.options["pure_funcs"]; if (typeof pure_funcs == "function") { diff --git a/lib/minify.js b/lib/minify.js index 9110d089..7d5c9578 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -42,7 +42,7 @@ function minify(files, options) { parse: {}, sourceMap: false, toplevel: false, - warnings: true, + warnings: false, wrap: false, }, true); set_shorthand("ie8", options, [ "compress", "mangle", "output" ]); @@ -70,7 +70,7 @@ function minify(files, options) { }, true); } var warnings = []; - if (!AST_Node.warn_function) { + if (options.warnings && !AST_Node.warn_function) { AST_Node.warn_function = function(warning) { warnings.push(warning); }; diff --git a/test/benchmark.js b/test/benchmark.js index 4a387b72..c67a8548 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -7,7 +7,7 @@ var createHash = require("crypto").createHash; var fork = require("child_process").fork; var args = process.argv.slice(2); if (!args.length) { - args.push("-mc", "warnings=false"); + args.push("-mc"); } args.push("--stats"); var urls = [ diff --git a/test/jetstream.js b/test/jetstream.js index a8195389..56da7ad8 100644 --- a/test/jetstream.js +++ b/test/jetstream.js @@ -12,7 +12,7 @@ if (typeof phantom == "undefined") { }); var args = process.argv.slice(2); if (!args.length) { - args.push("-mc", "warnings=false"); + args.push("-mc"); } args.push("--stats"); var child_process = require("child_process"); diff --git a/test/mocha/release.js b/test/mocha/release.js index 3b2d9a72..b73a3df7 100644 --- a/test/mocha/release.js +++ b/test/mocha/release.js @@ -42,8 +42,8 @@ describe("test/jetstream.js", function() { run("npm", ["install", "phantomjs-prebuilt@2.1.14"], done); }); [ - "-mc warnings=false", - "-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto,warnings=false", + "-mc", + "-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto", ].forEach(function(options) { it("Should pass with options " + options, function(done) { var args = options.split(/ /); diff --git a/test/ufuzz.json b/test/ufuzz.json index c4813470..cb014b12 100644 --- a/test/ufuzz.json +++ b/test/ufuzz.json @@ -11,20 +11,12 @@ "compress": false }, { - "compress": { - "warnings": false - }, "mangle": false }, + {}, { "compress": { - "warnings": false - } - }, - { - "compress": { - "toplevel": true, - "warnings": false + "toplevel": true }, "mangle": { "toplevel": true @@ -33,8 +25,7 @@ { "compress": { "keep_fargs": false, - "passes": 3, - "warnings": false + "passes": 3 } } ]