Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4099 ES6 Refactor lib/Compiler.js #5082

Merged
merged 8 commits into from
Jul 8, 2017
Merged

4099 ES6 Refactor lib/Compiler.js #5082

merged 8 commits into from
Jul 8, 2017

Conversation

KTruong008
Copy link
Contributor

@KTruong008 KTruong008 commented Jun 17, 2017

What kind of change does this PR introduce?

ES6 Refactor of lib/Compiler.js module

Did you add tests for your changes?

Yes

Summary

Refactored the lib/Compiler.js module to use ES6 as per issue: #4099

Other Notes

I'm also trying to refactor the lib/HotModuleReplacementPlugin and I'm getting a feeling that that file was not meant to be touched because the error messages there are odd. Should I just stop work on that module or is that one meant to be ES6-ified too?

Edit:

Local test suite passed but the checks failed when I pushed. Closed to let others know I am not currently working on this.

edit2:

Tried it again and tests seem to pass now but the test coverage dropped??

edit3:

Added some tests

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@webpack-bot
Copy link
Contributor

The minimum test ratio has been reached. Thanks!

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest fine

lib/Compiler.js Outdated
if(err) return self._done(err);
self.compiler.compile(function onCompiled(err, compilation) {
_go() {
const self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self was only an alias for this. This is no longer needed with arrow functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted 'self' to 'this' in the _go method. Shifted some normal functions around and converted them to arrow functions.

lib/Compiler.js Outdated
var watching = new Watching(this, watchOptions, handler);
return watching;
};
static Watching(compiler, watchOptions, handler) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the same.

Use Compiler.Watching = Watching; instead.

Copy link
Contributor Author

@KTruong008 KTruong008 Jul 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved static Watching method to a property of Compiler class near the last lines

lib/Compiler.js Outdated
self.applyPluginsAsync("before-run", self, function(err) {
if(err) return callback(err);
run(callback) {
const self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self was only an alias for this. This is no longer needed with arrow functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted 'self' to 'this' in the run method. converted old style function declarations into arrow functions and had to shift position of the function block within the method due to hoisting concerns I think.

lib/Compiler.js Outdated
// We can ignore self.
if(err) return callback();
readRecords(callback) {
const self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self was only an alias for this. This is no longer needed with arrow functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted 'self' to 'this' in the readRecords method.

lib/Compiler.js Outdated

self.applyPluginsParallel("make", compilation, function(err) {
compile(callback) {
const self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self was only an alias for this. This is no longer needed with arrow functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted references of self to this in the compile method

@webpack-bot
Copy link
Contributor

@KTruong888 Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

});
// describe("static method", () => {
// it("should have an accessible static method, Watching", (done) => {
// const actual = Compiler.Watching(compiler, 1000, err => err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const actual = Compiler.Watching(compiler, 1000, err => err);
const actual = new Compiler.Watching(compiler, 1000, err => err);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either remove this test or readd it. Don't use commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review again. Also wondering, would you prefer if I squashed all the commits or just leave it as it is?

lib/Compiler.js Outdated
});
},
apply: () => {
const args = arguments;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguments is not available in an arrow function.

Replace it with a function.

Spread arguments would be nicer, but they are not support in node 4.

@sokra sokra merged commit bcde519 into webpack:master Jul 8, 2017
@sokra
Copy link
Member

sokra commented Jul 8, 2017

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants