@@ -43,14 +43,14 @@ export class LuaPrinter {
4343 private options : CompilerOptions ;
4444 private currentIndent : string ;
4545
46- private sourceFile : string ;
46+ private sourceFile = "" ;
4747
4848 public constructor ( options : CompilerOptions ) {
4949 this . options = options ;
5050 this . currentIndent = "" ;
5151 }
5252
53- public print ( block : tstl . Block , luaLibFeatures ?: Set < LuaLibFeature > , sourceFile ?: string ) : [ string , string ] {
53+ public print ( block : tstl . Block , luaLibFeatures ?: Set < LuaLibFeature > , sourceFile = "" ) : [ string , string ] {
5454 // Add traceback lualib if sourcemap traceback option is enabled
5555 if ( this . options . sourceMapTraceback ) {
5656 if ( luaLibFeatures === undefined ) {
@@ -113,7 +113,7 @@ export class LuaPrinter {
113113 private printImplementation (
114114 block : tstl . Block ,
115115 luaLibFeatures ?: Set < LuaLibFeature > ,
116- sourceFile ?: string ) : SourceNode {
116+ sourceFile = "" ) : SourceNode {
117117
118118 let header = "" ;
119119
@@ -162,13 +162,15 @@ export class LuaPrinter {
162162 private createSourceNode ( node : tstl . Node , chunks : SourceChunk | SourceChunk [ ] ) : SourceNode {
163163 const originalPos = tstl . getOriginalPos ( node ) ;
164164
165- return originalPos !== undefined
165+ return originalPos !== undefined && originalPos . line !== undefined && originalPos . column !== undefined
166166 ? new SourceNode ( originalPos . line + 1 , originalPos . column , this . sourceFile , chunks )
167- : new SourceNode ( undefined , undefined , this . sourceFile , chunks ) ;
167+ // tslint:disable-next-line:no-null-keyword
168+ : new SourceNode ( null , null , this . sourceFile , chunks ) ;
168169 }
169170
170171 private concatNodes ( ...chunks : SourceChunk [ ] ) : SourceNode {
171- return new SourceNode ( undefined , undefined , this . sourceFile , chunks ) ;
172+ // tslint:disable-next-line:no-null-keyword
173+ return new SourceNode ( null , null , this . sourceFile , chunks ) ;
172174 }
173175
174176 private printBlock ( block : tstl . Block ) : SourceNode {
@@ -515,7 +517,7 @@ export class LuaPrinter {
515517 chunks . push ( " " ) ;
516518 const returnNode : SourceChunk [ ] = [
517519 "return " ,
518- ...this . joinChunks ( ", " , returnStatement . expressions . map ( e => this . printExpression ( e ) ) ) ,
520+ ...this . joinChunks ( ", " , returnStatement . expressions ! . map ( e => this . printExpression ( e ) ) ) ,
519521 ] ;
520522 chunks . push ( this . createSourceNode ( returnStatement , returnNode ) ) ;
521523 chunks . push ( " end" ) ;
@@ -616,19 +618,26 @@ export class LuaPrinter {
616618
617619 private printCallExpression ( expression : tstl . CallExpression ) : SourceNode {
618620 const chunks = [ ] ;
619- const parameterChunks = this . joinChunks ( ", " , expression . params . map ( e => this . printExpression ( e ) ) ) ;
620621
621- chunks . push ( this . printExpression ( expression . expression ) , "(" , ...parameterChunks , ")" ) ;
622+ const parameterChunks = expression . params !== undefined
623+ ? expression . params . map ( e => this . printExpression ( e ) )
624+ : [ ] ;
625+
626+ chunks . push ( this . printExpression ( expression . expression ) , "(" , ...this . joinChunks ( ", " , parameterChunks ) , ")" ) ;
622627
623628 return this . concatNodes ( ...chunks ) ;
624629 }
625630
626631 private printMethodCallExpression ( expression : tstl . MethodCallExpression ) : SourceNode {
627632 const prefix = this . printExpression ( expression . prefixExpression ) ;
628- const parameterChunks = this . joinChunks ( ", " , expression . params . map ( e => this . printExpression ( e ) ) ) ;
633+
634+ const parameterChunks = expression . params !== undefined
635+ ? expression . params . map ( e => this . printExpression ( e ) )
636+ : [ ] ;
637+
629638 const name = this . printIdentifier ( expression . name ) ;
630639
631- return this . concatNodes ( prefix , ":" , name , "(" , ...parameterChunks , ")" ) ;
640+ return this . concatNodes ( prefix , ":" , name , "(" , ...this . joinChunks ( ", " , parameterChunks ) , ")" ) ;
632641 }
633642
634643 private printIdentifier ( expression : tstl . Identifier ) : SourceNode {
0 commit comments