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

Variables not defined for selectors of higher specificity #98

Closed yangshun closed 5 years ago

yangshun commented 5 years ago

Thanks for this awesome plugin! I have some questions regarding how the plugin deals with selectors of higher specificity.

I see that

.button {
  --button-background-color: red;   
  color: var(--button-background-color);
}

.button:hover {
  --button-background-color: green;
}

correctly becomes

.button {   
  color: red;
}
.button:hover { 
  color: green;
}

because .button:hover is a pseudoclass of .button.

But the following:

.button {
  --button-background-color: red;   
  color: var(--button-background-color);
}
.button.button-primary {
  --button-background-color: green;
}

produces just

.button {   
  color: red;
}

I was expecting the following because .button.button-primary is more specific than .button:

.button.button-primary {    
  color: green;
}

Is this a bug or is this intended? If it's a bug I could try sending a PR to fix it.

MadLittleMods commented 5 years ago

Duplicate of https://github.com/MadLittleMods/postcss-css-variables/issues/77