@@ -47,6 +47,8 @@ export class LuaTransformer {
4747
4848 private checker : ts . TypeChecker ;
4949 protected options : CompilerOptions ;
50+ protected program : ts . Program ;
51+
5052 private isModule : boolean ;
5153
5254 private currentSourceFile ?: ts . SourceFile ;
@@ -68,6 +70,7 @@ export class LuaTransformer {
6870 public constructor ( program : ts . Program , options : CompilerOptions ) {
6971 this . checker = program . getTypeChecker ( ) ;
7072 this . options = options ;
73+ this . program = program ;
7174 this . isStrict = this . options . alwaysStrict || ( this . options . strict && this . options . alwaysStrict !== false ) ||
7275 ( this . isModule && this . options . target && this . options . target >= ts . ScriptTarget . ES2015 ) ;
7376
@@ -3113,7 +3116,7 @@ export class LuaTransformer {
31133116 }
31143117
31153118 const expressionType = this . checker . getTypeAtLocation ( node . expression ) ;
3116- if ( expressionType . symbol && expressionType . symbol . escapedName === "SymbolConstructor" ) {
3119+ if ( tsHelper . isStandardLibraryType ( expressionType , "SymbolConstructor" , this . program ) ) {
31173120 return this . transformLuaLibFunction ( LuaLibFeature . Symbol , node , ...parameters ) ;
31183121 }
31193122
@@ -3132,27 +3135,27 @@ export class LuaTransformer {
31323135 // If the function being called is of type owner.func, get the type of owner
31333136 const ownerType = this . checker . getTypeAtLocation ( node . expression . expression ) ;
31343137
3135- if ( ownerType . symbol && ownerType . symbol . escapedName === "Math" ) {
3138+ if ( tsHelper . isStandardLibraryType ( ownerType , "Math" , this . program ) ) {
31363139 return this . transformMathCallExpression ( node ) ;
31373140 }
31383141
3139- if ( ownerType . symbol && ownerType . symbol . escapedName === "StringConstructor" ) {
3142+ if ( tsHelper . isStandardLibraryType ( ownerType , "Console" , this . program ) ) {
3143+ return this . transformConsoleCallExpression ( node ) ;
3144+ }
3145+
3146+ if ( tsHelper . isStandardLibraryType ( ownerType , "StringConstructor" , this . program ) ) {
31403147 return tstl . createCallExpression (
31413148 this . transformStringExpression ( node . expression . name ) ,
31423149 this . transformArguments ( node . arguments ) ,
31433150 node
31443151 ) ;
31453152 }
31463153
3147- if ( ownerType . symbol && ownerType . symbol . escapedName === "ObjectConstructor" ) {
3154+ if ( tsHelper . isStandardLibraryType ( ownerType , "ObjectConstructor" , this . program ) ) {
31483155 return this . transformObjectCallExpression ( node ) ;
31493156 }
31503157
3151- if ( ownerType . symbol && ownerType . symbol . escapedName === "Console" ) {
3152- return this . transformConsoleCallExpression ( node ) ;
3153- }
3154-
3155- if ( ownerType . symbol && ownerType . symbol . escapedName === "SymbolConstructor" ) {
3158+ if ( tsHelper . isStandardLibraryType ( ownerType , "SymbolConstructor" , this . program ) ) {
31563159 return this . transformSymbolCallExpression ( node ) ;
31573160 }
31583161
@@ -3317,9 +3320,11 @@ export class LuaTransformer {
33173320
33183321 // Catch math expressions
33193322 if ( ts . isIdentifier ( node . expression ) ) {
3320- if ( node . expression . escapedText === "Math" ) {
3323+ const ownerType = this . checker . getTypeAtLocation ( node . expression ) ;
3324+
3325+ if ( tsHelper . isStandardLibraryType ( ownerType , "Math" , this . program ) ) {
33213326 return this . transformMathExpression ( node . name ) ;
3322- } else if ( node . expression . escapedText === "Symbol" ) {
3327+ } else if ( tsHelper . isStandardLibraryType ( ownerType , "Symbol" , this . program ) ) {
33233328 // Pull in Symbol lib
33243329 this . importLuaLibFeature ( LuaLibFeature . Symbol ) ;
33253330 }
0 commit comments