diff --git a/fixtures/compress/units/5.css b/fixtures/compress/units/5.css new file mode 100644 index 00000000..fce7f55c --- /dev/null +++ b/fixtures/compress/units/5.css @@ -0,0 +1,22 @@ +/* + issue #426 added min()/max()/clamp() to the math functions where a zero value + keeps its unit. The same rule applies to the other CSS math functions: inside + round(), mod(), rem(), hypot(), abs() etc. a unitless zero is a , not a + zero , so dropping the unit turns a valid value into an invalid one. +*/ + +.round { + width: round(0px, 3px); + height: round(nearest, 0px, 3px); +} +.mod-rem { + width: mod(0px, 3px); + height: rem(0px, 3px); +} +.hypot-abs { + width: hypot(0px, 3px); + height: abs(0px); +} +.nested { + width: calc(1px + round(0px, 3px)); +} diff --git a/fixtures/compress/units/5.min.css b/fixtures/compress/units/5.min.css new file mode 100644 index 00000000..b79de7e9 --- /dev/null +++ b/fixtures/compress/units/5.min.css @@ -0,0 +1 @@ +.round{width:round(0px,3px);height:round(nearest,0px,3px)}.mod-rem{width:mod(0px,3px);height:rem(0px,3px)}.hypot-abs{width:hypot(0px,3px);height:abs(0px)}.nested{width:calc(1px + round(0px,3px))} \ No newline at end of file diff --git a/lib/replace/Dimension.js b/lib/replace/Dimension.js index edb00388..008aa78f 100644 --- a/lib/replace/Dimension.js +++ b/lib/replace/Dimension.js @@ -2,9 +2,36 @@ import { packNumber } from './Number.js'; const MATH_FUNCTIONS = new Set([ 'calc', + + // comparison functions 'min', 'max', - 'clamp' + 'clamp', + + // stepped value functions + 'round', + 'mod', + 'rem', + + // trigonometric functions + 'sin', + 'cos', + 'tan', + 'asin', + 'acos', + 'atan', + 'atan2', + + // exponential functions + 'pow', + 'sqrt', + 'hypot', + 'log', + 'exp', + + // sign-related functions + 'abs', + 'sign' ]); const LENGTH_UNIT = new Set([ // absolute length units @@ -49,7 +76,8 @@ export default function compressDimension(node, item) { return; } - // issue #222: don't remove units inside calc + // issue #222: don't remove units inside a math function (calc(), round(), etc.), + // where a unitless zero is a rather than a zero if (this.function && MATH_FUNCTIONS.has(this.function.name)) { return; }