From 1040110dc4fa1a323dae991d74ba1102b83eaa67 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Mon, 8 May 2017 05:02:04 +0800 Subject: [PATCH] fix variable initialisation add mocha test --- bin/uglifyjs | 6 +++--- test/mocha/cli.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/uglifyjs b/bin/uglifyjs index 3aaa3280..5fa81f3b 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -15,6 +15,7 @@ var path = require("path"); var program = require("commander"); var UglifyJS = require("../tools/node"); +var skip_keys = [ "cname", "enclosed", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ]; var files = {}; var options = { compress: false, @@ -259,8 +260,8 @@ function run() { } function fatal(message) { - console.error(message); - process.exit(1); + console.error(message); + process.exit(1); } // A file glob function that only supports "*" and "?" wildcards in the basename. @@ -375,7 +376,6 @@ function to_cache(key) { return cache[key]; } -var skip_keys = [ "cname", "enclosed", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ]; function skip_key(key) { return skip_keys.indexOf(key) >= 0; } diff --git a/test/mocha/cli.js b/test/mocha/cli.js index cac920d3..8c7964ac 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -509,4 +509,15 @@ describe("bin/uglifyjs", function () { return JSON.stringify(map).replace(/"/g, '\\"'); } }); + it("Should dump AST as JSON", function(done) { + var command = uglifyjscmd + " test/input/global_defs/simple.js -mco ast"; + exec(command, function (err, stdout) { + if (err) throw err; + + var ast = JSON.parse(stdout); + assert.strictEqual(ast._class, "AST_Toplevel"); + assert.ok(Array.isArray(ast.body)); + done(); + }); + }); });