[Pkg-javascript-commits] [uglifyjs] 148/190: Retain comments before AST_Constants during mangle.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:21 UTC 2016


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

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit a0e03c9df47c411a40bceef02af2ce3dd1a329cc
Author: kzc <zaxxon2011 at gmail.com>
Date:   Tue May 3 15:08:40 2016 -0400

    Retain comments before AST_Constants during mangle.
---
 lib/output.js                         |  2 ++
 test/mocha/comment_before_constant.js | 27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/output.js b/lib/output.js
index a59066f..f878758 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -409,6 +409,7 @@ function OutputStream(options) {
 
     AST_Node.DEFMETHOD("print_to_string", function(options){
         var s = OutputStream(options);
+        if (!options) s._readonly = true;
         this.print(s);
         return s.get();
     });
@@ -416,6 +417,7 @@ function OutputStream(options) {
     /* -----[ comments ]----- */
 
     AST_Node.DEFMETHOD("add_comments", function(output){
+        if (output._readonly) return;
         var c = output.option("comments"), self = this;
         var start = self.start;
         if (start && !start._comments_dumped) {
diff --git a/test/mocha/comment_before_constant.js b/test/mocha/comment_before_constant.js
new file mode 100644
index 0000000..cfdb6da
--- /dev/null
+++ b/test/mocha/comment_before_constant.js
@@ -0,0 +1,27 @@
+var Uglify = require('../../');
+var assert = require("assert");
+
+describe("comment before constant", function() {
+    var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }';
+
+    it("Should test comment before constant is retained and output after mangle.", function() {
+        var result = Uglify.minify(js, {
+            fromString: true,
+            compress: { collapse_vars: false },
+            mangle: {},
+            output: { comments: true },
+        });
+        assert.strictEqual(result.code, 'function f(){/*c1*/var/*c2*/n=/*c3*/!1;return n}');
+    });
+
+    it("Should test code works when comments disabled.", function() {
+        var result = Uglify.minify(js, {
+            fromString: true,
+            compress: { collapse_vars: false },
+            mangle: {},
+            output: {},
+        });
+        assert.strictEqual(result.code, 'function f(){var n=!1;return n}');
+    });
+});
+

-- 
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