diff --git a/packages/babel/src/generation/index.js b/packages/babel/src/generation/index.js index e2fd0db831..56ceedde7b 100644 --- a/packages/babel/src/generation/index.js +++ b/packages/babel/src/generation/index.js @@ -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) { diff --git a/packages/babel/src/transformation/file/options/config.json b/packages/babel/src/transformation/file/options/config.json index ad38102420..58ee9b24e2 100644 --- a/packages/babel/src/transformation/file/options/config.json +++ b/packages/babel/src/transformation/file/options/config.json @@ -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",