Skip to content

Commit

Permalink
chore: refactor AST code into @functionless/ast (#541)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: AST nodes moded to new package @functionless/ast
  • Loading branch information
sam committed Oct 6, 2022
1 parent 55ad432 commit 8e7b596
Show file tree
Hide file tree
Showing 60 changed files with 899 additions and 816 deletions.
9 changes: 3 additions & 6 deletions apps/fl-exp-simple/tsconfig.json
Expand Up @@ -8,11 +8,8 @@
"include": ["."],
"exclude": ["lib", "test", "node_modules"],
"references": [
{
"path": "../../packages/@functionless/aws-constructs"
},
{
"path": "../../packages/@functionless/fl-exp"
}
{ "path": "../../packages/@functionless/aws-constructs" },
{ "path": "../../packages/@functionless/aws" },
{ "path": "../../packages/@functionless/fl-exp" }
]
}
Expand Up @@ -83,7 +83,7 @@ It contains the following hooks that will be called either during CDK synthesis

## Functionless AST

When you compile your application with `tsc`, the [`functionless/lib/compile`](../../../../packages/@functionless/aws-constructs/src/compile.ts) transformer will replace the function declaration, `F`, in `new AppsyncResolver(F)` with its corresponding [Abstract Syntax Tree](../../../../packages/@functionless/aws-constructs/src/expression.ts) representation. This representation is then synthesized to Velocity Templates and AWS AppSync Resolver configurations, using the `@aws-cdk/aws-appsync-alpha` CDK Construct Library.
When you compile your application with `tsc`, the [`functionless/lib/compile`](../../../../packages/@functionless/aws-constructs/src/compile.ts) transformer will replace the function declaration, `F`, in `new AppsyncResolver(F)` with its corresponding [Abstract Syntax Tree](../../../../packages/@functionless/ast/src/expression.ts) representation. This representation is then synthesized to Velocity Templates and AWS AppSync Resolver configurations, using the `@aws-cdk/aws-appsync-alpha` CDK Construct Library.

For example, this function declaration:

Expand Down
2 changes: 1 addition & 1 deletion apps/website/docs/concepts/appsync/syntax.md
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 2

In order to write effective VTL templates, it helps to understand how TypeScript syntax maps to Velocity Template Statements.

An AppSync Request Mapping Template is synthesized by evaluating all [Expressions](../../../../../packages/@functionless/aws-constructs/src/expression.ts) to a series of `#set`, `$util.qr`, `#foreach` and `#if` statements. The end result is an object containing the returned result of the function which can then be converted to JSON with `$util.toJson`.
An AppSync Request Mapping Template is synthesized by evaluating all [Expressions](../../../../../packages/@functionless/ast/src/expression.ts) to a series of `#set`, `$util.qr`, `#foreach` and `#if` statements. The end result is an object containing the returned result of the function which can then be converted to JSON with `$util.toJson`.

The following section provides a reference guide on how each of the supported TypeScript syntax is mapped to VTL.

Expand Down
66 changes: 66 additions & 0 deletions packages/@functionless/ast/package.json
@@ -0,0 +1,66 @@
{
"name": "@functionless/ast",
"version": "0.0.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc -b",
"typecheck": "tsc --noEmit",
"test": "jest"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/jest": "^29.0.3",
"typescript": "^4.8.3",
"jest": "^29.0.3",
"ts-jest": "^29.0.2"
},
"files": [
"lib"
],
"publishConfig": {
"access": "public"
},
"jest": {
"collectCoverage": false,
"coveragePathIgnorePatterns": [
"/test/",
"/node_modules/",
"/lib"
],
"transform": {
"^.+\\.(t|j)sx?$": [
"ts-jest",
{}
]
},
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.ts?(x)",
"<rootDir>/(test|src)/**/*(*.)@(spec|test).ts?(x)"
],
"clearMocks": true,
"coverageReporters": [
"json",
"lcov",
"clover",
"cobertura",
"text"
],
"coverageDirectory": "coverage",
"testPathIgnorePatterns": [
"/node_modules/"
],
"watchPathIgnorePatterns": [
"/node_modules/"
],
"reporters": [
"default",
[
"jest-junit",
{
"outputDirectory": "test-reports"
}
]
]
}
}
Expand Up @@ -9,7 +9,6 @@ import type {
PropName,
ReferenceExpr,
} from "./expression";
import type { Integration } from "./integration";
import { BaseNode, FunctionlessNode } from "./node";
import { NodeKind } from "./node-kind";
import type { Span } from "./span";
Expand Down Expand Up @@ -475,10 +474,6 @@ export class FunctionDecl<F extends AnyFunction = AnyFunction> extends BaseDecl<
}
}

export interface IntegrationInvocation {
integration: Integration<any>;
args: Expr[];
}
export class ParameterDecl extends BaseDecl<
NodeKind.ParameterDecl,
ArrowFunctionExpr | FunctionDecl | FunctionExpr | SetAccessorDecl
Expand Down Expand Up @@ -699,6 +694,3 @@ export class VariableDeclList extends BaseNode<
this.ensureArrayOf(decls, "decls", [NodeKind.VariableDecl]);
}
}

// to prevent the closure serializer from trying to import all of functionless.
export const deploymentOnlyModule = true;
File renamed without changes.
Expand Up @@ -15,6 +15,3 @@ export class Err extends BaseNode<NodeKind.Err> {
super(NodeKind.Err, span, arguments);
}
}

// to prevent the closure serializer from trying to import all of functionless.
export const deploymentOnlyModule = true;
Expand Up @@ -1053,6 +1053,3 @@ export class OmittedExpr extends BaseExpr<NodeKind.OmittedExpr> {
super(NodeKind.OmittedExpr, span, arguments);
}
}

// to prevent the closure serializer from trying to import all of functionless.
export const deploymentOnlyModule = true;
File renamed without changes.
14 changes: 14 additions & 0 deletions packages/@functionless/ast/src/index.ts
@@ -0,0 +1,14 @@
export * from "./declaration";
export * from "./ensure";
export * from "./error";
export * from "./expression";
export * from "./guards";
export * from "./node-clone";
export * from "./node-ctor";
export * from "./node-kind";
export * from "./node";
export * from "./s-expression";
export * from "./span";
export * from "./statement";
export * from "./util";
export * from "./visit";
File renamed without changes.
File renamed without changes.
Expand Up @@ -572,6 +572,3 @@ export abstract class BaseNode<
}
}
}

// to prevent the closure serializer from trying to import all of functionless.
export const deploymentOnlyModule = true;
File renamed without changes.
Expand Up @@ -453,6 +453,3 @@ export class WithStmt extends BaseStmt<NodeKind.WithStmt> {
this.ensure(stmt, "stmt", ["Stmt"]);
}
}

// to prevent the closure serializer from trying to import all of functionless.
export const deploymentOnlyModule = true;

0 comments on commit 8e7b596

Please sign in to comment.