forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.ts
More file actions
32 lines (30 loc) · 1.62 KB
/
Copy pathfunction.ts
File metadata and controls
32 lines (30 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as lua from "../../LuaAST";
import { TransformationContext } from "../context";
import { unsupportedProperty, unsupportedSelfFunctionConversion } from "../utils/diagnostics";
import { ContextType, getFunctionContextType } from "../utils/function-context";
import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
import { PropertyCallExpression, transformArguments } from "../visitors/call";
export function transformFunctionPrototypeCall(
context: TransformationContext,
node: PropertyCallExpression
): lua.CallExpression | undefined {
const expression = node.expression;
const callerType = context.checker.getTypeAtLocation(expression.expression);
if (getFunctionContextType(context, callerType) === ContextType.Void) {
context.diagnostics.push(unsupportedSelfFunctionConversion(node));
}
const signature = context.checker.getResolvedSignature(node);
const params = transformArguments(context, node.arguments, signature);
const caller = context.transformExpression(expression.expression);
const expressionName = expression.name.text;
switch (expressionName) {
case "apply":
return transformLuaLibFunction(context, LuaLibFeature.FunctionApply, node, caller, ...params);
case "bind":
return transformLuaLibFunction(context, LuaLibFeature.FunctionBind, node, caller, ...params);
case "call":
return transformLuaLibFunction(context, LuaLibFeature.FunctionCall, node, caller, ...params);
default:
context.diagnostics.push(unsupportedProperty(expression.name, "function", expressionName));
}
}