Vertispan / j2clmavenplugin

Maven plugin to launch new J2CL compilation
https://vertispan.github.io/j2clmavenplugin/
Apache License 2.0
53 stars 26 forks source link

"abc".split("") get error result ["","a","b","c"] #162

Closed xiaoxidashen closed 2 years ago

xiaoxidashen commented 2 years ago

Describe the bug

"abc".split("") get error array ["","a","b","c"]

To Reproduce

use j2clmavenplugin

//in java MathUtil.java
package cn.util;

import jsinterop.annotations.JsType;

@JsType
public class MathUtil {

    public static native void ppp(String s);

    public static void test() {
        String s = "abc";
        ppp(s);
        String[] split = s.split("");
        ppp("String.valueOf(split)"+"["+String.valueOf(split)+"]");
        ppp("split.length "+split.length+"");
        for (String s1 : split) {
            ppp("["+s1+"]");
        }
    }
}
//MathUtil.native.js
setTimeout(function() {

    MathUtil.ppp = function (s) {
        console.log(s);
    }

    MathUtil.test();

}, 0);

get result in browser console

abc
String.valueOf(split)[,a,b,c]
split.length 4
[]
[a]
[b]
[c]

"abc".split("") The expected result is ["a","b","c"]

niloc132 commented 2 years ago

It looks like this is an upstream error, we're going to close this for now, unless we decide it is necessary to patch this in our j2cl fork. Before creating a PR at https://github.com/Vertispan/j2cl, please try to resolve this at google/j2cl.

https://github.com/google/j2cl/issues/143