@@ -807,6 +807,11 @@ export abstract class LuaTranspiler {
807807 return this . transpileSpreadElement ( node as ts . SpreadElement ) ;
808808 case ts . SyntaxKind . NonNullExpression :
809809 return this . transpileExpression ( ( node as ts . NonNullExpression ) . expression ) ;
810+ case ts . SyntaxKind . ClassExpression :
811+ this . namespace . push ( "" ) ;
812+ const classDeclaration = this . transpileClass ( node as ts . ClassExpression , "_" ) ;
813+ this . namespace . pop ( ) ;
814+ return `(function() ${ classDeclaration } ; return _ end)()` ;
810815 case ts . SyntaxKind . Block :
811816 this . pushIndent ( ) ;
812817 const ret = "do \n" + this . transpileBlock ( node as ts . Block ) + "end\n" ;
@@ -1615,13 +1620,12 @@ export abstract class LuaTranspiler {
16151620 }
16161621
16171622 // Transpile a class declaration
1618- public transpileClass ( node : ts . ClassDeclaration ) : string {
1619- if ( ! node . name ) {
1623+ public transpileClass ( node : ts . ClassLikeDeclarationBase , nameOverride ?: string ) : string {
1624+ let className = node . name ? this . transpileIdentifier ( node . name ) : nameOverride ;
1625+ if ( ! className ) {
16201626 throw TSTLErrors . MissingClassName ( node ) ;
16211627 }
16221628
1623- let className = this . transpileIdentifier ( node . name ) ;
1624-
16251629 const decorators = tsHelper . getCustomDecorators ( this . checker . getTypeAtLocation ( node ) , this . checker ) ;
16261630
16271631 // Find out if this class is extension of existing class
@@ -1667,7 +1671,7 @@ export abstract class LuaTranspiler {
16671671 }
16681672
16691673 if ( ! isExtension && ! isMetaExtension ) {
1670- result += this . transpileClassCreationMethods ( node , instanceFields , extendsType ) ;
1674+ result += this . transpileClassCreationMethods ( node , className , instanceFields , extendsType ) ;
16711675 } else {
16721676 for ( const f of instanceFields ) {
16731677 // Get identifier
@@ -1716,10 +1720,9 @@ export abstract class LuaTranspiler {
17161720 return result ;
17171721 }
17181722
1719- public transpileClassCreationMethods ( node : ts . ClassDeclaration , instanceFields : ts . PropertyDeclaration [ ] ,
1723+ public transpileClassCreationMethods ( node : ts . ClassLikeDeclarationBase , className : string ,
1724+ instanceFields : ts . PropertyDeclaration [ ] ,
17201725 extendsType : ts . Type ) : string {
1721- const className = this . transpileIdentifier ( node . name ) ;
1722-
17231726 let noClassOr = false ;
17241727 if ( extendsType ) {
17251728 const decorators = tsHelper . getCustomDecorators ( extendsType , this . checker ) ;
0 commit comments