Skip to content

Contextual keywords rejected as statement labels #950

Closed

Description

@motlin

Since prettier-plugin-java migrated its parser from the Chevrotain-based java-parser to web-tree-sitter, valid Java that uses a contextual/restricted keyword as a statement label fails to parse.

  • prettier: 3.8.3
  • prettier-plugin-java: 2.9.7
  • Last known-good: [email protected] (Chevrotain java-parser)

Minimal reproduction

public class T {
    void m() {
        record: while (true) {
            break record;
        }
    }
}

Running plugin emits an error and prettier aborts, leaving the file unformatted.

$ prettier --plugin=prettier-plugin-java T.java
[error] T.java: Error: Failed to parse: (program (class_declaration ... body: (block (ERROR) (... )))) ...

Label keywords that fail:

  • record
  • yield
  • sealed
  • permits
  • var
  • open
  • module
  • requires
  • exports
  • to
  • with

A non-keyword label such as foo: works under both versions.

Activity

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