Skip to content

Commit 2e39d11

Browse files
committed
Cleaned up prototype code
1 parent 543f7a9 commit 2e39d11

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/Transpiler.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,10 @@ export class LuaTranspiler {
895895
let params;
896896
let callPath;
897897
if (ts.isPropertyAccessExpression(node.expression)) {
898-
const expType = this.checker.getTypeAtLocation(node.expression.expression);
898+
// If the function being called is of type owner.func, get the type of owner
899+
const ownerType = this.checker.getTypeAtLocation(node.expression.expression);
899900

900-
if (expType.symbol && expType.symbol.escapedName === "Math") {
901+
if (ownerType.symbol && ownerType.symbol.escapedName === "Math") {
901902
params = this.transpileArguments(node.arguments);
902903
return this.transpileMathExpression(node.expression.name) + `(${params})`;
903904
}
@@ -907,22 +908,22 @@ export class LuaTranspiler {
907908
return this.transpileStringExpression(node.expression.name) + `(${params})`;
908909
}
909910

910-
switch (expType.flags) {
911+
switch (ownerType.flags) {
911912
case ts.TypeFlags.String:
912913
case ts.TypeFlags.StringLiteral:
913914
return this.transpileStringCallExpression(node);
914915

915916
}
916-
if (tsHelper.isArrayType(expType, this.checker)) {
917+
if (tsHelper.isArrayType(ownerType, this.checker)) {
917918
return this.transpileArrayCallExpression(node);
918919
}
919920

920-
const expType2 = this.checker.getTypeAtLocation(node.expression);
921-
if (expType.symbol &&
922-
// Don't replace . with : for namespaces
923-
((expType.symbol.flags & ts.SymbolFlags.Namespace)
921+
// Get the type of the function
922+
const functionType = this.checker.getTypeAtLocation(node.expression);
923+
// Don't replace . with : for namespaces
924+
if ((ownerType.symbol && (ownerType.symbol.flags & ts.SymbolFlags.Namespace))
924925
// If function is defined as property with lambda type use . instead of :
925-
|| (expType2.symbol.flags & ts.SymbolFlags.TypeLiteral))) {
926+
|| (functionType.symbol && (functionType.symbol.flags & ts.SymbolFlags.TypeLiteral))) {
926927
callPath = this.transpileExpression(node.expression);
927928
params = this.transpileArguments(node.arguments);
928929
return `${callPath}(${params})`;

0 commit comments

Comments
 (0)