add shouldPrintComment option and output comments when compact option is set to true - fixes #1810

This commit is contained in:
Sebastian McKenzie 2015-07-14 20:55:56 +01:00
parent eb8d7e679e
commit e50babe916
2 changed files with 24 additions and 2 deletions

View File

@ -47,6 +47,7 @@ class CodeGenerator {
}
var format = {
shouldPrintComment: opts.shouldPrintComment,
retainLines: opts.retainLines,
comments: opts.comments == null || opts.comments,
compact: opts.compact,
@ -377,16 +378,32 @@ class CodeGenerator {
return (node && node[key]) || [];
}
/**
* [Please add a description.]
*/
shouldPrintComment(comment) {
if (this.format.shouldPrintComment) {
return this.format.shouldPrintComment(comment.value);
} else {
if (comment.value.indexOf("@license") >= 0 || comment.value.indexOf("@preserve") >= 0) {
return true;
} else {
return this.format.comments;
}
}
}
/**
* [Please add a description.]
*/
_printComments(comments) {
if (this.format.compact) return;
if (!this.format.comments) return;
if (!comments || !comments.length) return;
for (var comment of (comments: Array)) {
if (!this.shouldPrintComment(comment)) continue;
var skip = false;
if (this.ast.comments) {

View File

@ -163,6 +163,11 @@
"description": "strip/output comments in generated output (on by default)"
},
"shouldPrintComment": {
"hidden": true,
"description": "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored"
},
"compact": {
"type": "booleanString",
"default": "auto",