fix missing preamble when shebang is absent (#1742)

This commit is contained in:
Alex Lam S.L
2017-03-31 15:26:57 +08:00
committed by GitHub
parent a84564d1a8
commit 11e9bdc427
2 changed files with 11 additions and 3 deletions

View File

@@ -510,8 +510,8 @@ function OutputStream(options) {
})); }));
} }
if (comments.length > 0 && output.pos() == 0) { if (output.pos() == 0) {
if (output.option("shebang") && comments[0].type == "comment5") { if (comments.length > 0 && output.option("shebang") && comments[0].type == "comment5") {
output.print("#!" + comments.shift().value + "\n"); output.print("#!" + comments.shift().value + "\n");
output.indent(); output.indent();
} }

View File

@@ -79,5 +79,13 @@ describe("comment filters", function() {
output: { preamble: "/* Build */" } output: { preamble: "/* Build */" }
}).code; }).code;
assert.strictEqual(code, "#!/usr/bin/node\n/* Build */\nvar x=10;"); assert.strictEqual(code, "#!/usr/bin/node\n/* Build */\nvar x=10;");
}) });
it("Should handle preamble without shebang correctly", function() {
var code = UglifyJS.minify("var x = 10;", {
fromString: true,
output: { preamble: "/* Build */" }
}).code;
assert.strictEqual(code, "/* Build */\nvar x=10;");
});
}); });