Skip to content

extend like sass #1014

Closed
Closed

Description

@Most

less 1.4.0 converts:

ul.inline li { display: inline-block; }
nav ul { &:extend(.inline); }

to:

ul.inline li, ulnav ul li { display: inline-block; } 

Notice ulnav ul li selector.
Similar code in sass 3.2.1:

ul.inline li { display: inline-block; }
nav ul { @extend .inline; }

produces

ul.inline li, nav ul li { display: inline-block; }

Activity

  1. lukeapage commented on Nov 5, 2012

    @lukeapage
    Member

    just read http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#extend

    the selector merging appears to me quite un-intuitive.. in this example it produces cool output.. does it always?

    Not sure if it should make 1.4.0 in the same sass way...

  2. matthew-dean commented on Feb 18, 2013

    @matthew-dean
    Member

    SASS's extend is WAAAY to greedy. This (from the SASS documentation) is terrifying to me:

    #admin .tabbar a {
      font-weight: bold;
    }
    #demo .overview .fakelink {
      @extend a;
    }
    
    // is compiled to:
    
    #admin .tabbar a,
    #admin .tabbar #demo .overview .fakelink,
    #demo .overview #admin .tabbar .fakelink {
      font-weight: bold; }
    

    Why you would ever want extending a partial class which then injects that selector into every instance where that class appears is beyond me. I mean, think about how many instances of "a" there are in a typical web app. That's just pure craziness. But to each their own, I guess.

    So, for this:

    ul.inline li { display: inline-block; }
    nav ul { &:extend(.inline); }
    

    I would expect LESS to do nothing. If you want to extend ul.inline, which is not necessarily the same as .inline, then refactor and specify.

    ul.inline {
      li { display: inline-block; }
    }
    nav ul:extend(ul.inline);
    
  3. DesignByOnyx commented on Feb 18, 2013

    @DesignByOnyx

    Agreed with @MatthewDL. If I wanted to extend ul.inline li, I should have to do something like nav ul:extend(ul.inline li) { }. The SASS-like extend-every-single-f-ing-instance is more appropriate for something like extend-all in my opinion (mentioned in other discussions). And since the extend feature is taking on this "modifier" approach such as :extend(.inline all/nested/only) - then we have an opportunity to make a modifier which would allow developers to have a SASS-like modifier.

  4. lukeapage commented on Feb 18, 2013

    @lukeapage
    Member

    Or not.. we can revisit this later, but it will need some strong usecases I
    think.

  5. brianzimmerman commented on Feb 19, 2013

    @brianzimmerman

    Personally, I think that LESS should be a little more explicit. @MatthewDL's SASS example is pretty scary.

    So,

    ul.inline li { display: inline-block; }
    nav ul { &:extend(.inline); }

    should do nothing, but

    ul.inline li { display: inline-block; }
    nav ul { &:extend(ul.inline); }

    should output

    ul.inline li, nav ul li { display: inline-block; }

    This, of course, assumes current functionality of :extend in the alpha grabbing 'all' matches.

  6. lukeapage commented on Mar 6, 2013

    @lukeapage
    Member

    I've been writing up less behaviour in the context of sass behaviour. I have come to believe they give this functionality because they do not support extending multiple elements, e.g. "ul.inline" so this was a way for them to provide the ability to extend in the above case when you would not otherwise be able to. less is different.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions