mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
peek() can take a string too now
This commit is contained in:
@@ -48,13 +48,18 @@ var input, // LeSS input string
|
||||
current, // index of current chunk, in `input`
|
||||
inputLength;
|
||||
|
||||
function peek(regex) {
|
||||
function peek(tok) {
|
||||
var match;
|
||||
regex.lastIndex = i;
|
||||
|
||||
if ((match = regex.exec(input)) &&
|
||||
(regex.lastIndex - match[0].length === i)) {
|
||||
return match;
|
||||
if (typeof(tok) === 'string') {
|
||||
return input[i] === tok;
|
||||
} else {
|
||||
tok.lastIndex = i;
|
||||
|
||||
if ((match = tok.exec(input)) &&
|
||||
(tok.lastIndex - match[0].length === i)) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +284,7 @@ less.parser = {
|
||||
}
|
||||
$('(') && (args = $(this.entities.arguments)) && $(')');
|
||||
|
||||
if (elements.length > 0 && ($(';') || peek(/\}/g))) {
|
||||
if (elements.length > 0 && ($(';') || peek('}'))) {
|
||||
return new(tree.mixin.Call)(elements, args);
|
||||
}
|
||||
},
|
||||
@@ -326,7 +331,7 @@ less.parser = {
|
||||
}
|
||||
},
|
||||
end: function () {
|
||||
return $(';') || peek(/\}/g);
|
||||
return $(';') || peek('}');
|
||||
},
|
||||
alpha: function () {
|
||||
var value;
|
||||
@@ -411,10 +416,10 @@ less.parser = {
|
||||
var name, value, match;
|
||||
|
||||
if (name = $(this.property) || $(this.entities.variable, true)) {
|
||||
if ((name[0] != '@') && (match = peek(/([^@+\/*(;{}-]*)[;][\s\n]*/g))) {
|
||||
if ((name[0] != '@') && (match = peek(/([^@+\/*(;{}-]*);[\s\n]*/g))) {
|
||||
i += match[0].length;
|
||||
return new(tree.Rule)(name, match[1]);
|
||||
} else if ((value = $(this.value)) && ($(';') || peek(/\}/g))) {
|
||||
} else if ((value = $(this.value)) && ($(';') || peek('}'))) {
|
||||
return new(tree.Rule)(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user