Skip to content

Support the modern attr() type() syntax#495

Open
ATKasem wants to merge 1 commit into
microsoft:mainfrom
ATKasem:fix/attr-modern-type-syntax
Open

Support the modern attr() type() syntax#495
ATKasem wants to merge 1 commit into
microsoft:mainfrom
ATKasem:fix/attr-modern-type-syntax

Conversation

@ATKasem

@ATKasem ATKasem commented Jul 14, 2026

Copy link
Copy Markdown

Fixes #451

attr() is parsed through the generic function machinery, so the modern attr( <name> <type>?, <fallback>? ) form reported false syntax errors. attr(data-x type(<length>)) produced ) expected and at-rule or selector expected because the <length> syntax tokens inside type() aren't valid value terms.

This teaches the parser the type( <syntax> ) argument (*, <type-name> components joined with |, with optional +/# multipliers), scoped to inside attr() via a small depth counter so a user-defined type() function elsewhere (e.g. a Sass @function type()) is left alone.

Everything that already parsed keeps parsing the same way — legacy attr(name) / attr(name unit) / attr(name, fallback), raw-string, type(*), empty attr(), and Sass/Less variables. Malformed types such as attr(x type()) or attr(x type(<length)) still report an error.

Added parser tests in parser.test.ts covering the legacy forms, the modern type() forms, the non-attr type() guard, and the malformed cases.

attr() is parsed through the generic function machinery, so the modern
attr( <name> <type>?, <fallback>? ) form reported false syntax errors:
type(<length>) failed because the <length> syntax tokens are not valid
value terms.

Recognize type(<syntax>) as an argument, scoped to inside attr() via a
depth guard so a user-defined type() function elsewhere is unaffected.
Legacy attr(), units, raw-string, and Sass/Less variables are unchanged.

Fixes microsoft#451
@ATKasem

ATKasem commented Jul 14, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

new attr() function with type(<length>) falsely reports syntax error

1 participant