Standardize on the comment format function.

This commit is contained in:
Logan Smyth 2016-07-15 00:14:42 -07:00
parent a3c99278ba
commit 68bc3d7dfb
2 changed files with 6 additions and 14 deletions

View File

@ -70,6 +70,11 @@ function normalizeOptions(code, opts, tokens): Format {
if (format.minified) {
format.compact = true;
format.shouldPrintComment = format.shouldPrintComment || (() => format.comments);
} else {
format.shouldPrintComment = format.shouldPrintComment || ((value) => format.comments ||
(value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0));
}
if (format.compact === "auto") {

View File

@ -490,21 +490,8 @@ export default class Printer {
return (node && (leading ? node.leadingComments : node.trailingComments)) || [];
}
_shouldPrintComment(comment) {
if (this.format.shouldPrintComment) {
return this.format.shouldPrintComment(comment.value);
} else {
if (!this.format.minified &&
(comment.value.indexOf("@license") >= 0 || comment.value.indexOf("@preserve") >= 0)) {
return true;
} else {
return this.format.comments;
}
}
}
_printComment(comment) {
if (!this._shouldPrintComment(comment)) return;
if (!this.format.shouldPrintComment(comment.value)) return;
// Some plugins use this to mark comments as removed using the AST-root 'comments' property,
// where they can't manually mutate the AST node comment lists.