Skip to content

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

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

Closed
SomMeri opened this issue May 31, 2014 · 4 comments
Closed

Comments

@SomMeri
Copy link
Member

SomMeri commented May 31, 2014

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]

@seven-phases-max
Copy link
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();

@seven-phases-max
Copy link
Member

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

@SomMeri
Copy link
Member Author

SomMeri commented May 31, 2014

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).

@SomMeri
Copy link
Member Author

SomMeri commented May 31, 2014

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

@SomMeri SomMeri closed this as completed May 31, 2014
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

2 participants