From b9fac687ff0b2689f7ca7bdc26aa0b3671df72ce Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 7 Jan 2014 18:42:48 +0200 Subject: [PATCH] Support SpiderMonkey AST in UglifyJS.minify. Fix #393. --- tools/node.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/node.js b/tools/node.js index 614e083d1f4..7e6a38df9c7 100644 --- a/tools/node.js +++ b/tools/node.js @@ -51,6 +51,7 @@ for (var i in UglifyJS) { exports.minify = function(files, options) { options = UglifyJS.defaults(options, { + spidermonkey : false, outSourceMap : null, sourceRoot : null, inSourceMap : null, @@ -60,22 +61,26 @@ exports.minify = function(files, options) { output : null, compress : {} }); - if (typeof files == "string") - files = [ files ]; - UglifyJS.base54.reset(); // 1. parse var toplevel = null; - files.forEach(function(file){ - var code = options.fromString - ? file - : fs.readFileSync(file, "utf8"); - toplevel = UglifyJS.parse(code, { - filename: options.fromString ? "?" : file, - toplevel: toplevel + + if (options.spidermonkey) { + toplevel = UglifyJS.AST_Node.from_mozilla_ast(files); + } else { + if (typeof files == "string") + files = [ files ]; + files.forEach(function(file){ + var code = options.fromString + ? file + : fs.readFileSync(file, "utf8"); + toplevel = UglifyJS.parse(code, { + filename: options.fromString ? "?" : file, + toplevel: toplevel + }); }); - }); + } // 2. compress if (options.compress) {