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

Is this "& when" use case a bug? #1871

Closed
matthew-dean opened this issue Feb 13, 2014 · 4 comments
Closed

Is this "& when" use case a bug? #1871

matthew-dean opened this issue Feb 13, 2014 · 4 comments

Comments

@matthew-dean
Copy link
Member

I've just started experimenting with "& when" to do inline "if" style blocks. However, I can't get them to actually work (EDIT: I got them to work, sort of, but not as I want or expected them to work). I'm not certain if it's my use case or it's just now how they're currently designed.

Reduced test case:

#test {
  .start(@var: true) {
    & when(@var) {
      .output {
        property: value;
      }
    }
  }
}
#test > .start();

Error: Name error: variable @var is undefined

I thought that perhaps this was triggering a bug within a mixin (even though I regularly use & directly inside a mixin) so I reduced it further:

#test {
  @var: true;
    .start when(@var) {
      .output {
        property: value;
      }
    }
}
#test > .start;

Same error. However, I finally noticed that if I removed #test > .start in the reduced case, it output, so it seems like it's a variable scoping bug. Why does it cause a problem in the first mixin? A defined variable in the mixin should be available to a guard, should it not?

@seven-phases-max
Copy link
Member

Example 1 is #1750 (I think it was fixed in 1.6.2).
Example 2 is #57, #719 (it also seems to be partially fixed in 1.6.2 but there's still problems with scope visibility for non-conditional mixins):

#test {
    @var: true;

    .non-parametric when (true) {
        b: @var; // OK
    }

    .non-parametric {
        b: @var; // Err, not defined
    }

    .parametric() when (true) {
        b: @var; // Err, not defined
    }

    .parametric() {
        b: @var; // Err, not defined
    }
}

#test > .non-parametric;
#test > .parametric;

@lukeapage
Copy link
Member

also although I realise its just a test case, did you realise your first example can be written in a much simpler way..

#test {
  .start(@var: true)  when(@var) {
      .output {
        property: value;
      }
  }
}
#test > .start();

and closing as duplicate

@matthew-dean
Copy link
Member Author

Ah okay, I should have double-checked if it was addressed already in a Less update.

@lukeapage Yes, but as it's a reduced case, there's more that I was intending on putting in the .start() mixin (and outside of the guard). I just reduced it to the parts that threw an error. 😄

@lukeapage
Copy link
Member

there is an open issue for the 2nd one. #921

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants