Skip to content

Commit da1fb70

Browse files
committed
Don't propogate apply !important option to non-apply rules (#2376)
* Don't propogate apply !important option to non-apply rules Fixes #2362. * Update changelog
1 parent b9b4157 commit da1fb70

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

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

1314
## [1.8.8] - 2020-09-11
1415

__tests__/applyComplexClasses.test.js

+50
Original file line numberDiff line numberDiff line change
@@ -1094,3 +1094,53 @@ test('you can deeply apply classes in a custom nested @atrule', () => {
10941094
expect(result.warnings().length).toBe(0)
10951095
})
10961096
})
1097+
1098+
test('declarations within a rule that uses @apply can be !important', () => {
1099+
const input = `
1100+
.foo {
1101+
@apply text-center;
1102+
float: left;
1103+
display: block !important;
1104+
}
1105+
`
1106+
1107+
const expected = `
1108+
.foo {
1109+
text-align: center;
1110+
float: left;
1111+
display: block !important;
1112+
}
1113+
`
1114+
1115+
expect.assertions(2)
1116+
1117+
return run(input).then(result => {
1118+
expect(result.css).toMatchCss(expected)
1119+
expect(result.warnings().length).toBe(0)
1120+
})
1121+
})
1122+
1123+
test('declarations within a rule that uses @apply with !important remain not !important', () => {
1124+
const input = `
1125+
.foo {
1126+
@apply text-center !important;
1127+
float: left;
1128+
display: block !important;
1129+
}
1130+
`
1131+
1132+
const expected = `
1133+
.foo {
1134+
text-align: center !important;
1135+
float: left;
1136+
display: block !important;
1137+
}
1138+
`
1139+
1140+
expect.assertions(2)
1141+
1142+
return run(input).then(result => {
1143+
expect(result.css).toMatchCss(expected)
1144+
expect(result.warnings().length).toBe(0)
1145+
})
1146+
})

src/flagged/applyComplexClasses.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,13 @@ function processApplyAtRules(css, lookupTree, config) {
238238
: util => util.rule.nodes.forEach(n => afterRule.append(n.clone()))
239239
)
240240

241-
rulesToInsert.push(afterRule)
242-
243241
const { nodes } = _.tap(postcss.root({ nodes: rulesToInsert }), root =>
244242
root.walkDecls(d => {
245243
d.important = important
246244
})
247245
)
248246

249-
const mergedRules = mergeAdjacentRules(nearestParentRule, nodes)
247+
const mergedRules = mergeAdjacentRules(nearestParentRule, [...nodes, afterRule])
250248

251249
applyRule.remove()
252250
parent.after(mergedRules)

0 commit comments

Comments
 (0)