Skip to content

Extend within (reference) imported files. #1851

Open

Description

@donaldpipowitch

Say I have three files:

// fileA.less
.test-a {
  color: red;
}
// fileB.less
@import (reference) "fileA";

.test-b {
  background-color: green;
  &:extend(.test-a all);
}
// fileC.less
@import (reference) "fileB";

.test-c {
  &:extend(.test-b all);
}

What I expect, if I compile fileC.less (comments only to aid the understanding):

// .test-a,
// .test-b,
.test-c {
  color: red;
}

// .test-b,
.test-c {
  background-color: green;
}

What I get:

.test-b,
.test-c {
  color: red;
}
.test-c {
  background-color: green;
}

.test-b leaks in!

Activity

  1. seven-phases-max commented on Feb 5, 2014

    @seven-phases-max
    Member

    .test-b leaks in!

    This is just how extend works currently. It is questionabe if .test-b should appear in the output (i.e. ideally it may not output however there's also no reason why it must not), but the whole snippet looks more like "trying to use (reference) as a hack to achieve #1177".

  2. lukeapage commented on Feb 5, 2014

    @lukeapage
    Member

    I think its a bug, but would need to work out what's causing it to be sure.

  3. seven-phases-max commented on Feb 5, 2014

    @seven-phases-max
    Member

    Ah., sorry, my bad. I did miss that with the one level @import it actually supresses the output of the extended class (I was under impression that I have tried this as #1177 workaround before and it did not work... But aparently my test was somewhat wrong :)

  4. SomMeri commented on Feb 17, 2014

    @SomMeri
    Member

    I think that the expected output in the above should be:

    .test-c {
      color: red;
    }
    .test-c {
      background-color: green; // changed from color: red;
    }
    
  5. donaldpipowitch commented on Feb 17, 2014

    @donaldpipowitch
    Author

    You're right. That is a typo in my example. I will fix this.

  6. bassjobsen commented on Mar 2, 2014

    @bassjobsen
    Contributor

    as far as i understood, the problem also occurs without nesting:

    @import (reference) "testextend.less";

    with testextend.less contains:

    .extendthis {
    notvisible: notvisiblevalue;
    }
    .a:extend(.extendthis){}
    .c {
    notvisible: notvisiblevalue;
    }
    

    will be compiled into:

    .a {
      notvisible: notvisiblevalue;
    }
    

    Where i expected no output at all. Tested with 1.6.3 and 1.7.0

  7. 4 remaining items

  8. lukeapage commented on Nov 3, 2014

    @lukeapage
    Member

    I would create a test case, then debug extend visitor, look at where it creates the new selector and make sure its referenced field is only set to true if the extend is referenced (which it wont be if ibside a refrenced import).
    but not entirely sure, its been a while sjnce working on those features.

  9. donaldpipowitch commented on Nov 3, 2014

    @donaldpipowitch
    Author

    Thank you for the effort.

  10. bassjobsen commented on Nov 3, 2014

    @bassjobsen
    Contributor

    i wonder if this issue can be fixed by using the following lines of code in parser/parser.js:

    if(typeof elements[0].currentFileInfo.reference === "undefined"
    || elements[0].currentFileInfo.reference === false)
    {
        extend = new(tree.Extend)(new(tree.Selector)(elements), option, index);
        if (extendList) { extendList.push(extend); } else { extendList = [ extend ]; }
    }
    

    The above than should replace the lines:

        extend = new(tree.Extend)(new(tree.Selector)(elements), option, index);
        if (extendList) { extendList.push(extend); } else { extendList = [ extend ]; }
    
  11. lukeapage commented on Nov 4, 2014

    @lukeapage
    Member

    No, because that would stop you extending the result of an extend through a
    reference.

  12. bassjobsen commented on Nov 4, 2014

    @bassjobsen
    Contributor

    Well, i see. Thanks.
    It seems possible to fix this issue in the to-css-vistor.js inn the filter function:

                    .filter(function(p) {
                        var i;
                        if (p[0].elements[0].combinator.value === ' ') {
                            p[0].elements[0].combinator = new(tree.Combinator)('');
                        }
                        for(i = 0; i < p.length; i++) {
                            if(
                            typeof p[i].elements[0].currentFileInfo.reference === "boolean" && 
                            p[i].elements[0].currentFileInfo.reference &&
                            ) return false;
                            if (p[i].getIsReferenced() && p[i].getIsOutput()) {
                                return true;
                            }
                        }
                        return false;
                    });
    

    But that left other issues with mixins in the referenced files un-fixed; mixins called from the main file (#1979) and mixins with nested selectors (#1968). Probably this rules should get the referenced state of the caller instead of that from the mixin.

  13. assadtony commented on Apr 28, 2015

    @assadtony

    Any updates on this issue? :)

  14. self-assigned this
    on Oct 11, 2015
  15. added a commit that references this issue on Nov 20, 2015
  16. SomMeri commented on Dec 7, 2015

    @SomMeri
    Member

    This should be fixed by #2729 .

  17. donaldpipowitch commented on Dec 7, 2015

    @donaldpipowitch
    Author

    Just wow!

  18. SomMeri commented on Jan 31, 2016

    @SomMeri
    Member

    Re-opening, because it now compiles into

    .test-c {
      background-color: green;
    }

    instead of

    .test-c {
      color: red;
    }
    
    .test-c {
      background-color: green;
    }
  19. matthew-dean commented on Jan 31, 2016

    @matthew-dean
    Member

    Okay, if you get a fix for it, we can do a bugfix release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions