Skip to content

Commit 4686da6

Browse files
committed
forgot to properly handle indexOf
1 parent 2b92bf3 commit 4686da6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/compiler/jsgen.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ class JSGenerator {
399399
const list = this.referenceVariable(node.list);
400400
const idx = this.descendInput(node.item);
401401
if (idx instanceof ConstantInput) {
402-
return new TypedInput(`${list}.value.indexOf(${idx.constantValue})+1`, TYPE_NUMBER);
402+
let val = idx.constantValue;
403+
if (idx.isAlwaysNumberOrNaN()) val = idx.asNumber();
404+
else if (idx.isNeverNumber()) val = idx.asString();
405+
else val = idx.asUnknown();
406+
return new TypedInput(`${list}.value.indexOf(${val})+1`, TYPE_NUMBER);
403407
}
404408
return new TypedInput(`listIndexOf(${list},${idx})`, TYPE_NUMBER);
405409
}

0 commit comments

Comments
 (0)