-
Notifications
You must be signed in to change notification settings - Fork 13.4k
for await and nullish coalescing causes name collision #37418
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptThe issue relates to the emission of JavaScriptEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
Milestone
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 JavaScriptEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
It seems I stumbled on a bug in TypeScript when I used a for await loop containing two nullish coalescing operations inside an if condition. When targeting ES2017 or less, TypeScript uses _b as a temporary variable holding the iterator, calling _b.next() for every iteration. However, in the if condition _b is overwritten as another temporary variable. See the playground link to see the generated JS code, the bug happens inside the outerIterator function.
TypeScript Version: v3.9.0-dev.20200315
Search Terms: for await async iterable iterator name collision next nullish coalescing
Code
Expected behavior:
In the console:
Actual behavior:
Playground Link:
Playground Link
Related Issues:
Not sure, but maybe #28849 is related.