wallabyjs / quokka

Repository for Quokka.js questions and issues
https://quokkajs.com
1.18k stars 31 forks source link

Closures created within the initialization section of for loop #838

Closed rkrbashyan closed 2 years ago

rkrbashyan commented 2 years ago

Issue description or question

Is this issue related to Quokka not outputting the expected results of your code?: Yes

Sample code

for (let i = 0, getI = () => i; i < 3; i++) {
    console.log(getI());
}

Quokka.js Console Output

0
1
2

Expected Console Output

0
0
0

Code editor version

Visual Studio Code v1.73.1

OS name and version

OSX, 13.0.1

ArtemGovorov commented 2 years ago

When we run the code, it produces the expected output:

Screen Shot 2022-11-26 at 9 39 58 am

Can you please try creating new Quokka file, pasting your code and checking if it's working as expected?

By default Quokka reuses created node process, so it's possible that the i was closed over in global scope as you were typing the code. You may use this setting to disable process reuse by Quokka.

rkrbashyan commented 2 years ago

Thank you. The actual problem is my babel preset config

    "babel": {
        "presets": ["@babel/preset-env"],
        "plugins": [["@babel/plugin-proposal-decorators", { "version": "2022-03" }]]
    }