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.

When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly

See original GitHub issue

When I import a less file with the (reference) directive, I expect to see no CSS output from that file.

However, I am seeing content being output from the imported file when a mixin contains an & selector.

mixin.less

.mixin-no-parent-selector() {
  background-color: red;
}
.mixin-with-parent-selector() {
  &:first-child{ //  USING AN & SELECTOR HERE
    background-color: blue;
 }
}

less-for-reference.less

.container-1 {
   .mixin-no-parent-selector();
}
.container-2{
   .mixin-with-parent-selector()
}

style.less

/*!
 * styles.less
 */
@import "mixin.less";
@import (reference) "less-for-reference.less";

Expected Output

/*!
 * styles.less
 */

Actual Output

/*!
 * styles.less
 */

.container-2:first-child{
    background-color: blue;
}

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:30 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
almeidapcommented, Dec 17, 2014

@seven-phases-max For sure, I did not forget that less.js is a volunteer-based project and I am very grateful to the contributors. I just wanted to bring the focus back to the issue itself instead of not-so-useful (imo) discussions about the usage of imports.

I recently started refactoring our LESS resources as our framework hit the IE stylesheets limit when concatenated with other CSS project files. Fixing the (reference) import issue will help me to avoid duplicate selectors and better control outputted resources.

0reactions
SomMericommented, Dec 7, 2015

This should be fixed by #2729 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

SASS @mixin compiling in .css file - Stack Overflow
Everything looks like I would expect it to look from the SASS you wrote. The CSS is invalid because there are no selectors...
Read more >
Sass: @import
What's Wrong With @import ? The @import rule has a number of serious issues: @import makes all variables, mixins, and functions globally accessible....
Read more >
node_modules/less/test/less/import-reference-issues.less ... - GitLab
#1968 - When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly.
Read more >
Less.js @import At-Rules Reference - GeeksforGeeks
When the selector is extended, only the new selector has this designation, and it is inserted after the reference @import declaration.
Read more >
Sass Techniques from the Trenches | CSS-Tricks
Before we explore Sass variables with selectors, we need to ... the mixin alone, but also a block of code that gets output...
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