8000 `utils.reduceCSSSelector()` is not good enough · Issue #84 · peterbe/minimalcss · GitHub
[go: up one dir, main page]

Skip to content

utils.reduceCSSSelector() is not good enough #84

Open

Description

@peterbe

utils.reduceCSSSelector() does wrong things. Yep, you can remove pseudos classes like :hover, :focus and pseudo elements from a selector, but there are pseudos like :not(), :empty, :nth-child() etc that change the meaning of selector. Another problem that part of selector after any pseudo is cutting, e.g. "a:hover img" -> "a" so if there is no any img inside a the rule is still preserved. On the one hand, that's not a big dial, because you just left more rules that needed. On the other hand, this tool tries extract as minimal CSS as possible, so I think it should be fixed. Unfortunately, this is a complex problem so I left it as is at the moment. I let you know, when I found a better solution.

From #73 (comment)

@lahmatiy Recommended we hang tight till a better solution becomes available. One, ideally based on AST instead of some hopeful regex juggling.

We might want to consider a partial improvement that'll solve some of the easier things to tackle. For example, we can maintain a white list of pseudo selectors that are valid/important and works with cheerio. E.g. :not.
Another partial improvement is to split the selector by spaces, look for pseudo classes in each string and put it back together again. E.g. a:hover img becomes ['a:hover', 'img'] becomes ['a', 'img'] ultimately becomes a img.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0