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

fix(postcss-merge-longhand): allow mixing custom properties with regular values when merging #956

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/postcss-merge-longhand/src/__tests__/borders.js
Expand Up @@ -1229,3 +1229,11 @@ test(
);

test('should handle empty border', processCSS('h1{border:;}', 'h1{border:;}'));

test(
'should handle mixed custom property and regular declarations',
processCSS(
'h1{border:var(--v1) solid var(--v2, #abc123);border-right-color:blue}',
'h1{border:var(--v1) solid var(--v2, #abc123);border-right-color:blue}'
)
);
24 changes: 4 additions & 20 deletions packages/postcss-merge-longhand/src/lib/decl/borders.js
Expand Up @@ -54,10 +54,6 @@ function getLevel(prop) {

const isValueCustomProp = (value) => value && !!~value.search(/var\s*\(\s*--/i);

function canMergeValues(values) {
return !values.some(isValueCustomProp) || values.every(isValueCustomProp);
}

function getColorValue(decl) {
if (decl.prop.substr(-5) === 'color') {
return decl.value;
Expand Down Expand Up @@ -253,10 +249,6 @@ function merge(rule) {

const values = rules.map(({ value }) => value);

if (!canMergeValues(values)) {
return;
}

const parsed = values.map((value) => parseWsc(value));

if (!parsed.every(isValidWsc)) {
Expand All @@ -266,14 +258,10 @@ function merge(rule) {
wsc.forEach((d, i) => {
const value = parsed.map((v) => v[i] || defaults[i]);

if (canMergeValues(value)) {
insertCloned(lastNode.parent, lastNode, {
prop: borderProperty(d),
value: minifyTrbl(value),
});
} else {
insertCloned(lastNode.parent, lastNode);
}
insertCloned(lastNode.parent, lastNode, {
prop: borderProperty(d),
value: minifyTrbl(value),
});
});

rules.forEach(remove);
Expand All @@ -294,10 +282,6 @@ function merge(rule) {
[values[0][i], values[1][i], values[2][i]].join(' ')
);

if (!canMergeValues(mapped)) {
return;
}

const [width, style, color] = rules;
const reduced = getDistinctShorthands(mapped);

Expand Down