11import * as ts from "typescript" ;
22
33import { CompilerOptions } from "./CommandLineParser" ;
4- import { TSHelper as tsEx } from "./TSHelper" ;
4+ import { TSHelper as tsHelper } from "./TSHelper" ;
55
66import * as path from "path" ;
77
@@ -71,7 +71,7 @@ export class LuaTranspiler {
7171 this . namespace = [ ] ;
7272 this . importCount = 0 ;
7373 this . sourceFile = sourceFile ;
74- this . isModule = tsEx . isFileModule ( sourceFile ) ;
74+ this . isModule = tsHelper . isFileModule ( sourceFile ) ;
7575 }
7676
7777 public pushIndent ( ) : void {
@@ -245,7 +245,7 @@ export class LuaTranspiler {
245245
246246 public transpileNamespace ( node : ts . ModuleDeclaration ) : string {
247247 // If phantom namespace just transpile the body as normal
248- if ( tsEx . isPhantom ( this . checker . getTypeAtLocation ( node ) , this . checker ) && node . body ) {
248+ if ( tsHelper . isPhantom ( this . checker . getTypeAtLocation ( node ) , this . checker ) && node . body ) {
249249 return this . transpileNode ( node . body ) ;
250250 }
251251
@@ -277,7 +277,7 @@ export class LuaTranspiler {
277277 let result = "" ;
278278
279279 const type = this . checker . getTypeAtLocation ( node ) ;
280- const membersOnly = tsEx . isCompileMembersOnlyEnum ( type , this . checker ) ;
280+ const membersOnly = tsHelper . isCompileMembersOnlyEnum ( type , this . checker ) ;
281281
282282 if ( ! membersOnly ) {
283283 const name = node . name . escapedText ;
@@ -386,7 +386,7 @@ export class LuaTranspiler {
386386 const expression = this . transpileExpression ( node . expression ) ;
387387
388388 // Use ipairs for array types, pairs otherwise
389- const isArray = tsEx . isArrayType ( this . checker . getTypeAtLocation ( node . expression ) , this . checker ) ;
389+ const isArray = tsHelper . isArrayType ( this . checker . getTypeAtLocation ( node . expression ) , this . checker ) ;
390390 const pairs = isArray ? "ipairs" : "pairs" ;
391391
392392 // Make header
@@ -408,7 +408,7 @@ export class LuaTranspiler {
408408 // Transpile expression
409409 const expression = this . transpileExpression ( node . expression ) ;
410410
411- if ( tsEx . isArrayType ( this . checker . getTypeAtLocation ( node . expression ) , this . checker ) ) {
411+ if ( tsHelper . isArrayType ( this . checker . getTypeAtLocation ( node . expression ) , this . checker ) ) {
412412 throw new TranspileError ( "Iterating over arrays with 'for in' is not allowed." , node ) ;
413413 }
414414
@@ -462,7 +462,7 @@ export class LuaTranspiler {
462462 this . transpilingSwitch -- ;
463463
464464 let i = index + 1 ;
465- if ( i < clauses . length && ! tsEx . containsStatement ( clause . statements , ts . SyntaxKind . BreakStatement ) ) {
465+ if ( i < clauses . length && ! tsHelper . containsStatement ( clause . statements , ts . SyntaxKind . BreakStatement ) ) {
466466 let nextClause = clauses [ i ] ;
467467 while ( i < clauses . length
468468 && ts . isCaseClause ( nextClause )
@@ -538,8 +538,8 @@ export class LuaTranspiler {
538538 if ( node . expression ) {
539539 // If parent function is a TupleReturn function
540540 // and return expression is an array literal, leave out brackets.
541- const declaration = tsEx . findFirstNodeAbove ( node , ts . isFunctionDeclaration ) ;
542- if ( declaration && tsEx . isTupleReturnFunction ( this . checker . getTypeAtLocation ( declaration ) , this . checker )
541+ const declaration = tsHelper . findFirstNodeAbove ( node , ts . isFunctionDeclaration ) ;
542+ if ( declaration && tsHelper . isTupleReturnFunction ( this . checker . getTypeAtLocation ( declaration ) , this . checker )
543543 && ts . isArrayLiteralExpression ( node . expression ) ) {
544544 return "return " + node . expression . elements . map ( elem => this . transpileExpression ( elem ) ) . join ( "," ) ;
545545 }
@@ -617,7 +617,7 @@ export class LuaTranspiler {
617617 return this . transpileExpression ( ( node as ts . AsExpression ) . expression ) ;
618618 default :
619619 throw new TranspileError (
620- "Unsupported expression kind: " + tsEx . enumName ( node . kind , ts . SyntaxKind ) ,
620+ "Unsupported expression kind: " + tsHelper . enumName ( node . kind , ts . SyntaxKind ) ,
621621 node
622622 ) ;
623623 }
@@ -638,7 +638,7 @@ export class LuaTranspiler {
638638 result = `bit.band(${ lhs } ,${ rhs } )` ;
639639 break ;
640640 case ts . SyntaxKind . AmpersandEqualsToken :
641- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
641+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
642642 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression ,
643643 `bit.band(${ lhs } ,${ rhs } )` ) ;
644644 }
@@ -648,7 +648,7 @@ export class LuaTranspiler {
648648 result = `bit.bor(${ lhs } ,${ rhs } )` ;
649649 break ;
650650 case ts . SyntaxKind . BarEqualsToken :
651- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
651+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
652652 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression ,
653653 `bit.bor(${ lhs } ,${ rhs } )` ) ;
654654 }
@@ -658,7 +658,7 @@ export class LuaTranspiler {
658658 result = `bit.lshift(${ lhs } ,${ rhs } )` ;
659659 break ;
660660 case ts . SyntaxKind . LessThanLessThanEqualsToken :
661- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
661+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
662662 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression ,
663663 `bit.lshift(${ lhs } ,${ rhs } )` ) ;
664664 }
@@ -668,7 +668,7 @@ export class LuaTranspiler {
668668 result = `bit.arshift(${ lhs } ,${ rhs } )` ;
669669 break ;
670670 case ts . SyntaxKind . GreaterThanGreaterThanEqualsToken :
671- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
671+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
672672 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression ,
673673 `bit.arshift(${ lhs } ,${ rhs } )` ) ;
674674 }
@@ -678,7 +678,7 @@ export class LuaTranspiler {
678678 result = `bit.rshift(${ lhs } ,${ rhs } )` ;
679679 break ;
680680 case ts . SyntaxKind . GreaterThanGreaterThanGreaterThanEqualsToken :
681- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
681+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
682682 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression ,
683683 `bit.rshift(${ lhs } ,${ rhs } )` ) ;
684684 }
@@ -691,7 +691,7 @@ export class LuaTranspiler {
691691 result = `${ lhs } &${ rhs } ` ;
692692 break ;
693693 case ts . SyntaxKind . AmpersandEqualsToken :
694- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
694+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
695695 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } &${ rhs } ` ) ;
696696 }
697697 result = `${ lhs } =${ lhs } &${ rhs } ` ;
@@ -700,7 +700,7 @@ export class LuaTranspiler {
700700 result = `${ lhs } |${ rhs } ` ;
701701 break ;
702702 case ts . SyntaxKind . BarEqualsToken :
703- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
703+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
704704 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } |${ rhs } ` ) ;
705705 }
706706 result = `${ lhs } =${ lhs } |${ rhs } ` ;
@@ -709,7 +709,7 @@ export class LuaTranspiler {
709709 result = `${ lhs } <<${ rhs } ` ;
710710 break ;
711711 case ts . SyntaxKind . LessThanLessThanEqualsToken :
712- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
712+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
713713 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } <<${ rhs } ` ) ;
714714 }
715715 result = `${ lhs } =${ lhs } <<${ rhs } ` ;
@@ -718,7 +718,7 @@ export class LuaTranspiler {
718718 result = `${ lhs } >>${ rhs } ` ;
719719 break ;
720720 case ts . SyntaxKind . GreaterThanGreaterThanEqualsToken :
721- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
721+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
722722 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } >>${ rhs } ` ) ;
723723 }
724724 result = `${ lhs } =${ lhs } >>${ rhs } ` ;
@@ -727,7 +727,7 @@ export class LuaTranspiler {
727727 result = `${ lhs } >>>${ rhs } ` ;
728728 break ;
729729 case ts . SyntaxKind . GreaterThanGreaterThanGreaterThanEqualsToken :
730- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
730+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
731731 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } >>>${ rhs } ` ) ;
732732 }
733733 result = `${ lhs } =${ lhs } >>>${ rhs } ` ;
@@ -739,25 +739,25 @@ export class LuaTranspiler {
739739 if ( result === "" ) {
740740 switch ( node . operatorToken . kind ) {
741741 case ts . SyntaxKind . PlusEqualsToken :
742- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
742+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
743743 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } +${ rhs } ` ) ;
744744 }
745745 result = `${ lhs } =${ lhs } +${ rhs } ` ;
746746 break ;
747747 case ts . SyntaxKind . MinusEqualsToken :
748- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
748+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
749749 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } -${ rhs } ` ) ;
750750 }
751751 result = `${ lhs } =${ lhs } -${ rhs } ` ;
752752 break ;
753753 case ts . SyntaxKind . AsteriskEqualsToken :
754- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
754+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
755755 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } *${ rhs } ` ) ;
756756 }
757757 result = `${ lhs } =${ lhs } *${ rhs } ` ;
758758 break ;
759759 case ts . SyntaxKind . SlashEqualsToken :
760- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
760+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
761761 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , `${ lhs } /${ rhs } ` ) ;
762762 }
763763 result = `${ lhs } =${ lhs } /${ rhs } ` ;
@@ -803,7 +803,7 @@ export class LuaTranspiler {
803803 result = `${ lhs } <=${ rhs } ` ;
804804 break ;
805805 case ts . SyntaxKind . EqualsToken :
806- if ( tsEx . hasSetAccessor ( node . left , this . checker ) ) {
806+ if ( tsHelper . hasSetAccessor ( node . left , this . checker ) ) {
807807 return this . transpileSetAccessor ( node . left as ts . PropertyAccessExpression , rhs ) ;
808808 }
809809 result = `${ lhs } =${ rhs } ` ;
@@ -864,7 +864,8 @@ export class LuaTranspiler {
864864 case ts . SyntaxKind . MinusMinusToken :
865865 return `${ operand } =${ operand } -1` ;
866866 default :
867- throw new TranspileError ( "Unsupported unary postfix: " + tsEx . enumName ( node . kind , ts . SyntaxKind ) , node ) ;
867+ throw new TranspileError ( "Unsupported unary postfix: " + tsHelper . enumName ( node . kind , ts . SyntaxKind ) ,
868+ node ) ;
868869 }
869870 }
870871
@@ -880,7 +881,8 @@ export class LuaTranspiler {
880881 case ts . SyntaxKind . MinusToken :
881882 return `-${ operand } ` ;
882883 default :
883- throw new TranspileError ( "Unsupported unary prefix: " + tsEx . enumName ( node . kind , ts . SyntaxKind ) , node ) ;
884+ throw new TranspileError ( "Unsupported unary prefix: " + tsHelper . enumName ( node . kind , ts . SyntaxKind ) ,
885+ node ) ;
884886 }
885887 }
886888
@@ -914,7 +916,7 @@ export class LuaTranspiler {
914916 return this . transpileStringCallExpression ( node ) ;
915917
916918 }
917- if ( tsEx . isArrayType ( expType , this . checker ) ) {
919+ if ( tsHelper . isArrayType ( expType , this . checker ) ) {
918920 return this . transpileArrayCallExpression ( node ) ;
919921 }
920922
@@ -1060,15 +1062,15 @@ export class LuaTranspiler {
10601062 case ts . TypeFlags . StringLiteral :
10611063 return this . transpileStringProperty ( node ) ;
10621064 case ts . TypeFlags . Object :
1063- if ( tsEx . isArrayType ( type , this . checker ) ) {
1065+ if ( tsHelper . isArrayType ( type , this . checker ) ) {
10641066 return this . transpileArrayProperty ( node ) ;
1065- } else if ( tsEx . hasGetAccessor ( node , this . checker ) ) {
1067+ } else if ( tsHelper . hasGetAccessor ( node , this . checker ) ) {
10661068 return this . transpileGetAccessor ( node ) ;
10671069 }
10681070 }
10691071
10701072 // Do not output path for member only enums
1071- if ( tsEx . isCompileMembersOnlyEnum ( type , this . checker ) ) {
1073+ if ( tsHelper . isCompileMembersOnlyEnum ( type , this . checker ) ) {
10721074 return property ;
10731075 }
10741076
@@ -1150,9 +1152,9 @@ export class LuaTranspiler {
11501152 const index = this . transpileExpression ( node . argumentExpression ) ;
11511153
11521154 const type = this . checker . getTypeAtLocation ( node . expression ) ;
1153- if ( tsEx . isArrayType ( type , this . checker ) || tsEx . isTupleType ( type , this . checker ) ) {
1155+ if ( tsHelper . isArrayType ( type , this . checker ) || tsHelper . isTupleType ( type , this . checker ) ) {
11541156 return `${ element } [${ index } +1]` ;
1155- } else if ( tsEx . isStringType ( type ) ) {
1157+ } else if ( tsHelper . isStringType ( type ) ) {
11561158 return `string.sub(${ element } ,${ index } +1,${ index } +1)` ;
11571159 } else {
11581160 return `${ element } [${ index } ]` ;
@@ -1196,15 +1198,16 @@ export class LuaTranspiler {
11961198
11971199 // Don't unpack TupleReturn decorated functions
11981200 if ( ts . isCallExpression ( node . initializer )
1199- && tsEx . isTupleReturnFunction ( this . checker . getTypeAtLocation ( node . initializer . expression ) , this . checker )
1201+ && tsHelper . isTupleReturnFunction ( this . checker . getTypeAtLocation ( node . initializer . expression ) ,
1202+ this . checker )
12001203 ) {
12011204 return `local ${ vars } =${ value } \n` ;
12021205 } else {
12031206 return `local ${ vars } =unpack(${ value } )\n` ;
12041207 }
12051208 } else {
12061209 throw new TranspileError (
1207- "Unsupported variable declaration type " + tsEx . enumName ( node . name . kind , ts . SyntaxKind ) ,
1210+ "Unsupported variable declaration type " + tsHelper . enumName ( node . name . kind , ts . SyntaxKind ) ,
12081211 node
12091212 ) ;
12101213 }
@@ -1314,10 +1317,10 @@ export class LuaTranspiler {
13141317 if ( clause . token === ts . SyntaxKind . ExtendsKeyword ) {
13151318 const superType = this . checker . getTypeAtLocation ( clause . types [ 0 ] ) ;
13161319 // Ignore purely abstract types (decorated with /** @PureAbstract */)
1317- if ( ! tsEx . isPureAbstractClass ( superType , this . checker ) ) {
1320+ if ( ! tsHelper . isPureAbstractClass ( superType , this . checker ) ) {
13181321 extendsType = clause . types [ 0 ] ;
13191322 }
1320- noClassOr = tsEx . hasCustomDecorator ( superType , this . checker , "!NoClassOr" ) ;
1323+ noClassOr = tsHelper . hasCustomDecorator ( superType , this . checker , "!NoClassOr" ) ;
13211324 }
13221325 } ) ;
13231326 }
@@ -1330,7 +1333,7 @@ export class LuaTranspiler {
13301333 let result = "" ;
13311334
13321335 // Skip header if this is an extension class
1333- const isExtension = tsEx . isExtensionClass ( this . checker . getTypeAtLocation ( node ) , this . checker ) ;
1336+ const isExtension = tsHelper . isExtensionClass ( this . checker . getTypeAtLocation ( node ) , this . checker ) ;
13341337 if ( ! isExtension ) {
13351338 // Write class declaration
13361339 const classOr = noClassOr ? "" : `${ className } or ` ;
0 commit comments