postcss / postcss-custom-properties

Use Custom Properties in CSS
https://postcss.github.io/postcss-custom-properties
MIT License
595 stars 77 forks source link

fix: plugin will parse fallback until it finds a known value #240

Closed calebdwilliams closed 3 years ago

calebdwilliams commented 3 years ago

This pull request provides a fix for #208 Custom Property as Fallback for Custom Property .

Existing behavior

Currently the library only parses one level of the custom property tree to set a fallback value, so the

:root {
  --primary: tomato;
}
.rule {
  color: var(--override, var(--primary));
}

will yield

:root {
  --primary: tomato;
}
.rule {
  color: var(--primary);
  color: var(--override, var(--primary));
}

New behavior

The above example will now yield

:root {
  --primary: tomato;
}
.rule {
  color: tomato;
  color: var(--override, var(--primary));
}

This should work regardless of how many fallbacks are used.

calebdwilliams commented 3 years ago

See also #240

calebdwilliams commented 3 years ago

@jonathantneal Is there anything else this needs before being merged? My organization's ability to use PostCSS for our purposes kind of hinges on this functionality.

jonathantneal commented 3 years ago

Fantastic work, @calebdwilliams. Thank you!