Skip to content

[2.9.7] native GWT JSNI methods get a spurious () appended after }-*/, breaking compilation #957

Closed

Description

@ArLau

Environment

  • prettier-plugin-java: 2.10.1
  • prettier: 3.8.3
  • JDK used to compile output: 21.0.10

Execution

"format": "prettier \"**/*.(yaml|yml|md|ts|tsx|java)\" --write"

Description

When formatting a GWT JSNI native method, the plugin inserts an extra () between the closing JSNI delimiter }-*/ and the terminating semicolon. This corrupts the JSNI block and causes the GWT compiler to fail:

[ERROR] <no source info>: <source info not available>
         [ERROR] at XX.java(91): XXX.getInitiator()Ljava/lang/String;
            com.google.gwt.dev.jjs.ast.JMethod

This worked correctly before 2.9.7 (tested in 2.8.1) and is still broken in 2.10.1 (tested).

Input

private native JsArray<MyItem> getItems() /*-{
    return this.items
}-*/;
private static native void registerHandler(
    MyHandler handler
) /*-{
    $doc.addEventListener("visibilitychange", function () {
        [email protected]::onEvent()();
    });
}-*/;

Actual output (does not compile)

private native JsArray<MyItem> getItems() /*-{
    return this.items
}-*/();
private static native void registerHandler(
    MyHandler handler /*-{
    $doc.addEventListener("visibilitychange", function () {
        [email protected]::onEvent()();
    });
}-*/
);

Expected output

Identical to the input — the JSNI block must be left untouched and no () should be added.

Activity

  1. jtkiesel commented on Jun 28, 2026

    @jtkiesel
    Contributor

    Thanks for reporting this issue! I wasn't aware of JSNI. I'll look into fixing this now and adding some tests for it to avoid this sort of regression in the future, but I wonder if it would also make sense to try to support formatting the JavaScript inside of the comments with Prettier as well, by treating it as an embedded language? I may work on that as a separate feature, similar to #794. Let me know if you have thoughts, as a user of JSNI.

  2. ArLau commented on Jun 29, 2026

    @ArLau
    Author

    Thanks for taking a look so soon and all the work you do for this project! Our JSNI methods are always quite short, normally just 1-3 lines, and we only have a handful of them, so having them properly formatted is not that important to us because it is easy to write them readable by ourselves. Ofc we would not be sad if they would be uniformly formatted, but they are currently not causing worries for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions