fix CLI parsing of `--source-map content` (#2088)
authorZiad El Khoury Hanna <zaygraveyard@users.noreply.github.com>
Tue, 13 Jun 2017 08:30:46 +0000 (10:30 +0200)
committerAlex Lam S.L <alexlamsl@gmail.com>
Tue, 13 Jun 2017 08:30:46 +0000 (16:30 +0800)
fixes #2082

bin/uglifyjs
test/input/issue-2082/sample.js [new file with mode: 0644]
test/input/issue-2082/sample.js.map [new file with mode: 0644]
test/mocha/cli.js

index 52708cc..f4feb39 100755 (executable)
@@ -371,7 +371,7 @@ function parse_js(flag, constants) {
 function parse_source_map() {
     var parse = parse_js("sourceMap", true);
     return function(value, options) {
-        var hasContent = options && options.sourceMap && "content" in options.sourceMap;
+        var hasContent = options && "content" in options;
         var settings = parse(value, options);
         if (!hasContent && settings.content && settings.content != "inline") {
             print_error("INFO: Using input source map: " + settings.content);
diff --git a/test/input/issue-2082/sample.js b/test/input/issue-2082/sample.js
new file mode 100644 (file)
index 0000000..f92e3a1
--- /dev/null
@@ -0,0 +1 @@
+console.log(x);
\ No newline at end of file
diff --git a/test/input/issue-2082/sample.js.map b/test/input/issue-2082/sample.js.map
new file mode 100644 (file)
index 0000000..88b42f5
--- /dev/null
@@ -0,0 +1 @@
+{"version": 3,"sources": ["index.js"],"mappings": ";"}
index 3228e4e..fa6f146 100644 (file)
@@ -77,6 +77,23 @@ describe("bin/uglifyjs", function () {
             done();
         });
     });
+    it("should not consider source map file content as source map file name (issue #2082)", function (done) {
+        var command = [
+            uglifyjscmd,
+            "test/input/issue-2082/sample.js",
+            "--source-map", "content=test/input/issue-2082/sample.js.map",
+            "--source-map", "url=inline",
+        ].join(" ");
+
+        exec(command, function (err, stdout, stderr) {
+            if (err) throw err;
+
+            var stderrLines = stderr.split('\n');
+            assert.strictEqual(stderrLines[0], 'INFO: Using input source map: test/input/issue-2082/sample.js.map');
+            assert.notStrictEqual(stderrLines[1], 'INFO: Using input source map: {"version": 3,"sources": ["index.js"],"mappings": ";"}');
+            done();
+        });
+    });
     it("Should work with --keep-fnames (mangle only)", function (done) {
         var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m';