File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
src/transformation/visitors/class Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { createClassSetup } from "./setup";
2121import { LuaTarget } from "../../../CompilerOptions" ;
2222import { transformInPrecedingStatementScope } from "../../utils/preceding-statements" ;
2323import { createClassPropertyDecoratingExpression } from "./decorators" ;
24+ import { findFirstNodeAbove } from "../../utils/typescript" ;
2425
2526export const transformClassDeclaration : FunctionVisitor < ts . ClassLikeDeclaration > = ( declaration , context ) => {
2627 // If declaration is a default export, transform to export variable assignment instead
@@ -249,5 +250,11 @@ export const transformSuperExpression: FunctionVisitor<ts.SuperExpression> = (ex
249250 baseClassName = lua . createTableIndexExpression ( className , lua . createStringLiteral ( "____super" ) , expression ) ;
250251 }
251252
252- return lua . createTableIndexExpression ( baseClassName , lua . createStringLiteral ( "prototype" ) ) ;
253+ const f = findFirstNodeAbove ( expression , ts . isFunctionLike ) ;
254+ if ( f && ts . canHaveModifiers ( f ) && isStaticNode ( f ) ) {
255+ // In static method, don't add prototype to super call
256+ return baseClassName ;
257+ } else {
258+ return lua . createTableIndexExpression ( baseClassName , lua . createStringLiteral ( "prototype" ) ) ;
259+ }
253260} ;
Original file line number Diff line number Diff line change @@ -833,3 +833,22 @@ test("static member definition order (#1457)", () => {
833833 return A.a;
834834 ` . expectToMatchJsResult ( ) ;
835835} ) ;
836+
837+ // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1504
838+ test ( "Calling static inherited functions works (#1504)" , ( ) => {
839+ util . testFunction `
840+ class A {
841+ static Get() {
842+ return "A";
843+ }
844+ }
845+
846+ class B extends A {
847+ static Get() {
848+ return super.Get() + "B";
849+ }
850+ }
851+
852+ return B.Get();
853+ ` . expectToMatchJsResult ( ) ;
854+ } ) ;
You can’t perform that action at this time.
0 commit comments