Skip to content

Is css-calc suitable for use in a minifier? #1450

Answered by romainmenke
ludofischer asked this question in Q&A
Discussion options

You must be logged in to vote

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…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@ludofischer
Comment options

@romainmenke
Comment options

@ludofischer
Comment options

@romainmenke
Comment options

Answer selected by ludofischer
Comment options

You must be logged in to vote
1 reply
@romainmenke
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants