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

[Parser] Support rename this's property for IIFE #5076

Merged
merged 2 commits into from Jul 1, 2017

Conversation

ljqx
Copy link
Member

@ljqx ljqx commented Jun 16, 2017

What kind of change does this PR introduce?
bugfix

Did you add tests for your changes?
Yes

If relevant, link to documentation update:
N/A

Summary

This is for fixing #5067.
ProvidePlugin supports replacing IIFE argument's property with resolved modules, but not this's. This PR makes it available.

For example, for code

(function(){
  window.export = this.jQuery;

}).call(window);

config

new webpack.ProvidePlugin({
  'window.jQuery': 'jquery',
})

will replace the jQuery with resolved one.

Does this PR introduce a breaking change?
No

Other information
This PR only handles iife.call() or iife.bind() style call of IIFE, not

  1. The simple iife() style as it has more complicated this resolving rules (environment, strict mode or not).
  2. .apply
  3. arrow functions
  4. object method
  5. getter/setter
  6. constructor (seems not needed)
  7. callback

@jsf-clabot
Copy link

jsf-clabot commented Jun 16, 2017

CLA assistant check
All committers have signed the CLA.

@webpack-bot
Copy link
Contributor

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

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.

Please add a config test case testing the Provide plugin with IIFE like in the issue.

lib/Parser.js Outdated
}
const params = functionExpression.params;
const args = options.map(renameArgOrThis, this);
const renameThis = currentThis ? renameArgOrThis.call(this, currentThis) : null;
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 switch this line with the previous line? So that arguments are evaluated in the correct order.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

@webpack-bot
Copy link
Contributor

@ljqx Thanks for your update.

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

@sokra Please review the new changes.

@ljqx
Copy link
Member Author

ljqx commented Jun 19, 2017

Hi, @sokra , ci/circleci failed because some unrelated tests timeout. How could I force reevaluate the tests? thanks.

@ljqx ljqx force-pushed the parser-support-rename-this-for-iife branch from 4a407a5 to cc2df2f Compare June 23, 2017 03:05
@ljqx
Copy link
Member Author

ljqx commented Jun 26, 2017

Hi, @sokra , the comments are resolved, ci checks are passed too. Could you help continue the review? Thanks.

@sokra sokra merged commit 9ff3c7a into webpack:master Jul 1, 2017
@sokra
Copy link
Member

sokra commented Jul 1, 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

4 participants