File tree Expand file tree Collapse file tree 3 files changed +67
-25
lines changed
src/transformation/visitors Expand file tree Collapse file tree 3 files changed +67
-25
lines changed Original file line number Diff line number Diff line change @@ -182,16 +182,19 @@ export function transformPropertyAccessExpressionWithCapture(
182182 } ;
183183 }
184184 if ( node . expression . kind === SyntaxKind . SuperKeyword ) {
185- return {
186- expression : transformLuaLibFunction (
187- context ,
188- LuaLibFeature . DescriptorGet ,
189- node ,
190- lua . createIdentifier ( "self" ) ,
191- table ,
192- lua . createStringLiteral ( property )
193- ) ,
194- } ;
185+ const symbol = context . checker . getSymbolAtLocation ( node ) ;
186+ if ( symbol && symbol . flags & ts . SymbolFlags . GetAccessor ) {
187+ return {
188+ expression : transformLuaLibFunction (
189+ context ,
190+ LuaLibFeature . DescriptorGet ,
191+ node ,
192+ lua . createIdentifier ( "self" ) ,
193+ table ,
194+ lua . createStringLiteral ( property )
195+ ) ,
196+ } ;
197+ }
195198 }
196199 return { expression : lua . createTableIndexExpression ( table , lua . createStringLiteral ( property ) , node ) } ;
197200}
Original file line number Diff line number Diff line change @@ -78,21 +78,24 @@ export function transformAssignment(
7878
7979 if ( ts . isPropertyAccessExpression ( lhs ) || ts . isElementAccessExpression ( lhs ) ) {
8080 if ( lhs . expression . kind === SyntaxKind . SuperKeyword ) {
81- return [
82- lua . createExpressionStatement (
83- transformLuaLibFunction (
84- context ,
85- LuaLibFeature . DescriptorSet ,
86- parent ,
87- lua . createIdentifier ( "self" ) ,
88- context . transformExpression ( lhs . expression ) ,
89- ts . isPropertyAccessExpression ( lhs )
90- ? lua . createStringLiteral ( lhs . name . text )
91- : context . transformExpression ( lhs . argumentExpression ) ,
92- right
93- )
94- ) ,
95- ] ;
81+ const symbol = context . checker . getSymbolAtLocation ( lhs ) ;
82+ if ( symbol && symbol . flags & ts . SymbolFlags . SetAccessor ) {
83+ return [
84+ lua . createExpressionStatement (
85+ transformLuaLibFunction (
86+ context ,
87+ LuaLibFeature . DescriptorSet ,
88+ parent ,
89+ lua . createIdentifier ( "self" ) ,
90+ context . transformExpression ( lhs . expression ) ,
91+ ts . isPropertyAccessExpression ( lhs )
92+ ? lua . createStringLiteral ( lhs . name . text )
93+ : context . transformExpression ( lhs . argumentExpression ) ,
94+ right
95+ )
96+ ) ,
97+ ] ;
98+ }
9699 }
97100 }
98101
Original file line number Diff line number Diff line change @@ -852,3 +852,39 @@ test("Calling static inherited functions works (#1504)", () => {
852852 return B.Get();
853853 ` . expectToMatchJsResult ( ) ;
854854} ) ;
855+
856+ // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1537
857+ test ( "get inherted __index member from super (DotA 2 inheritance) (#1537)" , ( ) => {
858+ util . testFunction `
859+ // Inherit 'connected' class
860+ class C extends Connected {
861+ bar() {
862+ return super.foo();
863+ }
864+ }
865+
866+ return new C().bar();`
867+ . setTsHeader (
868+ `interface I {
869+ foo(): string;
870+ }
871+
872+ // Hacky interface/class merging
873+ interface Connected extends I {}
874+ class Connected {}
875+
876+ declare function setmetatable(this: void, t: any, mt: any);
877+
878+ const A = {
879+ foo() {
880+ return "foo";
881+ }
882+ };
883+
884+ // Connect class 'Connected' to 'traditional' class A
885+ setmetatable(Connected.prototype, {
886+ __index: A
887+ });`
888+ )
889+ . expectToEqual ( "foo" ) ;
890+ } ) ;
You can’t perform that action at this time.
0 commit comments