Skip to content

Commit 2c69934

Browse files
authored
fix(postcss-merge-longhand): don't explode custom properties (#1356)
Fix #1354 Fix #675 - postcss-merge-longhand first 'explodes' longhand declarations to the smallest unit (for example border-width -> border-top-width). If the declaration value contains a custom property, it is not possible to safely explode width/size/color, as the custom property might be equivalent to multiple space-separated values. - this plugin lowercases property names as a side-effect of exploding, so to preserve the old behaviour we lowercase the property that cannot be exploded - remove incorrect tests and add tests for new behaviour
1 parent 1e01938 commit 2c69934

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

packages/postcss-merge-longhand/src/lib/decl/borders.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ function explode(rule) {
231231
return false;
232232
}
233233

234+
if (isCustomProp(decl)) {
235+
decl.prop = decl.prop.toLowerCase();
236+
return false;
237+
}
234238
parseTrbl(decl.value).forEach((value, i) => {
235239
insertCloned(
236240
/** @type {import('postcss').Rule} */ (decl.parent),

packages/postcss-merge-longhand/test/borders.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,22 +1153,6 @@ test(
11531153
)
11541154
);
11551155

1156-
test(
1157-
'Should correctly merge borders with custom properties (#652)',
1158-
processCSS(
1159-
'h1{border-width:var(--a);border-style:var(--b);border-color:var(--c)}',
1160-
'h1{border:var(--a) var(--b) var(--c)}'
1161-
)
1162-
);
1163-
1164-
test(
1165-
'Should correctly merge borders with custom properties (#652) (uppercase)',
1166-
processCSS(
1167-
'h1{BORDER-WIDTH:VAR(--A);BORDER-STYLE:VAR(--B);BORDER-COLOR:VAR(--C)}',
1168-
'h1{border:VAR(--A) VAR(--B) VAR(--C)}'
1169-
)
1170-
);
1171-
11721156
test(
11731157
'Should not throw error when a border property value is undefined (#639)',
11741158
processCSS(
@@ -1206,12 +1190,31 @@ test(
12061190
);
12071191

12081192
test(
1209-
'should not break border rules mixing custorm and regular properties',
1193+
'should not break border rules mixing custom and regular properties',
12101194
passthroughCSS(
12111195
'h1{border:var(--v1) solid var(--v2, #abc123);border-right-color:blue}'
12121196
)
12131197
);
12141198

1199+
test(
1200+
'should not merge declarations with custom properties #1354',
1201+
passthroughCSS(
1202+
'h1{border-width:var(--width); border-style:solid; border-color: hotpink;}'
1203+
)
1204+
);
1205+
1206+
test(
1207+
'should not merge declarations with custom properties #675',
1208+
passthroughCSS(
1209+
'.class{border-width:var(--border-width);border-style:var(--border-style);border-color:var(--border-color);}'
1210+
)
1211+
);
1212+
1213+
test(
1214+
'should not merge declarations with custom properties #1044',
1215+
passthroughCSS('div{border:1px solid;border-color:red var(--grey);}')
1216+
);
1217+
12151218
test(
12161219
'do not crash',
12171220
processCSS(

0 commit comments

Comments
 (0)