Skip to content

CSS: tokenize a dashed ident followed by ( as a function token - #135

Closed
yxshee wants to merge 1 commit into
tdewolff:masterfrom
yxshee:css-custom-function-token
Closed

yxshee wants to merge 1 commit into
tdewolff:masterfrom
yxshee:css-custom-function-token

Conversation

@yxshee

@yxshee yxshee commented Nov 9, 2026

Copy link
Copy Markdown

An ident sequence directly followed by ( is a function token, and that includes dashed idents: --fn(1px) is the <dashed-function> syntax of CSS custom functions (css-values-5 / css-mixins-1, shipping in Chrome). The CSS lexer returns every ident that starts with -- as a CustomPropertyNameToken without looking at the next byte, so --fn( comes out as a custom property name followed by a parenthesis:

--fn(1px)     parse:    CustomPropertyName("--fn") LeftParenthesis("(") Dimension("1px") RightParenthesis(")")
              css-tree: Function("--fn(") Dimension("1px") RightParenthesis(")")

This checks for ( after the custom property name and returns a FunctionToken in that case. --x: and --fn ( (with whitespace before the parenthesis) are unchanged. Three cases added to TestTokens; go test ./... passes, and minify's css tests pass against this branch (its output for a{width:--fn(1px)} is unchanged, since unknown functions are passed through).

Found by comparing the lexer with css-tree's tokenizer on generated input. The other differences in that comparison are intentional in this lexer (a quoted argument stays inside the URL token, \url( is treated as a URL) or on css-tree's side (\ followed by NUL is a valid escape here, which matches the spec).

An ident sequence followed by ( is a function token, and that includes
dashed idents: --fn(1px) is the <dashed-function> syntax of CSS custom
functions (css-values-5). The lexer returned every ident starting with --
as a CustomPropertyNameToken without looking at the next byte, so --fn(
came out as a custom property name followed by a parenthesis, where
css-tree and the specification give a single function token. Only a (
directly after the name changes; --x: and --fn ( are unaffected.
@yxshee yxshee closed this Nov 9, 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