diff options
author | kzc <zaxxon2011@gmail.com> | 2016-05-03 15:08:40 -0400 |
---|---|---|
committer | Richard van Velzen <rvanvelzen@experty.com> | 2016-05-04 20:11:45 +0200 |
commit | a0e03c9df47c411a40bceef02af2ce3dd1a329cc (patch) | |
tree | 93080c8910992672242fc99bdfbd352ced6c56db | |
parent | 6641dcafb60091f0f944fcd5269ca67cb66ada2a (diff) | |
download | tracifyjs-a0e03c9df47c411a40bceef02af2ce3dd1a329cc.tar.gz tracifyjs-a0e03c9df47c411a40bceef02af2ce3dd1a329cc.zip |
Retain comments before AST_Constants during mangle.
-rw-r--r-- | lib/output.js | 2 | ||||
-rw-r--r-- | test/mocha/comment_before_constant.js | 27 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/output.js b/lib/output.js index a59066fc..f8787582 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 00000000..cfdb6da1 --- /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}'); + }); +}); + |