AST_Node.DEFMETHOD("print_to_string", function(options){
var s = OutputStream(options);
+ if (!options) s._readonly = true;
this.print(s);
return s.get();
});
/* -----[ 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) {
--- /dev/null
+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}');
+ });
+});
+