From 8c7c1077654a3923baebb27e62f7b1dc0a7892b5 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 9 May 2017 15:58:46 +0800 Subject: [PATCH 1/4] update `minify()` usage in `test/ufuzz.js` (#1888) fixes #1887 --- test/ufuzz.js | 59 ++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/test/ufuzz.js b/test/ufuzz.js index b2ec9e09..0a043c2f 100644 --- a/test/ufuzz.js +++ b/test/ufuzz.js @@ -856,23 +856,21 @@ function createVarName(maybe, dontStore) { } function try_beautify(code, result) { - try { - var beautified = UglifyJS.minify(code, { - compress: false, - mangle: false, - output: { - beautify: true, - bracketize: true, - }, - }).code; - if (sandbox.same_stdout(sandbox.run_code(beautified), result)) { - console.log("// (beautified)"); - console.log(beautified); - return; - } - } catch (e) { + var beautified = UglifyJS.minify(code, { + compress: false, + mangle: false, + output: { + beautify: true, + bracketize: true, + }, + }); + if (beautified.error) { console.log("// !!! beautify failed !!!"); - console.log(e.stack); + console.log(beautified.error.stack); + } else if (sandbox.same_stdout(sandbox.run_code(beautified.code), result)) { + console.log("// (beautified)"); + console.log(beautified.code); + return; } console.log("//"); console.log(code); @@ -908,12 +906,13 @@ function log_suspects(minify_options, component) { var o = JSON.parse(JSON.stringify(options)); o[name] = false; m[component] = o; - try { - var r = sandbox.run_code(UglifyJS.minify(original_code, m).code); - return sandbox.same_stdout(original_result, r); - } catch (e) { + var result = UglifyJS.minify(original_code, m); + if (result.error) { console.log("Error testing options." + component + "." + name); - console.log(e); + console.log(result.error); + } else { + var r = sandbox.run_code(result.code); + return sandbox.same_stdout(original_result, r); } } }); @@ -981,18 +980,16 @@ for (var round = 1; round <= num_iterations; round++) { original_code = createTopLevelCode(); original_result = sandbox.run_code(original_code); (typeof original_result != "string" ? fallback_options : minify_options).forEach(function(options) { - try { - uglify_code = UglifyJS.minify(original_code, JSON.parse(options)).code; - } catch (e) { - uglify_code = e; - } - - ok = typeof uglify_code == "string"; - if (ok) { + uglify_code = UglifyJS.minify(original_code, JSON.parse(options)); + if (!uglify_code.error) { + uglify_code = uglify_code.code; uglify_result = sandbox.run_code(uglify_code); ok = sandbox.same_stdout(original_result, uglify_result); - } else if (typeof original_result != "string") { - ok = uglify_code.name == original_result.name; + } else { + uglify_code = uglify_code.error; + if (typeof original_result != "string") { + ok = uglify_code.name == original_result.name; + } } if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options); else if (verbose_error && typeof original_result != "string") { From bc3fa78e8cedfda4cc0eb7aa7bc7b00c5e860650 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 9 May 2017 16:08:04 +0800 Subject: [PATCH 2/4] mention `minify().error` --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a665c06d..52c44ccd 100644 --- a/README.md +++ b/README.md @@ -596,7 +596,8 @@ performs all the steps in a configurable manner. Example: ```javascript var result = UglifyJS.minify("var b = function() {};"); -console.log(result.code); // minified output +console.log(result.code); // minified output +console.log(result.error); // runtime error ``` You can also compress multiple files: From c14e2805859a3d85788af5d694fca73a6782530e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 9 May 2017 16:36:44 +0800 Subject: [PATCH 3/4] print error stack in CLI (#1890) --- bin/uglifyjs | 8 ++++---- test/mocha/cli.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/uglifyjs b/bin/uglifyjs index 8bb8e700..d75b0ee1 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -193,7 +193,7 @@ function run() { } } } catch (ex) { - fatal("ERROR: " + ex.message); + fatal(ex.stack); } var result = UglifyJS.minify(files, options); if (result.error) { @@ -220,7 +220,7 @@ function run() { console.error("Supported options:"); console.error(ex.defs); } - fatal("ERROR: " + ex.message); + fatal(ex.stack); } else if (program.output == "ast") { console.log(JSON.stringify(result.ast, function(key, value) { if (skip_key(key)) return; @@ -263,7 +263,7 @@ function run() { } function fatal(message) { - console.error(message); + console.error(message.replace(/^\S*?Error:/, "ERROR:")); process.exit(1); } @@ -303,7 +303,7 @@ function read_file(path, default_value) { return fs.readFileSync(path, "utf8"); } catch (ex) { if (ex.code == "ENOENT" && default_value != null) return default_value; - fatal("ERROR: " + ex.message); + fatal(ex.stack); } } diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 8c7964ac..8cf53ab4 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -185,7 +185,7 @@ describe("bin/uglifyjs", function () { exec(command, function (err, stdout, stderr) { assert.ok(err); - assert.strictEqual(stderr, "ERROR: inline source map only works with singular input\n"); + assert.strictEqual(stderr.split(/\n/)[0], "ERROR: inline source map only works with singular input"); done(); }); }); From 5fd8244a2e36b8f5c2de956e365e8e491e39ca26 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 10 May 2017 01:52:00 +0800 Subject: [PATCH 4/4] v3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 864eba56..e037535e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "http://lisperator.net/uglifyjs", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.0.1", + "version": "3.0.2", "engines": { "node": ">=0.8.0" },