-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Block-scoping bug #3235
Milestone
Comments
kdy1
added a commit
to kdy1/swc
that referenced
this issue
Mar 3, 2022
kdy1
added a commit
to kdy1/swc
that referenced
this issue
Mar 3, 2022
2 tasks
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have the following script:
let res = [];
let a = 2;
res.push(a === 2);
{
let b = 1;
}
res.push(typeof b === "undefined");
if(true) {
let b = 0;
}
res.push(typeof b === "undefined");
for(let b = 0; b < 10; b++) {
}
res.push(typeof b === "undefined");
function test() {
let b = 7;
}
res.push(typeof b === "undefined");
console.log(res);
I expect this to evaluate to [true, true, true, true, true], but am getting [true, false, false, false, false] because the first block-scoped variable b is not renamed or prepended with an underscore. Here's the link to the swc-playground transpilation. In babel the transpilation looks like the following with all block-scoped let assignments prepended with underscores and incremented:
var res = [];
var a = 2;
res.push(a === 2);
{
var _b = 1;
}
res.push(typeof b === "undefined");
if (true) {
var _b2 = 0;
}
res.push(typeof b === "undefined");
for (var _b3 = 0; _b3 < 10; _b3++) {}
res.push(typeof b === "undefined");
function test() {
var b = 7;
}
res.push(typeof b === "undefined");
res;
Config:
{
"jsc": {
"target": "es5",
"parser": {
"syntax": "ecmascript"
}
}
"module": {
"type": "commonjs",
"strict": true
"strictMode": true
},
"sourceMaps": true
}
The text was updated successfully, but these errors were encountered: