Skip to content

Commit

Permalink
fix(postcss-merge-longhand): preserve hyphenated custom property case
Browse files Browse the repository at this point in the history
Extends the regex that is used to locate custom properties inside a
value so that their case is preserved to also preserve the case of
custom property names that contain hyphen-minus characters.

For example, the case of the custom property in the following rule
should be preserved:

```css
border: 1px solid rgba(var(--colors-secondaryColor));
```
  • Loading branch information
ingmarh authored and ludofischer committed Jun 16, 2022
1 parent 858a8b7 commit 120a888
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/postcss-merge-longhand/src/lib/parseWsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const none = /^\s*(none|medium)(\s+none(\s+(none|currentcolor))?)?\s*$/i;

/* Approximate https://drafts.csswg.org/css-values-4/#typedef-dashed-ident */
// eslint-disable-next-line no-control-regex
const varRE = /--(\w|[^\x00-\x7F])+/g;
const varRE = /--(\w|-|[^\x00-\x7F])+/g;
/** @type {(v: string) => string} */
const toLower = (v) => {
let match;
Expand Down
5 changes: 5 additions & 0 deletions packages/postcss-merge-longhand/test/borders.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,11 @@ test(
)
);

test(
'Should preserve case of css custom property names with hyphens',
passthroughCSS('h1 { border: 1px solid rgba(var(--colors-secondaryColor)); }')
);

test(
'Should preserve case of css custom properties example 2',
processCSS(
Expand Down

0 comments on commit 120a888

Please sign in to comment.