[Pkg-javascript-commits] [uglifyjs] 40/49: feat: add option.outFileName for JS API, if absense, sourceMap.file field will deduced

Jonas Smedegaard dr at jones.dk
Fri Dec 9 11:43:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 0a35acbbe7e663c643c5b227e455816278e08b89
Author: 1111hui <26634873 at qq.com>
Date:   Sat Oct 29 15:21:28 2016 +0800

    feat: add option.outFileName for JS API, if absense, sourceMap.file field will deduced
---
 test/mocha/minify-file-map.js | 14 +++++++++++---
 test/mocha/minify.js          |  3 ++-
 tools/node.js                 |  4 +++-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/test/mocha/minify-file-map.js b/test/mocha/minify-file-map.js
index aa42d25..169e730 100644
--- a/test/mocha/minify-file-map.js
+++ b/test/mocha/minify-file-map.js
@@ -7,10 +7,18 @@ describe("Input file as map", function() {
             '/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']);
+        assert.strictEqual(map.file, undefined);
+
+        result = Uglify.minify(jsMap, {fromString: true, outFileName: 'out.js'});
+        assert.strictEqual(result.map, null);
+
+        result = Uglify.minify(jsMap, {fromString: true, outFileName: 'out.js', outSourceMap: true});
+        map = JSON.parse(result.map);
+        assert.strictEqual(map.file, 'out.js');
     });
 
     it("Should accept array of objects and strings", function() {
@@ -19,7 +27,7 @@ describe("Input file as map", function() {
             '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');
@@ -31,7 +39,7 @@ describe("Input file as map", function() {
             '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/test/mocha/minify.js b/test/mocha/minify.js
index ce5e849..70cf73a 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -63,13 +63,14 @@ describe("minify", function() {
     describe("inSourceMap", function() {
         it("Should read the given string filename correctly when sourceMapIncludeSources is enabled (#1236)", function() {
             var result = Uglify.minify('./test/input/issue-1236/simple.js', {
-                outSourceMap: "simple.js.min.map",
+                outSourceMap: "simple.min.js.map",
                 inSourceMap: "./test/input/issue-1236/simple.js.map",
                 sourceMapIncludeSources: true
             });
 
             var map = JSON.parse(result.map);
 
+            assert.equal(map.file, 'simple.min.js');
             assert.equal(map.sourcesContent.length, 1);
             assert.equal(map.sourcesContent[0],
                 'let foo = x => "foo " + x;\nconsole.log(foo("bar"));');
diff --git a/tools/node.js b/tools/node.js
index a16169b..0b2d519 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -41,6 +41,7 @@ exports.minify = function(files, options) {
     options = UglifyJS.defaults(options, {
         spidermonkey     : false,
         outSourceMap     : null,
+        outFileName      : null,
         sourceRoot       : null,
         inSourceMap      : null,
         sourceMapUrl     : null,
@@ -120,7 +121,8 @@ exports.minify = function(files, options) {
     }
     if (options.outSourceMap || options.sourceMapInline) {
         output.source_map = UglifyJS.SourceMap({
-            file: options.outSourceMap,
+            // prefer outFileName, otherwise use outSourceMap without .map suffix
+            file: options.outFileName || (typeof options.outSourceMap === 'string' ? options.outSourceMap.replace(/\.map$/i, '') : null),
             orig: inMap,
             root: options.sourceRoot
         });

-- 
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