forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.ts
More file actions
22 lines (20 loc) · 890 Bytes
/
transform.ts
File metadata and controls
22 lines (20 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import * as ts from "typescript";
import * as lua from "../../LuaAST";
import { castArray } from "../../utils";
import { TransformationContext } from "../context";
import { createImmediatelyInvokedFunctionExpression } from "./lua-ast";
import { ScopeType, pushScope, popScope } from "./scope";
export interface ImmediatelyInvokedFunctionParameters {
statements: lua.Statement | lua.Statement[];
result: lua.Expression | lua.Expression[];
}
export function transformToImmediatelyInvokedFunctionExpression(
context: TransformationContext,
transformFunction: () => ImmediatelyInvokedFunctionParameters,
tsOriginal?: ts.Node
): lua.CallExpression {
pushScope(context, ScopeType.Function);
const { statements, result } = transformFunction();
popScope(context);
return createImmediatelyInvokedFunctionExpression(castArray(statements), result, tsOriginal);
}