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 missing when using variable with CSS functions (nested) #96

Closed
juliovedovatto opened this issue Apr 16, 2019 · 4 comments
Closed

Comments

@juliovedovatto
Copy link
Contributor

I'm facing problems with IE11 browser using css variables. So I decided to use this awesome lib to convert CSS variables to normal representation value, to make work in the browser.

But the css is broken after parsing it. It does not work in any browser.

After a time debugging, I noticed a wrong behavior.

Example:

Without postcss-css-variables

:root {
  --variable-name-goes-here: 24px;
}
/* [...] */
.css_class {
    width: calc(58.3333333333% - var(--variable-name-goes-here, 0px)); 
}

Using postcss-css-variables

.css_class {
width: calc(58.3333333333% - 24px; /* <- missing )) */
}

It seems the string replacement is not working as expected.

I'm using 0.12.0 version.

@MadLittleMods MadLittleMods changed the title Problems with nested CSS functions. Parenthesis missing when using variable with CSS functions (nested) Apr 17, 2019
@cuberoot
Copy link

I hit this too, so I took a quick look. The issue seems to be this regex.

/var\(\s*(--[^,\s]+?)(?:\s*,\s*(.+))?\s*\)/

When it matches calc(58.3333333333% - var(--variable-name-goes-here, 0px)), it steals an extra paren.

This sort of problem is really hard to solve well with regular expressions, sadly. The expression I am trying to parse is even worse:

padding: var(--spectrum-global-dimension-size-50)
        calc(
            var(
                    --spectrum-button-primary-padding-x,
                    var(--spectrum-global-dimension-size-200)
                ) - var(--spectrum-button-primary-border-size, 2px)
        );

@juliovedovatto
Copy link
Contributor Author

@cuberoot There is a pull request in process of approval to solve this problem #97 :)

let's hope @MadLittleMods approve it soon 🤞🏻

@cuberoot
Copy link

FYI, the fix from @juliovedovatto in #97 solves my more complicate case as well. Thanks!

@MadLittleMods
Copy link
Owner

Fixed via #97

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

No branches or pull requests

3 participants