@@ -42,7 +42,7 @@ export function transformStringPrototypeCall(
4242 "find" ,
4343 node ,
4444 caller ,
45- params [ 0 ] ,
45+ params [ 0 ] ?? lua . createNilLiteral ( ) ,
4646 params [ 1 ]
4747 ? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0
4848 lua . createCallExpression (
@@ -110,7 +110,7 @@ export function transformStringPrototypeCall(
110110 const literalValue = getNumberLiteralValue ( params [ 0 ] ) ;
111111 // Inline string.sub call if we know that parameter is pure and isn't negative
112112 if ( literalValue !== undefined && literalValue >= 0 ) {
113- const firstParamPlusOne = addToNumericExpression ( params [ 0 ] , 1 ) ;
113+ const firstParamPlusOne = addToNumericExpression ( params [ 0 ] ?? lua . createNilLiteral ( ) , 1 ) ;
114114 return createStringCall ( "sub" , node , caller , firstParamPlusOne , firstParamPlusOne ) ;
115115 }
116116
@@ -122,7 +122,12 @@ export function transformStringPrototypeCall(
122122 // Inline string.sub call if we know that parameter is pure and isn't negative
123123 if ( literalValue !== undefined && literalValue >= 0 ) {
124124 return lua . createBinaryExpression (
125- createStringCall ( "byte" , node , caller , addToNumericExpression ( params [ 0 ] , 1 ) ) ,
125+ createStringCall (
126+ "byte" ,
127+ node ,
128+ caller ,
129+ addToNumericExpression ( params [ 0 ] ?? lua . createNilLiteral ( ) , 1 )
130+ ) ,
126131 createNaN ( ) ,
127132 lua . SyntaxKind . OrOperator
128133 ) ;
@@ -140,7 +145,9 @@ export function transformStringPrototypeCall(
140145 case "repeat" :
141146 const math = lua . createIdentifier ( "math" ) ;
142147 const floor = lua . createStringLiteral ( "floor" ) ;
143- const parameter = lua . createCallExpression ( lua . createTableIndexExpression ( math , floor ) , [ params [ 0 ] ] ) ;
148+ const parameter = lua . createCallExpression ( lua . createTableIndexExpression ( math , floor ) , [
149+ params [ 0 ] ?? lua . createNilLiteral ( ) ,
150+ ] ) ;
144151 return createStringCall ( "rep" , node , caller , parameter ) ;
145152 case "padStart" :
146153 return transformLuaLibFunction ( context , LuaLibFeature . StringPadStart , node , caller , ...params ) ;
0 commit comments