Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

selectorCombinatorSpaceChecker.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @ts-nocheck
  2. 'use strict';
  3. const isStandardSyntaxCombinator = require('../utils/isStandardSyntaxCombinator');
  4. const isStandardSyntaxRule = require('../utils/isStandardSyntaxRule');
  5. const parseSelector = require('../utils/parseSelector');
  6. const report = require('../utils/report');
  7. module.exports = function (opts) {
  8. let hasFixed;
  9. opts.root.walkRules((rule) => {
  10. if (!isStandardSyntaxRule(rule)) {
  11. return;
  12. }
  13. hasFixed = false;
  14. const selector = rule.raws.selector ? rule.raws.selector.raw : rule.selector;
  15. const fixedSelector = parseSelector(selector, opts.result, rule, (selectorTree) => {
  16. selectorTree.walkCombinators((node) => {
  17. // Ignore non-standard combinators
  18. if (!isStandardSyntaxCombinator(node)) {
  19. return;
  20. }
  21. // Ignore spaced descendant combinator
  22. if (/\s/.test(node.value)) {
  23. return;
  24. }
  25. // Check the exist of node in prev of the combinator.
  26. // in case some that aren't the first begin with combinators (nesting syntax)
  27. if (opts.locationType === 'before' && !node.prev()) {
  28. return;
  29. }
  30. const parentParentNode = node.parent && node.parent.parent;
  31. // Ignore pseudo-classes selector like `.foo:nth-child(2n + 1) {}`
  32. if (parentParentNode && parentParentNode.type === 'pseudo') {
  33. return;
  34. }
  35. const sourceIndex = node.sourceIndex;
  36. const index =
  37. node.value.length > 1 && opts.locationType === 'before'
  38. ? sourceIndex
  39. : sourceIndex + node.value.length - 1;
  40. check(selector, node, index, rule, sourceIndex);
  41. });
  42. });
  43. if (hasFixed) {
  44. if (!rule.raws.selector) {
  45. rule.selector = fixedSelector;
  46. } else {
  47. rule.raws.selector.raw = fixedSelector;
  48. }
  49. }
  50. });
  51. function check(source, combinator, index, node, sourceIndex) {
  52. opts.locationChecker({
  53. source,
  54. index,
  55. errTarget: combinator.value,
  56. err: (m) => {
  57. if (opts.fix && opts.fix(combinator)) {
  58. hasFixed = true;
  59. return;
  60. }
  61. report({
  62. message: m,
  63. node,
  64. index: sourceIndex,
  65. result: opts.result,
  66. ruleName: opts.checkedRuleName,
  67. });
  68. },
  69. });
  70. }
  71. };