Skip to content

v0.0.40 - Round 15 (Merge, calc)

Choose a tag to compare

@TheJaredWilcurt TheJaredWilcurt released this 25 Sep 03:29
· 59 commits to main since this release
f1c06c1

What was failing and how I fixed it

whitespace/0020 — numbers inside custom properties src\rules\custom-properties.js
Only leading zeros were stripped, so 0.020em survived. Replaced the regex with a token-driven pass: the value is run through the existing tokenizeCssValue, and only number/dimension/percentage tokens are restated compactly — strings, urls, and hash colors are untouched by construction. The rewrite is discarded if re-tokenizing shows any token boundary moved (which is what keeps 1.0.0 from collapsing into 10), and numbers that only round-trip through scientific notation are left alone.

merging/0021–0024 — merging same-selector rules across a separator src\rules\optimize.js:1354-1461
The placement check asked only whether relocating a rule's declarations was safe, which specificity alone always answered "no" here. Added the missing idea: declarations that lose the cascade inside the merged rule are dropped anyway, so they can cross anything. findDecidingDeclarations works out which declaration wins each leaf property of the combined body (important beats non-important, otherwise last wins), and the merged rule is placed wherever the declarations that outlive the merge already were. Only when both rules still decide something does it fall back to the relocation analysis.

calc/0027–0029 — negative results on non-negative properties src\value\math.js
Added clampResolvedValueToPropertyRange, applied to what calc()/min()/max() resolve to. It's deliberately applied only at the point a math function dissolves, so a literal width:-5px stays invalid (and gets dropped by the engine) rather than becoming 0, per the spec's range-checking rules. The property list covers the non-negative properties broadly (sizing, padding, border widths/radii, gaps, flex, durations…), not just width.

calc/0007, calc/0030 — resolving percentage division
The old code explicitly preserved calc(100%/N), which is what the upstream tests used to want. Replaced it with resolvePercentageDivision, which resolves the division and keeps whichever of the result and the calculation is shorter. Precision comes from a new formatResolvedNumber in src\value\shared.js, implementing the README's rule directly: at most 7 characters of digits-plus-decimal-point, correctly rounded. I applied that same budget everywhere a calculation resolves to a number (dimension folding, the trailing rounding pass, standalone numeric values) so calc(100px/3) → 33.3333px matches calc(100%/3) → 33.3333%, rather than leaving two different precisions in the codebase.

Two incidental fixes along the way: roundCompactNumber stripped trailing zeros from whole numbers (roundCompactNumber(1000000, 0) returned 1), which the new budget would have triggered; and formatDimension became unused once the resolved-dimension helper replaced it, so I removed it rather than leave it exported and orphaned.