Skip to content

Comments

Use var for IIFE#4588

Merged
lukastaegert merged 1 commit intomasterfrom
use-var-for-iife
Jul 26, 2022
Merged

Use var for IIFE#4588
lukastaegert merged 1 commit intomasterfrom
use-var-for-iife

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

Development

Successfully merging this pull request may close these issues.

Bug: iife should startsWith var instead of const evev if i set preset to es2015 iife code generated by vite3 is not working

2 participants