@@ -537,17 +537,21 @@ var LuaTranspiler = /** @class */ (function () {
537537 if ( TSHelper_1 . TSHelper . isArrayType ( type ) )
538538 return this . transpileArrayCallExpression ( node ) ;
539539 }
540- // Include context parameter if present
541540 var expType = this . checker . getTypeAtLocation ( node . expression . expression ) ;
541+ if ( expType . symbol && expType . symbol . escapedName == "Math" ) {
542+ var params_1 = this . transpileArguments ( node . arguments ) ;
543+ return this . transpileMathExpression ( node . expression . name ) + ( "(" + params_1 + ")" ) ;
544+ }
545+ // Include context parameter if present
542546 var callPath_1 = ( expType && expType . symbol ) ? expType . symbol . name + "." + node . expression . name . escapedText : this . transpileExpression ( node . expression ) ;
543- var params_1 = this . transpileArguments ( node . arguments , node . expression . expression ) ;
544- return callPath_1 + "(" + params_1 + ")" ;
547+ var params_2 = this . transpileArguments ( node . arguments , node . expression . expression ) ;
548+ return callPath_1 + "(" + params_2 + ")" ;
545549 }
546550 // Handle super calls properly
547551 if ( node . expression . kind == ts . SyntaxKind . SuperKeyword ) {
548552 var callPath_2 = this . transpileExpression ( node . expression ) ;
549- var params_2 = this . transpileArguments ( node . arguments , ts . createNode ( ts . SyntaxKind . ThisKeyword ) ) ;
550- return "self.__base.constructor(" + params_2 + ")" ;
553+ var params_3 = this . transpileArguments ( node . arguments , ts . createNode ( ts . SyntaxKind . ThisKeyword ) ) ;
554+ return "self.__base.constructor(" + params_3 + ")" ;
551555 }
552556 var callPath = this . transpileExpression ( node . expression ) ;
553557 var params = this . transpileArguments ( node . arguments ) ;
@@ -638,9 +642,42 @@ var LuaTranspiler = /** @class */ (function () {
638642 if ( TSHelper_1 . TSHelper . isCompileMembersOnlyEnum ( type , this . checker ) ) {
639643 return property ;
640644 }
645+ // Catch math expressions
646+ if ( ts . isIdentifier ( node . expression ) && node . expression . escapedText == "Math" ) {
647+ return this . transpileMathExpression ( node . name ) ;
648+ }
641649 var path = this . transpileExpression ( node . expression ) ;
642650 return path + "." + property ;
643651 } ;
652+ // Transpile a Math._ property
653+ LuaTranspiler . prototype . transpileMathExpression = function ( identifier ) {
654+ var translation = {
655+ abs : "abs" ,
656+ acos : "acos" ,
657+ asin : "asin" ,
658+ atan : "atan" ,
659+ ceil : "ceil" ,
660+ cos : "cos" ,
661+ exp : "exp" ,
662+ floor : "floor" ,
663+ log : "log" ,
664+ max : "max" ,
665+ min : "min" ,
666+ PI : "pi" ,
667+ pow : "pow" ,
668+ random : "random" ,
669+ round : "round" ,
670+ sin : "sin" ,
671+ sqrt : "sqrt" ,
672+ tan : "tan"
673+ } ;
674+ if ( translation [ identifier . escapedText ] ) {
675+ return "math." + translation [ identifier . escapedText ] ;
676+ }
677+ else {
678+ throw new TranspileError ( "Unsupported math property " + identifier . escapedText + "." , identifier ) ;
679+ }
680+ } ;
644681 // Transpile access of string properties, only supported properties are allowed
645682 LuaTranspiler . prototype . transpileStringProperty = function ( node ) {
646683 var property = node . name ;
0 commit comments