Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parenthesis pair mangled when variables declared within a CSS function #62

Open
cmauduit opened this issue Oct 23, 2017 · 5 comments
Open
Labels

Comments

@cmauduit
Copy link

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

@MadLittleMods
Copy link
Owner

Hey @cmauduit,

I just tested this out and I am not getting the same results. Could another plugin be interfering here?

I also added a test to the codebase to make sure this test case is covered, dfb5ec1

Input:

.box-foo {
	background-color: color(var(--some-color, white));
}

Output:

.box-foo {
	background-color: color(white);
}

@kenbellows
Copy link

@MadLittleMods I see this as well in the PostCSS Playground. I'm running Chrome 62 on Windows 7, in case that makes any difference. Screenshot attached.
postcss-varsinfunctions-bug

@MadLittleMods
Copy link
Owner

Thanks @kenbellows, it looks like the key is to actually have the variable defined which I assumed wasn't because OP had the output value as the fallback value.

Input,

:root {
	--some-color: #f00;
}

.box-foo {
	background-color: color(var(--some-color, white));
}

Output:

.box-foo {
	background-color: color(#f00;
}

@MadLittleMods MadLittleMods changed the title Error with variables declared within a function Parenthesis pair mangled when variables declared within a CSS function Nov 13, 2017
@equinusocio
Copy link

Any update?

@MadLittleMods
Copy link
Owner

@equinusocio No update, PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants