@@ -31,10 +31,7 @@ const escapeString = (value: string) => `"${value.replace(escapeStringRegExp, ch
3131 * `foo.bar` => passes (`function foo.bar()` is valid)
3232 * `getFoo().bar` => fails (`function getFoo().bar()` would be illegal)
3333 */
34- function isValidLuaFunctionDeclarationName ( str : string ) : boolean {
35- const match = str . match ( / [ a - z A - Z 0 - 9 _ \. ] + / ) ;
36- return match !== null && match [ 0 ] === str ;
37- }
34+ const isValidLuaFunctionDeclarationName = ( str : string ) => / ^ [ a - z A - Z 0 - 9 _ \. ] + $ / . test ( str ) ;
3835
3936/**
4037 * Returns true if expression contains no function calls.
@@ -172,24 +169,21 @@ export class LuaPrinter {
172169 }
173170
174171 private printStackTraceOverride ( rootNode : SourceNode ) : string {
175- let line = 1 ;
176- const map : { [ line : number ] : number } = { } ;
172+ let currentLine = 1 ;
173+ const map : Record < number , number > = { } ;
177174 rootNode . walk ( ( chunk , mappedPosition ) => {
178175 if ( mappedPosition . line !== undefined && mappedPosition . line > 0 ) {
179- if ( map [ line ] === undefined ) {
180- map [ line ] = mappedPosition . line ;
176+ if ( map [ currentLine ] === undefined ) {
177+ map [ currentLine ] = mappedPosition . line ;
181178 } else {
182- map [ line ] = Math . min ( map [ line ] , mappedPosition . line ) ;
179+ map [ currentLine ] = Math . min ( map [ currentLine ] , mappedPosition . line ) ;
183180 }
184181 }
185- line += chunk . split ( "\n" ) . length - 1 ;
186- } ) ;
187182
188- const mapItems = [ ] ;
189- for ( const lineNr in map ) {
190- mapItems . push ( `["${ lineNr } "] = ${ map [ lineNr ] } ` ) ;
191- }
183+ currentLine += chunk . split ( "\n" ) . length - 1 ;
184+ } ) ;
192185
186+ const mapItems = Object . entries ( map ) . map ( ( [ line , original ] ) => `["${ line } "] = ${ original } ` ) ;
193187 const mapString = "{" + mapItems . join ( "," ) + "}" ;
194188
195189 return `__TS__SourceMapTraceBack(debug.getinfo(1).short_src, ${ mapString } );` ;
@@ -203,15 +197,14 @@ export class LuaPrinter {
203197 }
204198
205199 const luaLibImport = this . options . luaLibImport || LuaLibImportKind . Inline ;
206- // Require lualib bundle
207200 if (
208- ( luaLibImport === LuaLibImportKind . Require && luaLibFeatures . size > 0 ) ||
209- luaLibImport === LuaLibImportKind . Always
201+ luaLibImport === LuaLibImportKind . Always ||
202+ ( luaLibImport === LuaLibImportKind . Require && luaLibFeatures . size > 0 )
210203 ) {
204+ // Require lualib bundle
211205 header += `require("lualib_bundle");\n` ;
212- }
213- // Inline lualib features
214- else if ( luaLibImport === LuaLibImportKind . Inline && luaLibFeatures . size > 0 ) {
206+ } else if ( luaLibImport === LuaLibImportKind . Inline && luaLibFeatures . size > 0 ) {
207+ // Inline lualib features
215208 header += "-- Lua Library inline imports\n" ;
216209 header += loadLuaLibFeatures ( luaLibFeatures , this . emitHost ) ;
217210 }
0 commit comments