Skip to content

Discard calc operations that operate on zero values #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ben-eb opened this issue Mar 19, 2015 · 3 comments
Closed

Discard calc operations that operate on zero values #2

ben-eb opened this issue Mar 19, 2015 · 3 comments

Comments

@ben-eb
Copy link
Collaborator

ben-eb commented Mar 19, 2015

Would it be possible to discard parts of the calc() function that operate on zero values? For example:

div {
    width: calc(100vw / 2 - 6px + 0px);
}

Can be:

div {
    width: calc(100vw / 2 - 6px);
}

And:

div {
    width: calc(500px - 0px);
}

Can be:

div {
    width: 500px;
}

It's from this edge case in CSSO:

css/csso#222

@MoOx
Copy link
Owner

MoOx commented Mar 19, 2015

calc(500px - 0px) is already transformed to 500px.

You can try here http://cssnext.github.io/cssnext-playground/ since cssnext use postcss-calc which use this package ;)

For the first example, we need to handle math operator priorities (which is not the case for now).
I am open for a PR for this.

Meanwhile, maybe you can do something like:

div {
    width: calc(100vw / 2 - (6px + 0px));
}

which is transformed to

div {
    width: calc(100vw / 2 - 6px);
}

@ben-eb
Copy link
Collaborator Author

ben-eb commented Mar 19, 2015

Didn't realise that was already transformed, thanks 👍

Perhaps it's possible to use this module for it? https://www.npmjs.com/package/math-analysis - though I've got a lot on my plate at the minute so I probably won't be able to work on a PR right away.

@ben-eb
Copy link
Collaborator Author

ben-eb commented May 8, 2017

@ben-eb ben-eb closed this as completed May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants