Skip to content

Commit f3c7f70

Browse files
committed
calc() fix - fixes #974
1 parent 4508495 commit f3c7f70

File tree

17 files changed

+35
-34
lines changed

17 files changed

+35
-34
lines changed

lib/less/contexts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ contexts.Eval.prototype.outOfParenthesis = function () {
7373
this.parensStack.pop();
7474
};
7575

76+
contexts.Eval.prototype.mathOn = true;
7677
contexts.Eval.prototype.isMathOn = function () {
78+
if (!this.mathOn) {
79+
return false;
80+
}
7781
return this.strictMath ? (this.parensStack && this.parensStack.length) : true;
7882
};
7983

lib/less/parser/parser.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ var Parser = function Parser(context, imports, fileInfo) {
421421
}
422422

423423
parserInput.forget();
424-
return new(tree.Call)(name, args, index, fileInfo);
424+
var call = new(tree.Call)(name, args, index, fileInfo);
425+
if (name === 'calc') {
426+
call.mathOff = true;
427+
}
428+
return call;
425429
},
426430

427431
//
@@ -596,7 +600,7 @@ var Parser = function Parser(context, imports, fileInfo) {
596600
}
597601
},
598602

599-
// A property entity useing the protective {} e.g. @{prop}
603+
// A property entity useing the protective {} e.g. ${prop}
600604
propertyCurly: function () {
601605
var curly, index = parserInput.i;
602606

lib/less/tree/call.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ Call.prototype.accept = function (visitor) {
2929
// The function should receive the value, not the variable.
3030
//
3131
Call.prototype.eval = function (context) {
32-
var args = this.args.map(function (a) { return a.eval(context); }),
33-
result, funcCaller = new FunctionCaller(this.name, context, this.getIndex(), this.fileInfo());
32+
/* Used for calc() */
33+
if (this.mathOff) {
34+
context.mathOn = false;
35+
}
36+
var args = this.args.map(function (a) { return a.eval(context); });
37+
if (this.mathOff) {
38+
context.mathOn = true;
39+
}
40+
var result, funcCaller = new FunctionCaller(this.name, context, this.getIndex(), this.fileInfo());
3441

3542
if (funcCaller.isValid()) {
3643
try {

lib/less/tree/directive.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/less/tree/quoted.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var Node = require("./node"),
2-
JsEvalNode = require("./js-eval-node"),
32
Variable = require("./variable"),
43
Property = require("./property");
54

lib/less/tree/rule.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/css/calc.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.no-math {
2+
width: calc(50% + (25vh - 20px));
3+
}

test/css/comments2.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.first,
99
.planning {
1010
margin: 10px;
11-
total-width: (1 * 6em * 12) + (2em * 12);
11+
total-width: 96em;
1212
}
1313
.some-inline-comments {
1414
a: yes /* comment */;
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ console.log("\n" + stylize("Less", 'underline') + "\n");
88
lessTester.prepBomTest();
99
var testMap = [
1010
[{
11-
strictMath: true,
11+
strictMath: false,
1212
relativeUrls: true,
1313
silent: true,
1414
javascriptEnabled: true,
1515
// Set explicitly for legacy tests for >3.0
1616
ieCompat: true
1717
}],
18+
[{
19+
strictMath: true,
20+
ieCompat: true
21+
}, "strict-math/"],
1822
[{strictMath: true, strictUnits: true, javascriptEnabled: true}, "errors/",
1923
lessTester.testErrors, null],
2024
[{strictMath: true, strictUnits: true, javascriptEnabled: false}, "no-js-errors/",
@@ -56,7 +60,7 @@ testMap.forEach(function(args) {
5660
lessTester.runTestSet.apply(lessTester, args)
5761
});
5862
lessTester.testSyncronous({syncImport: true}, "import");
59-
lessTester.testSyncronous({syncImport: true}, "css");
63+
lessTester.testSyncronous({syncImport: true}, "strict-math/css");
6064
lessTester.testNoOptions();
6165
lessTester.testJSImport();
6266
lessTester.finished();

test/less/calc.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.no-math {
2+
@var: 50vh/2;
3+
width: calc(50% + (@var - 20px));
4+
}

test/less/media.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@ratio_large: 16;
2424
@ratio_small: 9;
2525

26-
@media all and (device-aspect-ratio: @ratio_large / @ratio_small) {
26+
@media all and (device-aspect-ratio: ~"@{ratio_large} / @{ratio_small}") {
2727
body { max-width: 800px; }
2828
}
2929

@@ -177,7 +177,7 @@ body {
177177
}
178178
}
179179

180-
@media (-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (-o-min-device-pixel-ratio: 2/1), (min-resolution: 2dppx), (min-resolution: 128dpcm) {
180+
@media (-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (-o-min-device-pixel-ratio: ~"2/1"), (min-resolution: 2dppx), (min-resolution: 128dpcm) {
181181
.b {
182182
background: red;
183183
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)