mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Preserve whitespace in operations
This commit is contained in:
@@ -1378,13 +1378,15 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
multiplication: function () {
|
||||
var m, a, op, operation, expression = [];
|
||||
var m, a, op, operation, isSpaced, expression = [];
|
||||
if (m = $(this.operand)) {
|
||||
isSpaced = isWhitespace(input.charAt(i - 1));
|
||||
while (!peek(/^\/[*\/]/) && (op = ($('/') || $('*')))) {
|
||||
if (a = $(this.operand)) {
|
||||
m.parensInOp = true;
|
||||
a.parensInOp = true;
|
||||
operation = new(tree.Operation)(op, [operation || m, a]);
|
||||
operation = new(tree.Operation)(op, [operation || m, a], isSpaced);
|
||||
isSpaced = isWhitespace(input.charAt(i - 1));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -1393,13 +1395,15 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
addition: function () {
|
||||
var m, a, op, operation;
|
||||
var m, a, op, operation, isSpaced;
|
||||
if (m = $(this.multiplication)) {
|
||||
while ((op = $(/^[-+]\s+/) || (!isWhitespace(input.charAt(i - 1)) && ($('+') || $('-')))) &&
|
||||
isSpaced = isWhitespace(input.charAt(i - 1));
|
||||
while ((op = $(/^[-+]\s+/) || (!isSpaced && ($('+') || $('-')))) &&
|
||||
(a = $(this.multiplication))) {
|
||||
m.parensInOp = true;
|
||||
a.parensInOp = true;
|
||||
operation = new(tree.Operation)(op, [operation || m, a]);
|
||||
operation = new(tree.Operation)(op, [operation || m, a], isSpaced);
|
||||
isSpaced = isWhitespace(input.charAt(i - 1));
|
||||
}
|
||||
return operation || m;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Operation = function (op, operands) {
|
||||
tree.Operation = function (op, operands, isSpaced) {
|
||||
this.op = op.trim();
|
||||
this.operands = operands;
|
||||
this.isSpaced = isSpaced;
|
||||
};
|
||||
tree.Operation.prototype.eval = function (env) {
|
||||
var a = this.operands[0].eval(env),
|
||||
@@ -25,11 +26,12 @@ tree.Operation.prototype.eval = function (env) {
|
||||
|
||||
return a.operate(env, this.op, b);
|
||||
} else {
|
||||
return new(tree.Operation)(this.op, [a, b]);
|
||||
return new(tree.Operation)(this.op, [a, b], this.isSpaced);
|
||||
}
|
||||
};
|
||||
tree.Operation.prototype.toCSS = function (env) {
|
||||
return this.operands[0].toCSS() + " " + this.op + " " + this.operands[1].toCSS();
|
||||
var separator = this.isSpaced ? " " : "";
|
||||
return this.operands[0].toCSS() + separator + this.op + separator + this.operands[1].toCSS();
|
||||
};
|
||||
|
||||
tree.operate = function (env, op, a, b) {
|
||||
|
||||
@@ -73,12 +73,12 @@ p::before {
|
||||
}
|
||||
}
|
||||
.units {
|
||||
font: 1.2rem / 2rem;
|
||||
font: 8vw / 9vw;
|
||||
font: 10vh / 12vh;
|
||||
font: 12vm / 15vm;
|
||||
font: 12vmin / 15vmin;
|
||||
font: 1.2ch / 1.5ch;
|
||||
font: 1.2rem/2rem;
|
||||
font: 8vw/9vw;
|
||||
font: 10vh/12vh;
|
||||
font: 12vm/15vm;
|
||||
font: 12vmin/15vmin;
|
||||
font: 1.2ch/1.5ch;
|
||||
}
|
||||
@supports ( box-shadow: 2px 2px 2px black ) or
|
||||
( -moz-box-shadow: 2px 2px 2px black ) {
|
||||
|
||||
@@ -50,8 +50,8 @@ p + h1 {
|
||||
}
|
||||
#shorthands {
|
||||
border: 1px solid #000;
|
||||
font: 12px / 16px Arial;
|
||||
font: 100% / 16px Arial;
|
||||
font: 12px/16px Arial;
|
||||
font: 100%/16px Arial;
|
||||
margin: 1px 0;
|
||||
padding: 0 auto;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ p + h1 {
|
||||
margin: 0;
|
||||
padding: 1px 0 2px 0;
|
||||
font: normal small / 20px 'Trebuchet MS', Verdana, sans-serif;
|
||||
font: 0 / 0 a;
|
||||
font: 0/0 a;
|
||||
border-radius: 5px / 10px;
|
||||
background: url("img.jpg") center / 100px;
|
||||
background: #ffffff url(image.png) center / 1px 100px repeat-x scroll content-box padding-box;
|
||||
|
||||
@@ -73,8 +73,8 @@ body {
|
||||
width: "{";
|
||||
}
|
||||
.slash-vs-math {
|
||||
border-radius: 2px / 5px;
|
||||
border-radius: 5px / 10px;
|
||||
border-radius: 2px/5px;
|
||||
border-radius: 5px/10px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.comma-vs-semi-colon {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
.nested-parens {
|
||||
width: 2 * (4 * (2 + (1 + 6))) - 1;
|
||||
height: ((2+3)*(2+3) / (9-4)) + 1;
|
||||
height: ((2 + 3) * (2 + 3) / (9 - 4)) + 1;
|
||||
}
|
||||
|
||||
.mixed-units {
|
||||
|
||||
Reference in New Issue
Block a user