Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested mixins ignore guards #1418

Closed
ESchuderer opened this issue Jul 12, 2013 · 4 comments
Closed

nested mixins ignore guards #1418

ESchuderer opened this issue Jul 12, 2013 · 4 comments

Comments

@ESchuderer
Copy link

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';
}
@ESchuderer
Copy link
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.

@lukeapage
Copy link
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.

@SomMeri
Copy link
Member

SomMeri commented Jul 15, 2013

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';
}

@SomMeri SomMeri self-assigned this Sep 1, 2014
SomMeri pushed a commit to SomMeri/less-rhino.js that referenced this issue Sep 5, 2014
@SomMeri
Copy link
Member

SomMeri commented Sep 8, 2014

Closing this since it will be fixed in v2.0

@SomMeri SomMeri closed this as completed Sep 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants