Skip to content

Commit f9f5fd7

Browse files
lightrabbitPerryvw
authored andcommitted
Fix transform string.indexOf with out plain parameter. (#679)
* Add edge test case. That makes unit test for `string.indexOf` failure. * Fix transform `string.indexOf` with out `plain` parameter. * Fix make two expressions collapsed to a single call
1 parent f7cb2a2 commit f9f5fd7

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/LuaTransformer.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,17 +4350,14 @@ export class LuaTransformer {
43504350
case "concat":
43514351
return this.transformLuaLibFunction(LuaLibFeature.StringConcat, node, caller, ...params);
43524352
case "indexOf":
4353-
const stringExpression =
4354-
node.arguments.length === 1
4355-
? this.createStringCall("find", node, caller, params[0])
4356-
: this.createStringCall(
4357-
"find",
4358-
node,
4359-
caller,
4360-
params[0],
4361-
this.expressionPlusOne(params[1]),
4362-
tstl.createBooleanLiteral(true)
4363-
);
4353+
const stringExpression = this.createStringCall(
4354+
"find",
4355+
node,
4356+
caller,
4357+
params[0],
4358+
params[1] ? this.expressionPlusOne(params[1]) : tstl.createNilLiteral(),
4359+
tstl.createBooleanLiteral(true)
4360+
);
43644361

43654362
return tstl.createParenthesizedExpression(
43664363
tstl.createBinaryExpression(

test/unit/string.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ test.each([
132132
{ inp: "hello test", searchValue: "t" },
133133
{ inp: "hello test", searchValue: "h" },
134134
{ inp: "hello test", searchValue: "invalid" },
135+
{ inp: "hello.test", searchValue: "." },
135136
])("string.indexOf (%p)", ({ inp, searchValue }) => {
136137
const result = util.transpileAndExecute(`return "${inp}".indexOf("${searchValue}")`);
137138

0 commit comments

Comments
 (0)