Hello, everyone. I’m trying to create a multi-platform library. There is a strange problem with JS output.
In my kt file, I export a function like this
@JsExport
fun calculatePrice(
position: FuturePosition,
positionList: List<FuturePosition>,
balanceList: List<FutureBalance>,
bracketList: List<FutureBracket>,
): Double {
val balance = balanceList.find { it.asset == position.collateral } ?: return INVALID_PRICE
and there is my config
js(IR) {
compilations["main"].packageJson {
customField("name", "@orgName/abacus")
}
browser {}
binaries.executable()
}
because it’s a multi-platform library then I run
./gradlew jsBrowserProductionWebpack
It generates a npm package include codes below:
function calculatePrice(position, positionList, balanceList, bracketList) {
var tmp$ret$2;
$l$block_2: {
var tmp$ret$1;
$l$block_1: {
var tmp0_iterator_1_1 = balanceList.iterator_0_k$();
while (tmp0_iterator_1_1.hasNext_0_k$()) {
var element_2_2 = tmp0_iterator_1_1.next_0_k$();
var tmp$ret$0;
$l$block: {
tmp$ret$0 = element_2_2._asset === position._collateral;
break $l$block;
}
if (tmp$ret$0) {
tmp$ret$1 = element_2_2;
break $l$block_1;
} else {
}
}
tmp$ret$1 = null;
break $l$block_1;
}
tmp$ret$2 = tmp$ret$1;
break $l$block_2;
}
it seems that balanceList.find
function convert to iterator_0_k$
and next_0_k$
. But when I call this function in my app, error occurs:
TypeError: balanceList.iterator_0_k$ is not a function
Is there any wrong with my code or config or build command? Why not support List.find function?
Thanks for your reading? any suggestions?