Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function itemCmp(a: IItem, b: IItem): number {
// Sort first based on selector specificity.
let s1 = Selector.calculateSpecificity(a.selector);
let s2 = Selector.calculateSpecificity(b.selector);
if (s1 !== s2) {
return s2 - s1;
}
// If specificities are equal, sort based on rank.
let r1 = a.rank;
let r2 = b.rank;
if (r1 !== r2) {
return r1 < r2 ? -1 : 1; // Infinity-safe
}
// When all else fails, sort by item id.
return a.id - b.id;
}
}
function itemCmp(a: IItem, b: IItem): number {
// Sort first based on selector specificity.
let s1 = Selector.calculateSpecificity(a.selector);
let s2 = Selector.calculateSpecificity(b.selector);
if (s1 !== s2) {
return s2 - s1;
}
// If specificities are equal, sort based on rank.
let r1 = a.rank;
let r2 = b.rank;
if (r1 !== r2) {
return r1 < r2 ? -1 : 1; // Infinity-safe
}
// When all else fails, sort by item id.
return a.id - b.id;
}
}
if (sqm === SequenceMatch.Partial) {
if (!partial && targetDistance(binding.selector, event) !== -1) {
partial = true;
}
continue;
}
// Ignore the match if the selector doesn't match, or if the
// matched node is farther away than the current best match.
let td = targetDistance(binding.selector, event);
if (td === -1 || td > distance) {
continue;
}
// Get the specificity for the selector.
let sp = Selector.calculateSpecificity(binding.selector);
// Update the best match if this match is stronger.
if (!exact || td < distance || sp >= specificity) {
exact = binding;
distance = td;
specificity = sp;
}
}
// Return the match result.
return { exact, partial };
}