mirror of
https://github.com/less/less.js.git
synced 2026-02-06 21:15:14 -05: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) {
|
||||
|
||||
Reference in New Issue
Block a user