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.

@at-root with #{&} inside a comma-separated selector generates wrong code

See original GitHub issue

Tested versions: v3.3.6 via node-sass (sorry, I can’t run/test it against the ruby implementation directly)

Given the following input:

.class-a {
    .class-b,
    .class-c {
        color: yellow;

        @at-root .something-at-root#{&} {
            color: pink;
        }
    }
}

You’ll get the following output:

.class-a .class-b,
.class-a .class-c {
    color: yellow;
}

.something-at-root.class-a .class-b,
.class-a .class-c {
    color: pink;
}

The problem here is that #{&}, which I used here in this example to prepend some selector (.something-at-root) right at the beginning, which causes the compiler to generate wrong output.

I’d expect the following output for the second block:

.class-a .class-b,
.class-a .class-c {
    color: yellow;
}

.something-at-root.class-a .class-b,
.something-at-root.class-a .class-c {
    color: pink;
}

Clearly one could argue that I’ve abused #{} and & here though I couldn’t find another way to achieve the same result (apart from the potential bug). I’ve just expected that the compiler would treat string interpolation with the same rules as the rest.

To me it looks like the entire string is just pasted into its destination without honoring the ,.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
SalimBensialicommented, Dec 5, 2018

@richgcook See docs for selector-append. What you are looking for is selector_nest

0reactions
richgcookcommented, Nov 23, 2018

@chriseppstein This actually doesn’t work as it doesn’t create a space between the root selector and the child selector.

a, a:active, a:focus, a:hover {
	color: $color--primary;
	outline: none;
	text-decoration: none;
	@at-root #{selector-append("body.is--reversed", &)} {
		color: $color--bg;
	}
}

This compiles to

body.is--reverseda,
body.is--reverseda:active,
body.is--reverseda:focus,
body.is--reverseda:hover {
    color:#fcfbf6
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to take comma seperated number input as argument in a ...
Thanx juanpa,I want the function to take arbitary number of inputs hence I have using *args. Could you help to resolve the generator...
Read more >
Handle comma(,) in column value in comma separated ...
I have comma separated delimited file as input and using ADF copy activity to copy it to a .CSV file. Now if a...
Read more >
How to Create a Comma-Separated String From a List of ...
In this article, we are going to learn how to create a comma-separated string from a list of strings in C#. To download...
Read more >
Comma-separated labels should be used in Switch with colon ...
This rule reports an issue when multiple cases in a Switch can be grouped into a single comma-separated case. Noncompliant Code Example. //...
Read more >
Customization Guide - WeeWX
If you are only interested in customizing the generated reports you can ... A list is a set of numbers (or ranges) separated...
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