Skip to content

[JSON] Trailing comments are not handled #5263

@ikatyang

Description

@ikatyang

We use the js expression parser (which shares the same printer with JSON) to parse binding syntax in HTML, but the trailing comments are removed (reported by #5259 (comment)).

Prettier 1.14.3
Playground link

--parser json

Input:

index /* TODO: use id when links will be provided by API */

Output:

Error: Comment "TODO: use id when links will be provided by API" was not printed. Please report this error!
    at https://prettier.io/lib/standalone.js:10671:13
    at Array.forEach (<anonymous>)
    at ensureAllCommentsPrinted (https://prettier.io/lib/standalone.js:10669:15)
    at coreFormat (https://prettier.io/lib/standalone.js:10719:3)
    at format (https://prettier.io/lib/standalone.js:10874:16)
    at formatWithCursor (https://prettier.io/lib/standalone.js:10886:12)
    at https://prettier.io/lib/standalone.js:21134:15
    at Object.format (https://prettier.io/lib/standalone.js:21142:12)
    at formatCode (https://prettier.io/worker.js:188:21)
    at handleMessage (https://prettier.io/worker.js:139:18)

Expected behavior:
Comments are printed.

Metadata

Metadata

Assignees

Labels

area:commentsIssues with how Prettier prints commentslang:jsonIssues affecting JSONlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions