Skip to content

Commit 2a1bcff

Browse files
committed
refactor the _done method of Watching
- we can safely ignore the "else" cases of not having an error as _done() is only called without arguments if "this.invalid is true" - if we get passed the point of `this.invalid` either `err` or `compilation` are !!always!! set. therefore later checks can again be ignored - early return in error case - ignore `this.error` if we make it passed the error as it will be unset at this point. - remove the setting of `this.error` or `this.stats` as the only use is inside this method and only allow weird behaviour if someone set them from outside
1 parent 8165164 commit 2a1bcff

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/Compiler.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var ContextModuleFactory = require("./ContextModuleFactory");
1313
function Watching(compiler, watchOptions, handler) {
1414
this.startTime = null;
1515
this.invalid = false;
16-
this.error = null;
1716
this.handler = handler;
1817
this.closed = false;
1918
if(typeof watchOptions === "number") {
@@ -81,19 +80,21 @@ Watching.prototype._go = function() {
8180
Watching.prototype._done = function(err, compilation) {
8281
this.running = false;
8382
if(this.invalid) return this._go();
84-
this.error = err || null;
85-
this.stats = compilation ? new Stats(compilation) : null;
86-
if(this.stats) {
87-
this.stats.startTime = this.startTime;
88-
this.stats.endTime = new Date().getTime();
83+
84+
if(err) {
85+
this.compiler.applyPlugins("failed", err);
86+
this.handler(err);
87+
return;
8988
}
90-
if(this.stats)
91-
this.compiler.applyPlugins("done", this.stats);
92-
else
93-
this.compiler.applyPlugins("failed", this.error);
94-
this.handler(this.error, this.stats);
95-
if(!this.error && !this.closed)
89+
90+
var stats = new Stats(compilation);
91+
stats.startTime = this.startTime;
92+
stats.endTime = new Date().getTime();
93+
this.compiler.applyPlugins("done", stats);
94+
this.handler(null, stats);
95+
if(!this.closed) {
9696
this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies);
97+
}
9798
};
9899

99100
Watching.prototype.watch = function(files, dirs, missing) {

0 commit comments

Comments
 (0)