Skip to content

Commit d2461da

Browse files
committed
improve code (review)
1 parent 71933e9 commit d2461da

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎lib/optimize/UglifyJsPlugin.js‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@ class UglifyJsPlugin {
126126
case "boolean":
127127
var b = condition[key];
128128
condition[key] = () => b;
129-
case "function": // eslint-disable-line no-fallthrough
129+
break;
130+
case "function":
130131
break;
131132
case "string":
132133
if(condition[key] === "all") {
133134
condition[key] = () => true;
134135
break;
135136
}
136-
condition[key] = new RegExp(condition[key]);
137-
default: // eslint-disable-line no-fallthrough
138-
var regex = condition[key];
137+
var regex = new RegExp(condition[key]);
138+
condition[key] = (astNode, comment) => regex.test(comment.value);
139+
break;
140+
default:
141+
regex = condition[key];
139142
condition[key] = (astNode, comment) => regex.test(comment.value);
140143
}
141144
});
@@ -163,11 +166,11 @@ class UglifyJsPlugin {
163166
ast.print(stream);
164167
if(map) map = map + "";
165168
const stringifiedStream = stream + "";
166-
asset.__UglifyJsPlugin = compilation.assets[file] = (map ?
169+
let outputSource = (map ?
167170
new SourceMapSource(stringifiedStream, file, JSON.parse(map), input, inputSourceMap) :
168171
new RawSource(stringifiedStream));
169172
if(extractedComments.length > 0) {
170-
let commentsFile = options.extractComments.file || file + ".LICENSE";
173+
let commentsFile = options.extractComments.filename || file + ".LICENSE";
171174
if(typeof commentsFile === "function") {
172175
commentsFile = commentsFile(file);
173176
}
@@ -195,12 +198,13 @@ class UglifyJsPlugin {
195198
banner = banner(commentsFile);
196199
}
197200
if(banner) {
198-
asset.__UglifyJsPlugin = compilation.assets[file] = new ConcatSource(
199-
"/*! " + banner + " */\n", compilation.assets[file]
201+
outputSource = new ConcatSource(
202+
"/*! " + banner + " */\n", outputSource
200203
);
201204
}
202205
}
203206
}
207+
asset.__UglifyJsPlugin = compilation.assets[file] = outputSource;
204208
if(warnings.length > 0) {
205209
compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n")));
206210
}

‎test/UglifyJsPlugin.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe("UglifyJsPlugin", function() {
227227
comments: false,
228228
extractComments: {
229229
condition: 'should be extracted',
230-
file: function(file) {
230+
filename: function(file) {
231231
return file.replace(/(\.\w+)$/, '.license$1');
232232
},
233233
banner: function(licenseFile) {
@@ -575,7 +575,7 @@ describe("UglifyJsPlugin", function() {
575575
comments: "all",
576576
extractComments: {
577577
condition: /.*/,
578-
file: "extracted-comments.js"
578+
filename: "extracted-comments.js"
579579
}
580580
});
581581
plugin.apply(compilerEnv);

0 commit comments

Comments
 (0)