Commit 9e6d6bf
authored
fix(compiler): preserve dangling comments in empty operation parameter list (#10351)
## Summary
`tsp format` crashed on:
```tsp
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.1 parent b99f92f commit 9e6d6bf
3 files changed
Lines changed: 35 additions & 6 deletions
File tree
- .chronus/changes
- packages/compiler
- src/formatter/print
- test/formatter
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
969 | 969 | | |
970 | 970 | | |
971 | 971 | | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
978 | 985 | | |
979 | 986 | | |
980 | 987 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
737 | 737 | | |
738 | 738 | | |
739 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
740 | 755 | | |
741 | 756 | | |
742 | 757 | | |
| |||
0 commit comments