Skip to content

fix(compiler): preserve dangling comments in empty operation parameter list#10351

Merged
timotheeguerin merged 2 commits intomicrosoft:mainfrom
tokuhirom:fix/formatter-dangling-comment-empty-params
Apr 13, 2026
Merged

fix(compiler): preserve dangling comments in empty operation parameter list#10351
timotheeguerin merged 2 commits intomicrosoft:mainfrom
tokuhirom:fix/formatter-dangling-comment-empty-params

Conversation

@tokuhirom
Copy link
Copy Markdown
Contributor

Summary

tsp format crashed on:

namespace MyApp;

op find(/* conditions */): unknown;

with TypeError: Cannot read properties of undefined (reading 'trim')
from prettier's ensureAllCommentsPrinted.

Root cause

printModelExpression (used for operation parameter lists) returned an
empty string when the property list was empty, dropping any dangling
comments. Prettier then detected an unprinted comment and threw.

Fix

Print dangling comments in the empty-properties branch so the block
comment survives formatting.

Test

Added keeps block comment in empty parameter list to
formatter.test.ts. All 199 formatter tests pass.

…r list

`tsp format` crashed on `op find(/* conditions */): unknown;` because
`printModelExpression` discarded dangling comments when the property
list was empty, tripping prettier's `ensureAllCommentsPrinted` check.
Print dangling comments in that branch so the block comment survives
formatting.
@tokuhirom
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10351

commit: 0b4b4d9

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Fix formatter crash when an operation's parameter list contains only a block comment (e.g. op find(/* conditions */): unknown;). Dangling comments in empty parameter lists are now preserved instead of being dropped.

Copy link
Copy Markdown
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tokuhirom thanks for the fix, looks like just need to run pnpm format

@timotheeguerin timotheeguerin added this pull request to the merge queue Apr 13, 2026
Merged via the queue into microsoft:main with commit 9e6d6bf Apr 13, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants