@@ -666,27 +666,37 @@ var LuaTranspiler = /** @class */ (function () {
666666 noClassOr = TSHelper_1 . TSHelper . hasCustomDecorator ( superType , "!NoClassOr" ) ;
667667 }
668668 } ) ;
669- // Write class declaration
670669 var className = node . name . escapedText ;
671- var classOr = noClassOr ? "" : className + " or " ;
672670 var result = "" ;
673- if ( ! extendsType ) {
674- result += this . indent + ( className + " = " + classOr + "{}\n" ) ;
671+ // Skip header if this is an extension class
672+ var isExtension = TSHelper_1 . TSHelper . isExtensionClass ( this . checker . getTypeAtLocation ( node ) ) ;
673+ if ( ! isExtension ) {
674+ // Write class declaration
675+ var classOr = noClassOr ? "" : className + " or " ;
676+ if ( ! extendsType ) {
677+ result += this . indent + ( className + " = " + classOr + "{}\n" ) ;
678+ }
679+ else {
680+ var baseName = extendsType . expression . escapedText ;
681+ result += this . indent + ( className + " = " + classOr + baseName + ".new()\n" ) ;
682+ }
683+ result += this . indent + ( className + ".__index = " + className + "\n" ) ;
684+ if ( extendsType ) {
685+ var baseName = extendsType . expression . escapedText ;
686+ result += this . indent + ( className + ".__base = " + baseName + "\n" ) ;
687+ }
688+ result += this . indent + ( "function " + className + ".new(construct, ...)\n" ) ;
689+ result += this . indent + ( " local instance = setmetatable({}, " + className + ")\n" ) ;
690+ result += this . indent + ( " if construct and " + className + ".constructor then " + className + ".constructor(instance, ...) end\n" ) ;
691+ result += this . indent + " return instance\n" ;
692+ result += this . indent + "end\n" ;
675693 }
676694 else {
677- var baseName = extendsType . expression . escapedText ;
678- result += this . indent + ( className + " = " + classOr + baseName + ".new()\n" ) ;
679- }
680- result += this . indent + ( className + ".__index = " + className + "\n" ) ;
681- if ( extendsType ) {
682- var baseName = extendsType . expression . escapedText ;
683- result += this . indent + ( className + ".__base = " + baseName + "\n" ) ;
684- }
685- result += this . indent + ( "function " + className + ".new(construct, ...)\n" ) ;
686- result += this . indent + ( " local instance = setmetatable({}, " + className + ")\n" ) ;
687- result += this . indent + ( " if construct and " + className + ".constructor then " + className + ".constructor(instance, ...) end\n" ) ;
688- result += this . indent + " return instance\n" ;
689- result += this . indent + "end\n" ;
695+ // Overwrite the original className with the class we are overriding for extensions
696+ if ( extendsType ) {
697+ className = extendsType . expression . escapedText ;
698+ }
699+ }
690700 // Get all properties with value
691701 var properties = node . members . filter ( ts . isPropertyDeclaration )
692702 . filter ( function ( _ ) { return _ . initializer ; } ) ;
0 commit comments