You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the app code, I use variable hoisting inside a loop:
constmessages={good: 'You should see me',bad: 'You should not see me - hoisting broken!',};constobj={};for(constkeyinmessages){obj[key]=()=>messages[key];// <---- each closure uses a hoisted key}element.innerHTML=`${obj.good()}`;
What I expect is that the code works identically in both modern and legacy build.
Instead, the legacy build doesn't hoist key in the above loop. The resulting code is clearly wrong:
obj={};for(keyinmessages){obj[key]=()=>messages[key];// <---- key is not hoisted}element.innerHTML=`${obj.good()}`;
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I am compiling a legacy build for Chrome 49 with:
In the app code, I use variable hoisting inside a loop:
What I expect is that the code works identically in both modern and legacy build.
Instead, the legacy build doesn't hoist
key
in the above loop. The resulting code is clearly wrong:Reproduction
https://stackblitz.com/edit/vitejs-vite-ndrwsg?file=vite.config.js,counter.js&terminal=dev
Steps to reproduce
Build and run production build:
Load the modern build. The page will say: "You should see me"
Load the legacy build. To do so on a modern browser, edit
dist/index.html
and remove two lines:<script type="module" crossorigin src="/assets/index-9d88f3c8.js"></script>
if (window.__vite_is_modern_browser) return;
The page will say: "You should not see me - hoisting broken!"
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: