mirror of
https://github.com/less/less.js.git
synced 2026-02-06 13:05:07 -05:00
Removed Shorthand and Ratio parsers; Fixed some issues with paren depth state; Adjusted tests to pass on new output
This commit is contained in:
@@ -91,7 +91,7 @@ var less = {
|
||||
'call', 'url', 'alpha', 'import',
|
||||
'mixin', 'comment', 'anonymous', 'value',
|
||||
'javascript', 'assignment', 'condition', 'paren',
|
||||
'media', 'ratio', 'unicode-descriptor', 'extend'
|
||||
'media', 'unicode-descriptor', 'extend'
|
||||
].forEach(function (n) {
|
||||
require('./tree/' + n);
|
||||
});
|
||||
|
||||
@@ -606,7 +606,7 @@ less.Parser = function Parser(env) {
|
||||
nameLC = name.toLowerCase();
|
||||
|
||||
if (nameLC === 'url') { return null }
|
||||
else { i += name.length }
|
||||
else { i += name.length }
|
||||
|
||||
if (nameLC === 'alpha') {
|
||||
alpha_ret = $(this.alpha);
|
||||
@@ -620,7 +620,10 @@ less.Parser = function Parser(env) {
|
||||
|
||||
args = $(this.entities.arguments);
|
||||
|
||||
if (! $(')')) return;
|
||||
if (! $(')')) {
|
||||
parens--;
|
||||
return;
|
||||
}
|
||||
parens--;
|
||||
|
||||
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath) }
|
||||
@@ -635,8 +638,7 @@ less.Parser = function Parser(env) {
|
||||
return args;
|
||||
},
|
||||
literal: function () {
|
||||
return $(this.entities.ratio) ||
|
||||
$(this.entities.dimension) ||
|
||||
return $(this.entities.dimension) ||
|
||||
$(this.entities.color) ||
|
||||
$(this.entities.quoted) ||
|
||||
$(this.entities.unicodeDescriptor);
|
||||
@@ -730,20 +732,6 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// A Ratio
|
||||
//
|
||||
// 16/9
|
||||
//
|
||||
ratio: function () {
|
||||
var value, c = input.charCodeAt(i);
|
||||
if (c > 57 || c < 48) return;
|
||||
|
||||
if (value = $(/^(\d+\/\d+)/)) {
|
||||
return new(tree.Ratio)(value[1]);
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// A unicode descriptor, as is used in unicode-range
|
||||
//
|
||||
@@ -787,27 +775,6 @@ less.Parser = function Parser(env) {
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1] }
|
||||
},
|
||||
|
||||
//
|
||||
// A font size/line-height shorthand
|
||||
//
|
||||
// small/12px
|
||||
//
|
||||
// We need to peek first, or we'll match on keywords and dimensions
|
||||
//
|
||||
shorthand: function () {
|
||||
var a, b;
|
||||
|
||||
if (! peek(/^[@\w.%-]+\/[@\w.-]+/)) return;
|
||||
|
||||
save();
|
||||
|
||||
if ((a = $(this.entity)) && $('/') && (b = $(this.entity))) {
|
||||
return new(tree.Shorthand)(a, b);
|
||||
}
|
||||
|
||||
restore();
|
||||
},
|
||||
|
||||
//
|
||||
// extend syntax - used to extend selectors
|
||||
//
|
||||
@@ -1192,8 +1159,6 @@ less.Parser = function Parser(env) {
|
||||
if (!env.compress && (name.charAt(0) != '@') && (match = /^([^@+\/'"*`(;{}-]*);/.exec(chunks[j]))) {
|
||||
i += match[0].length - 1;
|
||||
value = new(tree.Anonymous)(match[1]);
|
||||
} else if (name === "font") {
|
||||
value = $(this.font);
|
||||
} else {
|
||||
value = $(this.value);
|
||||
}
|
||||
@@ -1244,7 +1209,7 @@ less.Parser = function Parser(env) {
|
||||
nodes.push(e);
|
||||
} else if ($('(')) {
|
||||
p = $(this.property);
|
||||
e = $(this.entity);
|
||||
e = $(this.value);
|
||||
if ($(')')) {
|
||||
if (p && e) {
|
||||
nodes.push(new(tree.Paren)(new(tree.Rule)(p, e, null, i, true)));
|
||||
@@ -1378,22 +1343,6 @@ less.Parser = function Parser(env) {
|
||||
|
||||
restore();
|
||||
},
|
||||
font: function () {
|
||||
var value = [], expression = [], weight, shorthand, font, e;
|
||||
|
||||
while (e = $(this.shorthand) || $(this.entity)) {
|
||||
expression.push(e);
|
||||
}
|
||||
value.push(new(tree.Expression)(expression));
|
||||
|
||||
if ($(',')) {
|
||||
while (e = $(this.expression)) {
|
||||
value.push(e);
|
||||
if (! $(',')) { break }
|
||||
}
|
||||
}
|
||||
return new(tree.Value)(value);
|
||||
},
|
||||
|
||||
//
|
||||
// A Value is a comma-delimited list of Expressions
|
||||
@@ -1425,10 +1374,11 @@ less.Parser = function Parser(env) {
|
||||
|
||||
if ($('(')) {
|
||||
parens++;
|
||||
e = $(this.expression);
|
||||
expect(')');
|
||||
parens--;
|
||||
return e;
|
||||
if (e = $(this.expression)) {
|
||||
expect(')');
|
||||
parens--;
|
||||
return e;
|
||||
}
|
||||
}
|
||||
},
|
||||
multiplication: function () {
|
||||
@@ -1515,6 +1465,9 @@ less.Parser = function Parser(env) {
|
||||
|
||||
while (e = $(this.addition) || $(this.entity)) {
|
||||
entities.push(e);
|
||||
if (!peek(/^\/\*/) && (delim = $('/'))) {
|
||||
entities.push(new(tree.Anonymous)(delim));
|
||||
}
|
||||
}
|
||||
if (entities.length > 0) {
|
||||
return new(tree.Expression)(entities);
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Ratio = function (value) {
|
||||
this.value = value;
|
||||
};
|
||||
tree.Ratio.prototype = {
|
||||
toCSS: function (env) {
|
||||
return this.value;
|
||||
},
|
||||
eval: function () { return this }
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
Reference in New Issue
Block a user