Is css-calc suitable for use in a minifier? #1450
-
Hello, I am maintaining postcss-calc to use it inside of the cssnano minifier. I was wondering if css-calc could replace most of the current code, which relies on a currently unmaintained parser generator. css-calc even uses some tests derived from postcss-calc issues, but it is not advertised as a minifier: would using it as such would conflict with the intended development direction? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @ludofischer,
While a minifier will often try to optimize any expression, even when no outcome can be calculated.
I wrote When it encounters something it can't solve it aborts the entire mutation. I think it is definitely possible to instead keep trying to solve as many parts as possible. There will definitely be edge cases where I've followed some of the issues in |
Beta Was this translation helpful? Give feedback.
-
Thank you for all your explanations, it's going to take some time to digest! I did not remember correctly when I said that
I suppose that's the reason calc(100px + (100px - 100%)) b calc(200px - 100%)
I notice it says that white space is discarded, which covers another difference with
I did not know about the internal representation at all. This is very interesting! When you say refactoring, do you mean you would like to also change the |
Beta Was this translation helpful? Give feedback.
Hi @ludofischer,
css-calc
is not really build to be a minifier.It was build primarily to support relative color syntax.
For relative colors it is important to find the final outcome of a calc expression.
Any expression that doesn't have an outcome known at build-time is ignored.
While a minifier will often try to optimize any expression, even when no outcome can be calculated.
For example:
calc(100% - 10px + 20px)
->calc(100% + 10px)
calc(var(--foo) - 10px + 20px)
->calc(var(--foo) + 10px)
I wrote
css-calc
as a recursive descent parser that instead of return the full AST of all children returns the solved calc expression of the children.When it encounters something it can't solve i…