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

SWC handles closures in loops incorrectly #4052

Closed
lorenzobersano opened this issue Mar 16, 2022 · 4 comments
Closed

SWC handles closures in loops incorrectly #4052

lorenzobersano opened this issue Mar 16, 2022 · 4 comments
Labels
Milestone

Comments

@lorenzobersano
Copy link

Describe the bug

If I run the same code with node in a script file the result is correct (1,2,3...), however in Next i always get (32,32,32...), as if let was a var.

Input code

let cols = []

for (let i = 1; i <= 31; i++) {
  cols.push({
    accessor: () => {
      console.log(i)
    }
  })
}

cols.map(({ accessor }) => accessor())

Config

I'm using next 12.1.0, so no .swcrc

Playground link

No response

Expected behavior

I expect to get printed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Actual behavior

On Next, i get
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32

Version

As per next peerDeps: "@swc/core": ">=1.2.50",

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Mar 17, 2022
@Austaras
Copy link
Member

Should already be fixed in latest swc

@Brooooooklyn
Copy link
Member

vercel/next.js#35395 will fix it

@lorenzobersano
Copy link
Author

Great, thanks for your work! 🥇

@kdy1 kdy1 modified the milestones: Planned, v1.2.156 Mar 17, 2022
@kdy1 kdy1 closed this as completed Mar 17, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 17, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants