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

Nested selectors break compilation #32

Closed firedev closed 8 years ago

firedev commented 8 years ago

Given:

:root {
  --color: red;
}

h1 {
  background: var(--color);
  &:hover {
    background: var(--color);
  }
}
h2, input[type=text] {
  background: var(--color);
  &:hover {
    background: var(--color);
  }
}

Expected:

h1 {
  background: red;
  &:hover {
    background: red;
  }
}
h2 {
  background: red;
  &:hover {
    background: red;
  }
}
input[type=text] {
  background: red;
  &:hover {
    background: red;
  }
}

Actual:

h1 {
  background: red;
  &:hover {
    background: red;
  }
}
h2 {
  background: red;
  &:hover {
    background: var(--color);
  }
}
input[type=text] {
  background: red;
  &:hover {
    background: var(--color);
  }
}
MadLittleMods commented 8 years ago

Run postcss-nested before postcss-css-variables: https://github.com/MadLittleMods/postcss-css-variables#nested-rules

Which would turn into after running through postcss-nested:

:root {
  --color: red;
}

h1 {
  background: var(--color);
}

h1:hover {
  background: var(--color);
}
h2, input[type=text] {
  background: var(--color);
}
h2:hover, input[type=text]:hover {
  background: var(--color);
}

And then postcss-css-variables:

h1 {
  background: red;
}

h1:hover {
  background: red;
}
h2 {
  background: red;
}
input[type=text] {
  background: red;
}
h2:hover {
  background: red;
}
input[type=text]:hover {
  background: red;
}
firedev commented 8 years ago

I see, thanks