@@ -107,7 +107,7 @@ export abstract class LuaTranspiler {
107107 "local " : "" ;
108108 }
109109
110- public pushExport ( nameIn : string , nodeIn : ts . Node , dummyIn : boolean = false ) {
110+ public pushExport ( nameIn : string , nodeIn : ts . Node , dummyIn : boolean = false ) : void {
111111 this . exportStack [ this . exportStack . length - 1 ] . push ( { name : nameIn , node : nodeIn , dummy : dummyIn } ) ;
112112 }
113113
@@ -135,24 +135,23 @@ export abstract class LuaTranspiler {
135135
136136 public makeExports ( ) : string {
137137 let result = "" ;
138- this . exportStack . pop ( ) . forEach (
139- exp => result += this . makeExport ( exp . name , exp . node , exp . dummy ) ) ;
138+ this . exportStack . pop ( ) . forEach ( exp => result += this . makeExport ( exp . name , exp . node , exp . dummy ) ) ;
140139 return result ;
141140 }
142141
143- public importLuaLibFeature ( feature : LuaLibFeature ) {
142+ public importLuaLibFeature ( feature : LuaLibFeature ) : void {
144143 // TODO inline imported features in output i option set
145144 this . luaLibFeatureSet . add ( feature ) ;
146145 }
147146
148- public getAbsoluteImportPath ( relativePath : string ) {
147+ public getAbsoluteImportPath ( relativePath : string ) : string {
149148 if ( relativePath . charAt ( 0 ) !== "." && this . options . baseUrl ) {
150149 return path . resolve ( this . options . baseUrl , relativePath ) ;
151150 }
152151 return path . resolve ( path . dirname ( this . sourceFile . fileName ) , relativePath ) ;
153152 }
154153
155- public getImportPath ( relativePath : string ) {
154+ public getImportPath ( relativePath : string ) : string {
156155 // Calculate absolute path to import
157156 const absolutePathToImport = this . getAbsoluteImportPath ( relativePath ) ;
158157 if ( this . options . rootDir ) {
@@ -166,7 +165,7 @@ export abstract class LuaTranspiler {
166165 return `"${ this . pathToLuaRequirePath ( relativePath ) } "` ;
167166 }
168167
169- public pathToLuaRequirePath ( filePath : string ) {
168+ public pathToLuaRequirePath ( filePath : string ) : string {
170169 return filePath . replace ( new RegExp ( "\\\\|\/" , "g" ) , "." ) ;
171170 }
172171
@@ -299,19 +298,20 @@ export abstract class LuaTranspiler {
299298 if ( ts . isNamedImports ( imports ) ) {
300299 const fileImportTable = path . basename ( importPathWithoutQuotes ) + this . importCount ;
301300 const resolvedImportPath = this . getImportPath ( importPathWithoutQuotes ) ;
301+
302302 let result = `local ${ fileImportTable } = require(${ resolvedImportPath } )\n` ;
303303 this . importCount ++ ;
304+
304305 imports . elements . forEach ( element => {
305306 const nameText = this . transpileIdentifier ( element . name ) ;
306307 if ( element . propertyName ) {
307308 const propertyText = this . transpileIdentifier ( element . propertyName ) ;
308- result +=
309- `local ${ nameText } = ${ fileImportTable } .${ propertyText } \n` ;
309+ result += `local ${ nameText } = ${ fileImportTable } .${ propertyText } \n` ;
310310 } else {
311- result +=
312- `local ${ nameText } = ${ fileImportTable } .${ nameText } \n` ;
311+ result += `local ${ nameText } = ${ fileImportTable } .${ nameText } \n` ;
313312 }
314313 } ) ;
314+
315315 return result ;
316316 } else if ( ts . isNamespaceImport ( imports ) ) {
317317 const resolvedImportPath = this . getImportPath ( importPathWithoutQuotes ) ;
@@ -875,7 +875,7 @@ export abstract class LuaTranspiler {
875875 throw new TranspileError ( `Bit operations are not supported in Lua ${ this . options . target } ` , node ) ;
876876 }
877877
878- public transpileTemplateExpression ( node : ts . TemplateExpression ) {
878+ public transpileTemplateExpression ( node : ts . TemplateExpression ) : string {
879879 const parts = [ `"${ node . head . text } "` ] ;
880880 node . templateSpans . forEach ( span => {
881881 const expr = this . transpileExpression ( span . expression , true ) ;
@@ -963,7 +963,7 @@ export abstract class LuaTranspiler {
963963 return isTupleReturn && ! isInDestructingAssignment ? `({ ${ callPath } (${ params } ) })` : `${ callPath } (${ params } )` ;
964964 }
965965
966- public transpilePropertyCall ( node : ts . CallExpression ) {
966+ public transpilePropertyCall ( node : ts . CallExpression ) : string {
967967 let params ;
968968 let callPath ;
969969
@@ -1240,6 +1240,8 @@ export abstract class LuaTranspiler {
12401240 }
12411241 }
12421242
1243+ // Counter-act typescript's identifier escaping:
1244+ // https://github.com/Microsoft/TypeScript/blob/master/src/compiler/utilities.ts#L556
12431245 public transpileIdentifier ( identifier : ts . Identifier ) : string {
12441246 const escapedText = identifier . escapedText as string ;
12451247 const underScoreCharCode = "_" . charCodeAt ( 0 ) ;
@@ -1254,7 +1256,7 @@ export abstract class LuaTranspiler {
12541256
12551257 public transpileArrayBindingElement ( name : ts . ArrayBindingElement ) : string {
12561258 if ( ts . isOmittedExpression ( name ) ) {
1257- return "_ " ;
1259+ return "__ " ;
12581260 } else if ( ts . isIdentifier ( name ) ) {
12591261 return this . transpileIdentifier ( name ) ;
12601262 } else {
@@ -1274,8 +1276,8 @@ export abstract class LuaTranspiler {
12741276
12751277 node . declarationList . declarations . forEach ( declaration => {
12761278 result += this . transpileVariableDeclaration ( declaration as ts . VariableDeclaration ) ;
1277- if ( ts . isIdentifier ( ( declaration . name as ts . Identifier ) ) ) {
1278- this . pushExport ( this . transpileIdentifier ( ( declaration . name as ts . Identifier ) ) , node ) ;
1279+ if ( ts . isIdentifier ( declaration . name ) ) {
1280+ this . pushExport ( this . transpileIdentifier ( declaration . name as ts . Identifier ) , node ) ;
12791281 }
12801282 } ) ;
12811283
@@ -1301,9 +1303,7 @@ export abstract class LuaTranspiler {
13011303 throw new TranspileError ( `Ellipsis destruction is not allowed.` , node ) ;
13021304 }
13031305
1304- const vars = node . name . elements . map (
1305- element =>
1306- ( this . transpileIdentifier ( ( element as ts . BindingElement ) . name as ts . Identifier ) ) ) . join ( "," ) ;
1306+ const vars = node . name . elements . map ( this . transpileArrayBindingElement ) . join ( "," ) ;
13071307
13081308 // Don't unpack TupleReturn decorated functions
13091309 if ( tsHelper . isTupleReturnCall ( node . initializer , this . checker ) ) {
0 commit comments