Skip to content

Commit 9a64787

Browse files
committed
Fix stack overflow while simplifying calc expressions with nested functions
Fixes #166
1 parent 677277c commit 9a64787

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,6 +5502,10 @@ mod tests {
55025502
minify_test(".foo { width: calc(1cap + 2cap) }", ".foo{width:3cap}");
55035503
minify_test(".foo { width: calc(1lh + 2lh) }", ".foo{width:3lh}");
55045504
minify_test(".foo { width: calc(1x + 2x) }", ".foo{width:calc(1x + 2x)}");
5505+
minify_test(
5506+
".foo { left: calc(50% - 100px + clamp(0px, calc(50vw - 50px), 100px)) }",
5507+
".foo{left:calc(50% - 100px + clamp(0px,50vw - 50px,100px))}",
5508+
);
55055509
}
55065510

55075511
#[test]

src/values/calc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ impl<
394394
(Calc::Number(a), Calc::Number(b)) => Calc::Number(a + b),
395395
(Calc::Value(a), b) => (*a + V::from(b)).into(),
396396
(a, Calc::Value(b)) => (V::from(a) + *b).into(),
397+
(Calc::Function(a), b) => Calc::Sum(Box::new(Calc::Function(a)), Box::new(b)),
398+
(a, Calc::Function(b)) => Calc::Sum(Box::new(a), Box::new(Calc::Function(b))),
397399
(a, b) => (V::from(a) + V::from(b)).into(),
398400
}
399401
}

src/values/percentage.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,7 @@ impl<D: TryAdd<D> + Clone + std::cmp::PartialEq<CSSNumber> + std::cmp::PartialOr
298298
}
299299

300300
match (a, b) {
301-
(DimensionPercentage::Calc(a), DimensionPercentage::Calc(b)) => {
302-
return DimensionPercentage::Calc(Box::new(*a + *b))
303-
}
301+
(DimensionPercentage::Calc(a), DimensionPercentage::Calc(b)) => DimensionPercentage::Calc(Box::new(*a + *b)),
304302
(DimensionPercentage::Calc(calc), b) => {
305303
if let Calc::Value(a) = *calc {
306304
a.add(b)

0 commit comments

Comments
 (0)