Skip to content

Commit

Permalink
- Remove ‘self’ references from lib/Compiler and use more arrow funct…
Browse files Browse the repository at this point in the history
…ions instead
  • Loading branch information
Kyle Truong authored and Kyle Truong committed Jul 7, 2017
1 parent 4378c92 commit 6dffcca
Showing 1 changed file with 75 additions and 76 deletions.
151 changes: 75 additions & 76 deletions lib/Compiler.js
Expand Up @@ -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();

if(self.compiler.applyPluginsBailResult("should-emit", compilation) === false) {
return self._done(null, compilation);
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(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);
});
}

Expand Down Expand Up @@ -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(err) return callback(err);
if(compilation.applyPluginsBailResult("need-additional-pass")) {
compilation.needAdditionalPass = true;

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);

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("additional-pass", err => {
if(err) return callback(err);
this.compile(onCompiled);
});
return;
}

self.emitAssets(compilation, err => {
if(err) return callback(err);
this.emitRecords(err => {
if(err) return callback(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);
return callback(null, stats);
});
});
};

const stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = Date.now();
self.applyPlugins("done", stats);
this.applyPluginsAsync("before-run", this, err => {
if(err) return callback(err);

self.applyPluginsAsync("additional-pass", err => {
if(err) return callback(err);
self.compile(onCompiled);
});
return;
}
this.applyPluginsAsync("run", this, err => {
if(err) return callback(err);

self.emitRecords(err => {
if(err) return callback(err);
this.readRecords(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);
});
});
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -496,24 +496,23 @@ 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();

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);
Expand Down

0 comments on commit 6dffcca

Please sign in to comment.