Skip to content

Scoping of mixin unlocked from namespaced mixin does not work properly #2039

Closed

Description

@SomMeri

This is probably related to #2038

1.) Mixin unlocked from namespaced mixin does not see callers variables.

Less:

#namespace {
  .unlocker {
    .mixin { 
      property: @variable; 
    }
  }
}
#namespace > .unlocker();

#mixin {
  @variable: in-caller;
  .mixin();
}

actual output:

SyntaxError: variable @variable is undefined in test.less on line 8, column 1:
7 }
8 #namespace > .unlocker();
9

expected output:

#mixin {
  property: in-caller; 
}

2.) I defined a detached ruleset inside a namespaced mixin. The ruleset is unable to see variables defined in its outer namespace (the #2038 is the same except with detached rulesets).

#namespace {
  @variable: in-namespace;
  .unlocker {
    .mixin { 
      property: @variable; 
    }
  }
}
#namespace > .unlocker();

#mixin {
  @variable: another;
  .mixin();
}

actual output:

SyntaxError: variable @variable is undefined in test.less on line 9, column 1:
8 }
9 #namespace > .unlocker();
10

expected output:

#mixin {
  property: in-namespace; 
}

I use node.js with lessc 1.7.0 (LESS Compiler) [JavaScript]

Activity

  1. seven-phases-max commented on May 31, 2014

    @seven-phases-max
    Member

    If I'm not mistaken the (1) error is actually expected since it occurs when the .mixin class is exposed to the global scope where no @variable is defined. I.e. the error is actually in:

    #namespace {
      .unlocker {
        .mixin {
          property: @variable; 
        }
      }
    }
    
    #namespace > .unlocker();
    
  2. seven-phases-max commented on May 31, 2014

    @seven-phases-max
    Member

    And (2) is just one more example for #1316.

  3. SomMeri commented on May 31, 2014

    @SomMeri
    MemberAuthor

    EDIT: ignore this comment, contains mistakes.

    2.) You are right. I forgot about that one.

    1.) Mixin should see callers variables. I can not find related discussion now, but I'm sure about it. I will try to find it tomorrow. That being said, this issue has nothing to do with unlocking.

    It seems like .mixin { and .mixin() { behave differently. This:

    .mixin() { 
      property: @variable; 
    }
    
    #usePlace {
      .mixin();
      @variable: in-caller;
    }

    compiles into:

    #usePlace {
      property: in-caller;
    }

    On the other hand, this fails:

    .mixin { 
      property: @variable; 
    }
    
    #usePlace {
      .mixin();
      @variable: in-caller;
    }

    Error:

    NameError: variable @variable is undefined in test.less on line 2, column 13:
    1 .mixin {
    2   property: @variable;
    3 }
    

    Do you agree? If yes I will close this issue and open new one for .mixin { vs .mixin() { difference with better title (if it does not exist).

  4. SomMeri commented on May 31, 2014

    @SomMeri
    MemberAuthor

    Blah, ignore previous comment. Closing issue because 1.) works as expected and 2.) is duplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions