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

utils.reduceCSSSelector() is not good enough #84

Open
peterbe opened this issue Jan 19, 2018 · 0 comments
Open

utils.reduceCSSSelector() is not good enough #84

peterbe opened this issue Jan 19, 2018 · 0 comments

Comments

@peterbe
Copy link
Owner

peterbe commented Jan 19, 2018

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.

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
@peterbe and others