You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This modifies our down-level emit for async functions when they contain non-trivial parameter lists that may potentially throw when bound. Prior to this change, the following would throw immediately when it should instead produce a rejected promise:
To address this, this PR repurposes the second parameter to __awaiter, which was previously only used to bind a lexically-captured arguments, to instead be used to forward arguments for the function to the down-level generator body, producing the following emit instead:
When the transformed function is not an arrow function, we merely forward the function's arguments and emit placeholders for each fixed parameter to preserve the function's length, as can be seen with x_1 above.
Arrow functions, however, do not have their own arguments. In that case, we instead capture all fixed arguments, followed by a rest parameter that holds any additional arguments.
This change means that we can no longer rely on the previous mechanism for lexical arguments capturing (i.e., just passing it along as the second parameter to __awaiter), and instead must manually capture a lexical arguments binding.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This modifies our down-level emit for async functions when they contain non-trivial parameter lists that may potentially throw when bound. Prior to this change, the following would throw immediately when it should instead produce a rejected promise:
The reason for this is that we eagerly evaluate the parameter list in the down-level emit:
To address this, this PR repurposes the second parameter to
__awaiter
, which was previously only used to bind a lexically-capturedarguments
, to instead be used to forward arguments for the function to the down-level generator body, producing the following emit instead:When the transformed function is not an arrow function, we merely forward the function's
arguments
and emit placeholders for each fixed parameter to preserve the function'slength
, as can be seen withx_1
above.Arrow functions, however, do not have their own
arguments
. In that case, we instead capture all fixed arguments, followed by a rest parameter that holds any additional arguments.Thus,
now transforms to
This change means that we can no longer rely on the previous mechanism for lexical
arguments
capturing (i.e., just passing it along as the second parameter to__awaiter
), and instead must manually capture a lexicalarguments
binding.Thus,
now transforms to
Aside from the change to lexical
arguments
capturing, a function with a trivial parameter list does not undergo this transformation.Thus,
still transforms to
in an effort to limit the complexity of the down-level emit when it is unwarranted.
It should also be noted that this PR applies a similar change to async generators as well.
Fixes #40410