Don't load source map until the JS source is fully received (#3040)

This commit is contained in:
b-fuze
2018-03-31 07:26:40 -04:00
committed by Alex Lam S.L
parent 02f47e1713
commit 8adfc29f91
5 changed files with 51 additions and 16 deletions

View File

@@ -1,9 +1,9 @@
var assert = require("assert");
var exec = require("child_process").exec;
var readFileSync = require("fs").readFileSync;
var fs = require("fs");
function read(path) {
return readFileSync(path, "utf8");
return fs.readFileSync(path, "utf8");
}
describe("bin/uglifyjs", function () {
@@ -106,6 +106,35 @@ describe("bin/uglifyjs", function () {
done();
});
});
it("Should not load source map before finish reading from STDIN", function(done) {
var mapFile = "tmp/input.js.map";
try {
fs.mkdirSync("./tmp");
} catch (e) {
if (e.code != "EEXIST") throw e;
}
try {
fs.unlinkSync(mapFile);
} catch (e) {
if (e.code != "ENOENT") throw e;
}
var command = [
uglifyjscmd,
"--source-map", "content=" + mapFile,
"--source-map", "url=inline"
].join(" ");
var child = exec(command, function(err, stdout) {
if (err) throw err;
assert.strictEqual(stdout, read("test/input/pr-3040/expect.js"));
done();
});
setTimeout(function() {
fs.writeFileSync(mapFile, read("test/input/pr-3040/input.js.map"));
child.stdin.end(read("test/input/pr-3040/input.js"));
}, 1000);
});
it("Should work with --keep-fnames (mangle only)", function (done) {
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m';