Skip to content

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

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 () {
        handler.@com.example.MyHandler::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 () {
        handler.@com.example.MyHandler::onEvent()();
    });
}-*/
);

Expected output

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions