Skip to content

feat: minify colors in var() fallback values #1143

Open
yisibl wants to merge 7 commits intoparcel-bundler:masterfrom
yisibl:minify-color-in-var
Open

feat: minify colors in var() fallback values #1143
yisibl wants to merge 7 commits intoparcel-bundler:masterfrom
yisibl:minify-color-in-var

Conversation

@yisibl
Copy link
Contributor

@yisibl yisibl commented Jan 29, 2026

Fixes: #601

For security purposes, a whitelist mechanism has been added, which only
takes effect for color-related properties and within `var()` expressions.
Add support for minifying colors inside var() fallback values when usedwithin CSS gradient functions and image-related properties.

Changes:

- Rename `COLOR_KEYWORDS` to `MINIFY_COLORS_IN_FN`
- Extend has_color_function() to include more gradient functions and `image-set()`:
- Update tests to verify color minification in var() fallbacks
@yisibl yisibl marked this pull request as draft February 2, 2026 02:39
Preserve parsing context when reading var() fallbacks inside unparsed property token lists, so color-ident minification respects function-level whitelisting instead of being reapplied as top-level parsing.

e.g.

Added/updated regression tests in test_custom_properties covering:
non-whitelisted function: foo(var(--c, blue)) should keep blue,
@yisibl yisibl force-pushed the minify-color-in-var branch from 1077b8e to c8c21ea Compare February 8, 2026 16:10
…colors

Pass function-level `TokenListParseOptions` into `UnresolvedColor::parse` so
`light-dark(...)` arguments inherit the same color-ident minification context
as the surrounding function parse.

In the unresolved `light-dark` branch, parse light/dark arguments with
`TokenList::read_token_list(..., parse_options)` instead of `TokenList::parse(...)`,
so `var()` fallbacks can be minified where allowed while still respecting
non-whitelisted nested functions.
@yisibl yisibl marked this pull request as ready for review February 8, 2026 17:10
@yisibl
Copy link
Contributor Author

yisibl commented Feb 8, 2026

@devongovett This is ready for review, PTAL

@yisibl yisibl force-pushed the minify-color-in-var branch from fbffc31 to a83cc2c Compare February 11, 2026 09:25
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.

Minify CSS variable fallbacks

1 participant