old-selector.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. (function() {
  2. var OldSelector;
  3. OldSelector = (function() {
  4. function OldSelector(selector, prefix1) {
  5. var i, len, prefix, ref;
  6. this.prefix = prefix1;
  7. this.prefixed = selector.prefixed(this.prefix);
  8. this.regexp = selector.regexp(this.prefix);
  9. this.prefixeds = [];
  10. ref = selector.possible();
  11. for (i = 0, len = ref.length; i < len; i++) {
  12. prefix = ref[i];
  13. this.prefixeds.push([selector.prefixed(prefix), selector.regexp(prefix)]);
  14. }
  15. this.unprefixed = selector.name;
  16. this.nameRegexp = selector.regexp();
  17. }
  18. OldSelector.prototype.isHack = function(rule) {
  19. var before, i, index, len, ref, ref1, regexp, rules, some, string;
  20. index = rule.parent.index(rule) + 1;
  21. rules = rule.parent.nodes;
  22. while (index < rules.length) {
  23. before = rules[index].selector;
  24. if (!before) {
  25. return true;
  26. }
  27. if (before.indexOf(this.unprefixed) !== -1 && before.match(this.nameRegexp)) {
  28. return false;
  29. }
  30. some = false;
  31. ref = this.prefixeds;
  32. for (i = 0, len = ref.length; i < len; i++) {
  33. ref1 = ref[i], string = ref1[0], regexp = ref1[1];
  34. if (before.indexOf(string) !== -1 && before.match(regexp)) {
  35. some = true;
  36. break;
  37. }
  38. }
  39. if (!some) {
  40. return true;
  41. }
  42. index += 1;
  43. }
  44. return true;
  45. };
  46. OldSelector.prototype.check = function(rule) {
  47. if (rule.selector.indexOf(this.prefixed) === -1) {
  48. return false;
  49. }
  50. if (!rule.selector.match(this.regexp)) {
  51. return false;
  52. }
  53. if (this.isHack(rule)) {
  54. return false;
  55. }
  56. return true;
  57. };
  58. return OldSelector;
  59. })();
  60. module.exports = OldSelector;
  61. }).call(this);