You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scope inheritance in LESS4J is not working as intended in LESS.
Basically, child mixins inherit global scope OR parent scope before any operations on variables take place.
Simple example
In the following code @width is inherited from the global scope in .fluid-col().
The .calculate() mixin then converts the number to a valid percentage, and as @width is not explicitly set within the scope of .fluid-col(), the unlocked @width variable should override the inherited one, as is specified in LESS documentation:
Variables and mixins defined in a mixin are visible and can be used in caller's scope. There is only one exception, a variable is not copied if the caller contains a variable with the same name (that includes variables defined by another mixin call). Only variables present in callers local scope are protected. Variables inherited from parent scopes are overridden.
The overridden @width variable should now be inherited by the .inner-scope-test() mixin, however, in LESS4J this is not the case.
/* Scope test */
// Global scope
@width: 1/3;
// Caller
.test {
.fluid-col();
}
// Mixin
.fluid-col() {
// @width should be changed to 33.33333333%
.calculate(@width);
width: @width;
.inner-scope-test();
.inner-scope-test() {
width2: @width;
}
}
// Operator
.calculate(@arg) {
@width: unit(@arg * 100, %);
}
Workaround
Passing the operated variable as a parameter to the inner mixin produces the correct result, however, this is less than ideal when you are dealing with multiple parameters which you then need to keep track of manually.
/* Scope test */
// Global scope
@width: 1/3;
// Caller
.test {
.fluid-col();
}
// Mixin
.fluid-col() {
// @width should be changed to 33.33333333%
.calculate(@width);
width: @width;
.inner-scope-test(@width);
.inner-scope-test(@width) {
width2: @width;
}
}
// Operator
.calculate(@arg) {
@width: unit(@arg * 100, %);
}
// it the mixin calls itself recursively, each copy should work on
// independent copy of local data
// that is matters mostly for scope placeholders - if both close
// placeholders in same copy error happen
mixinWorkingScope.toIndependentWorkingCopy();
The toIndependentWorkingCopy ensures that second call does not see imported variables. Solution: the joinIfIndependent method needs to work differently for local calls.
Scope inheritance in LESS4J is not working as intended in LESS.
Basically, child mixins inherit global scope OR parent scope before any operations on variables take place.
Simple example
In the following code
@width
is inherited from the global scope in.fluid-col()
.The
.calculate()
mixin then converts the number to a valid percentage, and as@width
is not explicitly set within the scope of.fluid-col()
, the unlocked@width
variable should override the inherited one, as is specified in LESS documentation:The overridden
@width
variable should now be inherited by the.inner-scope-test()
mixin, however, in LESS4J this is not the case.Correct output from LESS compiler
Incorrect output from LESS4J compiler
Workaround
Passing the operated variable as a parameter to the inner mixin produces the correct result, however, this is less than ideal when you are dealing with multiple parameters which you then need to keep track of manually.
Output
The text was updated successfully, but these errors were encountered: