When you write
```
for (const x of l) {
setTimeout(() => x);
}
```
we need to add a closure because the variable is meant to be block-scoped and recreated each time the block runs. We do this.
However, we also add the closure when no loop is present. This isn't necessary, because if no loop is present then each piece of code runs at most once. I changed the transform to only add a closure if a variable is referenced from within a loop.
32 lines
592 B
JavaScript
32 lines
592 B
JavaScript
function foo() {
|
|
while (true) {
|
|
switch (2) {
|
|
case 0:
|
|
{
|
|
var _ret = function () {
|
|
if (true) {
|
|
return {
|
|
v: void 0
|
|
};
|
|
}
|
|
|
|
var stuff = new Map();
|
|
var data = 0;
|
|
stuff.forEach(function () {
|
|
var d = data;
|
|
});
|
|
return "break";
|
|
}();
|
|
|
|
switch (_ret) {
|
|
case "break":
|
|
break;
|
|
|
|
default:
|
|
if (typeof _ret === "object") return _ret.v;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|