Skip to content

Commit 5399ae9

Browse files
RobinMalfaitphilipp-spiess
authored andcommitted
Pretty print !important in declarations (#14611)
This PR is a very small improvement. We started pretty printing the generated CSS (proper indentation) a while ago, so that we can use the output as-is for intellisense (on hover). The other day I noticed that when you use `!important` that we attach it directly to the declaration. Not the end of the world, but this PR injects a little space to make sure that the `!important` is separated from the value which makes it a little easier to read and looks more like what you would write by hand. Before: ```css .flex\! { display: flex!important; } ``` After: ```css .flex\! { display: flex !important; } ```
1 parent f1b6c33 commit 5399ae9

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

CHANGELOG.md

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

1212
- Add support for `tailwindcss/colors.js`, `tailwindcss/defaultTheme.js`, and `tailwindcss/plugin.js` exports ([#14595](https://github.com/tailwindlabs/tailwindcss/pull/14595))
1313
- Support `keyframes` in JS config file themes ([14594](https://github.com/tailwindlabs/tailwindcss/pull/14594))
14+
- Pretty print `!important` in declarations ([#14611](https://github.com/tailwindlabs/tailwindcss/pull/14611))
1415

1516
### Fixed
1617

packages/tailwindcss/src/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export function toCss(ast: AstNode[]) {
206206

207207
// Declaration
208208
else if (node.property !== '--tw-sort' && node.value !== undefined && node.value !== null) {
209-
css += `${indent}${node.property}: ${node.value}${node.important ? '!important' : ''};\n`
209+
css += `${indent}${node.property}: ${node.value}${node.important ? ' !important' : ''};\n`
210210
}
211211

212212
return css

packages/tailwindcss/src/compat/config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,15 +1428,15 @@ test('important: true', async () => {
14281428

14291429
expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toMatchInlineSnapshot(`
14301430
".custom {
1431-
color: red!important;
1431+
color: red !important;
14321432
}
14331433
.underline {
1434-
text-decoration-line: underline!important;
1434+
text-decoration-line: underline !important;
14351435
}
14361436
.hover\\:line-through {
14371437
&:hover {
14381438
@media (hover: hover) {
1439-
text-decoration-line: line-through!important;
1439+
text-decoration-line: line-through !important;
14401440
}
14411441
}
14421442
}

packages/tailwindcss/src/important.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ test('Utilities can be marked with important', async () => {
4545

4646
expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(`
4747
".underline {
48-
text-decoration-line: underline!important;
48+
text-decoration-line: underline !important;
4949
}
5050
.hover\\:line-through {
5151
&:hover {
5252
@media (hover: hover) {
53-
text-decoration-line: line-through!important;
53+
text-decoration-line: line-through !important;
5454
}
5555
}
5656
}
@@ -74,12 +74,12 @@ test('Utilities can be wrapped with a selector and marked as important', async (
7474
expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(`
7575
"#app {
7676
.underline {
77-
text-decoration-line: underline!important;
77+
text-decoration-line: underline !important;
7878
}
7979
.hover\\:line-through {
8080
&:hover {
8181
@media (hover: hover) {
82-
text-decoration-line: line-through!important;
82+
text-decoration-line: line-through !important;
8383
}
8484
}
8585
}

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ test('Utilities, when marked as important, show as important in intellisense', a
160160
expect(design.candidatesToCss(['underline', 'hover:line-through'])).toMatchInlineSnapshot(`
161161
[
162162
".underline {
163-
text-decoration-line: underline!important;
163+
text-decoration-line: underline !important;
164164
}
165165
",
166166
".hover\\:line-through {
167167
&:hover {
168168
@media (hover: hover) {
169-
text-decoration-line: line-through!important;
169+
text-decoration-line: line-through !important;
170170
}
171171
}
172172
}

0 commit comments

Comments
 (0)