MadLittleMods / postcss-css-variables

PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation
https://madlittlemods.github.io/postcss-css-variables/playground/
Other
536 stars 62 forks source link

Fix RE_VAR_FUNC for fallback. #25

Closed simono closed 8 years ago

simono commented 8 years ago

Given var(--me, 1) a() the first group would have been --me and the second group 1) a( which is wrong. With this fix the second group is correctly matched as 1.

This should fix #23.

MadLittleMods commented 8 years ago

@simono Thank you for the PR :grinning:

Can you add some tests that would have failed previously and are now fixed? This is to ensure we don't regress later on.

simono commented 8 years ago

@MadLittleMods Thanks for the great plugin 😀

I've added two tests in my branch. They fail on master and pass on my branch.

  1) postcss-css-variables missing variable declarations should work as function arguments:

      AssertionError: expected 'div{background-color:color(#fff) alpha(.5)}' to equal 'div{backgroun
d-color:color(#fff alpha(.5))}'
      + expected - actual

      -div{background-color:color(#fff) alpha(.5)}
      +div{background-color:color(#fff alpha(.5))}

and

  2) postcss-css-variables missing variable declarations should work with two consecutive vars:

      AssertionError: expected 'div{border:solid) var(--color,red}' to equal 'div{border:solid red}'
      + expected - actual

      -div{border:solid) var(--color,red}
      +div{border:solid red}
simono commented 8 years ago

Please don't merge right now. I'm investigating a regression my fix introduced.

div {
    --foo-color: #fff;
    background-color: var(--foo-color, rgb(1,1,1));
}

is broken and produces

div {
    background-color: #fff);
}
MadLittleMods commented 8 years ago

Please add a test to cover this case, thanks for the update :)

simono commented 8 years ago

I've added a test (variable-with-fallback-as-function) which fails at the moment.

This issue can't be fixed with the current Regex. Something like balanced-match could be used. postcss-custom-properties uses it and works correctly.

Right now I won't have the time to fix this. Feel free to close this PR and keep the current implementation. Thanks!