Skip to content

Can't print comment after directive #14080

@fisker

Description

@fisker

Prettier 2.8.1
Playground link

--parser acorn
--no-semi

Input:

'use strict';

/* comment */
[].forEach();

Output:

"use strict"

/* comment */
;[].forEach()

Second Output:

Error: Comment "comment" was not printed. Please report this error!
    at Object.N [as ensureAllCommentsPrinted] (https://prettier.io/lib/standalone.js:41:7554)
    at A (https://prettier.io/lib/standalone.js:41:15193)
    at x (https://prettier.io/lib/standalone.js:45:576)
    at Object.formatWithCursor (https://prettier.io/lib/standalone.js:116:7283)
    at formatCode (https://prettier.io/worker.js:173:21)
    at handleFormatMessage (https://prettier.io/worker.js:161:34)
    at handleMessage (https://prettier.io/worker.js:77:14)
    at self.onmessage (https://prettier.io/worker.js:53:14)

Expected behavior:

Should be able to print


Reproduce in semi mode

Prettier 2.8.1
Playground link

--parser acorn

Input:

'use strict' /* comment */;

Output:

Error: Comment "comment" was not printed. Please report this error!
    at Object.N [as ensureAllCommentsPrinted] (https://prettier.io/lib/standalone.js:41:7554)
    at A (https://prettier.io/lib/standalone.js:41:15193)
    at x (https://prettier.io/lib/standalone.js:45:576)
    at Object.formatWithCursor (https://prettier.io/lib/standalone.js:116:7283)
    at formatCode (https://prettier.io/worker.js:173:21)
    at handleFormatMessage (https://prettier.io/worker.js:104:24)
    at handleMessage (https://prettier.io/worker.js:77:14)
    at self.onmessage (https://prettier.io/worker.js:53:14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentsarea:no-semilang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions