Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Identifier,
ReferenceExpr,
ThisExpr,
UndefinedLiteralExpr,
} from "./expression";
import { Function } from "./function";
import {
Expand Down Expand Up @@ -649,7 +650,9 @@ export class APIGatewayVTL extends VTL {
public eval(node: Stmt, returnVar?: string): void;
public eval(node?: Expr | Stmt, returnVar?: string): string | void {
if (isReturnStmt(node)) {
return this.add(this.exprToJson(node.expr));
return this.add(
this.exprToJson(node.expr ?? node.fork(new UndefinedLiteralExpr()))
);
} else if (
isPropAccessExpr(node) &&
isIdentifier(node.name) &&
Expand Down
12 changes: 9 additions & 3 deletions src/appsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ReferenceExpr,
StringLiteralExpr,
ThisExpr,
UndefinedLiteralExpr,
} from "./expression";
import {
isVariableStmt,
Expand Down Expand Up @@ -482,7 +483,10 @@ function synthesizeFunctions(api: appsync.GraphqlApi, decl: FunctionLike) {
* Flatten variable declarations into multiple variable statements.
*/
return node.declList.decls.map(
(decl) => new VariableStmt(new VariableDeclList([decl]))
(decl) =>
new VariableStmt(
new VariableDeclList([decl], node.declList.varKind)
)
);
} else if (isBinaryExpr(node)) {
/**
Expand Down Expand Up @@ -608,7 +612,9 @@ function synthesizeFunctions(api: appsync.GraphqlApi, decl: FunctionLike) {
return createStage(
service,
`${pre ? `${pre}\n` : ""}#set( $context.stash.return__flag = true )
#set( $context.stash.return__val = ${getResult(stmt.expr)} )
#set( $context.stash.return__val = ${getResult(
stmt.expr ?? stmt.fork(new UndefinedLiteralExpr())
)} )
{}`
);
} else if (
Expand Down Expand Up @@ -683,7 +689,7 @@ function synthesizeFunctions(api: appsync.GraphqlApi, decl: FunctionLike) {
}
} else if (isLastExpr) {
if (isReturnStmt(stmt)) {
template.return(stmt.expr);
template.return(stmt.expr ?? stmt.fork(new UndefinedLiteralExpr()));
} else if (isIfStmt(stmt)) {
template.eval(stmt);
} else {
Expand Down
Loading