-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Bug] : css nano strips away important factors from multiplications in calc() #107
Comments
Sorry for delay, feel free to send a PR, it should be easy |
Seems to happen with division as well: const postcss = require('postcss');
const calc = require('postcss-calc');
const INPUT = `
.a {
border-width: calc(var(--foo) / 2 - var(--bar) / 2);
}
`;
const output = postcss().use(calc()).process(INPUT).css;
console.log(output.trim());
/*
.a {
border-width: calc(var(--foo) - var(--bar));
}
*/ |
Unfortunately #114 does not fix the following case ( Source: :root {
--fluid-min-width: 320;
--fluid-max-width: 1140;
--fluid-screen: 100vw;
--fluid-bp: calc(
(var(--fluid-screen) - ((var(--fluid-min-width) / 16) * 1rem)) /
((var(--fluid-max-width) / 16) - (var(--fluid-min-width) / 16))
);
} 7.0.4 outputs: :root {
--fluid-min-width: 320;
--fluid-max-width: 1140;
--fluid-screen: 100vw;
--fluid-bp: calc(
(var(--fluid-screen) - var(--fluid-min-width) / 16 * 1rem) /
(var(--fluid-max-width) - var(--fluid-min-width)) / 16
);
} The output should instead be: :root {
--fluid-bp: calc(
(var(--fluid-screen) - (var(--fluid-min-width) / 16) * 1rem)) /
((var(--fluid-max-width) - var(--fluid-min-width)) / 16
);
}
|
@coreyworrell please open a new issue and feel free to send a fix |
@evilebottnawi opened #115 just now. I am not familiar enough with the source code to send fix but hopefully someone else will be. |
Describe the bug
A CSS input with a
calc
function using css variables strips away factors from multiplications:calc(var(--foo) * 0.4 - var(--bar) * 0.4);
... will get converted to ...
calc(var(--foo) - var(--bar));
... and that is incorrect. This happens using cssnanos
default
preset.Input given:
Expected output
Actual output
Repo for reproduction
https://github.com/Sanderand/css-nano-calc-bug
Additional context
Disabling the
calc
optimization is a temporary workaround that I now use. I guess the calc optimization needs to be fixed.Thanks!
The text was updated successfully, but these errors were encountered: