google / jsinterop-generator

Generates Java annotated with JsInterop from JavaScript extern sources
Apache License 2.0
75 stars 24 forks source link

Infinite loop when transpiling to Java html5.js from Closure Compiler contribs. #42

Open didier-durand opened 4 years ago

didier-durand commented 4 years ago

Hello,

We are working on providing to the GWT community Java bindings (Java source code) to many standard Javascript libraries: see https://github.com/didier-durand/JSClosure2Interop This work is based on this JSInterop Generator and Javscript contribs to the Closure Compiler project (replicated wih identical structure in js directory)

So, in the gen directory, you will see that successful transpiling back to Java for various small Javascript is achieved : GeoJson, Async-2.0, es3, etc.

But, our final targets is bigger libraries like Google Maps (prio 1), jQuery, Ace, Angular, etc. For those, the list of dependency is bigger. For example, you will see that Google Maps requires 27 dependencies (see src/test/java/oss/jsinterop/cl2jsi/test/TestConverterGmaps.java)

As they use many browser features, those large libraries end up (see src/test/java/oss/jsinterop/cl2jsi/test/TestConverterFailure.java) all involving html5.js to solve their dependencies.

html5.js (see /js/google-closure-compiler/externs/browser/html5.js) comes from Google Closure Compiler contribs.

At this point in time, when its isolated transpiling is tried, JSInterop Genarator seems to go into an infinite loop (please, run src/test/java/oss/jsinterop/cl2jsi/test/TestConverterHtml5.java - The jar of Generator is embarked, so it should run).

Same thing with the transpiling of all large libraries requiring it: when we introduce html5.js to complete the needs, the transpiler loops forever. Its Jar was created from master of March, 21st (commit: https://github.com/google/jsinterop-generator/commit/e68a27e22658ecc806c8be1ae398c9ec9ad876d8)

The debug mode of the Generator doesn't say anything user about this loop.

Is the error on our side?

Thanks!

Didier

tbroyer commented 4 years ago

How about using Elemental2 bindings?

didier-durand commented 4 years ago

Hello Thomas, where do I get them (preferably in source code)? happy to try that.

niloc132 commented 4 years ago

I have produced some draft copies of google maps v3 and ace editor v1.2.3 through jsinterop-generator, by modifying elemental2 a bit, but the same outcome can probably be achieved through another bazel project which references elemental2. The process requires editing the extern files (or jsinterop-generator itself) to handle cases with externs that are valid for closure-compiler but not for jsinterop-generator.

Source jars (no .gwt.xml, no bytecode, but you could unpack these and build them, try them out) from the projects I've gotten working so far: https://colinalworth.com/ace-editor-src.jar https://colinalworth.com/google_maps_api_v3.jar

Some notes:

I'm running low on free time these days, but will try to get this into a usable shape so that I can put it in a git repo. @stockiNail has been collaborating with me by trying out the jars a bit and finding issues with either the externs or how jsinterop-generator handles them, as time permits we'll see about making some improvements and publishing these.

gkdn commented 4 years ago

Hello Thomas, where do I get them (preferably in source code)? happy to try that.

https://github.com/google/elemental2

didier-durand commented 4 years ago

Hello Thomas, where do I get them (preferably in source code)? happy to try that.

https://github.com/google/elemental2

Thanks, Goktug! I will try those bindings. Didier

didier-durand commented 4 years ago

https://colinalworth.com/ace-editor-src.jar https://colinalworth.com/google_maps_api_v3.jar

Colin, I'll try your source code and will let you know. Didier

stockiNail commented 4 years ago

@didier-durand FYI I'm gonna test ACE because I've already used in GWT (by JSNI). @niloc132 I've found an error into a method definition. Do you prefer having a complete list of items to fix or item by item when I'll face them?

stockiNail commented 4 years ago

AceFirstTestJ2CL

didier-durand commented 4 years ago

@stockiNail : Hi, yes, please, let us know : i tried to generate ace-1.2.3.js But, it's in my failling tests due to its dependency on html5.js which triggers the infinite loop of this ticket.

See line 204 of https://github.com/didier-durand/JSClosure2Interop/blob/master/src/test/java/oss/jsinterop/cl2jsi/test/TestConverterFailure.java

Best Didier

stockiNail commented 4 years ago

@didier-durand yes, I do my best! Let me say that I'm using the sources provided by @niloc132 and the ace builds from https://github.com/ajaxorg/ace-builds/.

didier-durand commented 4 years ago

@didier-durand yes, I do my best! Let me say that I'm using the sources provided by @niloc132 and the ace builds from https://github.com/ajaxorg/ace-builds/.

Mine are the closure of ace-1.2.3.js copied from the Closure Compiler project (source all of the js in my trials)

niloc132 commented 4 years ago

@didier-durand it is better to depend not on closure-compiler's own externs directly, but on the output of elemental2 running. You need elemental2-core and elemental2-dom. Very roughly:

jsinterop_generator(
    name = "ace-editor",
    srcs = ["ace-1.2.3.js"],
    extension_type_prefix = "AceEditor",
    #    integer_entities_files = ["integer_entities.txt"],
    # override auto generated js_deps in order not to provide extern files
    # Common extern file are included by default.
    j2cl_js_deps = [],
    deps = [
        "//java/elemental2/core",
        "//java/elemental2/dom",
    ],
)

and fix

/**
 * The main class required to set up an Ace instance in the browser.
 * @const
 * @see https://ace.c9.io/#nav=api&api=ace
 */
var ace;

to be initialized to an empty object, {}.

If I get a chance today I'll start a github project and link it here.

didier-durand commented 4 years ago

@didier-durand it is better to depend not on closure-compiler's own externs directly, but on the output of elemental2 running. You need elemental2-core and elemental2-dom. Very roughly:

jsinterop_generator(
    name = "ace-editor",
    srcs = ["ace-1.2.3.js"],
    extension_type_prefix = "AceEditor",
    #    integer_entities_files = ["integer_entities.txt"],
    # override auto generated js_deps in order not to provide extern files
    # Common extern file are included by default.
    j2cl_js_deps = [],
    deps = [
        "//java/elemental2/core",
        "//java/elemental2/dom",
    ],
)

and fix

/**
 * The main class required to set up an Ace instance in the browser.
 * @const
 * @see https://ace.c9.io/#nav=api&api=ace
 */
var ace;

to be initialized to an empty object, {}.

If I get a chance today I'll start a github project and link it here.

@niloc132 : thanks. I'll wait for your github project: I am trying your Gmaps source code in the meantime.

didier-durand commented 4 years ago

This is NOT directly related to the ticket itself which remains active but some feedback may be of interest for all.

@tbroyer @gkdn @niloc132 : I have combined your hints and code kindly provided by @niloc132 to get an initial subset (Map, Marker, InfoWindow, etc.) of Google Maps JSInterop bindings to work properly with GWT 2.8.1 by including Elemental2 & JSInterops modules in GWT. Thanks to all! (Ping me for more details if needed)

niloc132 commented 4 years ago

Likewise off-topic: https://github.com/Vertispan/gwt-googlemaps-api now hosts a bazel+maven project, and points at coords to use in maven to use this library - Any other followup on that should move to that repo's issues for discussion.