Skip to content

Commit

Permalink
Support SpiderMonkey AST in UglifyJS.minify. Fix mishoo#393.
Browse files Browse the repository at this point in the history
  • Loading branch information
mishoo committed Jan 7, 2014
1 parent 2c88eb6 commit b9fac68
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tools/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit b9fac68

Please sign in to comment.