Skip to content
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

Missing parenthesis for AwaitExpression inside an optional chain #1410

Open
simonihmig opened this issue Jul 3, 2024 · 0 comments
Open

Missing parenthesis for AwaitExpression inside an optional chain #1410

simonihmig opened this issue Jul 3, 2024 · 0 comments

Comments

@simonihmig
Copy link

simonihmig commented Jul 3, 2024

I was running into an issue with jscodeshift, which seems to be similar to #589. I was seeing this in astexplorer.net, which is using some older versions, but I was observing the same behaviour when running the transform with npx jscodeshift, which AFAICT should be using the latest recast version.

Here is a reproduction: https://astexplorer.net/#/gist/19cd83009b20b00367a24ded3c031eb2/d25151fcdcea6a1d24788c3606799b579eaa6f14.

When wrapping a function call (asyncFn() in this example) with an AwaitExpression, the serialized output differs when this is part of an MemberExpression vs. an OptionalMemberExpression.

// before:
asyncFn().filter(x => x);
// after:
(await asyncFn()).filter(x => x); // correct! ✅

// before:
asyncFn()?.filter(x => x);
// after:
await asyncFn()?.filter(x => x); // wrong! ❌
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant