Skip to content

Guards on css styles and variables scoping #1813

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 Jan 17, 2014 · 1 comment
Closed

Guards on css styles and variables scoping #1813

SomMeri opened this issue Jan 17, 2014 · 1 comment

Comments

@SomMeri
Copy link
Member

SomMeri commented Jan 17, 2014

Guarded css styles defined inside mixin use global scope instead of local one. The consequence the same variable has different value in guard and different value in declaration.

1.) Mixin redefines @usedScope variable:

@usedScope: global;
.mixin() {
  @usedScope: mixin; 
  .global when (@usedScope=global) {
    guard-used-scope: global;
    declaration-used-scope: @usedScope;
  }
  .mixin when (@usedScope=mixin) {
    guard-used-scope: mixin;
    declaration-used-scope: @usedScope;
  }
  @usedScope: mixin; 
}

.mixin();

actual output:

.global {
  guard-used-scope: global;
  declaration-used-scope: mixin;
}

expected output:

.mixin{
  guard-used-scope: mixin;
  declaration-used-scope: mixin;
}

2.) Mixin argument redefines @usedScope:

@usedScope: global;

.mixin(@usedScope: argument) {
  .global when (@usedScope=global){
    guard-used-scope: global;
    declaration-used-scope: @usedScope;
  }
  .argument when (@usedScope=argument){
    guard-used-scope: argument;
    declaration-used-scope: @usedScope;
  }
}

.mixin();

actual output:

.global {
  guard-used-scope: global;
  declaration-used-scope: argument;
}

expected output:

.argument {
  guard-used-scope: argument;
  declaration-used-scope: argument;
}

3.) Variable defined in caller is visible:

@caller: global;
.caller() {
  .caller when (@caller=caller){ // this should use global variable value
    guard-expected-caller-but-is: @caller;
  }
  .global when (@caller=global){ // this should use global variable value
    guard-expected-global-but-is: @caller;
  }
}
.local-in-caller {
  .caller();
  @caller: caller;
}

compiles into:

.local-in-caller .caller {
  guard-expected-caller-but-is: global;
}

expected css:

.local-in-caller .global{
  guard-expected-global-but-is: global;
}

Tested with windows node.js lessc 1.6.1 (LESS Compiler) [JavaScript]

SomMeri pushed a commit to SomMeri/less4j that referenced this issue Jan 17, 2014
less/less.js#1813 . I implemented it as I think
is right, but will change its behaviour if less.js thinks less.js is
right.
@lukeapage
Copy link
Member

there was a bug in guarded mixins that resulted in some frankly odd behaviour.

the only thing fixing it broke was this test

.light when (lightness(@a) > 50%) {
  color: green;
}
.dark when (lightness(@a) < 50%) {
  color: orange;
}
@a: #ddd;

.see-the {
  @a: #444; // this mirrors what mixins do - they evaluate the guards at the point of definition
  .light();
  .dark();
}

.hide-the {
  .light();
  .dark();
}

and previous the local definition of @a changed which of the mixins came through. which is frankly pretty odd.

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