Skip to content

fix: treat comment-like tokens inside text blocks as string fragments - #1128

Open
hoanle0126 wants to merge 1 commit into
jhipster:mainfrom
hoanle0126:fix/text-block-comment-fragments
Open

hoanle0126 wants to merge 1 commit into
jhipster:mainfrom
hoanle0126:fix/text-block-comment-fragments

Conversation

@hoanle0126

Copy link
Copy Markdown

What changed with this PR:

In tree-sitter-java-orchard, multiline_string_fragment is not marked as token.immediate, so comment tokens (block_comment and line_comment) in extras can match inside text blocks when a comment-like line contains " or \ (which stops multiline_string_fragment early and lets the comment rule win by longest match). This caused processTree to collect those inner tokens into ast.comments, leading Prettier to fail with Comment "..." was not printed (or omit the fragment when printing interpolated text blocks).

Comment nodes whose parent is a string_literal are now treated as multiline_string_fragment nodes rather than comments.

Example

Input

class A {
  String s = """
    /* a "b" c */
    // a "b" c
    /* a \n c */
    // a \n c
    """;
}

Output

class A {

  String s = """
    /* a "b" c */
    // a "b" c
    /* a \n c */
    // a \n c
    """;
}

Relative issues or prs:

Closes #1112

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Text block containing a comment-like line with " or \ fails with "Comment was not printed"

1 participant