Skip to content

Commit 3ebd2f9

Browse files
Don’t break @apply … #{'!important'} sorting (#212)
* Don’t break `@apply … #{'!important'}` sorting `#{!important}` was already handled but SCSS allows one to wrap it in any number of matched single or double quotes so we check for that as well * Update changelog
1 parent 7694e65 commit 3ebd2f9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Type `tailwindFunctions` and `tailwindAttributes` as optional ([#206](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/206))
13+
- Don’t break `@apply … #{'!important'}` sorting ([#212](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/212))
1314

1415
## [0.5.3] - 2023-08-15
1516

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ function transformCss(ast, { env }) {
533533
if (node.type === 'css-atrule' && node.name === 'apply') {
534534
node.params = sortClasses(node.params, {
535535
env,
536-
ignoreLast: /\s+(?:!important|#{!important})\s*$/.test(node.params),
536+
ignoreLast: /\s+(?:!important|#{(['"]*)!important\1})\s*$/.test(
537+
node.params,
538+
),
537539
})
538540
}
539541
})

tests/format.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,18 @@ let tests = {
145145
// t`<div [ngClass]="{ '${no}': foo && definitely&a:syntax*error }" class="${yes}"></div>`,
146146
],
147147
css: [...css, t`@apply ${yes} !important;`],
148-
scss: [...css, t`@apply ${yes} #{!important};`],
148+
scss: [
149+
...css,
150+
t`@apply ${yes} #{!important};`,
151+
t`@apply ${yes} #{'!important'};`,
152+
t`@apply ${yes} #{"!important"};`,
153+
154+
// These shouldn't ever be used but they are valid
155+
// syntax so we might as well not break them
156+
t`@apply ${yes} #{""!important""};`,
157+
t`@apply ${yes} #{'''!important'''};`,
158+
t`@apply ${yes} #{"'"'"!important"'"'"};`,
159+
],
149160
less: [...css, t`@apply ${yes} !important;`],
150161
babel: javascript,
151162
typescript: javascript,

0 commit comments

Comments
 (0)