-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Invalid code generated for async functions containing multiple for..of loops with same variable #2910
Comments
Thanks for the report! It looks like this is a problem with our generator transpilation that's triggered by how we rewrite for-of loops. Here's a repro where the input is the code from above, just before reaching generator transpilation: |
A Googler is working on a fix for this internally. |
For now, using different variable names in each for-of loop will work around the bug. It appears to happen only when one for loop has an await and the other does not. |
Fixes google#2910 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=196136758
I ran into a bizarre error after having rewritten some code to use Promises, which I'll include here for the benefit of anyone who may be searching for it:
If an async function contains multiple
for...of
loops sharing the same variable name, some of which containawait
and some of which do not containawait
, Closure Compiler will generate invalid code for accessing the variable in the latter.Here is a minimal test case which reproduces the issue.
The generated code (with options
--formatting=PRETTY_PRINT --debug=true
) is as follows:Note that the
number
variable has been renamed to$$jscomp$key$number$$
for both loops. However, the variable is declared as part of the second loop (withoutawait
), which breaks the first loop as its value is cleared between generator calls. If the second loop is removed,$$jscomp$key$number$$
is declared outside the generator, and the first loop functions correctly.The text was updated successfully, but these errors were encountered: