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
23 changes: 13 additions & 10 deletions src/transformation/visitors/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,19 @@ export function transformPropertyAccessExpressionWithCapture(
};
}
if (node.expression.kind === SyntaxKind.SuperKeyword) {
return {
expression: transformLuaLibFunction(
context,
LuaLibFeature.DescriptorGet,
node,
lua.createIdentifier("self"),
table,
lua.createStringLiteral(property)
),
};
const symbol = context.checker.getSymbolAtLocation(node);
if (symbol && symbol.flags & ts.SymbolFlags.GetAccessor) {
return {
expression: transformLuaLibFunction(
context,
LuaLibFeature.DescriptorGet,
node,
lua.createIdentifier("self"),
table,
lua.createStringLiteral(property)
),
};
}
}
return { expression: lua.createTableIndexExpression(table, lua.createStringLiteral(property), node) };
}
Expand Down
33 changes: 18 additions & 15 deletions src/transformation/visitors/binary-expression/assignments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,24 @@ export function transformAssignment(

if (ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) {
if (lhs.expression.kind === SyntaxKind.SuperKeyword) {
return [
lua.createExpressionStatement(
transformLuaLibFunction(
context,
LuaLibFeature.DescriptorSet,
parent,
lua.createIdentifier("self"),
context.transformExpression(lhs.expression),
ts.isPropertyAccessExpression(lhs)
? lua.createStringLiteral(lhs.name.text)
: context.transformExpression(lhs.argumentExpression),
right
)
),
];
const symbol = context.checker.getSymbolAtLocation(lhs);
if (symbol && symbol.flags & ts.SymbolFlags.SetAccessor) {
return [
lua.createExpressionStatement(
transformLuaLibFunction(
context,
LuaLibFeature.DescriptorSet,
parent,
lua.createIdentifier("self"),
context.transformExpression(lhs.expression),
ts.isPropertyAccessExpression(lhs)
? lua.createStringLiteral(lhs.name.text)
: context.transformExpression(lhs.argumentExpression),
right
)
),
];
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions test/unit/classes/classes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,39 @@ test("Calling static inherited functions works (#1504)", () => {
return B.Get();
`.expectToMatchJsResult();
});

// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1537
test("get inherted __index member from super (DotA 2 inheritance) (#1537)", () => {
util.testFunction`
// Inherit 'connected' class
class C extends Connected {
bar() {
return super.foo();
}
}

return new C().bar();`
.setTsHeader(
`interface I {
foo(): string;
}

// Hacky interface/class merging
interface Connected extends I {}
class Connected {}

declare function setmetatable(this: void, t: any, mt: any);

const A = {
foo() {
return "foo";
}
};

// Connect class 'Connected' to 'traditional' class A
setmetatable(Connected.prototype, {
__index: A
});`
)
.expectToEqual("foo");
});