MadLittleMods / MadLittleMods/postcss-css-variables
Parenthesis pair mangled when variables declared within a CSS function
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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