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

invalid order of pseudo-selectors #484

Closed
FND opened this issue Sep 26, 2018 · 4 comments
Closed

invalid order of pseudo-selectors #484

FND opened this issue Sep 26, 2018 · 4 comments
Assignees

Comments

@FND
Copy link

FND commented Sep 26, 2018

Using v1.14.0, the following code:

%highlight {
    &:before {
        color: red;
    }
}

article:empty {
    @extend %highlight;
}

results in

article:before:empty {
  color: red;
}

(only when using @extend though; when embedding the nested &:before rule set, the order of pseudo-selectors is reversed)

This order of pseudo-selectors :before:empty appears to be invalid, as both Firefox (v62.0.2) and Chrome (v69.0.3497.100) simply ignore the entire rule set (even if it's a list of multiple selectors, those are ignored as well) - reversing the order to :empty:before makes everything work as expected: test case

@nex3
Copy link
Contributor

nex3 commented Sep 26, 2018

The single-colon syntax for :before is deprecated, specifically because it's semantically a pseudo-element but that syntax makes it look like a pseudo-class. If you write it ::before, this will work; Sass knows to put pseudo-elements at the end of selectors, but it treats all pseudo-classes as equivalent.

@nex3 nex3 closed this as completed Sep 26, 2018
@FND
Copy link
Author

FND commented Sep 27, 2018

Thanks @nex3, that did indeed fix it!

In a way, I'm glad to finally have a concrete reason to use ::. Having said that, given the pervasive use of single colons (I'm guessing many people are unaware of the distinction), this behavior seems like a hazardous trap: It took me several hours to debug this issue - indeed, recognizing the order of pseudo-selectors as a potential culprit was a lucky accident. (So much so that for a while I'd lost trust in the @extend mechanism's reliability.)

So while I appreciate dart-sass being strict about this, emitting a warning might save some users a lot of trouble down the road - especially given browsers' (surprising) behavior of ignoring subsequent selectors.

@nex3
Copy link
Contributor

nex3 commented Oct 11, 2018

Fair enough, I suppose it's not too hard to special-case :before, :after, :first-line, and :first-letter.

@FND
Copy link
Author

FND commented Oct 11, 2018

Great, I appreciate that!

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

No branches or pull requests

2 participants