From 1f8582d05e5e821e7dc16f6ef5f21bac41abcac2 Mon Sep 17 00:00:00 2001 From: eleith Date: Thu, 24 Oct 2013 00:20:26 -0700 Subject: [PATCH 1/3] declare a source file even when passing in a string --- tools/node.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index 614e083d..5f9ae178 100644 --- a/tools/node.js +++ b/tools/node.js @@ -55,6 +55,7 @@ exports.minify = function(files, options) { sourceRoot : null, inSourceMap : null, fromString : false, + fromFile : null, warnings : false, mangle : {}, output : null, @@ -72,7 +73,7 @@ exports.minify = function(files, options) { ? file : fs.readFileSync(file, "utf8"); toplevel = UglifyJS.parse(code, { - filename: options.fromString ? "?" : file, + filename: options.fromString ? options.fromFile || "?" : file, toplevel: toplevel }); }); From da1caf6bb7a1721f7201b16eaf07fc32eb868cc3 Mon Sep 17 00:00:00 2001 From: eleith Date: Thu, 24 Oct 2013 00:29:57 -0700 Subject: [PATCH 2/3] allow for multiple files to be associated with an array of strings --- tools/node.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/node.js b/tools/node.js index 5f9ae178..89f7f246 100644 --- a/tools/node.js +++ b/tools/node.js @@ -61,19 +61,24 @@ exports.minify = function(files, options) { output : null, compress : {} }); - if (typeof files == "string") + if (typeof files == "string") { files = [ files ]; + if (options.fromFile !== null) { + option.fromFile = [options.fromFile]; + } + } + UglifyJS.base54.reset(); // 1. parse var toplevel = null; - files.forEach(function(file){ + files.forEach(function(file, index){ var code = options.fromString ? file : fs.readFileSync(file, "utf8"); toplevel = UglifyJS.parse(code, { - filename: options.fromString ? options.fromFile || "?" : file, + filename: options.fromString ? options.fromFile[index] || "?" : file, toplevel: toplevel }); }); From fa82161a4cef2e30ee67e84c1cfe1d3ca7312b94 Mon Sep 17 00:00:00 2001 From: eleith Date: Thu, 24 Oct 2013 00:42:19 -0700 Subject: [PATCH 3/3] bug --- tools/node.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/node.js b/tools/node.js index 89f7f246..09d1ecaf 100644 --- a/tools/node.js +++ b/tools/node.js @@ -63,10 +63,7 @@ exports.minify = function(files, options) { }); if (typeof files == "string") { files = [ files ]; - - if (options.fromFile !== null) { - option.fromFile = [options.fromFile]; - } + options.fromFile = options.fromFile ? [options.fromFile] : ["?"] } UglifyJS.base54.reset(); @@ -78,7 +75,7 @@ exports.minify = function(files, options) { ? file : fs.readFileSync(file, "utf8"); toplevel = UglifyJS.parse(code, { - filename: options.fromString ? options.fromFile[index] || "?" : file, + filename: options.fromString ? options.fromFile[index] : file, toplevel: toplevel }); });