correct sort function: they have to return negative or positive values, not false or true (false maps to 0, not -1)

This commit is contained in:
Konstantin Käfer 2011-02-03 15:38:35 -05:00
parent a5d85fd3d0
commit 76ae45312f
2 changed files with 18 additions and 17 deletions

View File

@ -345,10 +345,10 @@ mess.Parser = function Parser(env) {
var as = a.specificity;
var bs = b.specificity;
for (var i = 0; i < as.length; i++) {
if (as[i] < bs[i]) return true;
if (as[i] > bs[i]) break;
}
if (as[0] != bs[0]) return bs[0] - as[0];
if (as[1] != bs[1]) return bs[1] - as[1];
if (as[2] != bs[2]) return bs[2] - as[2];
return bs[3] - as[3];
};
// If `i` is smaller than the `input.length - 1`,

View File

@ -264,18 +264,19 @@ mess.Renderer = function Renderer(env) {
*/
inheritRules: function(definitions) {
var inheritTime = +new Date();
// definitions are ordered in specificity,
// definitions are ordered by specificity,
// high (index 0) to low
var result = {};
var existing = {}, previous, attachment;
var current;
var byAttachment = {}, byFilter = {};
var result = [];
var current, previous, attachment;
for (var i = 0; i < definitions.length; i++) {
attachment = definitions[i].attachment;
if (!result[attachment]) {
result[attachment] = [];
existing[attachment] = {};
if (!byAttachment[attachment]) {
byAttachment[attachment] = [];
byAttachment[attachment].attachment = attachment;
byFilter[attachment] = {};
result.push(byAttachment[attachment]);
}
current = [ definitions[i] ];
@ -283,13 +284,13 @@ mess.Renderer = function Renderer(env) {
for (var j = i + 1; j < definitions.length; j++) {
if (definitions[j].attachment === attachment) {
// Only inherit rules from the same attachment.
current = this.addRules(current, definitions[j], existing);
current = this.addRules(current, definitions[j], byFilter);
}
}
for (var j = 0; j < current.length; j++) {
existing[attachment][current[j].filters] = current[j];
result[attachment].push(current[j]);
byFilter[attachment][current[j].filters] = current[j];
byAttachment[attachment].push(current[j]);
}
}
@ -363,8 +364,8 @@ mess.Renderer = function Renderer(env) {
var definitions = that.inheritRules(matching);
for (var attachment in definitions) {
var style = new tree.Style(l.id, attachment, definitions[attachment]);
for (var i = 0; i < definitions.length; i++) {
var style = new tree.Style(l.id, definitions[i].attachment, definitions[i]);
if (style) {
l.styles.push(style.name);