Skip to content

Commit 37d2df0

Browse files
authoredSep 2, 2019
fix: make extractComments API more consistent (#129)
BREAKING CHANGE: using the `extractComments.condition` option with `true` value extract only `some` comments
1 parent edbd3e0 commit 37d2df0

File tree

3 files changed

+130
-446
lines changed

3 files changed

+130
-446
lines changed
 

‎src/minify.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ const buildTerserOptions = ({
4949
safari10,
5050
});
5151

52+
const someCommentsRegExp = /^\**!|@preserve|@license|@cc_on/i;
53+
5254
const buildComments = (options, terserOptions, extractedComments) => {
5355
const condition = {};
5456
const commentsOpts = terserOptions.output.comments;
5557

5658
// Use /^\**!|@preserve|@license|@cc_on/i RegExp
5759
if (typeof options.extractComments === 'boolean') {
5860
condition.preserve = commentsOpts;
59-
condition.extract = /^\**!|@preserve|@license|@cc_on/i;
61+
condition.extract = someCommentsRegExp;
6062
} else if (
6163
typeof options.extractComments === 'string' ||
6264
options.extractComments instanceof RegExp
@@ -72,7 +74,11 @@ const buildComments = (options, terserOptions, extractedComments) => {
7274
) {
7375
// Extract condition is given in extractComments.condition
7476
condition.preserve = commentsOpts;
75-
condition.extract = options.extractComments.condition;
77+
condition.extract =
78+
typeof options.extractComments.condition === 'boolean' &&
79+
options.extractComments.condition
80+
? 'some'
81+
: options.extractComments.condition;
7682
} else {
7783
// No extract condition is given. Extract comments that match commentsOpts instead of preserving them
7884
condition.preserve = false;
@@ -102,7 +108,7 @@ const buildComments = (options, terserOptions, extractedComments) => {
102108
condition[key] = (astNode, comment) => {
103109
return (
104110
comment.type === 'comment2' &&
105-
/^\**!|@preserve|@license|@cc_on/i.test(comment.value)
111+
someCommentsRegExp.test(comment.value)
106112
);
107113
};
108114

0 commit comments

Comments
 (0)
Failed to load comments.