Skip to content

Commit 712993c

Browse files
authored
fix(postcss-merge-longhand): preserve fallback for color() function (#1397)
* fix(postcss-merge-longhand): preserve fallback for color() function Fix #1396 * fix(postcss-merge-longhand): add more color functions to regex
1 parent dd37500 commit 712993c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const { isValidWsc } = require('../validateWsc.js');
2020

2121
const wsc = ['width', 'style', 'color'];
2222
const defaults = ['medium', 'none', 'currentcolor'];
23+
const colorMightRequireFallback =
24+
/(hsla|rgba|color|hwb|lab|lch|oklab|oklch)\(/i;
2325

2426
/**
2527
* @param {...string} parts
@@ -832,9 +834,11 @@ function merge(rule) {
832834
);
833835

834836
if (duplicates.length) {
835-
if (/hsla\(|rgba\(/i.test(getColorValue(lastNode))) {
837+
if (colorMightRequireFallback.test(getColorValue(lastNode))) {
836838
const preserve = duplicates
837-
.filter((node) => !/hsla\(|rgba\(/i.test(getColorValue(node)))
839+
.filter(
840+
(node) => !colorMightRequireFallback.test(getColorValue(node))
841+
)
838842
.pop();
839843

840844
duplicates = duplicates.filter((node) => node !== preserve);

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

+6
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ test(
706706
)
707707
);
708708

709+
test(
710+
'should not merge fallback colours with color function',
711+
passthroughCSS(
712+
'h1{ border-color:rgb(37,45,49);border-color:color(display-p3 0.1451 0.1765 0.1922 / 1)}'
713+
)
714+
);
709715
test(
710716
'should not merge fallback colours with shorthand property',
711717
processCSS(

0 commit comments

Comments
 (0)