Compare commits

...

2 Commits

Author SHA1 Message Date
Alex Lam S.L
f8a71b56fd v2.8.20 2017-03-31 15:27:40 +08:00
Alex Lam S.L
11e9bdc427 fix missing preamble when shebang is absent (#1742) 2017-03-31 15:26:57 +08:00
3 changed files with 12 additions and 4 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

@@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs", "homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)", "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"version": "2.8.19", "version": "2.8.20",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

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;");
});
}); });