calcRulePatternPriority.js 432 B

12345678910111213141516171819
  1. module.exports = function calcRulePatternPriority(pattern, node) {
  2. // 0 — it pattern doesn't match
  3. // 1 — pattern without `selector`
  4. // 2 — pattern match `selector`
  5. let priority = 0;
  6. // doesn't have `selector`
  7. if (!pattern.hasOwnProperty('selector')) {
  8. priority = 1;
  9. }
  10. // match `selector`
  11. if (pattern.hasOwnProperty('selector') && pattern.selector.test(node.selector)) {
  12. priority = 2;
  13. }
  14. return priority;
  15. };