Skip to content

Variable is undefined in mixins #921

Closed

Description

@maxsite
@color: red;

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

.scope > .mixin; 

h1 red

.scope() {
    @color: red;

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

.scope > .mixin; 

ERROR: @color is undefined

Why?

Activity

  1. lukeapage commented on Dec 10, 2012

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

  2. seven-phases-max commented on Sep 5, 2014

    @seven-phases-max
    Member

    Merging to #996.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions