Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,10 @@ export abstract class LuaTranspiler {
const name = this.transpileIdentifier(node.expression.name);
if (name === "toString") {
return `tostring(${this.transpileExpression(node.expression.expression)})`;
} else if (name === "hasOwnProperty") {
const expr = this.transpileExpression(node.expression.expression);
params = this.transpileArguments(node.arguments);
return `(rawget(${expr}, ${params} )~=nil)`;
} else {
callPath =
`${this.transpileExpression(node.expression.expression)}:${name}`;
Expand Down
37 changes: 37 additions & 0 deletions test/unit/class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,44 @@ export class ClassTests {
// Assert
Expect(result).toBe("instance of a");
}
@Test("HasOwnProperty true")
public hasOwnProperty1(): void {
// Transpile
const lua = util.transpileString(
`class a {
public test(): void {
}
}
let inst = new a();
inst["prop"] = 17;
return inst.hasOwnProperty("prop");`
);

// Execute
const result = util.executeLua(lua);

// Assert
Expect(result).toBe(true);
}
@Test("HasOwnProperty false")
public hasOwnProperty2(): void {
// Transpile
const lua = util.transpileString(
`class a {
public test(): void {
}
}
let inst = new a();
inst["prop"] = 17;
return inst.hasOwnProperty("test");`
);

// Execute
const result = util.executeLua(lua);

// Assert
Expect(result).toBe(false);
}
@Test("CastClassMethodCall")
public extraParenthesisAssignment(): void {
// Transpile
Expand Down