MadLittleMods / MadLittleMods/postcss-css-variables

Parenthesis pair mangled when variables declared within a CSS function

Open
#62 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
551
Forks
63
PR merge metrics
No merged PRs in 30d

Description

Hello,

I try to transform a css file (material-components-web.css) that contains variables declared in differents ways.
Some of them are not replaced by the plugin. For example :
background-color: color(var(--mdc-theme-text-primary-on-primary, white));
gives :
background-color: color(white;
So it miss a ')' before ';'

I had a look to the code of the plugin and I think that I found a solution. In the file resolve-value.js, I modified the regex variable :
RE_VAR_FUNC = (/var\((--[^,\s]+?)(?:\s*,\s*(.+))?\)/)
to
RE_VAR_FUNC = (/var\((--[^,\s]+?)(?:\s*,\s*([^\)\(]+|(.+)))?\)/);

It seems to work. If it is ok for you, can you implement it in your future versions?
Thx

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in resolve-value.js and inspect the RE_VAR_FUNC expression. Reproduce the material-components-web.css example with color(var(--mdc-theme-text-primary-on-primary, white)); then verify that transforming it preserves the closing parenthesis before the semicolon. The proposed regular-expression change provides a starting point, and done means the variable is replaced without mangling the function.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript
Domain
frontend, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.