Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty print !important in declarations #14611

Merged
merged 2 commits into from
Oct 7, 2024
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 @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add support for `tailwindcss/colors.js`, `tailwindcss/defaultTheme.js`, and `tailwindcss/plugin.js` exports ([#14595](https://github.com/tailwindlabs/tailwindcss/pull/14595))
- Support `keyframes` in JS config file themes ([14594](https://github.com/tailwindlabs/tailwindcss/pull/14594))
- Pretty print `!important` in declarations ([#14611](https://github.com/tailwindlabs/tailwindcss/pull/14611))
RobinMalfait marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export function toCss(ast: AstNode[]) {

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

return css
Expand Down
6 changes: 3 additions & 3 deletions packages/tailwindcss/src/compat/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,15 +1428,15 @@ test('important: true', async () => {

expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toMatchInlineSnapshot(`
".custom {
color: red!important;
color: red !important;
}
.underline {
text-decoration-line: underline!important;
text-decoration-line: underline !important;
}
.hover\\:line-through {
&:hover {
@media (hover: hover) {
text-decoration-line: line-through!important;
text-decoration-line: line-through !important;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/tailwindcss/src/important.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ test('Utilities can be marked with important', async () => {

expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(`
".underline {
text-decoration-line: underline!important;
text-decoration-line: underline !important;
}
.hover\\:line-through {
&:hover {
@media (hover: hover) {
text-decoration-line: line-through!important;
text-decoration-line: line-through !important;
}
}
}
Expand All @@ -74,12 +74,12 @@ test('Utilities can be wrapped with a selector and marked as important', async (
expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(`
"#app {
.underline {
text-decoration-line: underline!important;
text-decoration-line: underline !important;
}
.hover\\:line-through {
&:hover {
@media (hover: hover) {
text-decoration-line: line-through!important;
text-decoration-line: line-through !important;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/tailwindcss/src/intellisense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ test('Utilities, when marked as important, show as important in intellisense', a
expect(design.candidatesToCss(['underline', 'hover:line-through'])).toMatchInlineSnapshot(`
[
".underline {
text-decoration-line: underline!important;
text-decoration-line: underline !important;
}
",
".hover\\:line-through {
&:hover {
@media (hover: hover) {
text-decoration-line: line-through!important;
text-decoration-line: line-through !important;
}
}
}
Expand Down