Avoid introducing linebreaks in template interpolations (#15209)

This commit is contained in:
Kevin Gibbons authored and GitHub committed 2023-12-17 18:10:20 +08:00
1 parent d541f0d699
commit cb6fea81fb
10 files changed
+151 -102

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#### Avoid introducing linebreaks in template interpolations (#15209 by @bakkot)
In a template string like
<!-- prettier-ignore -->
```js
`this is a long message which contains an interpolation: ${format(data)} <- like this`;
```
avoid adding a linebreak when formatting the expression unless one is already present or it's unavoidable due to e.g. a nested function. Previously a linebreak could be introduced whenever some interpolation in the template was sufficiently "not simple":
<!-- prettier-ignore -->
```js
`this is a long message which contains an interpolation: ${format(
data,
)} <- like this`;
```
Now it will instead be left alone.
If a linebreak is already present within the `${...}`, format as normal.