@@ -47,6 +47,9 @@ var LuaTranspiler = /** @class */ (function () {
4747 LuaTranspiler . prototype . popIndent = function ( ) {
4848 this . indent = this . indent . slice ( 4 ) ;
4949 } ;
50+ LuaTranspiler . prototype . definitionName = function ( name ) {
51+ return this . namespace . concat ( name ) . join ( "." ) ;
52+ } ;
5053 // Transpile a block
5154 LuaTranspiler . prototype . transpileBlock = function ( node ) {
5255 var _this = this ;
@@ -73,6 +76,10 @@ var LuaTranspiler = /** @class */ (function () {
7376 return this . transpileImport ( node ) ;
7477 case ts . SyntaxKind . ClassDeclaration :
7578 return this . transpileClass ( node ) ;
79+ case ts . SyntaxKind . ModuleDeclaration :
80+ return this . transpileNamespace ( node ) ;
81+ case ts . SyntaxKind . ModuleBlock :
82+ return this . transpileBlock ( node ) ;
7683 case ts . SyntaxKind . EnumDeclaration :
7784 return this . transpileEnum ( node ) ;
7885 case ts . SyntaxKind . FunctionDeclaration :
@@ -128,14 +135,26 @@ var LuaTranspiler = /** @class */ (function () {
128135 throw new TranspileError ( "Unsupported import type." , node ) ;
129136 }
130137 } ;
138+ LuaTranspiler . prototype . transpileNamespace = function ( node ) {
139+ // If phantom namespace just transpile the body as normal
140+ if ( TSHelper_1 . TSHelper . isPhantom ( this . checker . getTypeAtLocation ( node ) ) )
141+ return this . transpileNode ( node . body ) ;
142+ var defName = this . definitionName ( node . name . text ) ;
143+ var result = this . indent + ( defName + " = {}\n" ) ;
144+ this . namespace . push ( node . name . text ) ;
145+ result += this . transpileNode ( node . body ) ;
146+ this . namespace . pop ( ) ;
147+ return result ;
148+ } ;
131149 LuaTranspiler . prototype . transpileEnum = function ( node ) {
132150 var _this = this ;
133151 var val = 0 ;
134152 var result = "" ;
135153 var type = this . checker . getTypeAtLocation ( node ) ;
136154 var membersOnly = TSHelper_1 . TSHelper . isCompileMembersOnlyEnum ( type ) ;
137155 if ( ! membersOnly ) {
138- result += this . indent + ( node . name . escapedText + "={}\n" ) ;
156+ var defName = this . definitionName ( node . name . escapedText ) ;
157+ result += this . indent + ( defName + "={}\n" ) ;
139158 }
140159 node . members . forEach ( function ( member ) {
141160 if ( member . initializer ) {
@@ -146,12 +165,13 @@ var LuaTranspiler = /** @class */ (function () {
146165 throw new TranspileError ( "Only numeric initializers allowed for enums." , node ) ;
147166 }
148167 }
149- var name = member . name . escapedText ;
150168 if ( membersOnly ) {
151- result += _this . indent + ( name + "=" + val + "\n" ) ;
169+ var defName = _this . definitionName ( name ) ;
170+ result += _this . indent + ( defName + "=" + val + "\n" ) ;
152171 }
153172 else {
154- result += _this . indent + ( node . name . escapedText + "." + name + "=" + val + "\n" ) ;
173+ var defName = _this . definitionName ( node . name . escapedText + "." + member . name . escapedText ) ;
174+ result += _this . indent + ( defName + "=" + val + "\n" ) ;
155175 }
156176 val ++ ;
157177 } ) ;
@@ -646,7 +666,7 @@ var LuaTranspiler = /** @class */ (function () {
646666 paramNames . push ( param . name . escapedText ) ;
647667 } ) ;
648668 // Build function header
649- result += this . indent + ( "function " + methodName + "(" + paramNames . join ( "," ) + ")\n" ) ;
669+ result += this . indent + ( "function " + this . definitionName ( methodName ) + "(" + paramNames . join ( "," ) + ")\n" ) ;
650670 this . pushIndent ( ) ;
651671 result += this . transpileBlock ( body ) ;
652672 this . popIndent ( ) ;
0 commit comments