Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this with --strict-math=on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/m just tested and seeing it work as intended.

@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