Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment in IfStatement not printed. #15168

Closed
fisker opened this issue Jul 29, 2023 · 3 comments · Fixed by #15826
Closed

Comment in IfStatement not printed. #15168

fisker opened this issue Jul 29, 2023 · 3 comments · Fixed by #15826
Labels
area:comments Issues with how Prettier prints comments lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@fisker
Copy link
Member

fisker commented Jul 29, 2023

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)

@fisker fisker added type:bug Issues identifying ugly output, or a defect in the program area:comments Issues with how Prettier prints comments lang:javascript Issues affecting JS labels Jul 29, 2023
@markstein-moll
Copy link

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

@sosukesuzuki
Copy link
Member

This is duplicated to #15470

@sosukesuzuki
Copy link
Member

Sorry I mistook

@sosukesuzuki sosukesuzuki reopened this Sep 30, 2023
@fisker fisker mentioned this issue Dec 18, 2023
4 tasks
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Apr 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:comments Issues with how Prettier prints comments lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants