-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Warn if selector contains a pseudo-class #591
Conversation
const tokens = selector.split(containsQuotes); | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i]; | ||
if (containsColon.test(token) && i % 2 === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works assuming that an attribute value doesn't contain a quote ('[data-foo="foo':bar'"]'
), which seems reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we could use some
to do this without a loop? return tokens.some((token, i) => containsColon.test(token) && i % 2 === 0)
?
Also pseudo-spelling errors
141f3a7
to
2d94e53
Compare
@@ -187,6 +200,9 @@ export const SELECTOR = { | |||
}; | |||
|
|||
export function selectorType(selector) { | |||
if (isPseudoClassSelector(selector)) { | |||
throw selectorError(selector, 'pseudo-class'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there usually a hyphen in pseudoclass
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hyphenated in the spec.
LGTM |
We still don't support these, so we need to warn about them. Parsing this with a RegEx is really difficult so instead
isPseudoClassSelector
does some minimal pattern matching combined with some logic to only match cases where:
is not within quotes.cc @ljharb