-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Incorrect ES5 code emitted for closures in loops when noCheck is enabled #59262
Comments
@weswigham / @DanielRosenwasser any thoughts on this? |
I was looking at this last night; this seems like a flag case missed in #58364 (but I didn't spend enough time on it to actually figure out where or fix anything). |
Doing more debugging with this test: // @target: es5
const fns = [];
for (const value of [1, 2, 3]) {
fns.push(() => ({ value }));
}
const result = fns.map(fn => fn());
console.log(result) Shows that (No need to set noCheck or vary it in tests, all tests verify that checking does not change emit, we just didn't have a test for this case.) |
This seems like something specifically to do with it being |
|
Thank you for a very quick fix! |
π Search Terms
ES5, noCheck, loop, closures, transpilation, transpileModule
π Version & Regression Information
This broke in either #57934 or #58364
β― Playground Link
https://www.typescriptlang.org/dev/bug-workbench/?target=1&noCheck=true#code/PTAEAEDsHsGEAsCmBjA1gLlAFwE4FdEAoECLAQxwHNEtNEBnAVmLHHvmgHcBRAWwEsshQsmiR6WUADNxoALygA2gF0A3ISnQcoABSjxkgG5kANgVDQpSgIwAaUACZ7AZnsAWZQEpQAb0KgA6XEAOgAHPHYdHW85AD5dH1BjM0RQAF9PT3U0kTEJUBwGPBNJBRl6YN4yUJ0ZeXiZaKzc8WgTRGCTaEodQvpirE8gA
π» Code
π Actual behavior
The following incorrect code is produced:
Which evaluates to this incorrect value:
[{ value: 3 }, { value: 3 }, { value: 3 }]
π Expected behavior
The following should be produced:
Which would evaluate to:
[{ value: 1 }, { value: 2 }, { value: 3 }]
Additional information about the issue
transpileModule(ts, { compilerOptions: { target: ScriptTarget.ES5 } })
started producing incorrect code in TypeScript 5.5, since I believenoCheck: true
is the default there.The text was updated successfully, but these errors were encountered: