Skip to content

Commit

Permalink
fix(rosetta): Rosetta does not support await (#3915)
Browse files Browse the repository at this point in the history
Now it does.

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
rix0rrr committed Jan 18, 2023
1 parent 0d51278 commit e4c51c4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/jsii-rosetta/lib/languages/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export abstract class DefaultVisitor<C> implements AstHandler<C> {
return this.regularCallExpression(node, context);
}

public awaitExpression(node: ts.AwaitExpression, context: AstRenderer<C>): OTree {
return context.convert(node.expression);
}

public regularCallExpression(node: ts.CallExpression, context: AstRenderer<C>): OTree {
return new OTree([context.convert(node.expression), '(', this.argumentList(node.arguments, context), ')']);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/jsii-rosetta/lib/languages/visualize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export class VisualizeAstVisitor implements AstHandler<void> {
return this.defaultNode('newExpression', node, context);
}

public awaitExpression(node: ts.AwaitExpression, context: AstRenderer<void>): OTree {
return this.defaultNode('await', node, context);
}

public propertyAssignment(node: ts.PropertyAssignment, context: AstRenderer<void>): OTree {
return this.defaultNode('propertyAssignment', node, context);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/jsii-rosetta/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ export class AstRenderer<C> {
if (ts.isPropertyAccessExpression(tree)) {
return visitor.propertyAccessExpression(tree, this);
}
if (ts.isAwaitExpression(tree)) {
return visitor.awaitExpression(tree, this);
}
if (ts.isCallExpression(tree)) {
return visitor.callExpression(tree, this);
}
Expand Down Expand Up @@ -471,6 +474,7 @@ export interface AstHandler<C> {
binaryExpression(node: ts.BinaryExpression, context: AstRenderer<C>): OTree;
ifStatement(node: ts.IfStatement, context: AstRenderer<C>): OTree;
propertyAccessExpression(node: ts.PropertyAccessExpression, context: AstRenderer<C>): OTree;
awaitExpression(node: ts.AwaitExpression, context: AstRenderer<C>): OTree;
callExpression(node: ts.CallExpression, context: AstRenderer<C>): OTree;
expressionStatement(node: ts.ExpressionStatement, context: AstRenderer<C>): OTree;
token<A extends ts.SyntaxKind>(node: ts.Token<A>, context: AstRenderer<C>): OTree;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int x = Future();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x := future()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Number x = future();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = future()
7 changes: 7 additions & 0 deletions packages/jsii-rosetta/test/translations/expressions/await.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// !hide
function future(): Promise<number> {
return Promise.resolve(5);
}
/// !show

const x = await future();

0 comments on commit e4c51c4

Please sign in to comment.