-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptThe issue relates to the emission of JavaScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
Bug Report
🔎 Search Terms
transformer,es5,bindings declared in loop initializer
🕗 Version & Regression Information
typescript 4.2.4
yesterday i found my code can't work using transformer provided by ts
- This is a crash
- This changed between versions 3.33 and 4.35
⏯ Playground Link
Playground link with relevant code
💻 Code
// before
function test() {
for (let i = 0; setTimeout(() => console.log(i)), i < 2; setTimeout(() => console.log(i)), i++) {
}
}
// after
`"use strict";\n
function test() {
var _loop_1 = function (i) {
if (inc_1)
setTimeout(function () { return console.log(i); }), i++;
else
inc_1 = true;
if (!(setTimeout(function () { return console.log(i); }), i < 2))
return "break";
};
var inc_1 = false;
for (var i = 0;;) {
var state_1 = _loop_1(i);
if (state_1 === "break")
break;
}
}`
🙁 Actual behavior
variable i keep zero,for loop can't stop
🙂 Expected behavior
it shoulud declarae a variable out of function body and change it in the end of function body and assign it to i before call function ,then the code will work well.
wwwzbwcomandrewbranch
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptThe issue relates to the emission of JavaScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone