@@ -163,12 +163,12 @@ var LuaTranspiler = /** @class */ (function () {
163163 var condition = this . transpileExpression ( node . expression ) ;
164164 var result = this . indent + ( "if " + condition + " then\n" ) ;
165165 this . pushIndent ( ) ;
166- result += this . transpileBlock ( node . thenStatement ) ;
166+ result += this . transpileStatement ( node . thenStatement ) ;
167167 this . popIndent ( ) ;
168168 if ( node . elseStatement ) {
169169 result += this . indent + "else\n" ;
170170 this . pushIndent ( ) ;
171- result += this . transpileBlock ( node . elseStatement ) ;
171+ result += this . transpileStatement ( node . elseStatement ) ;
172172 this . popIndent ( ) ;
173173 }
174174 return result + this . indent + "end\n" ;
@@ -177,7 +177,7 @@ var LuaTranspiler = /** @class */ (function () {
177177 var condition = this . transpileExpression ( node . expression ) ;
178178 var result = this . indent + ( "while " + condition + " do\n" ) ;
179179 this . pushIndent ( ) ;
180- result += this . transpileBlock ( node . statement ) ;
180+ result += this . transpileStatement ( node . statement ) ;
181181 this . popIndent ( ) ;
182182 return result + this . indent + "end\n" ;
183183 } ;
@@ -193,7 +193,7 @@ var LuaTranspiler = /** @class */ (function () {
193193 var result = this . indent + ( "for " + identifier . escapedText + "=" + start + "," + end + "," + step + " do\n" ) ;
194194 // Add body
195195 this . pushIndent ( ) ;
196- result += this . transpileBlock ( node . statement ) ;
196+ result += this . transpileStatement ( node . statement ) ;
197197 this . popIndent ( ) ;
198198 return result + this . indent + "end\n" ;
199199 } ;
@@ -204,13 +204,13 @@ var LuaTranspiler = /** @class */ (function () {
204204 // Transpile expression
205205 var expression = this . transpileExpression ( node . expression ) ;
206206 // Use ipairs for array types, pairs otherwise
207- var isArray = this . checker . getTypeAtLocation ( node . expression ) . symbol . escapedName == "Array" ;
207+ var isArray = TSHelper_1 . TSHelper . isArrayType ( this . checker . getTypeAtLocation ( node . expression ) ) ;
208208 var pairs = isArray ? "ipairs" : "pairs" ;
209209 // Make header
210210 var result = this . indent + ( "for _, " + identifier . escapedText + " in " + pairs + "(" + expression + ") do\n" ) ;
211211 // For body
212212 this . pushIndent ( ) ;
213- result += this . transpileBlock ( node . statement ) ;
213+ result += this . transpileStatement ( node . statement ) ;
214214 this . popIndent ( ) ;
215215 return result + this . indent + "end\n" ;
216216 } ;
@@ -221,16 +221,24 @@ var LuaTranspiler = /** @class */ (function () {
221221 // Transpile expression
222222 var expression = this . transpileExpression ( node . expression ) ;
223223 // Use ipairs for array types, pairs otherwise
224- var isArray = this . checker . getTypeAtLocation ( node . expression ) . symbol . escapedName == "Array" ;
224+ var isArray = TSHelper_1 . TSHelper . isArrayType ( this . checker . getTypeAtLocation ( node . expression ) ) ;
225225 var pairs = isArray ? "ipairs" : "pairs" ;
226226 // Make header
227227 var result = this . indent + ( "for " + identifier . escapedText + ", _ in " + pairs + "(" + expression + ") do\n" ) ;
228228 // For body
229229 this . pushIndent ( ) ;
230- result += this . transpileBlock ( node . statement ) ;
230+ result += this . transpileStatement ( node . statement ) ;
231231 this . popIndent ( ) ;
232232 return result + this . indent + "end\n" ;
233233 } ;
234+ LuaTranspiler . prototype . transpileStatement = function ( node ) {
235+ if ( ts . isBlock ( node ) ) {
236+ return this . transpileBlock ( node ) ;
237+ }
238+ else {
239+ return this . transpileNode ( node ) ;
240+ }
241+ } ;
234242 LuaTranspiler . prototype . transpileSwitch = function ( node ) {
235243 var _this = this ;
236244 var expression = this . transpileExpression ( node . expression , true ) ;
@@ -697,7 +705,7 @@ var LuaTranspiler = /** @class */ (function () {
697705 this . pushIndent ( ) ;
698706 result += this . transpileBlock ( node . body ) ;
699707 this . popIndent ( ) ;
700- return result + this . indent + "end " ;
708+ return result + this . indent + "end\n " ;
701709 } ;
702710 LuaTranspiler . prototype . transpileArrowFunction = function ( node ) {
703711 // Build parameter string
@@ -710,7 +718,7 @@ var LuaTranspiler = /** @class */ (function () {
710718 this . pushIndent ( ) ;
711719 result += this . transpileBlock ( node . body ) ;
712720 this . popIndent ( ) ;
713- return result + this . indent + "end " ;
721+ return result + this . indent + "end\n " ;
714722 }
715723 else {
716724 return "function(" + paramNames . join ( "," ) + ") return " + this . transpileExpression ( node . body ) + " end" ;
0 commit comments