[Pkg-javascript-commits] [uglifyjs] 181/228: fix missing preamble when shebang is absent (#1742)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 11e9bdc42746832cfa1c52ca70b0171b31a422ba
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Mar 31 15:26:57 2017 +0800

    fix missing preamble when shebang is absent (#1742)
---
 lib/output.js                |  4 ++--
 test/mocha/comment-filter.js | 10 +++++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index c8c8739..ac9e065 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -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();
                 }
diff --git a/test/mocha/comment-filter.js b/test/mocha/comment-filter.js
index 9474e73..ec17aa8 100644
--- a/test/mocha/comment-filter.js
+++ b/test/mocha/comment-filter.js
@@ -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;");
+    });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list