question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending a compound selector violates extend semantics

See original GitHub issue

Currently, when a compound selector is extended, Sass will only replace instances of the full extendee with the extender. For example:

.a {x: y}
.b {x: y}
.a.b {x: y}

.c {@extend .a.b}

produces

.a {x: y}
.b {x: y}
.a.b, .c {x: y}

when it should produce

.a, .c {x: y}
.b, .c {x: y}
.a.b, .c {x: y}

according to the semantics of @extend. We should fix this, especially as CSS moves closer to supporting @extend natively.

Tasks:

  • Deprecate existing behavior in stable.
  • Remove behavior from master.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:25
  • Comments:95 (20 by maintainers)

github_iconTop GitHub Comments

26reactions
ArmorDarkscommented, Jul 13, 2017

If an element matches .a.b, that means it also matches both .a and .b individually, so .c {@extend .a.b} should mean the same thing as .c {@extend .a; @extend .b}.

I still miss the logic why .a.b. also matches .a and .b individually. Those are 3 different selectors, it just so happens that they consist from same elements, but nothing more.

It just goes against CSS logic, since when in CSS we write more complex selectors, we increasing its specificity on purpose, to ensure that only “those instances of class” with class='a b' will receive that style, not class='a' and class='b'.

I think Sass can follow pretty much close same logic — when you increase specificity of extend, you want to extend only specific selectors, not everything related to them, otherwise you would write more generic extend.

20reactions
mdesantiscommented, Jul 20, 2017

-1 to this. If I want .c to extend .a and .b I write .c { @extend .a; @extend .b; }.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking Change: Extending Compound Selectors - Sass
When one selector extends another, Sass styles all elements that match the extender as though they also match the class being extended.
Read more >
Selectors Level 4 - W3C
Prepending another compound selector and a combinator to a sequence imposes additional matching constraints, such that the subjects of a complex ...
Read more >
Extending In Sass Without Creating A Mess
The @extend directive in Sass is a powerful directive that facilitates the sharing of rules and relationships between selectors.
Read more >
Redex: Practical Semantics Engineering
The tutorial works though a model of the λ-calculus extended with ... The compound rewriter is given a list of lw structs that...
Read more >
HTML Standard
The defining instance of an element, attribute, or API is marked up like this . ... In order to allow the language syntax...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found