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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Add support for OXC + Hermes Prettier plugins ([#376](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/376))
- Sort template literals in Angular expressions ([#377](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/377))

## [0.6.13] - 2025-06-19

Expand Down
38 changes: 38 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,44 @@ function transformDynamicAngularAttribute(attr: any, env: TransformerEnv) {
}),
})
},

TemplateLiteral(node, path) {
if (!node.quasis.length) return

let concat = path.find((entry) => {
return (
entry.parent &&
entry.parent.type === 'BinaryExpression' &&
entry.parent.operator === '+'
)
})

for (let i = 0; i < node.quasis.length; i++) {
let quasi = node.quasis[i]

changes.push({
start: quasi.start,
end: quasi.end,
before: quasi.value.raw,
after: sortClasses(quasi.value.raw, {
env,

// Is not the first "item" and does not start with a space
ignoreFirst: i > 0 && !/^\s/.test(quasi.value.raw),

// Is between two expressions
// And does not end with a space
ignoreLast:
i < node.expressions.length && !/\s$/.test(quasi.value.raw),

collapseWhitespace: {
start: concat?.key !== 'right' && i === 0,
end: concat?.key !== 'left' && i >= node.expressions.length,
},
}),
})
}
},
})

attr.value = spliceChangesIntoString(attr.value, changes)
Expand Down
3 changes: 3 additions & 0 deletions tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ export let tests: Record<string, TestEntry[]> = {

// TODO: Enable this test — it causes console noise but not a failure
// t`<div [ngClass]="{ '${no}': foo && definitely&a:syntax*error }" class="${yes}"></div>`,

// TODO: Enable test once we can run all tests against Prettier v3.6
// t`<div [ngClass]="\`${yes}\`"></div>`,
],
css: [...css, t`@apply ${yes} !important;`],
scss: [
Expand Down