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

Variable is undefined in mixins #921

Closed
maxsite opened this issue Aug 27, 2012 · 2 comments
Closed

Variable is undefined in mixins #921

maxsite opened this issue Aug 27, 2012 · 2 comments

Comments

@maxsite
Copy link

maxsite commented Aug 27, 2012

@color: red;

.scope() {
    .mixin () {
        h1: @color;
    }
}

.scope > .mixin; 

h1 red

.scope() {
    @color: red;

    .mixin () {
        h1: @color;
    }
}

.scope > .mixin; 

ERROR: @color is undefined

Why?

@lukeapage
Copy link
Member

I thought it would be easy but it turns out this isn't..

one point - if the outer is a mixin definition we would have to execute it and then remember that any rules produced from execution should not be output.. so
your exact example I think should show an error... but, anyway, assuming you change to a id namespace

program 1

#test {
  .b() {
    @b: @a;
  }
  .c();
}

.c() {
  @a: 1;
}

#test > .b;

at the moment, this executes the .test > .b mixin call first - in case it imports variables/mixins into the scope, used in .test() and .c()

for this to work though, you have to execute .test() mixin, and then execute the .c() mixin, then the .test > .b mixin - but this means essentially executing things in order..

program 2

@d: 0;

.d() {
  @d: 1;
}

.test {
  hu: @d;
}

.d();

.test {
  hu: @d;
}

current output:

.test {
  hu: 1;
}
.test {
  hu: 1;
}

If we made this change without significant refactoring, this would show 0, 1..

I think thats ok, but I'm more warey now I know it isn't so straight forward.

An alternative would be to do significant refactoring so things are expanded in visits and variables are executed according to the current visit.

@seven-phases-max
Copy link
Member

Merging to #996.

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