Standardize on the comment format function.
This commit is contained in:
parent
a3c99278ba
commit
68bc3d7dfb
@ -70,6 +70,11 @@ function normalizeOptions(code, opts, tokens): Format {
|
|||||||
|
|
||||||
if (format.minified) {
|
if (format.minified) {
|
||||||
format.compact = true;
|
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") {
|
if (format.compact === "auto") {
|
||||||
|
|||||||
@ -490,21 +490,8 @@ export default class Printer {
|
|||||||
return (node && (leading ? node.leadingComments : node.trailingComments)) || [];
|
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) {
|
_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,
|
// 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.
|
// where they can't manually mutate the AST node comment lists.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user