Behavior change when lowering async function which throws during argument evaluation #40410
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
TypeScript Version: 4.0.2
Search Terms: async argument throw emit lower incorrect behavior
Code
Expected behavior:
The code should run without crashing, both when compiled to
ESNext
and when compiled toES2015
.Actual behavior:
The code crashes with
ReferenceError: z is not defined
when compiled toES2015
. This is because the generated code moves the evaluation of default arguments from inside the promise context to outside of the promise context during lowering:There are many ways to fix this, but an example correct compilation might look something like this:
The
_0
variables are to ensuref1.length
andf2.length
don't change.I discovered this correctness issue because I replicated TypeScript's approach to async function lowering into esbuild but it turned out to have this correctness issue.
Playground Link: link
Related Issues:
The text was updated successfully, but these errors were encountered: