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

Add flattenNestedSelector #1267

Conversation

romainmenke
Copy link
Member

@romainmenke romainmenke commented Jan 31, 2024

See : stylelint/stylelint#6234

Stylelint has a bunch of rules which analyse selectors in a more analytical and less functional way.
For these rules it isn't relevant that the final selector is valid, or an equivalent.
It is much more important that it contains the right parts and the correct number of duplications. Just wrapping everything with :is() does not work there.


Name needs bikeshedding.

I want this to communicate that the outcome is the combination of the current and parent selector by using & as insertion points.

While at the same time making it clear that the result is not valid or equivalent.

Maybe :

  • glueNestedSelector
  • insertParentSelector
  • combineNestedSelector
  • ...

Copy link
Member

@Antonio-Laguna Antonio-Laguna left a comment

Choose a reason for hiding this comment

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

This LGTM! I think I'd go with either combine or flatten maybe?

@romainmenke
Copy link
Member Author

romainmenke commented Jan 31, 2024

I like flatten!

@ybiquitous
Copy link
Contributor

ybiquitous commented Feb 1, 2024

Hi, I love this work! 😄

For naming. The CSS Nesting spec uses "desugar" for :is(), too. Is this confusing?

The nesting selector can be desugared by replacing it with the parent style rule’s selector, wrapped in an :is() selector.

@romainmenke
Copy link
Member Author

For naming. The CSS Nesting spec uses "desugar" for :is(), too. Is this confusing?

Yup, that is confusing, and also why I am looking for a better name :)

@ybiquitous
Copy link
Contributor

I see. For now, +1 flattern. There may be a better name, though. 😅

@ehoogeveen-medweb
Copy link
Contributor

desugar is usually used to mean "translate to equivalent, older syntax" so I agree that it's confusing/wrong.

flatten sounds okay to me - it doesn't necessarily imply equivalence, since similar functions like Array.prototype.flat in JavaScript also aren't reversible (in that case, you throw away information about the size of the nested arrays). The downside is that it isn't clear from the name what information gets retained.

Other options that come to mind for me (not necessarily better than flatten):

  • concat (or concatenate) - I don't think this makes it clear how & is handled.
  • substitute - since IIUC you're essentially recursively substituting parent rules into the & selectors of their children.
  • resolve - this sounds too much like it implies equivalence to me.

@romainmenke romainmenke changed the title Add desugarNestedSelector Add flattenNestedSelector Feb 1, 2024
@romainmenke
Copy link
Member Author

flatten it is!

Thank you everyone for the feedback 🙇

@romainmenke romainmenke merged commit 67acd34 into main Feb 1, 2024
7 checks passed
@romainmenke romainmenke deleted the desugar-nested-selector--compassionate-deutsche-bracke-09ca512999 branch February 1, 2024 16:54
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.

None yet

4 participants