Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Collapse whitespace in template literals with adjacent quasis ([#427](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/427))

## [0.7.2] - 2025-12-01

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function canCollapseWhitespaceIn(path: Path<import('@babel/types').Node, any>) {
let nodeEnd = entry.node.end ?? null

for (let quasi of entry.parent.quasis) {
let quasiStart = quasi.end ?? null
let quasiStart = quasi.start ?? null
Copy link
Contributor

Choose a reason for hiding this comment

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

lol 🤦‍♂️

let quasiEnd = quasi.end ?? null

if (nodeStart !== null && quasiEnd !== null && nodeStart - quasiEnd <= 2) {
Expand Down
8 changes: 8 additions & 0 deletions tests/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ describe('whitespace', () => {
expect(result).toEqual(";<div className={`header${isExtendable ? ' header-extendable' : ''}`} />")
})

test('whitespace is not trimmed before template literal quasis without leading space', async ({ expect }) => {
let result = await format(";<div className={`${foo ? 'sm:p-0 p-0 ' : ''}header`}></div>", {
parser: 'babel',
})

expect(result).toEqual(";<div className={`${foo ? 'p-0 sm:p-0 ' : ''}header`}></div>")
})

test('duplicate classes are dropped', async ({ expect }) => {
let result = await format('<div class="underline line-through underline flex"></div>')

Expand Down