Repository navigation
Fix async arrow functions with a destructuring rest parameter - #2261
NathanColosimo wants to merge 1 commit into
Conversation
Async arrow heads are parsed as a call expression, so the rest parameter
arrives as a SpreadElement. reparseArrowParameters wrapped its argument in
a RestElementNode without reparsing it, so `async (...[a, b]) => {}`
failed with "invalid destructuring target". Reparse the argument with
reparseAssignmentPattern, like other arrow parameters.
Fixes meta#2260
|
Hi @NathanColosimo! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Fixes #2260. Related: expo/expo#51842 (breaks
@orpc/clientin Expo apps). The failing code in oRPC is here: https://github.com/middleapi/orpc/blob/f198f7474d5cbea613b5bff7f0656fc4e35a1c2a/packages/client/src/client.ts#L24-L28async (...[a, b]) => {}fails witherror: invalid destructuring target.Async arrow heads are parsed as a call expression, so the rest parameter arrives in
reparseArrowParametersas aSpreadElement. That branch wrappedspread->_argumentin aRestElementNodewithout reparsing it, which left anArrayExpression/ObjectExpressionthatSemanticResolverrejects.The fix reparses the argument with
reparseAssignmentPattern(..., /*inDecl*/ true), the same way other arrow parameters and array-pattern rest elements are handled. Side effect:async (...(a)) => {}is now a SyntaxError, matching the sync arrow form and the spec. It was previously accepted.Test Plan
Added
test/hermes/async-arrow-rest-pattern.js, which covers array, object, and nested rest patterns, a leading parameter, and a throwing default that becomes a rejection. It runs with the default,-O, and-lazy.Repro (
repro.js):Before (
static_h@ e760a68):After:
Invalid forms still error:
async (...a, b) => 0(rest parameter must be last),async (...a = 1) => 0,async (...await) => 0. Calls likeasync(...[1, 2])are unchanged.cmake --build build --target check-hermes(Release, macOS arm64): 4126 expected passes, 6 expected failures, 188 unsupported, 0 unexpected failures.