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
540 stars 62 forks source link

TypeError in './lib/resolve-value.js' when the value of css-variable is not of string type. #83

Closed shonie closed 6 years ago

shonie commented 6 years ago

Hello!

I use your great package with this postcss.config.

I pass plain javascript object with variables to option variables. But if any variable is set to not-string value build process crashes with this TypeError.

screen shot 2018-09-07 at 1 49 37 pm

I've created reproduce repo here.

You can do:

git clone https://github.com/shonie/postcss-css-variables-bug-reproduce.git

npm i

npm start

Can i create PR for fixing this?

MadLittleMods commented 6 years ago

@shonie PR welcome (add some tests)! 🙂

shonie commented 6 years ago

Thank you for your response!

But before rushing into implementation, i want to discuss solution with you. I can propose two methods of fixing this.

Simplest one is to cast each variable value to string, which is safe, but not transparent.

Other, and, on my opinion better one, is to validate plugin options by some validations tool (something like schema-utils or ajv.

Me, personally, like schema-utils as it most likely to be already in client's node_modules as webpack uses it under the hood.

Thank you.

shonie commented 6 years ago

I have just now realized that ajv is strict dependency of schema-utils 😄. So better to use ajv directly.

MadLittleMods commented 6 years ago

@shonie Casting to string seems reasonable. We already do it for undefined -> 'undefined', https://github.com/MadLittleMods/postcss-css-variables/pull/44