Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions fixtures/compress/units/5.css
Original file line number Diff line number Diff line change
@@ -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 <number>, not a
zero <length>, 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));
}
1 change: 1 addition & 0 deletions fixtures/compress/units/5.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions lib/replace/Dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <number> rather than a zero <length>
if (this.function && MATH_FUNCTIONS.has(this.function.name)) {
return;
}
Expand Down