[Pkg-javascript-commits] [uglifyjs] 183/190: Allow input files to be map (url->filename)
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit 85924bb32e1c27f555aad1651f4575b45bcbadb1
Author: Geraint <luffgd at gmail.com>
Date: Mon Jun 27 12:01:21 2016 +0100
Allow input files to be map (url->filename)
---
test/mocha/minify-file-map.js | 40 ++++++++++++++++++++++++++++++++++++++++
tools/node.js | 17 ++++++++++++-----
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/test/mocha/minify-file-map.js b/test/mocha/minify-file-map.js
new file mode 100644
index 0000000..aa42d25
--- /dev/null
+++ b/test/mocha/minify-file-map.js
@@ -0,0 +1,40 @@
+var Uglify = require('../../');
+var assert = require("assert");
+
+describe("Input file as map", function() {
+ it("Should accept object", function() {
+ var jsMap = {
+ '/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};'
+ };
+ var result = Uglify.minify(jsMap, {fromString: true, outSourceMap: true});
+
+ var map = JSON.parse(result.map);
+ assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};');
+ assert.deepEqual(map.sources, ['/scripts/foo.js']);
+ });
+
+ it("Should accept array of objects and strings", function() {
+ var jsSeq = [
+ {'/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};'},
+ 'var bar = 15;'
+ ];
+ var result = Uglify.minify(jsSeq, {fromString: true, outSourceMap: true});
+
+ var map = JSON.parse(result.map);
+ assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3},bar=15;');
+ assert.strictEqual(map.sources[0], '/scripts/foo.js');
+ });
+
+ it("Should correctly include source", function() {
+ var jsSeq = [
+ {'/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};'},
+ 'var bar = 15;'
+ ];
+ var result = Uglify.minify(jsSeq, {fromString: true, outSourceMap: true, sourceMapIncludeSources: true});
+
+ var map = JSON.parse(result.map);
+ assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3},bar=15;');
+ assert.deepEqual(map.sourcesContent, ['var foo = {"x": 1, y: 2, \'z\': 3};', 'var bar = 15;']);
+ });
+
+});
diff --git a/tools/node.js b/tools/node.js
index 3997637..2ee7df2 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -61,18 +61,25 @@ exports.minify = function(files, options) {
if (options.spidermonkey) {
toplevel = UglifyJS.AST_Node.from_mozilla_ast(files);
} else {
- if (typeof files == "string")
- files = [ files ];
- files.forEach(function(file, i){
+ function addFile(file, fileUrl) {
var code = options.fromString
? file
: fs.readFileSync(file, "utf8");
- sourcesContent[file] = code;
+ sourcesContent[fileUrl] = code;
toplevel = UglifyJS.parse(code, {
- filename: options.fromString ? i : file,
+ filename: fileUrl,
toplevel: toplevel,
bare_returns: options.parse ? options.parse.bare_returns : undefined
});
+ }
+ [].concat(files).forEach(function (files, i) {
+ if (typeof files === 'string') {
+ addFile(files, options.fromString ? i : files);
+ } else {
+ for (var fileUrl in files) {
+ addFile(files[fileUrl], fileUrl);
+ }
+ }
});
}
if (options.wrap) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list