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

Extract to parser helpers #3843

Merged
merged 12 commits into from Jan 8, 2017
Merged

Conversation

timse
Copy link
Member

@timse timse commented Jan 8, 2017

What kind of change does this PR introduce?

refactoring

Did you add tests for your changes?

Is covered by existing tests

If relevant, link to documentation update:

N/A

Summary

While doing my refactorings to es6 i noticed that certain calls to the parser repeat themselves over several modules.
First I tried to pull them as a whole into a helper function but then realized that for now a more atomic approach should probably be more reasonable, as it removes the sideeffects and makes it reusable throughout the code.

For me the these helper functions abstract a lot of the clutter away and make the code more readable as I can see with one glimpse what is happening.

Does this PR introduce a breaking change?

No

Other information

If this approach is "ok" I would love to continue on this bit by bit.
If the PR gets to big it will introduce too many conflicts with existing PRs I guess.
Therefore if I may continue, I would try this with a bunch of smaller PRs to keep the impact on files and therefore other PRs as small as possible.

};
};

ParserHelpers.evaluateToString = function setTypeof(value) {
Copy link
Member

Choose a reason for hiding this comment

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

wrong function name

Copy link
Member Author

Choose a reason for hiding this comment

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

done :)

};

ParserHelpers.toConstantDependency = function toConstantDependency(value) {
return function(expr) {
Copy link
Member

Choose a reason for hiding this comment

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

could you name these anonymous function? It better for stacktraces and profiling...

Copy link
Member Author

Choose a reason for hiding this comment

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

done :)

@timse
Copy link
Member Author

timse commented Jan 8, 2017

What still personally "annoys" me, is that the callbacks of the plugins are called with the parser as the context and then mutate the parsers state implicitly by adding the ConstDependency to it.
Is there any way we can pass the state as a parameter e.g. in Tapable? Or make Tapable a promise?
If i just return the e.g. ConstDependency created by the callback and assign it to the state it gets fairly verbose again.

Promises would probably make the "return true/false" impossible though?

@TheLarkInn
Copy link
Member

Tapable could maybe return a promise in the future but it's kind of tough.

Nice work on this though. This is significantly easier to read now.

@TheLarkInn TheLarkInn merged commit 86c0020 into webpack:master Jan 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants