postcss / postcss-custom-properties

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

Throw error for circular variables references #23

Closed hgl closed 9 years ago

hgl commented 9 years ago

Fix the things I mentioned in the gist.

MoOx commented 9 years ago

No test, no merge. I need to see what are the improvements here. This also need docs & a line in the CHANGELOG too please.

hgl commented 9 years ago

I was going to add unit tests. But what this does is to simply throw an error. And none of the unit tests test thrown error. So not sure how to test it.

For such code

:root {
    --color: var(--bg-color);
    --bg-color: var(--color)
}
body {
    color: var(--bg-color);
}

It throws:

self-referential variable: --bg-color

Manually tested.

hgl commented 9 years ago

Once you think the commit is good, I will add doc and changelog.

hgl commented 9 years ago

This commit does two things:

Both don't affect normal usage. Not sure if I should mention them in doc.

MoOx commented 9 years ago

Please add a test using https://github.com/substack/tape#tthrowsfn-expected-msg Example here https://github.com/MoOx/reduce-css-calc/blob/master/test/index.js

hgl commented 9 years ago

Done.

hgl commented 9 years ago

Just found out this.

If there is a cycle in the dependency graph, all the custom properties in the cycle must compute to their initial value (which is a guaranteed-invalid value)

The initial value of a custom property is an empty value

Probably shouldn't throw an error?

MoOx commented 9 years ago

Just a warning. See postcss 4.1 api.

hgl commented 9 years ago

I end up using console.warn as you did for undefined variables.