Skip to content

Commit f24e6ff

Browse files
committed
Fixes getAccessor with this and added isntancefield translation for extension classes
1 parent d0f7a1d commit f24e6ff

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/Transpiler.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ export abstract class LuaTranspiler {
12591259
public transpilePropertyAccessExpression(node: ts.PropertyAccessExpression): string {
12601260
const property = node.name.text;
12611261

1262+
if (tsHelper.hasGetAccessor(node, this.checker)) {
1263+
return this.transpileGetAccessor(node);
1264+
}
1265+
12621266
// Check for primitive types to override
12631267
const type = this.checker.getTypeAtLocation(node.expression);
12641268
switch (type.flags) {
@@ -1268,8 +1272,6 @@ export abstract class LuaTranspiler {
12681272
case ts.TypeFlags.Object:
12691273
if (tsHelper.isArrayType(type, this.checker)) {
12701274
return this.transpileArrayProperty(node);
1271-
} else if (tsHelper.hasGetAccessor(node, this.checker)) {
1272-
return this.transpileGetAccessor(node);
12731275
}
12741276
}
12751277

@@ -1593,13 +1595,6 @@ export abstract class LuaTranspiler {
15931595

15941596
let result = "";
15951597

1596-
if (!isExtension && !isMetaExtension) {
1597-
result += this.transpileClassCreationMethods(node, instanceFields, extendsType);
1598-
} else {
1599-
// export empty table
1600-
this.pushExport(className, node, true);
1601-
}
1602-
16031598
// Overwrite the original className with the class we are overriding for extensions
16041599
if (isMetaExtension) {
16051600
if (!extendsType) {
@@ -1619,6 +1614,20 @@ export abstract class LuaTranspiler {
16191614
}
16201615
}
16211616

1617+
if (!isExtension && !isMetaExtension) {
1618+
result += this.transpileClassCreationMethods(node, instanceFields, extendsType);
1619+
} else {
1620+
for (const f of instanceFields) {
1621+
// Get identifier
1622+
const fieldIdentifier = f.name as ts.Identifier;
1623+
const fieldName = this.transpileIdentifier(fieldIdentifier);
1624+
1625+
const value = this.transpileExpression(f.initializer);
1626+
1627+
result += this.indent + `${className}.${fieldName} = ${value}\n`;
1628+
}
1629+
}
1630+
16221631
// Add static declarations
16231632
for (const field of staticFields) {
16241633
const fieldName = this.transpileIdentifier(field.name as ts.Identifier);

src/targets/Transpiler.52.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ export class LuaTranspiler52 extends LuaTranspiler51 {
6767
/** @override */
6868
public transpileSpreadElement(node: ts.SpreadElement): string {
6969
return "table.unpack(" + this.transpileExpression(node.expression) + ")";
70-
}
70+
}
7171
}

src/targets/Transpiler.GLua.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { LuaTranspilerJIT } from "./Transpiler.JIT";
22

33
import * as path from "path";
4+
import * as ts from "typescript";
5+
6+
import { LuaTranspiler } from "../Transpiler";
47

58
export class LuaTranspilerGLua extends LuaTranspilerJIT {
69
/** @override */
@@ -18,4 +21,14 @@ export class LuaTranspilerGLua extends LuaTranspilerJIT {
1821
public getRequireKeyword(): string {
1922
return "include";
2023
}
24+
25+
/** @override */
26+
public transpileDestructingAssignmentValue(node: ts.Expression): string {
27+
return LuaTranspiler.prototype.transpileDestructingAssignmentValue.call(this, node);
28+
}
29+
30+
/** @override */
31+
public transpileSpreadElement(node: ts.SpreadElement): string {
32+
return LuaTranspiler.prototype.transpileSpreadElement.call(this, node);
33+
}
2134
}

0 commit comments

Comments
 (0)