Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsInterop namespace seems to require being a closure namespace #70

Closed
niloc132 opened this issue Oct 23, 2019 · 2 comments
Closed

JsInterop namespace seems to require being a closure namespace #70

niloc132 opened this issue Oct 23, 2019 · 2 comments

Comments

@niloc132
Copy link
Contributor

This seems to be a fairly recent change. As an example, to expose JS static fields on a class:

@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
public class Node extends JavaScriptObject {
  /**
   * The node is an {@link Element}.
   */
  @JsProperty(namespace = "Node")
  public static short ELEMENT_NODE;

References to these end up being compiled to $synthetic__Node.ELEMENT_NODE, where $synthetic__Node is defined as

let $synthetic__Node = goog.forwardDeclare('Node');

This way of referencing the native Node type seems to be an error in closure-compiler's ADVANCED mode:

Element$$Overlay.impl.java.js:5: ERROR - Imported Closure namespace "Node" never defined.

If this is a deliberate breaking change, it seems easy enough to work around, if a bit ugly, by moving the namespace to the name, and repeating the field's java name in the string:

  @JsProperty(namespace = JsPackage.GLOBAL, name = "Node.ELEMENT_NODE")
  public static short ELEMENT_NODE;

This results in the expected compiled JS: Node.ELEMENT_NODE.

@gkdn
Copy link
Member

gkdn commented Oct 23, 2019

This was a deliberate change.
Roberto fixed a compiler bug which was treating namespace of properties/methods without . as something under GLOBAL namespace.

@gkdn gkdn closed this as completed Oct 23, 2019
@niloc132
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants