@@ -33,7 +33,7 @@ var LuaTranspiler = /** @class */ (function () {
3333 // Transpile a source file
3434 LuaTranspiler . transpileSourceFile = function ( node , checker ) {
3535 var transpiler = new LuaTranspiler ( checker ) ;
36- return transpiler . transpileBlock ( node ) ;
36+ return "require(\"lib.typescript\")\n" + transpiler . transpileBlock ( node ) ;
3737 } ;
3838 LuaTranspiler . prototype . pushIndent = function ( ) {
3939 this . indent = this . indent + " " ;
@@ -311,7 +311,7 @@ var LuaTranspiler = /** @class */ (function () {
311311 return this . transpileObjectLiteral ( node ) ;
312312 case ts . SyntaxKind . FunctionExpression :
313313 case ts . SyntaxKind . ArrowFunction :
314- return this . transpileFunctionExpression ( node ) ;
314+ return this . transpileArrowFunction ( node ) ;
315315 case ts . SyntaxKind . NewExpression :
316316 return this . transpileNewExpression ( node ) ;
317317 case ts . SyntaxKind . ComputedPropertyName :
@@ -365,7 +365,7 @@ var LuaTranspiler = /** @class */ (function () {
365365 var condition = this . transpileExpression ( node . condition ) ;
366366 var val1 = this . transpileExpression ( node . whenTrue ) ;
367367 var val2 = this . transpileExpression ( node . whenFalse ) ;
368- return "ITE (" + condition + ",function() return " + val1 + " end, function() return " + val2 + " end)" ;
368+ return "TS_ITE (" + condition + ",function() return " + val1 + " end, function() return " + val2 + " end)" ;
369369 } ;
370370 // Replace some missmatching operators
371371 LuaTranspiler . prototype . transpileOperator = function ( operator ) {
@@ -699,6 +699,23 @@ var LuaTranspiler = /** @class */ (function () {
699699 this . popIndent ( ) ;
700700 return result + this . indent + "end " ;
701701 } ;
702+ LuaTranspiler . prototype . transpileArrowFunction = function ( node ) {
703+ // Build parameter string
704+ var paramNames = [ ] ;
705+ node . parameters . forEach ( function ( param ) {
706+ paramNames . push ( param . name . escapedText ) ;
707+ } ) ;
708+ if ( ts . isBlock ( node . body ) ) {
709+ var result = "function(" + paramNames . join ( "," ) + ")\n" ;
710+ this . pushIndent ( ) ;
711+ result += this . transpileBlock ( node . body ) ;
712+ this . popIndent ( ) ;
713+ return result + this . indent + "end " ;
714+ }
715+ else {
716+ return "function(" + paramNames . join ( "," ) + ") return " + this . transpileExpression ( node . body ) + " end" ;
717+ }
718+ } ;
702719 return LuaTranspiler ;
703720} ( ) ) ;
704721exports . LuaTranspiler = LuaTranspiler ;
0 commit comments