Skip to content

Commit 0c18503

Browse files
committed
Add few comments to public plugin API
1 parent dca04d4 commit 0c18503

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/plugins.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import { Printer } from "./LuaPrinter";
22
import { Visitors } from "./transformation/context";
33

44
export interface Plugin {
5-
printer?: Printer;
5+
/**
6+
* An augmentation to the map of visitors that transform TypeScript AST to Lua AST.
7+
*
8+
* Key is a `SyntaxKind` of a processed node.
9+
*/
610
visitors?: Visitors;
11+
12+
/**
13+
* A function that converts Lua AST to a string.
14+
*
15+
* Only one plugin can provide `printer`.
16+
*/
17+
printer?: Printer;
718
}

src/transformation/context/visitors.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,20 @@ export type VisitorResult<T extends ts.Node> = T extends ExpressionLikeNode
145145
? lua.Block
146146
: OneToManyVisitorResult<lua.Node>;
147147

148-
export type FunctionVisitor<T extends ts.Node> = (node: T, context: TransformationContext) => VisitorResult<T>;
149-
export type ObjectVisitor<T extends ts.Node> = { transform: FunctionVisitor<T>; priority?: number };
150148
export type Visitor<T extends ts.Node> = FunctionVisitor<T> | ObjectVisitor<T>;
149+
export type FunctionVisitor<T extends ts.Node> = (node: T, context: TransformationContext) => VisitorResult<T>;
150+
export type ObjectVisitor<T extends ts.Node> = {
151+
transform: FunctionVisitor<T>;
152+
153+
/**
154+
* Visitors with higher priority are called first.
155+
*
156+
* Higher-priority visitors can call lower ones with `context.superTransformNode`.
157+
*
158+
* Standard visitors have the lowest (`-Infinity`) priority.
159+
*/
160+
priority?: number;
161+
};
162+
151163
export type Visitors = { [P in keyof NodesBySyntaxKind]?: Visitor<NodesBySyntaxKind[P]> };
152164
export type VisitorMap = Map<ts.SyntaxKind, Array<ObjectVisitor<ts.Node>>>;

0 commit comments

Comments
 (0)