Skip to content

Accept clamp() and env() wherever calc() is accepted - #606

Closed
davesnx wants to merge 1 commit into
lexer-signed-fractionfrom
grammar-clamp-env
Closed

davesnx wants to merge 1 commit into
lexer-signed-fractionfrom
grammar-clamp-env

Conversation

@davesnx

@davesnx davesnx commented Sep 19, 2026

Copy link
Copy Markdown
Owner

clamp() and env() were fully implemented as grammar functions but no property could reach them: the shared Extended_length and Extended_percentage value types listed calc(), min() and max() as their math alternatives and nothing else, so width: clamp(10px, 5vw, 100px) and padding-top: env(safe-area-inset-top) were rejected with "invalid value". The Ahrefs monorepo works around it with an inline style. Both functions are now alternatives wherever calc() already is: clamp() on length, percentage, angle, time and frequency; env() on length and percentage, the only types it produces. Fixing this exposed a second defect: env()'s own grammar demanded a comma even without a fallback, so the common env(safe-area-inset-top) form failed; the grammar now reads env( <custom-ident> [ ',' <declaration-value> ]? ).

width: clamp(10px, 5vw, 100px)          -> .css-zpelvd{width:clamp(10px, 5vw, 100px);}
padding-top: env(safe-area-inset-top)   -> .css-2ju9ys{padding-top:env(safe-area-inset-top);}
width: calc(clamp(1px, 2vw, 3px) + 1px) -> .css-1vs0z9k{width:calc(clamp(1px, 2vw, 3px) + 1px);}

Evidence at e1c6df5:

  • New cram test packages/ppx/test/css-support/clamp-env-functions.t: six declarations, all rejected before with the "Expected 'length', 'percentage', 'calc()', … 'min()'" message, all rendered after as passthrough text like calc().
  • Types.ml gains the matching variant arms; the runtime witnesses are unchanged because these values render as text.
  • make format-check, make build, make test: all exit 0.

Risk: two-way door. Only previously rejected values change behaviour; no existing output or hash changes.

@vercel

vercel Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
styled-ppx Ignored Ignored Preview Sep 23, 2026 6:40am UTC

Request Review

@davesnx
davesnx force-pushed the lexer-signed-fraction branch from 9fe43f3 to f436aed Compare September 22, 2026 12:46
@davesnx
davesnx force-pushed the grammar-clamp-env branch 2 times, most recently from ffd67f7 to 514f771 Compare September 22, 2026 13:32
@davesnx
davesnx force-pushed the lexer-signed-fraction branch 2 times, most recently from 07d18ea to 76558b4 Compare September 23, 2026 06:11
@davesnx
davesnx force-pushed the lexer-signed-fraction branch from 76558b4 to fe08a21 Compare September 23, 2026 06:39
@davesnx davesnx closed this Sep 23, 2026
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.

1 participant