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

Don't propogate apply !important option to non-apply rules #2376

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

- Add negative spacing values to inset plugin in the `extendedSpacingScale` experiment ([#2358](https://github.com/tailwindlabs/tailwindcss/pull/2358))
- Add `future` section to config stubs ([#2372](https://github.com/tailwindlabs/tailwindcss/pull/2372), [3090b98](https://github.com/tailwindlabs/tailwindcss/commit/3090b98ece766b1046abe5bbaa94204e811f7fac))
- Fix issue where `!important` was stripped from declarations within rules that used `@apply` with `applyComplexClasses` ([#2376](https://github.com/tailwindlabs/tailwindcss/pull/2376))

## [1.8.8] - 2020-09-11

Expand Down
50 changes: 50 additions & 0 deletions __tests__/applyComplexClasses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,3 +1094,53 @@ test('you can deeply apply classes in a custom nested @atrule', () => {
expect(result.warnings().length).toBe(0)
})
})

test('declarations within a rule that uses @apply can be !important', () => {
const input = `
.foo {
@apply text-center;
float: left;
display: block !important;
}
`

const expected = `
.foo {
text-align: center;
float: left;
display: block !important;
}
`

expect.assertions(2)

return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
})
})

test('declarations within a rule that uses @apply with !important remain not !important', () => {
const input = `
.foo {
@apply text-center !important;
float: left;
display: block !important;
}
`

const expected = `
.foo {
text-align: center !important;
float: left;
display: block !important;
}
`

expect.assertions(2)

return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
})
})
4 changes: 1 addition & 3 deletions src/flagged/applyComplexClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,13 @@ function processApplyAtRules(css, lookupTree, config) {
: util => util.rule.nodes.forEach(n => afterRule.append(n.clone()))
)

rulesToInsert.push(afterRule)

const { nodes } = _.tap(postcss.root({ nodes: rulesToInsert }), root =>
root.walkDecls(d => {
d.important = important
})
)

const mergedRules = mergeAdjacentRules(nearestParentRule, nodes)
const mergedRules = mergeAdjacentRules(nearestParentRule, [...nodes, afterRule])

applyRule.remove()
parent.after(mergedRules)
Expand Down