Fix canonicalization bug where we end up with a high precision number#20221
Conversation
100% / 3.5 = 28.571428571428573%, which is correct but not as user friendly. Especially when going from `w-[calc(100%/3.5)]` → `w-[28.571428571428573%]`
Confidence Score: 5/5The change is narrowly scoped to division folding in constant-fold-declaration.ts, uses Math.round correctly to avoid IEEE 754 edge cases, and is covered by targeted regression tests. Safe to merge. The precision guard correctly uses Math.round, which handles floating-point representations where multiplying by 100 lands just below an integer. The logic is straightforward, the existing test suite continues to pass, and two new tests cover both the high-precision bail-out and the normal-precision fold path. No files require special attention. Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThis PR prevents high-precision division results in 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/tailwindcss/src/constant-fold-declaration.test.ts (1)
131-133: 💤 Low valueTest correctly validates the fix.
The test verifies that
calc(100% / 3.5)is not folded to a high-precision result. Consider adding a few more test cases to strengthen coverage:
- High-precision cases:
calc(10 / 3),calc(100% / 7)- Confirm 2-decimal folding still works:
calc(100% / 8)→12.5%,calc(100% / 4)→25%However, as a focused regression test for issue
#1591, this is sufficient.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/tailwindcss/src/constant-fold-declaration.test.ts` around lines 131 - 133, Add additional unit cases around constantFoldDeclaration to strengthen coverage: include high-precision no-fold examples such as 'calc(10 / 3)' and 'calc(100% / 7)' to ensure they are returned unchanged, and add assertions that 2-decimal or exact folding still occurs (e.g., 'calc(100% / 8)' -> '12.5%' and 'calc(100% / 4)' -> '25%') so both non-folding high-precision and expected folding behaviors are validated alongside the existing 'calc(100% / 3.5)' test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/tailwindcss/src/constant-fold-declaration.test.ts`:
- Around line 131-133: Add additional unit cases around constantFoldDeclaration
to strengthen coverage: include high-precision no-fold examples such as 'calc(10
/ 3)' and 'calc(100% / 7)' to ensure they are returned unchanged, and add
assertions that 2-decimal or exact folding still occurs (e.g., 'calc(100% / 8)'
-> '12.5%' and 'calc(100% / 4)' -> '25%') so both non-folding high-precision and
expected folding behaviors are validated alongside the existing 'calc(100% /
3.5)' test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bbd63301-1104-40e4-8dc7-5bd569bbf7e4
📒 Files selected for processing (3)
packages/tailwindcss/src/canonicalize-candidates.test.tspackages/tailwindcss/src/constant-fold-declaration.test.tspackages/tailwindcss/src/constant-fold-declaration.ts
This PR fixes a bug where we suggest a canonicalization with a high precision number.
E.g.:
w-[calc(100%/3.5)]→w-[28.571428571428573%]While this is technically correct, it's also not as user friendly. This PR solves this issue by checking whether the result has a precision of
.xxat most. If that's not the case, then we keep the original expression.Fixes: tailwindlabs/tailwindcss-intellisense#1591
Test plan