@@ -886,18 +886,19 @@ function OutputStream(options) {
|
|||||||
self.body.print(output);
|
self.body.print(output);
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
});
|
});
|
||||||
function print_bracketed(self, output, allow_directives) {
|
function print_bracketed_empty(self, output) {
|
||||||
if (self.body.length > 0) {
|
|
||||||
output.with_block(function() {
|
|
||||||
display_body(self.body, false, output, allow_directives);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
output.print("{");
|
output.print("{");
|
||||||
output.with_indent(output.next_indent(), function() {
|
output.with_indent(output.next_indent(), function() {
|
||||||
output.append_comments(self, true);
|
output.append_comments(self, true);
|
||||||
});
|
});
|
||||||
output.print("}");
|
output.print("}");
|
||||||
}
|
}
|
||||||
|
function print_bracketed(self, output, allow_directives) {
|
||||||
|
if (self.body.length > 0) {
|
||||||
|
output.with_block(function() {
|
||||||
|
display_body(self.body, false, output, allow_directives);
|
||||||
|
});
|
||||||
|
} else print_bracketed_empty(self, output);
|
||||||
};
|
};
|
||||||
DEFPRINT(AST_BlockStatement, function(self, output){
|
DEFPRINT(AST_BlockStatement, function(self, output){
|
||||||
print_bracketed(self, output);
|
print_bracketed(self, output);
|
||||||
@@ -1092,7 +1093,7 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
output.space();
|
output.space();
|
||||||
var last = self.body.length - 1;
|
var last = self.body.length - 1;
|
||||||
if (last < 0) output.print("{}");
|
if (last < 0) print_bracketed_empty(self, output);
|
||||||
else output.with_block(function(){
|
else output.with_block(function(){
|
||||||
self.body.forEach(function(branch, i){
|
self.body.forEach(function(branch, i){
|
||||||
output.indent(true);
|
output.indent(true);
|
||||||
@@ -1347,7 +1348,7 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
output.newline();
|
output.newline();
|
||||||
});
|
});
|
||||||
else output.print("{}");
|
else print_bracketed_empty(self, output);
|
||||||
});
|
});
|
||||||
|
|
||||||
function print_property_name(key, quote, output) {
|
function print_property_name(key, quote, output) {
|
||||||
|
|||||||
@@ -139,6 +139,26 @@ describe("Comment", function() {
|
|||||||
assert.strictEqual(result.code, code);
|
assert.strictEqual(result.code, code);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should retain comments within brackets", function() {
|
||||||
|
var code = [
|
||||||
|
"{/* foo */}",
|
||||||
|
"a({/* foo */});",
|
||||||
|
"while (a) {/* foo */}",
|
||||||
|
"switch (a) {/* foo */}",
|
||||||
|
"if (a) {/* foo */} else {/* bar */}",
|
||||||
|
].join("\n\n");
|
||||||
|
var result = uglify.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, code);
|
||||||
|
});
|
||||||
|
|
||||||
it("Should correctly preserve new lines around comments", function() {
|
it("Should correctly preserve new lines around comments", function() {
|
||||||
var tests = [
|
var tests = [
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user