Skip to content

Contextual keywords rejected as statement labels #950

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: prettier-plugin-java@2.6.0 (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.

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