Skip to content

Commit

Permalink
fix(postcss-merge-longhand): add revert to unmergeable values (#1211)
Browse files Browse the repository at this point in the history
Fix #1204
  • Loading branch information
ludofischer authored Oct 19, 2021
1 parent bb0a76a commit b67cdc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/postcss-merge-longhand/src/__tests__/boxBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ addTests(
'h1{box-bottom:INHERIT;box-top:INHERIT;box-left:INHERIT;box-right:INHERIT}',
expected: 'h1{box:INHERIT}',
},
{
message: 'should not merge box props when one has a revert property',
fixture: 'h1{box:10px;box-left:revert}',
expected: (prop) => `h1{${prop.toLowerCase()}:10px;${prop}-left:revert}`,
},
{
message: 'should handle empty box properties',
fixture: 'h1{box:;}',
Expand Down
22 changes: 10 additions & 12 deletions packages/postcss-merge-longhand/src/lib/canMerge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import isCustomProp from './isCustomProp';
const important = (node) => node.important;
const unimportant = (node) => !node.important;

const hasInherit = (node) => node.value.toLowerCase() === 'inherit';
const hasInitial = (node) => node.value.toLowerCase() === 'initial';
const hasUnset = (node) => node.value.toLowerCase() === 'unset';
/* Cannot be combined with other values in shorthand
https://www.w3.org/TR/css-cascade-5/#shorthand */
const cssWideKeywords = ['inherit', 'initial', 'unset', 'revert'];

export default (props, includeCustomProps = true) => {
if (props.some(hasInherit) && !props.every(hasInherit)) {
return false;
}

if (props.some(hasInitial) && !props.every(hasInitial)) {
return false;
}
const uniqueProps = new Set(props.map((node) => node.value.toLowerCase()));

if (props.some(hasUnset) && !props.every(hasUnset)) {
return false;
if (uniqueProps.size > 1) {
for (const unmergeable of cssWideKeywords) {
if (uniqueProps.has(unmergeable)) {
return false;
}
}
}

if (
Expand Down

0 comments on commit b67cdc4

Please sign in to comment.