mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Division only when inside parentheses
This commit is contained in:
@@ -61,6 +61,7 @@ less.Parser = function Parser(env) {
|
||||
furthest, // furthest index the parser has gone to
|
||||
chunks, // chunkified input
|
||||
current, // index of current chunk, in `input`
|
||||
parens = 0, // current depth of nested parentheses
|
||||
parser;
|
||||
|
||||
var that = this;
|
||||
@@ -615,10 +616,12 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
|
||||
$('('); // Parse the '(' and consume whitespace.
|
||||
parens++;
|
||||
|
||||
args = $(this.entities.arguments);
|
||||
|
||||
if (! $(')')) return;
|
||||
parens--;
|
||||
|
||||
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath) }
|
||||
},
|
||||
@@ -852,7 +855,7 @@ less.Parser = function Parser(env) {
|
||||
var elements = [], e, c, argsSemiColon = [], argsComma = [], args, delim, arg, nameLoop, expressions, isSemiColonSeperated, expressionContainsNamed, index = i, s = input.charAt(i), name, value, important = false;
|
||||
|
||||
if (s !== '.' && s !== '#') { return }
|
||||
|
||||
|
||||
save(); // stop us absorbing part of an invalid selector
|
||||
|
||||
while (e = $(/^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/)) {
|
||||
@@ -861,6 +864,7 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
if ($('(')) {
|
||||
expressions = [];
|
||||
parens++;
|
||||
while (arg = $(this.expression)) {
|
||||
nameLoop = null;
|
||||
value = arg;
|
||||
@@ -890,6 +894,7 @@ less.Parser = function Parser(env) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parens--;
|
||||
if ($(';') || isSemiColonSeperated) {
|
||||
|
||||
if (expressionContainsNamed) {
|
||||
@@ -921,7 +926,7 @@ less.Parser = function Parser(env) {
|
||||
if (elements.length > 0 && ($(';') || peek('}'))) {
|
||||
return new(tree.mixin.Call)(elements, args, index, env.filename, important);
|
||||
}
|
||||
|
||||
|
||||
restore();
|
||||
},
|
||||
|
||||
@@ -982,7 +987,7 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
} while ($(',') || $(';'))
|
||||
|
||||
// .mixincall("@{a}");
|
||||
// .mixincall("@{a}");
|
||||
// looks a bit like a mixin definition.. so we have to be nice and restore
|
||||
if (!$(')')) {
|
||||
furthest = i;
|
||||
@@ -1215,9 +1220,9 @@ less.Parser = function Parser(env) {
|
||||
//
|
||||
"import": function () {
|
||||
var path, features, index = i;
|
||||
|
||||
|
||||
save();
|
||||
|
||||
|
||||
var dir = $(/^@import(?:-(once|multiple))?\s+/);
|
||||
|
||||
if (dir && (path = $(this.entities.quoted) || $(this.entities.url))) {
|
||||
@@ -1227,7 +1232,7 @@ less.Parser = function Parser(env) {
|
||||
return new(tree.Import)(path, imports, features, importOnce, index, env.rootpath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restore();
|
||||
},
|
||||
|
||||
@@ -1305,7 +1310,7 @@ less.Parser = function Parser(env) {
|
||||
if (value = $(this['import']) || $(this.media)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
save();
|
||||
|
||||
name = $(/^@[a-z-]+/);
|
||||
@@ -1370,7 +1375,7 @@ less.Parser = function Parser(env) {
|
||||
return directive;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restore();
|
||||
},
|
||||
font: function () {
|
||||
@@ -1418,15 +1423,27 @@ less.Parser = function Parser(env) {
|
||||
sub: function () {
|
||||
var e;
|
||||
|
||||
if ($('(') && (e = $(this.expression)) && $(')')) {
|
||||
if ($('(')) {
|
||||
parens++;
|
||||
e = $(this.expression);
|
||||
expect(')');
|
||||
parens--;
|
||||
return e;
|
||||
}
|
||||
},
|
||||
multiplication: function () {
|
||||
var m, a, op, operation;
|
||||
var m, a, op, operation, expression = [];
|
||||
if (m = $(this.operand)) {
|
||||
while (!peek(/^\/[*\/]/) && (op = ($('/') || $('*'))) && (a = $(this.operand))) {
|
||||
operation = new(tree.Operation)(op, [operation || m, a]);
|
||||
while (!peek(/^\/[*\/]/) && (op = ($('/') || $('*')))) {
|
||||
if (op === '/' && !parens) {
|
||||
expression.push(operation || m);
|
||||
expression.push(new(tree.Anonymous)('/'));
|
||||
operation = new(tree.Expression)(expression);
|
||||
} else if (a = $(this.operand)) {
|
||||
operation = new(tree.Operation)(op, [operation || m, a]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return operation || m;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user