Skip to content

Fix async arrow functions with a destructuring rest parameter - #2261

Open
NathanColosimo wants to merge 1 commit into
meta:static_hfrom
NathanColosimo:fix-async-arrow-rest-pattern
Open

NathanColosimo wants to merge 1 commit into
meta:static_hfrom
NathanColosimo:fix-async-arrow-rest-pattern

Conversation

@NathanColosimo

@NathanColosimo NathanColosimo commented Oct 21, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2260. Related: expo/expo#51842 (breaks @orpc/client in Expo apps). The failing code in oRPC is here: https://github.com/middleapi/orpc/blob/f198f7474d5cbea613b5bff7f0656fc4e35a1c2a/packages/client/src/client.ts#L24-L28

async (...[a, b]) => {} fails with error: invalid destructuring target.

Async arrow heads are parsed as a call expression, so the rest parameter arrives in reparseArrowParameters as a SpreadElement. That branch wrapped spread->_argument in a RestElementNode without reparsing it, which left an ArrayExpression/ObjectExpression that SemanticResolver rejects.

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):

var f = async (...[input, options = {}]) => input;
f("ok").then(print);

Before (static_h @ e760a68):

$ build/bin/hermes repro.js
repro.js:1:19: error: invalid destructuring target

After:

$ build/bin/hermes repro.js
ok
$ build/bin/hermes -lazy repro.js
ok

Invalid forms still error: async (...a, b) => 0 (rest parameter must be last), async (...a = 1) => 0, async (...await) => 0. Calls like async(...[1, 2]) are unchanged.

cmake --build build --target check-hermes (Release, macOS arm64): 4126 expected passes, 6 expected failures, 188 unsupported, 0 unexpected failures.

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
@meta-cla

meta-cla Bot commented Oct 21, 2026

Copy link
Copy Markdown

Hi @NathanColosimo!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Oct 21, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Oct 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async arrow function with a destructuring rest parameter fails: "invalid destructuring target"

1 participant