Skip to content

Commit

Permalink
fix(postcss-merge-longhand): preserve fallback for color() function (#…
Browse files Browse the repository at this point in the history
…1397)

* fix(postcss-merge-longhand): preserve fallback for color() function

Fix #1396

* fix(postcss-merge-longhand): add more color functions to regex
  • Loading branch information
ludofischer committed May 20, 2022
1 parent dd37500 commit 712993c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/postcss-merge-longhand/src/lib/decl/borders.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const { isValidWsc } = require('../validateWsc.js');

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

/**
* @param {...string} parts
Expand Down Expand Up @@ -832,9 +834,11 @@ function merge(rule) {
);

if (duplicates.length) {
if (/hsla\(|rgba\(/i.test(getColorValue(lastNode))) {
if (colorMightRequireFallback.test(getColorValue(lastNode))) {
const preserve = duplicates
.filter((node) => !/hsla\(|rgba\(/i.test(getColorValue(node)))
.filter(
(node) => !colorMightRequireFallback.test(getColorValue(node))
)
.pop();

duplicates = duplicates.filter((node) => node !== preserve);
Expand Down
6 changes: 6 additions & 0 deletions packages/postcss-merge-longhand/test/borders.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,12 @@ test(
)
);

test(
'should not merge fallback colours with color function',
passthroughCSS(
'h1{ border-color:rgb(37,45,49);border-color:color(display-p3 0.1451 0.1765 0.1922 / 1)}'
)
);
test(
'should not merge fallback colours with shorthand property',
processCSS(
Expand Down

0 comments on commit 712993c

Please sign in to comment.