Interpolation with parent reference (#{&}) inside multiple selector generates incorrect selector
See original GitHub issueWhen you have a multiple selector and then you have #{&}
interpolation inside, you get very strange output:
.a,
.b,
.c,
.d {
#{&} .foo {
width: 25px;
}
}
Renders now (using gem install sass --pre) to:
.a .a, .a .b, .a .c, .a .d .foo,
.b .a,
.b .b,
.b .c,
.b .d .foo,
.c .a,
.c .b,
.c .c,
.c .d .foo,
.d .a,
.d .b,
.d .c,
.d .d .foo {
width: 25px; }
I won’t call it expected 😃
Issue Analytics
- State:
- Created 10 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
In Sass, how to reference two parent classes with ampersand ...
Using interpolation on the parent selector causes Sass to evaluate it as a string ... This is now possible in pure CSS with...
Read more >Parent Selector - Sass
The parent selector, & , is a special selector invented by Sass that's used in nested selectors to refer to the outer selector....
Read more >The Sass Ampersand - CSS-Tricks
The & comes in handy when you're nesting and you want to create a more specific ... The & always refers to the...
Read more >Syntax improvements related to the & selector #286 - GitHub
Having selectors be a first-class type (that is, storing them in variables) is very, very different than allowing variables without interpolation in selectors....
Read more >Features In-Depth | Less.js
Multiple &. & may appear more than once within a selector. This makes it possible to repeatedly refer to a parent selector without...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is just a minimal example, in my case it is used for bem-like classes, like this:
Which is impossible without interpolation. And in some complex cases things like this:
Again, artifical example, but not impossible, there could be such cases, but with current Sass it expands… look for yourself, I won’t put here those 653kb and 131150 lines of generated trash 😃
This also fails miserably:
Produces:
Should produce:
In Less and Stylus this works fine since forever.
@kizu, could you please mention “parent selector” and “&” in this thread’s title?
UPD: works as a charm like this (kudos to @Snugug):