Skip to content

Commit

Permalink
Fixes #3235 (#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean authored Jun 30, 2018
1 parent c5f18f4 commit f1a3a25
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/less/functions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ functionRegistry.addMultiple({
},
length: function(values) {
return new Dimension(getItemsFromNode(values).length);
},
_SELF: function(n) {
return n;
}
});
11 changes: 9 additions & 2 deletions lib/less/tree/variable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Node = require('./node');
var Node = require('./node'),
Call = require('./call');

var Variable = function (name, index, currentFileInfo) {
this.name = name;
Expand Down Expand Up @@ -30,7 +31,13 @@ Variable.prototype.eval = function (context) {
var importantScope = context.importantScope[context.importantScope.length - 1];
importantScope.important = v.important;
}
return v.value.eval(context);
// If in calc, wrap vars in a function call to cascade evaluate args first
if (context.inCalc) {
return (new Call('_SELF', [v.value])).eval(context);
}
else {
return v.value.eval(context);
}
}
});
if (variable) {
Expand Down
2 changes: 2 additions & 0 deletions test/css/calc.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.no-math {
root: calc(100% - 30px);
root2: calc(100% - 40px);
width: calc(50% + (25vh - 20px));
height: calc(50% + (25vh - 20px));
min-height: calc((10vh) + calc(5vh));
Expand Down
5 changes: 5 additions & 0 deletions test/less/calc.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@val: 10px;
.no-math {
@c: 10px + 20px;
@calc: (@val + 30px);
root: calc(100% - @c);
root2: calc(100% - @calc);
@var: 50vh/2;
width: calc(50% + (@var - 20px));
height: calc(50% + ((@var - 20px)));
Expand Down

0 comments on commit f1a3a25

Please sign in to comment.