Skip to content

Replace CSSSyntaxParser with CSSValueParser in data type sinks#55754

Closed
NickGerleman wants to merge 2 commits into
react:mainfrom
NickGerleman:export-D94357104
Closed

Replace CSSSyntaxParser with CSSValueParser in data type sinks#55754
NickGerleman wants to merge 2 commits into
react:mainfrom
NickGerleman:export-D94357104

Conversation

@NickGerleman

Copy link
Copy Markdown
Contributor

Summary:
Previously, CSSDataTypeParser sinks received a raw CSSSyntaxParser& reference,
which exposed low-level tokenization APIs (consumeComponentValue with lambdas,
consumeToken, etc.) that data type parsers should not use directly. This made
it unclear what operations are appropriate when implementing a new CSS data
type.

This change promotes detail::CSSValueParser to a public CSSValueParser class
that wraps CSSSyntaxParser and exposes only value-level parsing operations:
parseNextValue, peekNextValue, consumeWhitespace, consumeDelimiter, isFinished,
peekNextTokenIs, and saveState/restoreState for lookahead patterns.

All CSSDataTypeParser sink methods now receive CSSValueParser& instead of
CSSSyntaxParser&, and use parser.parseNextValue() instead of the free
function parseNextCSSValue(parser). Direct consumeComponentValue calls in
gradient parsers (CSSBackgroundImage.h) are replaced with keyword set parsing
via parseNextValue, with new To/At keywords added to CSSKeyword.

The free functions parseCSSProperty, parseNextCSSValue, and peekNextCSSValue
remain as convenience wrappers for backward compatibility.

Changelog: [Internal]

Reviewed By: jorge-cab

Differential Revision: D94357104

NickGerleman and others added 2 commits February 25, 2026 02:23
Summary:
Previously, CSS compound data types used two separate types:
`CSSCompoundDataType<T1, T2, ...>` as an empty marker struct for template
parameter deduction, and `CSSVariantWithTypes<CSSCompoundDataType<T1, T2, ...>>`
which resolved to `std::variant<T1, T2, ...>` for actual storage. This resulted
in redundant type aliases like `CSSTransformFunctionVariant`.

This change makes `CSSCompoundDataType<T1, T2, ...>` a `using` alias for
`std::variant<T1, T2, ...>` directly, so one type serves both roles: template
parameter deduction for parsing AND storage.

- Change `CSSCompoundDataType` from a marker struct to a `using` alias for
  `std::variant`
- Replace `CSSValidCompoundDataType` concept with `is_variant_of_data_types`
  trait that pattern-matches `std::variant` where all types satisfy `CSSDataType`
- Update `merge_data_types` and `merge_variant` specializations to use
  `std::variant` directly
- Store `AllowedTypesT` directly in `CSSList` compound type specialization
  (since it IS now the variant)
- Remove redundant `CSSTransformFunctionVariant`, `CSSFilterFunctionVariant`,
  and `CSSBackgroundImageVariant` aliases
- Update all downstream references in conversions

Changelog: [Internal]

Differential Revision: D94347088
Summary:
Previously, CSSDataTypeParser sinks received a raw CSSSyntaxParser& reference,
which exposed low-level tokenization APIs (consumeComponentValue with lambdas,
consumeToken, etc.) that data type parsers should not use directly. This made
it unclear what operations are appropriate when implementing a new CSS data
type.

This change promotes detail::CSSValueParser to a public CSSValueParser class
that wraps CSSSyntaxParser and exposes only value-level parsing operations:
parseNextValue, peekNextValue, consumeWhitespace, consumeDelimiter, isFinished,
peekNextTokenIs, and saveState/restoreState for lookahead patterns.

All CSSDataTypeParser sink methods now receive CSSValueParser& instead of
CSSSyntaxParser&, and use parser.parseNextValue<T>() instead of the free
function parseNextCSSValue<T>(parser). Direct consumeComponentValue calls in
gradient parsers (CSSBackgroundImage.h) are replaced with keyword set parsing
via parseNextValue<KeywordEnum>, with new To/At keywords added to CSSKeyword.

The free functions parseCSSProperty, parseNextCSSValue, and peekNextCSSValue
remain as convenience wrappers for backward compatibility.

Changelog: [Internal]

Reviewed By: jorge-cab

Differential Revision: D94357104
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2026
@meta-codesync

meta-codesync Bot commented Feb 25, 2026

Copy link
Copy Markdown

@NickGerleman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D94357104.

@react-native-bot

Copy link
Copy Markdown
Collaborator

Closing as this has been merged in 4d66a26

@react-native-bot react-native-bot added the Merged This PR has been merged. label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants