Skip to content

Commit 543f7a9

Browse files
committed
Try transpiling lambda properties as dot methods instead of colon methods
1 parent 4899d68 commit 543f7a9

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/Transpiler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,12 @@ export class LuaTranspiler {
917917
return this.transpileArrayCallExpression(node);
918918
}
919919

920-
if (expType.symbol && ((expType.symbol.flags & ts.SymbolFlags.Namespace)
921-
|| (expType.symbol.flags & ts.SymbolFlags.TypeLiteral))) {
920+
const expType2 = this.checker.getTypeAtLocation(node.expression);
921+
if (expType.symbol &&
922922
// Don't replace . with : for namespaces
923+
((expType.symbol.flags & ts.SymbolFlags.Namespace)
924+
// If function is defined as property with lambda type use . instead of :
925+
|| (expType2.symbol.flags & ts.SymbolFlags.TypeLiteral))) {
923926
callPath = this.transpileExpression(node.expression);
924927
params = this.transpileArguments(node.arguments);
925928
return `${callPath}(${params})`;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
classInstance:colonMethod()
2+
classInstance.dotMethod()
23
interfaceInstance:colonMethod()
3-
wrapperObj.dotMethod()
4+
interfaceInstance.dotMethod()
5+
TestNameSpace.dotMethod()
6+
TestNameSpace.dotMethod2()
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
declare class TestClass {
2+
public dotMethod: () => void;
23
public colonMethod(): void;
34
}
45

56
declare interface TestInterface {
7+
dotMethod: () => void;
68
colonMethod(): void;
79
}
810

9-
declare var wrapperObj: { dotMethod: () => void };
11+
declare namespace TestNameSpace {
12+
var dotMethod: () => void;
13+
function dotMethod2(): void;
14+
}
1015

1116
declare const classInstance: TestClass;
1217
declare const interfaceInstance: TestInterface;
1318

1419
classInstance.colonMethod();
20+
classInstance.dotMethod();
1521
interfaceInstance.colonMethod();
16-
wrapperObj.dotMethod();
22+
interfaceInstance.dotMethod();
23+
TestNameSpace.dotMethod();
24+
TestNameSpace.dotMethod2();

test/unit/assignments.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Expect, Test, TestCase, FocusTest } from "alsatian";
1+
import { Expect, Test, TestCase } from "alsatian";
22
import { TranspileError } from "../../src/Transpiler";
33

44
import * as util from "../src/util";

0 commit comments

Comments
 (0)