Sitelet https://github.com/evanw/esbuild/pull/4539
Skip to content

Preserve range checking for negative calc results - #4539

Open
snoopuppy582 wants to merge 1 commit into
evanw:mainfrom
snoopuppy582:fix/4197-negative-calc-range
Open

snoopuppy582 wants to merge 1 commit into
evanw:mainfrom
snoopuppy582:fix/4197-negative-calc-range

Conversation

@snoopuppy582

Copy link
Copy Markdown
Contributor

Fixes #4197.

Reducing width: calc(5px - 10px) to width: -5px changes its meaning: CSS clamps the calculation to zero, while the literal negative value invalidates the declaration. For example, an earlier width: 10px declaration 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:

  • Focused calc parser tests passed, including the 27 new subcases.
  • go test -p 1 ./cmd/... ./internal/... ./pkg/... -count=1 passed (16 packages; 14 additional packages have no tests).
  • go vet -p 1 ./cmd/... ./internal/... ./pkg/..., formatting of the changed files, and git diff --check passed.
  • A text-only Chromium 148 check compares the public CLI's minified output with the original CSS. All 11 fixtures have the expected original computed values; four semantic mismatches before the fix become zero afterward.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The conversion of calc() does not take into account the valid range of the property value

1 participant