From cc198dfdef2b493fe54ac60aaa3113c9d1daad5c Mon Sep 17 00:00:00 2001 From: lightpacerabbit Date: Tue, 23 Jul 2019 18:44:36 +0800 Subject: [PATCH 1/3] Add edge test case. That makes unit test for `string.indexOf` failure. --- test/unit/string.spec.ts | 1 + 1 file changed, 1 insertion(+) 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}")`); From 81bc21d5b68979abf558de3ff9826ef17d1d098b Mon Sep 17 00:00:00 2001 From: lightpacerabbit Date: Tue, 23 Jul 2019 18:47:40 +0800 Subject: [PATCH 2/3] Fix transform `string.indexOf` with out `plain` parameter. --- src/LuaTransformer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/LuaTransformer.ts b/src/LuaTransformer.ts index 4138f2af2..e6b771f03 100644 --- a/src/LuaTransformer.ts +++ b/src/LuaTransformer.ts @@ -4352,7 +4352,14 @@ export class LuaTransformer { case "indexOf": const stringExpression = node.arguments.length === 1 - ? this.createStringCall("find", node, caller, params[0]) + ? this.createStringCall( + "find", + node, + caller, + params[0], + tstl.createNilLiteral(), + tstl.createBooleanLiteral(true) + ) : this.createStringCall( "find", node, From 24825a18c9ee8e954938b53a8c941687b30766e6 Mon Sep 17 00:00:00 2001 From: lightpacerabbit Date: Wed, 24 Jul 2019 11:14:14 +0800 Subject: [PATCH 3/3] Fix make two expressions collapsed to a single call --- src/LuaTransformer.ts | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/LuaTransformer.ts b/src/LuaTransformer.ts index e6b771f03..ac8f49578 100644 --- a/src/LuaTransformer.ts +++ b/src/LuaTransformer.ts @@ -4350,24 +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], - tstl.createNilLiteral(), - tstl.createBooleanLiteral(true) - ) - : 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(