Visitar URL original
Comment in `IfStatement` not printed. · Issue #15168 · prettier/prettier · GitHub
Skip to content

Comment in IfStatement not printed. #15168

Closed

Description

@fisker

Prettier 3.0.0
Playground link

--parser babel

Input:

function a() {
  if (a) var c = 1 /* comment 6a */;
  else return 2;
}

Output:

Error: Comment "comment 6a" was not printed. Please report this error!
    at pu (https://prettier.io/lib/standalone.js:27:5829)
    at Ze (https://prettier.io/lib/standalone.js:27:7320)
    at async Ou (https://prettier.io/lib/standalone.js:27:11026)
    at async Rr (https://prettier.io/lib/standalone.js:32:581)
    at async formatCode (https://prettier.io/worker.js:170:12)
    at async handleFormatMessage (https://prettier.io/worker.js:82:24)
    at async self.onmessage (https://prettier.io/worker.js:37:14)

Expected behavior:

See #15076 (comment)

Activity

  1. markstein-moll commented on Sep 25, 2023

    @markstein-moll

    Same problem with version 3.0.0 in the following TypeScript snippet:

    for (const division of collidingDivisions) {
    	if (!division.properties.canRemove) {
    		if (division.canContainSingleParagraph(startParagraph)) continue; // selection starting in r/o div: always OK to delete
    		else if (endParagraph !== division.endParagraph && division.canContainSingleParagraph(endParagraph)) continue; // selection ending in r/o div: OK to delete IF it is NOT last paragraph (which would get absorbed)
    		else { // selection over whole r/o div OR ending in last paragraph (which would get absorbed) -> FAIL
    			console.warn('deleteSelectedTextAndJoinRemainingNodes(): cannot delete because of must-keep division: ' + division.properties.name);
    			return { success: false, reason: DeleteAndJoinErrorReason.READONLY_DIVISION };
    		}
    	}
    }
    

    Error:

    [error] EditableArticle.ts: Error: Comment "selection starting in r/o div: always OK to delete" was not printed. Please report this error!
    [error]     at ensureAllCommentsPrinted
    [error]     at printAstToDoc
    [error]     at async coreFormat
    [error]     at async formatWithCursor
    [error]     at async formatFiles
    [error]     at async main
    [error]     at async Module.run
    
  2. sosukesuzuki commented on Sep 30, 2023

    @sosukesuzuki
    Member

    This is duplicated to #15470

  3. sosukesuzuki commented on Sep 30, 2023

    @sosukesuzuki
    Member

    Sorry I mistook

  4. locked as resolved and limited conversation to collaborators on Apr 3, 2024
  5. added theissue type on Mar 3, 2025
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

    area:commentsIssues with how Prettier prints commentslang: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