cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

Transpilation issue with `super` #544

Closed lapo-luchini closed 4 years ago

lapo-luchini commented 4 years ago

This could be a duplicate of #147 but as far as I can read there it was just side-stepped.

I generated a minimal test-case that fails:

public class Test extends HashMap<String, Object> {

    public Test() {
    }

    @Override
    public boolean containsKey(Object key) {
        return get(key) != null;
    }

    @Override
    public Object get(Object key) {
        Object o = super.get(key);
        if ("null".equals(o))
            return null;
        return o;
    }

}

and fails like this:

$ gradle jsweet
[…]
> Task :jsweet FAILED
'super' must be followed by an argument list or member access at /home/lapo/svn/java/pdf.parser/trunk/java2js.minimal/t/src/main/java/Test.java(15)

Using tsOnly hides the error, but the produced TS still fails to compile with the same error, and the code indeed looks strange, with super used like a variable name:

    public get(key : any) : any {
        let o : any = /* get */((m,k) => m[k]===undefined?null:m[k])(super, key);
        if(/* equals */(<any>((o1: any, o2: any) => { if(o1 && o1.equals) { return o1.equals(o2); } else { return o1 === o2; } })("null",o))) return null;
        return o;
    }

Full test-case: super.zip

lgrignon commented 4 years ago

Hello, This seems to be a nice one, thanks for reporting!

I will take a look

lgrignon commented 4 years ago

It is fixed (added a unit test) and deployed on Maven / Gradle repo

lgrignon commented 4 years ago

2.3.5-SNAPSHOT

lapo-luchini commented 4 years ago

I tried 2.3.6-SNAPSHOT and it worked, thanks!