Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit 321c9f6

Browse files
evilebottnawimichael-ciniawsky
authored andcommitted
fix: comments behavior (options.uglifyOptions.comments/options.extractComments) (#174)
1 parent 07c57c1 commit 321c9f6

File tree

7 files changed

+11
-65
lines changed

7 files changed

+11
-65
lines changed

Diff for: src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class UglifyJsPlugin {
4646
exclude,
4747
uglifyOptions: {
4848
output: {
49-
comments: /^\**!|@preserve|@license|@cc_on/,
49+
comments: false,
5050
},
5151
...uglifyOptions,
5252
},

Diff for: src/uglify/minify.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const buildUglifyOptions = ({
2020
mangle: mangle == null ? true : mangle,
2121
output: {
2222
shebang: true,
23-
comments: /^\**!|@preserve|@license|@cc_on/,
23+
comments: false,
2424
beautify: false,
2525
semicolons: true,
2626
...output,
@@ -37,8 +37,11 @@ const buildComments = (options, uglifyOptions, extractedComments) => {
3737
const condition = {};
3838
const commentsOpts = uglifyOptions.output.comments;
3939

40-
if (
41-
typeof options.extractComments === 'boolean' ||
40+
// /^\**!|@preserve|@license|@cc_on/
41+
if (typeof options.extractComments === 'boolean') {
42+
condition.preserve = commentsOpts;
43+
condition.extract = /^\**!|@preserve|@license|@cc_on/;
44+
} else if (
4245
typeof options.extractComments === 'string' ||
4346
options.extractComments instanceof RegExp
4447
) {

Diff for: test/__snapshots__/extract-comments-options.test.js.snap

+4-19
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ exports[`errors 3`] = `Array []`;
88

99
exports[`errors 4`] = `Array []`;
1010

11-
exports[`errors 5`] = `Array []`;
12-
13-
exports[`test.js 1`] = `
14-
"/*! For license information please see test.js.LICENSE */
15-
var foo=1;"
16-
`;
11+
exports[`test.js 1`] = `"var foo=1;"`;
1712

1813
exports[`test.js 2`] = `"var foo=1;"`;
1914

@@ -52,10 +47,7 @@ exports[`test.license.js 1`] = `
5247
"
5348
`;
5449

55-
exports[`test1.js 1`] = `
56-
"/*! For license information please see test1.js.LICENSE */
57-
var foo=1;"
58-
`;
50+
exports[`test1.js 1`] = `"var foo=1;"`;
5951

6052
exports[`test1.js 2`] = `
6153
"/*! For license information please see test1.js.LICENSE */
@@ -68,21 +60,16 @@ var foo=1;"
6860
`;
6961

7062
exports[`test1.js.LICENSE 1`] = `
71-
"/* Comment */
72-
"
73-
`;
74-
75-
exports[`test1.js.LICENSE 2`] = `
7663
"// foo
7764
"
7865
`;
7966

80-
exports[`test1.js.LICENSE 3`] = `
67+
exports[`test1.js.LICENSE 2`] = `
8168
"/* Comment */
8269
"
8370
`;
8471

85-
exports[`test1.js.LICENSE 4`] = `
72+
exports[`test1.js.LICENSE 3`] = `
8673
"/* Comment */
8774
"
8875
`;
@@ -94,5 +81,3 @@ exports[`warnings 2`] = `Array []`;
9481
exports[`warnings 3`] = `Array []`;
9582

9683
exports[`warnings 4`] = `Array []`;
97-
98-
exports[`warnings 5`] = `Array []`;

Diff for: test/all-options.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe('when applied with all options', () => {
3232
mangle: false,
3333
output: {
3434
beautify: true,
35-
comments: false,
3635
},
3736
},
3837
});
@@ -48,7 +47,6 @@ describe('when applied with all options', () => {
4847
mangle: false,
4948
output: {
5049
beautify: true,
51-
comments: false,
5250
},
5351
warnings: true,
5452
},
@@ -295,7 +293,6 @@ describe('when applied with all options', () => {
295293
mangle: false,
296294
output: {
297295
beautify: true,
298-
comments: false,
299296
},
300297
},
301298
});
@@ -349,7 +346,6 @@ describe('when applied with all options', () => {
349346
mangle: false,
350347
output: {
351348
beautify: true,
352-
comments: false,
353349
},
354350
},
355351
});

Diff for: test/ecma.test.js

-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('when applied with uglifyOptions.ecma', () => {
2323
warnings: true,
2424
output: {
2525
beautify: true,
26-
comments: false,
2726
},
2827
},
2928
}).apply(compiler);
@@ -60,7 +59,6 @@ describe('when applied with uglifyOptions.ecma', () => {
6059
warnings: true,
6160
output: {
6261
beautify: true,
63-
comments: false,
6462
},
6563
},
6664
}).apply(compiler);
@@ -97,7 +95,6 @@ describe('when applied with uglifyOptions.ecma', () => {
9795
warnings: true,
9896
output: {
9997
beautify: true,
100-
comments: false,
10198
},
10299
},
103100
}).apply(compiler);
@@ -133,7 +130,6 @@ describe('when applied with uglifyOptions.ecma', () => {
133130
warnings: true,
134131
output: {
135132
beautify: true,
136-
comments: false,
137133
},
138134
},
139135
}).apply(compiler);
@@ -170,7 +166,6 @@ describe('when applied with uglifyOptions.ecma', () => {
170166
warnings: true,
171167
output: {
172168
beautify: true,
173-
comments: false,
174169
},
175170
},
176171
}).apply(compiler);

Diff for: test/extract-comments-options.test.js

-28
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ describe('when options.extractComments', () => {
1313
const plugin = new UglifyJsPlugin({
1414
uglifyOptions: {
1515
warnings: true,
16-
output: {
17-
comments: false,
18-
},
1916
mangle: {
2017
properties: {
2118
builtins: true,
@@ -77,11 +74,6 @@ describe('when options.extractComments', () => {
7774
compilerEnv.context = '';
7875

7976
const plugin = new UglifyJsPlugin({
80-
uglifyOptions: {
81-
output: {
82-
comments: false,
83-
},
84-
},
8577
extractComments: true,
8678
});
8779
plugin.apply(compilerEnv);
@@ -119,11 +111,6 @@ describe('when options.extractComments', () => {
119111
compilerEnv.context = '';
120112

121113
const plugin = new UglifyJsPlugin({
122-
uglifyOptions: {
123-
output: {
124-
comments: false,
125-
},
126-
},
127114
extractComments: /foo/,
128115
});
129116
plugin.apply(compilerEnv);
@@ -161,11 +148,6 @@ describe('when options.extractComments', () => {
161148
compilerEnv.context = '';
162149

163150
const plugin = new UglifyJsPlugin({
164-
uglifyOptions: {
165-
output: {
166-
comments: false,
167-
},
168-
},
169151
extractComments: 'all',
170152
});
171153
plugin.apply(compilerEnv);
@@ -204,11 +186,6 @@ describe('when options.extractComments', () => {
204186
compilerEnv.context = '';
205187

206188
const plugin = new UglifyJsPlugin({
207-
uglifyOptions: {
208-
output: {
209-
comments: false,
210-
},
211-
},
212189
extractComments: () => true,
213190
});
214191
plugin.apply(compilerEnv);
@@ -247,11 +224,6 @@ describe('when options.extractComments', () => {
247224
compilerEnv.context = '';
248225

249226
const plugin = new UglifyJsPlugin({
250-
uglifyOptions: {
251-
output: {
252-
comments: false,
253-
},
254-
},
255227
extractComments: {
256228
condition: true,
257229
filename(file) {

Diff for: test/uglify/worker.test.js

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ describe('matches snapshot', () => {
66
const options = {
77
file: 'test1.js',
88
input: 'var foo = 1;/* hello */',
9-
uglifyOptions: {
10-
output: {
11-
comments: false,
12-
},
13-
},
149
extractComments: /foo/,
1510
};
1611
worker(JSON.stringify(options, encode), (error, data) => {

0 commit comments

Comments
 (0)