fix missing preamble when shebang is absent (#1742)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 31 Mar 2017 07:26:57 +0000 (15:26 +0800)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2017 07:26:57 +0000 (15:26 +0800)
lib/output.js
test/mocha/comment-filter.js

index c8c8739..ac9e065 100644 (file)
@@ -510,8 +510,8 @@ function OutputStream(options) {
                 }));
             }
 
-            if (comments.length > 0 && output.pos() == 0) {
-                if (output.option("shebang") && comments[0].type == "comment5") {
+            if (output.pos() == 0) {
+                if (comments.length > 0 && output.option("shebang") && comments[0].type == "comment5") {
                     output.print("#!" + comments.shift().value + "\n");
                     output.indent();
                 }
index 9474e73..ec17aa8 100644 (file)
@@ -79,5 +79,13 @@ describe("comment filters", function() {
             output: { preamble: "/* Build */" }
         }).code;
         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;");
+    });
 });