Skip to content

Commit

Permalink
Don’t break @apply … #{'!important'} sorting (#212)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thecrypticace committed Aug 31, 2023
1 parent 7694e65 commit 3ebd2f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

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

## [0.5.3] - 2023-08-15

Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ function transformCss(ast, { env }) {
if (node.type === 'css-atrule' && node.name === 'apply') {
node.params = sortClasses(node.params, {
env,
ignoreLast: /\s+(?:!important|#{!important})\s*$/.test(node.params),
ignoreLast: /\s+(?:!important|#{(['"]*)!important\1})\s*$/.test(
node.params,
),
})
}
})
Expand Down
13 changes: 12 additions & 1 deletion tests/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ let tests = {
// t`<div [ngClass]="{ '${no}': foo && definitely&a:syntax*error }" class="${yes}"></div>`,
],
css: [...css, t`@apply ${yes} !important;`],
scss: [...css, t`@apply ${yes} #{!important};`],
scss: [
...css,
t`@apply ${yes} #{!important};`,
t`@apply ${yes} #{'!important'};`,
t`@apply ${yes} #{"!important"};`,

// These shouldn't ever be used but they are valid
// syntax so we might as well not break them
t`@apply ${yes} #{""!important""};`,
t`@apply ${yes} #{'''!important'''};`,
t`@apply ${yes} #{"'"'"!important"'"'"};`,
],
less: [...css, t`@apply ${yes} !important;`],
babel: javascript,
typescript: javascript,
Expand Down

0 comments on commit 3ebd2f9

Please sign in to comment.