diff --git a/src/transformation/visitors/class/index.ts b/src/transformation/visitors/class/index.ts index 9574d1efc..8c54afe12 100644 --- a/src/transformation/visitors/class/index.ts +++ b/src/transformation/visitors/class/index.ts @@ -21,6 +21,7 @@ import { createClassSetup } from "./setup"; import { LuaTarget } from "../../../CompilerOptions"; import { transformInPrecedingStatementScope } from "../../utils/preceding-statements"; import { createClassPropertyDecoratingExpression } from "./decorators"; +import { findFirstNodeAbove } from "../../utils/typescript"; export const transformClassDeclaration: FunctionVisitor = (declaration, context) => { // If declaration is a default export, transform to export variable assignment instead @@ -249,5 +250,11 @@ export const transformSuperExpression: FunctionVisitor = (ex baseClassName = lua.createTableIndexExpression(className, lua.createStringLiteral("____super"), expression); } - return lua.createTableIndexExpression(baseClassName, lua.createStringLiteral("prototype")); + const f = findFirstNodeAbove(expression, ts.isFunctionLike); + if (f && ts.canHaveModifiers(f) && isStaticNode(f)) { + // In static method, don't add prototype to super call + return baseClassName; + } else { + return lua.createTableIndexExpression(baseClassName, lua.createStringLiteral("prototype")); + } }; diff --git a/test/unit/classes/classes.spec.ts b/test/unit/classes/classes.spec.ts index 93c7640cf..a93177c88 100644 --- a/test/unit/classes/classes.spec.ts +++ b/test/unit/classes/classes.spec.ts @@ -833,3 +833,22 @@ test("static member definition order (#1457)", () => { return A.a; `.expectToMatchJsResult(); }); + +// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1504 +test("Calling static inherited functions works (#1504)", () => { + util.testFunction` + class A { + static Get() { + return "A"; + } + } + + class B extends A { + static Get() { + return super.Get() + "B"; + } + } + + return B.Get(); + `.expectToMatchJsResult(); +});