From ca55c2d976771f06b292819cfc8227b43f3a6336 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 28 Aug 2025 17:35:04 -0400 Subject: [PATCH 1/2] Handle quote escapes in LESS when sorting `@apply` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s perfect since the AST doesn’t actually have information on these (it’s just strings) but this should be good enough. --- src/index.ts | 21 ++++++++++++++++++++- tests/tests.ts | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 933d3ea..8d75911 100644 --- a/src/index.ts +++ b/src/index.ts @@ -810,7 +810,24 @@ function transformCss(ast: any, { env }: TransformerContext) { node.params, ) - node.params = sortClasses(node.params, { + let classList = node.params + + let prefix = '' + let suffix = '' + + if (classList.startsWith('~"') && classList.endsWith('"')) { + prefix = '~"' + suffix = '"' + classList = classList.slice(2, -1) + isImportant = false + } else if (classList.startsWith("~'") && classList.endsWith("'")) { + prefix = "~'" + suffix = "'" + classList = classList.slice(2, -1) + isImportant = false + } + + classList = sortClasses(classList, { env, ignoreLast: isImportant, collapseWhitespace: { @@ -818,6 +835,8 @@ function transformCss(ast: any, { env }: TransformerContext) { end: !isImportant, }, }) + + node.params = `${prefix}${classList}${suffix}` } }) } diff --git a/tests/tests.ts b/tests/tests.ts index b85b93e..f4f8be5 100644 --- a/tests/tests.ts +++ b/tests/tests.ts @@ -266,7 +266,7 @@ export let tests: Record = { t`@apply ${yes} #{'''!important'''};`, t`@apply ${yes} #{"'"'"!important"'"'"};`, ], - less: [...css, t`@apply ${yes} !important;`], + less: [...css, t`@apply ${yes} !important;`, t`@apply ~"${yes}";`, t`@apply ~'${yes}';`], babel: javascript, typescript: javascript, 'babel-ts': javascript, From b7a89c58fd6aeb8b0a559fcc80b7216ac5bbd09c Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 28 Aug 2025 17:36:39 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f4444d..ea5d80d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Format quotes in `@source`, `@plugin`, and `@config` ([#387](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/387)) - Support sorting in callable template literals ([#367](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/367)) - Support sorting in function calls mixed with property accesses ([#367](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/367)) +- Handle quote escapes in LESS when sorting `@apply` ([#392](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/392)) ## [0.6.14] - 2025-07-09