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

ssrTransform incorrectly transforms references in "for" block #13012

Closed
7 tasks done
sheremet-va opened this issue Apr 26, 2023 · 1 comment · Fixed by #13021
Closed
7 tasks done

ssrTransform incorrectly transforms references in "for" block #13012

sheremet-va opened this issue Apr 26, 2023 · 1 comment · Fixed by #13021
Labels
feat: ssr p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@sheremet-va
Copy link
Member

sheremet-va commented Apr 26, 2023

Describe the bug

Variable test is replaced with __vite_ssr_import_0__.test, even though the user referenced the local variable and not the named import.

Original code:

import { test } from './test.js'

for(const test of tests) {
  console.log(test)
}

for(let test = 0; test < 10; test++) {
  console.log(test)
}

for(const test in tests) {
  console.log(test)
}

Processed result:

const __vite_ssr_import_0__ = await __vite_ssr_import__("./test.js");

    

for(const test of tests) {
  console.log(__vite_ssr_import_0__.test)
}

for(let test = 0; __vite_ssr_import_0__.test < 10; __vite_ssr_import_0__.test++) {
  console.log(__vite_ssr_import_0__.test)
}

for(const test in tests) {
  console.log(__vite_ssr_import_0__.test)
}

Reproduction

https://stackblitz.com/edit/node-isfe8x?file=index.mjs

Steps to reproduce

Run node index.js

System Info

Stackblitz

Used Package Manager

npm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Apr 26, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added p4-important Violate documented behavior or significantly improves performance (priority) feat: ssr labels Apr 26, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: ssr p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants