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: support selector intersection #2827

Merged
merged 20 commits into from
Mar 16, 2023
Merged

feat: support selector intersection #2827

merged 20 commits into from
Mar 16, 2023

Conversation

idoros
Copy link
Collaborator

@idoros idoros commented Feb 23, 2023

This PR adds the inference for multiple selector types behinds a new experimental flag that enables support for transformation, validation and completion of cases that combine multiple selectors like: @st-scope, @custom-selector, :is(), :where(), :nth-x(, ), and future support of nested CSS and multiple extends.

In addition the new flag is changing the behavior of combinators and other selector nodes so that they will reset the selector inferred type back to the inferred context.

The flag is meant for testing in v5 and is intended to be the default behavior in the upcoming v6

Tasks

  • track multi-selector context while transforming
  • refactor to use new context
    • pseudo-class/element transformation
    • class/element transformation
    • mixin context
    • language service completions
    • remove old tracking code
  • add experimentalSelectorInference config flag to activate new behavior (supported from stylable.config)

Changes in selector type inference with flag

  • combine multiple selectors in :is()/:where()/:nth-x() with optional preceding selector type (:has()/:not() don't narrow the inference)
    • add nth-child/nth-last-child to list of pseudo-classes that support nested selectors (with An+B of S)
  • narrow inferred selector after custom-pseudo-state with multiple mapped selectors
  • narrow inferred selector for nested selectors within @st-scope with multiple selectors
  • narrow inferred selector after inline @custom-selector (":--custom") with multiple selectors
  • reset selector inference after combinator, global and native element
  • use intersection completions in LSP (only custom-pseudo-classes atm)
  • combine @custom-selector multiple selectors into :is() not possible because selectors need to be able to change the selector subject, :is() assumes the nested selectors subject is the preceding compound selector.

Fix

@idoros idoros added feature New syntax feature or behavior core Processing and transforming logic tech debt Updates, upgrades, stale code and work-arounds labels Feb 23, 2023
@idoros idoros self-assigned this Feb 23, 2023
@idoros idoros requested review from tomrav and removed request for tomrav March 6, 2023 14:00
- combine resolved selector data into a common type that can later be used to retrieve intersection resolve of multiple selectors
@idoros idoros force-pushed the ido/selector-intersection branch from 2cf5cca to b5e71b0 Compare March 8, 2023 09:11
- selectorAstResolveMap stores inferred selectors
- InferredSelector API for all pseudo-states
- add `nth-child/nth-last-child` to list of pseudo-classes with nested selectors
- flatten `@st-scope` at the end of the transformation
- pass nesting inferred selector between rules
- fix lsp completions to differ selector inferred context and nesting
…t type

- native element already set the inference - just added tests
- tech-debt: with the flag on the transformation of inline custom selector move
- remove extra exp flag arg from ScopeContext
- comment about InferredSelector assumptions
- add test to check that :not() does nothing yet
Copy link
Collaborator

@tomrav tomrav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, this definitely opens the door for some really cool features down the line, please address requested fixes.

packages/core/src/helpers/custom-state.ts Outdated Show resolved Hide resolved
packages/core/src/features/css-pseudo-class.ts Outdated Show resolved Hide resolved
packages/core/src/features/st-custom-selector.ts Outdated Show resolved Hide resolved
packages/core/src/stylable-transformer.ts Outdated Show resolved Hide resolved
packages/core/src/stylable-transformer.ts Outdated Show resolved Hide resolved
packages/core/src/stylable-transformer.ts Outdated Show resolved Hide resolved
packages/core/src/stylable-transformer.ts Outdated Show resolved Hide resolved
packages/core/src/stylable-transformer.ts Outdated Show resolved Hide resolved
- use "selectorNode" or "ruleOrAtRule" instead of "rule" to describe potential rule or atrule
- remove commented imports
- remove self referencing module import
- changed internal transformer name from "selectorContext" to "inferredNestSelector"
- cleaned transformer.createSelectorContext args
- remove temp "setCurrentInferredSelectorNode"
- unified "duplicateSelectors" pushes
- add explanation for SelectorMultiplier.duplicateSelectors
@idoros idoros linked an issue Mar 15, 2023 that may be closed by this pull request
inferred selector for nesting is inferred to the ast node (&), in any other case, fallback to infer the stylesheet root
- fix parent selector collection order
- clone selectors to avoid attaching inference to the wrong selector
- prefer to not delete fields from JS objects
- support same stats from the same meta
- support identical global states
@idoros idoros merged commit ee301dc into master Mar 16, 2023
@idoros idoros deleted the ido/selector-intersection branch March 16, 2023 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Processing and transforming logic feature New syntax feature or behavior tech debt Updates, upgrades, stale code and work-arounds
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

custom-selector .root:state is transformed as 2 nested elements
2 participants