Skip to content

nested mixins ignore guards #1418

Closed
Closed

Description

@eikelandin

Is this a wanted behavior? I've expected to give no output at all.

Code

@var: false;

.mixin (...) when (@var) {
  mixin {
    content: 'mixin';
  }

  .nested (...) {
    nested {
      content: 'nested';
    }
  }
}

.mixin;
.mixin.nested;

Output

nested {
  content: 'nested';
}

Activity

  1. eikelandin commented on Jul 12, 2013

    @eikelandin
    Author

    Practical Example

    @theme: none;  // Exchange with flat, to make it work!
    
    #button (...) {
      display: inline-block;
    
      cursor: pointer;
      line-height: normal;
      text-align: center;
      user-select: none;
      vertical-align: top;
      white-space: nowrap;
    }
    
    #button (@background: backround; @color: color; @border: border) when (@theme = flat) {
      .hover (@background-hover: @background; @color-hover: @color; @border-hover: @color-hover) when (@theme = flat) {
        border-color: @border-hover;
    
        background-color: @background-hover;
        color: @color-hover;
      }
    }
    
    button {
      #button;
      #button.hover;
    }
    

    Even when the mixins are disabled, I get this Name error: variable @background is undefined, until I activate one of my themes where the variables are defined.

  2. lukeapage commented on Jul 12, 2013

    @lukeapage
    Member

    hrmm, yes, its undefined what should happen. I confirm that less only looks at guards on the "top" mixin - when you do #mixin.inner it looks up the mixin and evaluates it without taking into account whether it is in a guarded scope. not sure what should happen though.

  3. SomMeri commented on Jul 15, 2013

    @SomMeri
    Member

    It ignores also mandatory parameters e.g., following will fail:

    @var: false;
    
    .mixin (@something) when (@something>2) {
      .nested (...) {
        nested {
          content: 'nested' @something;
        }
      }
    }
    
    .mixin () {
      .nested () {
        nested {
          content: 'alternative';
        }
      }
    }
    
    .mixin.nested;
    SyntaxError: variable @something is undefined in ...on line 21, column 1
    

    I would guess that inner mixin is written with assumption that guard conditions of outer mixin are satisfied and that mandatory parameters on the way up are filled. E.g. I would expect it to return following:

    nested {
      content: 'alternative';
    }
  4. self-assigned this
    on Sep 1, 2014
  5. SomMeri commented on Sep 8, 2014

    @SomMeri
    Member

    Closing this since it will be fixed in v2.0

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