Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Definition Syntax parser fails on "<an+b>" #263

Open
tidoust opened this issue Sep 8, 2023 · 2 comments
Open

Value Definition Syntax parser fails on "<an+b>" #263

tidoust opened this issue Sep 8, 2023 · 2 comments

Comments

@tidoust
Copy link

tidoust commented Sep 8, 2023

The following code throws a SyntaxError:

const { definitionSyntax } = require('css-tree');
definitionSyntax.parse('<an+b>');

Error is:

Expect `>`
  <an+b>
-----^

Looking at the Value Syntax Definition, nothing says that such a reference to a data type needs to be only composed of characters that match [a-zA-Z0-9\-], as the parser seems to assume. Granted, that's been the case until now across CSS specifications...

Problem is this construct is now used to define the :nth selector in the CSS Generated Content for Paged Media Module spec in particular, where it is to be interpreted as a reference to the basic data type <an+b>.

@lahmatiy
Copy link
Member

The substitution of <an+b> with <an-plus-b> in mdn/data and CSSTree is a practical solution, eliminating the need for parsing exceptions or rule modifications for this infrequently used syntax. While adding an exception or expanding the ident character set are alternatives, adopting <an-plus-b> uniformly ensures parsing consistency and simplicity. However, discussable, I have no strong opinion here.
Interesting fact that the Selectors spec doesn't refer to <an+b> production:
image

@tidoust
Copy link
Author

tidoust commented Oct 16, 2023

Yes, we have a workaround in place for Webref data (which gets injected into mdn/data). Now, the single source of truth is supposed to be the spec. Ideally, that source would remain usable. I raised w3c/csswg-drafts#9473 against the definition to suggest <an-plus-b> as an alternative.

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

No branches or pull requests

2 participants