Skip to content

Commit

Permalink
Don't propogate apply !important option to non-apply rules
Browse files Browse the repository at this point in the history
Fixes #2362.
  • Loading branch information
adamwathan committed Sep 13, 2020
1 parent 4e322b2 commit 364a7b6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
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

0 comments on commit 364a7b6

Please sign in to comment.