Open sparecycles opened 9 months ago
Thanks for looking at this, Nell!
My current use of this, if it helps to drive testing, is
fetch('http://example.com').await.json().await.data.x;
// --> (await (await fetch('http://example.com')).json()).data.x
via .transform(transformDotAwait)
export function transformDotAwait({
factory,
visitChildren,
}: TransformTraversalControl): ts.Node {
const result = visitChildren();
if (
ts.isPropertyAccessExpression(result) &&
result.name.getText() === "await"
) {
return factory.createParenthesizedExpression(
factory.createAwaitExpression(result.expression),
);
}
return result;
}
So, I had this hair-brained idea to use ts-morph to wrap await around sub-expressions.
E.g.
fetch('http://example.com').json().data.x
->(await (await fetch('http://example.com')).json()).data.x
Describe the bug
Version: 20.0.0
I get the following error attempting this
To Reproduce
Expected behavior
... as was produced after applying the following fix ... 😉
See also Issue #852 / PR #853