Skip to content

Version 1.1.0: major release with more Java support and built-in bundling

Compare
Choose a tag to compare
@renaudpawlak renaudpawlak released this 25 May 12:05
· 1334 commits to master since this release

Changes

More Java support

  • Field are allowed to have the same name as a method name. For instance the following code is now valid in JSweet:
    public class C {
        private int size;
        public int size() {
            return size;
        }
    }
  • More general support for complex overloading (methods and constructors). JSweet now emulates the Java behavior when overloads are detected. For example, the following code is now valid in JSweet (and behaves as expected by Java programmers):
    public class C {
        private int size;
        public int size() {
            return size;
        }
        public int size(int addTo) {
            return size + addTo;
        }
        public int size(String string) {
            return string.length;
        }
    }
  • Support for inner classes (both static and non-static). In the non-static case, the enclosing instances fields can be accessed preserving the Java semantics.
  • Support for default methods in interfaces
  • Support for static methods in interfaces
  • Support for JSNI (support to help forking GWT's JRE emulation...)
    public native void m() /*-{
       // JS code
    }-*/
  • Preserve Java integer semantics (for example, a cast to an int will be rounded)
  • Preserve Java array allocation semantics for any dimension
    String[][] array = new String[2][2];
    assert array.length == 2;
    assert array[0].length == 2;
  • Add 'instanceof' support (valid for classes and interfaces)
    assert "abc" instanceof String;
    assert true instanceof Boolean;
    Object object = new MyInterface() { ... };
    assert object instanceof MyInterface;
  • Add jsweet.util.Globals.typeof helper method to generate the typeof JavaScript operator:
    assert typeof("abc") === "string";
  • Change the == operator semantics to be closer to Java
    o1 == o2; now generates: o1 === o2;
    o1 != o2; => o1 !== o2;
    Because of the null/undefined duality in JavaScript, there are exceptions when comparing to null literal:   
    o == null; => o == null;
    null == o; => null == o;
    o != null; => o != null;
    null != o; => null != o;
  • Better mapping of some binary operators to TypeScript (for instance XOR and arithmetic operators on chars)
  • To control the use of == and === operators, add some helper methods:
    jsweet.util.Globals.equalsStrict => ===
    jsweet.util.Globals.notEqualsStrict => ===
    jsweet.util.Globals.equalsLoose => ==
    jsweet.util.Globals.notEqualsLoose => ==
  • Add jsweet.util.Globals.$map helper method for easy construction of untyped maps
    $map("a", 1, "b", true) transpiles to {"a": 1, "b": true}
  • Add support for labels
  • Add jsweet.util.Globals.any helper method, which completely erase typing (similar to a cast in TypeScript)
  • Emulate Java behavior for static field initialization and static initializers so that there are no initialization ordering issues. Static field are lazily initialized.
  • Support for anonymous classes (both static and non-static).
    int i = 2;
    void m() {
        return new Comparator<String> {
            @Override
            public int compareTo(String s1, String s2) {
                System.out.println("here I can access enclosing class fields: "+i);
                return ...;
            }
        };
    }
  • Support for final variables accesses from anonymous classes.
    void m() {
        final int i = 3;
        return new Comparator<String> {
            @Override
            public int compareTo(String s1, String s2) {
                System.out.println("here I can access final variables: "+i);
                return ...;
            }
        };
    }
  • Default initialization of fields as expected by Java programmers (numbers are initialized with 0, booleans with false).
  • Add various built-in macros to support core Java APIs:
    XX.class.getName()
    XX.class.getSimpleName()
    java.lang.Math.*
    java.lang.String.*

New bundles

  • Support for much more robust TypeScript/JavaScript bundles:
    • static-based and inheritance-based permutation to ensure correct ordering of classes
    • lazy initialization of static fields to avoid ordering issues
    • fix performance issue when calculating line numbers
    • use qualified names to avoid explicit imports (which may break the bundle)

Removed features

  • Strict mode removed (having J4TS and various macros implemented are two different visions that are not compatible and we do not have time to maintain both)
  • Removed former bundle support delegating to Browserify