diff --git a/src/LuaTransformer.ts b/src/LuaTransformer.ts index 4138f2af2..ac8f49578 100644 --- a/src/LuaTransformer.ts +++ b/src/LuaTransformer.ts @@ -4350,17 +4350,14 @@ export class LuaTransformer { case "concat": return this.transformLuaLibFunction(LuaLibFeature.StringConcat, node, caller, ...params); case "indexOf": - const stringExpression = - node.arguments.length === 1 - ? this.createStringCall("find", node, caller, params[0]) - : this.createStringCall( - "find", - node, - caller, - params[0], - this.expressionPlusOne(params[1]), - tstl.createBooleanLiteral(true) - ); + const stringExpression = this.createStringCall( + "find", + node, + caller, + params[0], + params[1] ? this.expressionPlusOne(params[1]) : tstl.createNilLiteral(), + tstl.createBooleanLiteral(true) + ); return tstl.createParenthesizedExpression( tstl.createBinaryExpression( diff --git a/test/unit/string.spec.ts b/test/unit/string.spec.ts index 8768818cf..9590c478d 100644 --- a/test/unit/string.spec.ts +++ b/test/unit/string.spec.ts @@ -132,6 +132,7 @@ test.each([ { inp: "hello test", searchValue: "t" }, { inp: "hello test", searchValue: "h" }, { inp: "hello test", searchValue: "invalid" }, + { inp: "hello.test", searchValue: "." }, ])("string.indexOf (%p)", ({ inp, searchValue }) => { const result = util.transpileAndExecute(`return "${inp}".indexOf("${searchValue}")`);