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

Warn if selector contains a pseudo-class #591

Merged
merged 2 commits into from
Sep 12, 2016

Conversation

aweary
Copy link
Collaborator

@aweary aweary commented Sep 12, 2016

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

const tokens = selector.split(containsQuotes);
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if (containsColon.test(token) && i % 2 === 0) {
Copy link
Collaborator Author

@aweary aweary Sep 12, 2016

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

Copy link
Member

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
@ljharb ljharb changed the title Warn if selector contains a psuedo-class Warn if selector contains a pseudo-class Sep 12, 2016
@@ -187,6 +200,9 @@ export const SELECTOR = {
};

export function selectorType(selector) {
if (isPseudoClassSelector(selector)) {
throw selectorError(selector, 'pseudo-class');
Copy link
Member

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?

Copy link
Collaborator Author

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.

@ljharb
Copy link
Member

ljharb commented Sep 12, 2016

LGTM

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

Successfully merging this pull request may close these issues.

2 participants