diff --git a/test/input/pr-3040/input.js b/test/input/pr-3040/input.js new file mode 100644 index 00000000..6515dcbd --- /dev/null +++ b/test/input/pr-3040/input.js @@ -0,0 +1,11 @@ +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +var _require = require("bar"), + foo = _require.foo; + +var _require2 = require("world"), + hello = _require2.hello; + +foo.x.apply(foo, _toConsumableArray(foo.y(hello.z))); + +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/test/input/pr-3040/input.js.map b/test/input/pr-3040/input.js.map new file mode 100644 index 00000000..f0883e22 --- /dev/null +++ b/test/input/pr-3040/input.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["input2.js"],"names":["require","foo","hello","x","apply","_toConsumableArray","y","z"],"mappings":"kLAAcA,QAAQ,OAAfC,aAAAA,kBACSD,QAAQ,SAAjBE,gBAAAA,MAEPD,IAAIE,EAAJC,MAAAH,IAAAI,mBAASJ,IAAIK,EAAEJ,MAAMK","sourcesContent":["const {foo} = require(\"bar\");\nconst {hello} = require(\"world\");\n\nfoo.x(...foo.y(hello.z));\n"]} \ No newline at end of file diff --git a/test/input/pr-3040/pipe.js b/test/input/pr-3040/pipe.js new file mode 100644 index 00000000..c675fa97 --- /dev/null +++ b/test/input/pr-3040/pipe.js @@ -0,0 +1,9 @@ +var fs = require("fs"); + +// Timeout to offset uglify loading in the test suite +setTimeout(function() { + fs.writeFileSync("test/input/pr-3040/input.js.map", '{"version":3,"sources":["input2.js"],"names":[],"mappings":";;eAAc,QAAQ,KAAR,C;IAAP,G,YAAA,G;;gBACS,QAAQ,OAAR,C;IAAT,K,aAAA,K;;AAEP,IAAI,CAAJ,+BAAS,IAAI,CAAJ,CAAM,MAAM,CAAZ,CAAT","file":"input.js","sourcesContent":["const {foo} = require(\\"bar\\");\\nconst {hello} = require(\\"world\\");\\n\\nfoo.x(...foo.y(hello.z));\\n"]}'); + + var fileContents = fs.readFileSync("test/input/pr-3040/input.js"); + process.stdout.write(fileContents, "utf8"); +}, 100); diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 10f0465a..b7b09899 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -94,6 +94,28 @@ describe("bin/uglifyjs", function () { done(); }); }); + it("should not load the source map before it fully receives the JS source", function(done) { + var command = [ + '"' + process.argv[0] + '" test/input/pr-3040/pipe.js |', uglifyjscmd, + "--source-map", "content=test/input/pr-3040/input.js.map", + "--source-map", "url=inline" + ].join(" "); + + exec(command, function(err, stdout) { + if (err) throw err; + + // Revert input file to initial state for future test validity + require("fs").writeFileSync("test/input/pr-3040/input.js.map", '{"version":3,"sources":["input2.js"],"names":["require","foo","hello","x","apply","_toConsumableArray","y","z"],"mappings":"kLAAcA,QAAQ,OAAfC,aAAAA,kBACSD,QAAQ,SAAjBE,gBAAAA,MAEPD,IAAIE,EAAJC,MAAAH,IAAAI,mBAASJ,IAAIK,EAAEJ,MAAMK","sourcesContent":["const {foo} = require(\\"bar\\");\\nconst {hello} = require(\\"world\\");\\n\\nfoo.x(...foo.y(hello.z));\\n"]}'); + + assert.strictEqual(stdout, [ + 'function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i