add shouldPrintComment option and output comments when compact option is set to true - fixes #1810
This commit is contained in:
parent
eb8d7e679e
commit
e50babe916
@ -47,6 +47,7 @@ class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var format = {
|
var format = {
|
||||||
|
shouldPrintComment: opts.shouldPrintComment,
|
||||||
retainLines: opts.retainLines,
|
retainLines: opts.retainLines,
|
||||||
comments: opts.comments == null || opts.comments,
|
comments: opts.comments == null || opts.comments,
|
||||||
compact: opts.compact,
|
compact: opts.compact,
|
||||||
@ -377,16 +378,32 @@ class CodeGenerator {
|
|||||||
return (node && node[key]) || [];
|
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.]
|
* [Please add a description.]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_printComments(comments) {
|
_printComments(comments) {
|
||||||
if (this.format.compact) return;
|
|
||||||
if (!this.format.comments) return;
|
|
||||||
if (!comments || !comments.length) return;
|
if (!comments || !comments.length) return;
|
||||||
|
|
||||||
for (var comment of (comments: Array)) {
|
for (var comment of (comments: Array)) {
|
||||||
|
if (!this.shouldPrintComment(comment)) continue;
|
||||||
|
|
||||||
var skip = false;
|
var skip = false;
|
||||||
|
|
||||||
if (this.ast.comments) {
|
if (this.ast.comments) {
|
||||||
|
|||||||
@ -163,6 +163,11 @@
|
|||||||
"description": "strip/output comments in generated output (on by default)"
|
"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": {
|
"compact": {
|
||||||
"type": "booleanString",
|
"type": "booleanString",
|
||||||
"default": "auto",
|
"default": "auto",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user