Preserve range checking for negative calc results - #4539
Open
snoopuppy582 wants to merge 1 commit into
Open
snoopuppy582 wants to merge 1 commit into
snoopuppy582 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4197.
Reducing
width: calc(5px - 10px)towidth: -5pxchanges its meaning: CSS clamps the calculation to zero, while the literal negative value invalidates the declaration. For example, an earlierwidth: 10pxdeclaration can then take effect. The same distinction affects negative numbers, percentages, and calculations passed through custom properties.Keep the outer
calc()when its simplified result is a negative numeric value. Arithmetic still folds inside the wrapper, and positive results, zero, and nested calculations retain their existing simplifications. Keeping the wrapper is conservative for properties that permit negatives, since this reducer does not know the property's allowed range.Tests cover the three numeric token kinds, cascade fallbacks, custom properties, and adjacent positive, zero, variable, and nested-expression cases. The 27 new subcases produced 16 failures and 11 passing controls before the fix on the current main commit.
Validation on Windows with Go 1.26.5:
go test -p 1 ./cmd/... ./internal/... ./pkg/... -count=1passed (16 packages; 14 additional packages have no tests).go vet -p 1 ./cmd/... ./internal/... ./pkg/..., formatting of the changed files, andgit diff --checkpassed.The JavaScript API/end-to-end, WebAssembly, race, and other operating-system suites were not run locally.
OpenAI Codex developed the implementation, regression tests, browser comparison, and this description. An independent agent reviewed the diff.
Written by an agent (OpenAI Codex, GPT-6).