aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/mocha/minify-file-map.js14
-rw-r--r--test/mocha/minify.js3
-rw-r--r--tools/node.js4
3 files changed, 16 insertions, 5 deletions
diff --git a/test/mocha/minify-file-map.js b/test/mocha/minify-file-map.js
index aa42d25a..169e730e 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 ce5e8497..70cf73ae 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 a16169b1..0b2d5197 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
});