When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly
See original GitHub issueWhen 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:
- Created 9 years ago
- Comments:30 (17 by maintainers)
Top 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 >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
@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.This should be fixed by #2729 .