Convert property merging to the new agreed syntax of +:

This commit is contained in:
Luke Page
2013-04-30 20:54:06 +01:00
parent 577d24cc97
commit 5cb5f561c8
5 changed files with 40 additions and 62 deletions

View File

@@ -1230,12 +1230,12 @@ less.Parser = function Parser(env) {
}
},
rule: function (tryAnonymous) {
var name, value, c = input.charAt(i), important, merge, match;
var name, value, c = input.charAt(i), important, merge = false, match;
save();
if (c === '.' || c === '#' || c === '&') { return }
if (name = $(this.variable) || $(this.property)) {
if (name = $(this.variable) || $(this.ruleProperty)) {
// prefer to try to parse first if its a variable or we are compressing
// but always fallback on the other one
value = !tryAnonymous && (env.compress || (name.charAt(0) === '@')) ?
@@ -1244,7 +1244,10 @@ less.Parser = function Parser(env) {
important = $(this.important);
merge = $(this.merge);
if (name[name.length-1] === "+") {
merge = true;
name = name.substr(0, name.length - 1);
}
if (value && $(this.end)) {
return new (tree.Rule)(name, value, important, merge, memo, env.currentFileInfo);
@@ -1497,21 +1500,6 @@ less.Parser = function Parser(env) {
return $(/^! *important/);
}
},
merge: function () {
var separator;
if (input.charAt(i) === '!') {
if ($(/^! *merge\(/)) {
separator = expect(/^ *space|comma */);
if (separator) {
separator = (separator.trim() === 'space')
? ' '
: ',';
}
expect(')');
}
}
return separator;
},
sub: function () {
var a, e;
@@ -1632,6 +1620,13 @@ less.Parser = function Parser(env) {
if (name = $(/^(\*?-?[_a-z0-9-]+)\s*:/)) {
return name[1];
}
},
ruleProperty: function () {
var name;
if (name = $(/^(\*?-?[_a-z0-9-]+)\s*(\+?)\s*:/)) {
return name[1] + (name[2] || "");
}
}
}
};

View File

@@ -20,7 +20,7 @@ tree.Rule.prototype = {
this.value = visitor.visit(this.value);
},
toCSS: function (env) {
if (this.variable) { return "" }
if (this.variable) { return ""; }
else {
try {
return this.name + (env.compress ? ':' : ': ') +

View File

@@ -178,7 +178,8 @@ tree.Ruleset.prototype = {
debugInfo, // Line number debugging
rule;
this.mergeRules();
this.mergeRules();
// Compile rules and rulesets
for (var i = 0; i < this.rules.length; i++) {
rule = this.rules[i];
@@ -468,8 +469,7 @@ tree.Ruleset.prototype = {
if ((rule instanceof tree.Rule) && rule.merge) {
key = [rule.name,
rule.important ? "!" : "",
rule.merge].join(",");
rule.important ? "!" : ""].join(",");
if (!groups[key]) {
parts = groups[key] = [];
@@ -487,7 +487,7 @@ tree.Ruleset.prototype = {
if (parts.length > 1) {
rule = parts[0];
rule.value = new ((rule.merge === ' ') ? tree.Expression : tree.Value)(parts.map(function (p) {
rule.value = new (tree.Value)(parts.map(function (p) {
return p.value;
}));
}