File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed
Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -384,7 +384,8 @@ export class LuaTransformer {
384384
385385 // Write class declaration
386386 if ( extendsType ) {
387- const baseName = tstl . createIdentifier ( extendsType . symbol . escapedName as string ) ;
387+ const extendedTypeNode = tsHelper . getExtendedTypeNode ( statement , this . checker ) ;
388+ const baseName = this . transformExpression ( extendedTypeNode . expression ) ;
388389
389390 // baseName.new
390391 const newIndex = tstl . createTableIndexExpression ( baseName , tstl . createStringLiteral ( "new" ) ) ;
@@ -428,7 +429,9 @@ export class LuaTransformer {
428429 result . push ( assignClassIndex ) ;
429430
430431 if ( extendsType ) {
431- const baseName = tstl . createIdentifier ( extendsType . symbol . escapedName as string ) ;
432+ const extendedTypeNode = tsHelper . getExtendedTypeNode ( statement , this . checker ) ;
433+ const baseName = this . transformExpression ( extendedTypeNode . expression ) ;
434+
432435 // className.__base = baseName
433436 const classBase = tstl . createTableIndexExpression ( className , tstl . createStringLiteral ( "__base" ) ) ;
434437
Original file line number Diff line number Diff line change @@ -56,21 +56,27 @@ export class TSHelper {
5656 return result ;
5757 }
5858
59- public static getExtendedType ( node : ts . ClassLikeDeclarationBase , checker : ts . TypeChecker ) : ts . Type | undefined {
59+ public static getExtendedTypeNode ( node : ts . ClassLikeDeclarationBase , checker : ts . TypeChecker ) :
60+ ts . ExpressionWithTypeArguments | undefined {
6061 if ( node && node . heritageClauses ) {
6162 for ( const clause of node . heritageClauses ) {
6263 if ( clause . token === ts . SyntaxKind . ExtendsKeyword ) {
6364 const superType = checker . getTypeAtLocation ( clause . types [ 0 ] ) ;
6465 const decorators = this . getCustomDecorators ( superType , checker ) ;
6566 if ( ! decorators . has ( DecoratorKind . PureAbstract ) ) {
66- return superType ;
67+ return clause . types [ 0 ] ;
6768 }
6869 }
6970 }
7071 }
7172 return undefined ;
7273 }
7374
75+ public static getExtendedType ( node : ts . ClassLikeDeclarationBase , checker : ts . TypeChecker ) : ts . Type | undefined {
76+ const extendedTypeNode = this . getExtendedTypeNode ( node , checker ) ;
77+ return extendedTypeNode && checker . getTypeAtLocation ( extendedTypeNode ) ;
78+ }
79+
7480 public static isFileModule ( sourceFile : ts . SourceFile ) : boolean {
7581 if ( sourceFile ) {
7682 // Vanilla ts flags files as external module if they have an import or
Original file line number Diff line number Diff line change @@ -277,6 +277,30 @@ export class ClassTests {
277277 Expect ( result ) . toBe ( 10 ) ;
278278 }
279279
280+ @Test ( "renamedClassExtends" )
281+ public renamedClassExtends ( ) : void
282+ {
283+ const result = util . transpileAndExecute (
284+ `const b = new B();
285+ return b.value;` ,
286+ undefined , undefined ,
287+ `namespace Classes {
288+ export class Base {
289+ public value: number;
290+ constructor(){ this.value = 3; }
291+ }
292+ }
293+
294+ const A = Classes.Base;
295+ class B extends A {
296+ constructor(){ super(); }
297+ };`
298+ ) ;
299+
300+ // Assert
301+ Expect ( result ) . toBe ( 3 ) ;
302+ }
303+
280304 @Test ( "ClassMethodCall" )
281305 public classMethodCall ( ) : void {
282306 const result = util . transpileAndExecute (
You can’t perform that action at this time.
0 commit comments