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

feat(core): New parser for CSS selectors #10514

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

CatchABus
Copy link
Contributor

@CatchABus CatchABus commented Apr 13, 2024

PR Checklist

What is the current behavior?

Right now, core css parser does not analyze CSS selectors like functional pseudo-classes.
This is one of the reasons the implementation of certain CSS features is a bit hard.

What is the new behavior?

Core will make use of css-what parser for selectors. This is a modern parser that returns a result with important details for CSS selectors. Apart from its popularity, size was also a factor for this choice.

Additions

  • Attribute selectors case insensitivity (see https://www.w3.org/TR/selectors-4/#attribute-case)
  • Proper implementation of :is() pseudo-class
  • Proper implementation of :where() pseudo-class
  • Proper implementation of :not() pseudo-class
  • Functional seudo-classes specificity is applied based on MDN docs
  • Added support for pseudo-class selector list types (Regular, Fogiving, Relative)
  • A functional pseudo-class can become dynamic provided that its selector list contains a dynamic selector
  • Fix for a small bug related to attribute selectors without value
  • Added support for combinators in functional pseudo-class selector list
  • Added support for ~ combinator
  • Added app UI sample for general sibling combinator
  • Added unit tests for functional pseudo-classes

The following css module functions are no longer used:

  • parseSelector
  • parseSimpleSelectorSequence
  • parseSimpleSelector
  • parseUniversalSelector
  • parseSimpleIdentifierSelector
  • parseAttributeSelector
  • parseCombinator

@cla-bot cla-bot bot added the cla: yes label Apr 13, 2024
@CatchABus CatchABus changed the title Css selector parser rework feat(core): New parser for CSS selectors Apr 13, 2024
@farfromrefug
Copy link
Collaborator

@CatchABus is CSS what supposed to work alongside rework or is it suppose to replace it ?

@CatchABus
Copy link
Contributor Author

CatchABus commented Apr 14, 2024

@CatchABus is CSS what supposed to work alongside rework or is it suppose to replace it ?

It's actually a replacement for all selector-related functions in this module: https://github.com/NativeScript/NativeScript/blob/main/packages/core/css/parser.ts

The functions I mentioned above are part of that module (though I've not removed them yet):

  • parseSelector
  • parseSimpleSelectorSequence
  • parseSimpleSelector
  • parseUniversalSelector
  • parseSimpleIdentifierSelector
  • parseAttributeSelector
  • parseCombinator

I made sure to adapt it to core without breaking existing functionality. New pseudo-classes are still missing 1 or 2 advanced features so I'm still working on them.

@farfromrefug
Copy link
Collaborator

@CatchABus OK makes sense! Good job

@rigor789
Copy link
Member

@CatchABus some selectors to consider for testing:

image

Note, right now we convert these to supported (albeit not exact) selectors in the @nativescript/tailwind plugin itself, but if we could support them oob that would simplify things...

Specifically, the :not() and :is() selectors we don't support, and I believe we also don't support the ~ combinators. https://github.com/NativeScript/tailwind/blob/fae88eece49ee5f6df4cf0de1a715768a4dd765c/src/removeUnsupported.js#L86-L90

@CatchABus
Copy link
Contributor Author

CatchABus commented Apr 15, 2024

@CatchABus some selectors to consider for testing:

Note, right now we convert these to supported (albeit not exact) selectors in the @nativescript/tailwind plugin itself, but if we could support them oob that would simplify things...

Specifically, the :not() and :is() selectors we don't support, and I believe we also don't support the ~ combinators. https://github.com/NativeScript/tailwind/blob/fae88eece49ee5f6df4cf0de1a715768a4dd765c/src/removeUnsupported.js#L86-L90

This PR contains support for :not(), :is(), and :where() Level 4.
I'll add ~ as TODO at first post 😄

@CatchABus CatchABus marked this pull request as ready for review April 20, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants