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

Use var for IIFE #4588

Merged
merged 1 commit into from Jul 26, 2022
Merged

Use var for IIFE #4588

merged 1 commit into from Jul 26, 2022

Conversation

lukastaegert
Copy link
Member

Otherwise, the created variable is not on the global object

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

IIFEs should not use const to declare global variables. While it still works of sort because a const declared in script scope is still visible in all scripts, it is not stored on the global object which will break flows that access the global object. Currently, this is only a problem when using the generatedCode option.

Otherwise, the created variable is not on the global object
@github-actions
Copy link

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#use-var-for-iife

or load it into the REPL:
https://rollupjs.org/repl/?pr=4588

@codecov
Copy link

codecov bot commented Jul 26, 2022

Codecov Report

Merging #4588 (6ace07c) into master (27c0557) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4588   +/-   ##
=======================================
  Coverage   98.86%   98.86%           
=======================================
  Files         209      209           
  Lines        7344     7344           
  Branches     2098     2098           
=======================================
  Hits         7261     7261           
  Misses         27       27           
  Partials       56       56           
Impacted Files Coverage Δ
src/finalisers/iife.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us.

@Jackie1210
Copy link

LGTM!

@lukastaegert lukastaegert merged commit 3502ac4 into master Jul 26, 2022
@lukastaegert lukastaegert deleted the use-var-for-iife branch July 26, 2022 07:19
antfu added a commit to vitejs/vite that referenced this pull request Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants