- Remove ‘self’ references from lib/Compiler and use more arrow functions instead

This commit is contained in:
Kyle Truong 2017-07-01 11:47:36 -04:00
parent 4378c92c60
commit 6dffccaa72
1 changed files with 76 additions and 77 deletions

View File

@ -40,45 +40,45 @@ class Watching {
}
_go() {
const self = this;
self.startTime = Date.now();
self.running = true;
self.invalid = false;
self.compiler.applyPluginsAsync("watch-run", self, err => {
if(err) return self._done(err);
self.compiler.compile(function onCompiled(err, compilation) {
if(err) return self._done(err);
if(self.invalid) return self._done();
this.startTime = Date.now();
this.running = true;
this.invalid = false;
this.compiler.applyPluginsAsync("watch-run", this, err => {
if(err) return this._done(err);
const onCompiled = (err, compilation) => {
if(err) return this._done(err);
if(this.invalid) return this._done();
if(self.compiler.applyPluginsBailResult("should-emit", compilation) === false) {
return self._done(null, compilation);
if(this.compiler.applyPluginsBailResult("should-emit", compilation) === false) {
return this._done(null, compilation);
}
self.compiler.emitAssets(compilation, err => {
if(err) return self._done(err);
if(self.invalid) return self._done();
this.compiler.emitAssets(compilation, err => {
if(err) return this._done(err);
if(this.invalid) return this._done();
self.compiler.emitRecords(err => {
if(err) return self._done(err);
this.compiler.emitRecords(err => {
if(err) return this._done(err);
if(compilation.applyPluginsBailResult("need-additional-pass")) {
compilation.needAdditionalPass = true;
const stats = new Stats(compilation);
stats.startTime = self.startTime;
stats.startTime = this.startTime;
stats.endTime = Date.now();
self.compiler.applyPlugins("done", stats);
this.compiler.applyPlugins("done", stats);
self.compiler.applyPluginsAsync("additional-pass", err => {
if(err) return self._done(err);
self.compiler.compiler(onCompiled);
this.compiler.applyPluginsAsync("additional-pass", err => {
if(err) return this._done(err);
this.compiler.compiler(onCompiled);
});
return;
}
return self._done(null, compilation);
return this._done(null, compilation);
});
});
});
};
this.compiler.compile(onCompiled);
});
}
@ -226,58 +226,59 @@ module.exports = class Compiler extends Tapable {
}
run(callback) {
const self = this;
const startTime = Date.now();
self.applyPluginsAsync("before-run", self, err => {
const onCompiled = (err, compilation) => {
if(err) return callback(err);
self.applyPluginsAsync("run", self, err => {
if(this.applyPluginsBailResult("should-emit", compilation) === false) {
const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
this.applyPlugins("done", stats);
return callback(null, stats);
}
this.emitAssets(compilation, err => {
if(err) return callback(err);
self.readRecords(err => {
if(compilation.applyPluginsBailResult("need-additional-pass")) {
compilation.needAdditionalPass = true;
const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
this.applyPlugins("done", stats);
this.applyPluginsAsync("additional-pass", err => {
if(err) return callback(err);
this.compile(onCompiled);
});
return;
}
this.emitRecords(err => {
if(err) return callback(err);
self.compile(function onCompiled(err, compilation) {
if(err) return callback(err);
const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
this.applyPlugins("done", stats);
return callback(null, stats);
});
});
};
if(self.applyPluginsBailResult("should-emit", compilation) === false) {
const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
self.applyPlugins("done", stats);
return callback(null, stats);
}
this.applyPluginsAsync("before-run", this, err => {
if(err) return callback(err);
self.emitAssets(compilation, err => {
if(err) return callback(err);
this.applyPluginsAsync("run", this, err => {
if(err) return callback(err);
if(compilation.applyPluginsBailResult("need-additional-pass")) {
compilation.needAdditionalPass = true;
this.readRecords(err => {
if(err) return callback(err);
const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
self.applyPlugins("done", stats);
self.applyPluginsAsync("additional-pass", err => {
if(err) return callback(err);
self.compile(onCompiled);
});
return;
}
self.emitRecords(err => {
if(err) return callback(err);
const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
self.applyPlugins("done", stats);
return callback(null, stats);
});
});
});
this.compile(onCompiled);
});
});
});
@ -387,21 +388,20 @@ module.exports = class Compiler extends Tapable {
}
readRecords(callback) {
const self = this;
if(!self.recordsInputPath) {
self.records = {};
if(!this.recordsInputPath) {
this.records = {};
return callback();
}
self.inputFileSystem.stat(self.recordsInputPath, err => {
this.inputFileSystem.stat(this.recordsInputPath, err => {
// It doesn't exist
// We can ignore self.
// We can ignore this.
if(err) return callback();
self.inputFileSystem.readFile(self.recordsInputPath, (err, content) => {
this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => {
if(err) return callback(err);
try {
self.records = JSON.parse(content.toString("utf-8"));
this.records = JSON.parse(content.toString("utf-8"));
} catch(e) {
e.message = "Cannot parse records: " + e.message;
return callback(e);
@ -496,16 +496,15 @@ module.exports = class Compiler extends Tapable {
}
compile(callback) {
const self = this;
const params = self.newCompilationParams();
self.applyPluginsAsync("before-compile", params, err => {
const params = this.newCompilationParams();
this.applyPluginsAsync("before-compile", params, err => {
if(err) return callback(err);
self.applyPlugins("compile", params);
this.applyPlugins("compile", params);
const compilation = self.newCompilation(params);
const compilation = this.newCompilation(params);
self.applyPluginsParallel("make", compilation, err => {
this.applyPluginsParallel("make", compilation, err => {
if(err) return callback(err);
compilation.finish();
@ -513,7 +512,7 @@ module.exports = class Compiler extends Tapable {
compilation.seal(err => {
if(err) return callback(err);
self.applyPluginsAsync("after-compile", compilation, err => {
this.applyPluginsAsync("after-compile", compilation, err => {
if(err) return callback(err);
return callback(null, compilation);