stylelint-browser-compat 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -0
  3. package/lib/at-rules/at_rules_name_set.js +16 -0
  4. package/lib/at-rules/collect_features.js +145 -0
  5. package/lib/at-rules/counter-style/collect_features.js +41 -0
  6. package/lib/at-rules/counter-style/descriptor_name_set.js +16 -0
  7. package/lib/at-rules/document/collect_features.js +46 -0
  8. package/lib/at-rules/document/regexp/collect_features.js +30 -0
  9. package/lib/at-rules/font-face/__font_type/collect_features.js +79 -0
  10. package/lib/at-rules/font-face/collect_features.js +67 -0
  11. package/lib/at-rules/font-face/descriptor_name_set.js +16 -0
  12. package/lib/at-rules/font-feature-values/at_rules_name_set.js +16 -0
  13. package/lib/at-rules/font-feature-values/collect_features.js +30 -0
  14. package/lib/at-rules/keyframes/collect_features.js +29 -0
  15. package/lib/at-rules/media/collect_features.js +118 -0
  16. package/lib/at-rules/media/media_feature_name_map.js +8 -0
  17. package/lib/at-rules/page/collect_features.js +82 -0
  18. package/lib/at-rules/page/descriptor_name_set.js +16 -0
  19. package/lib/at-rules/page/size/collect_features.js +55 -0
  20. package/lib/at-rules/property/collect_features.js +60 -0
  21. package/lib/at-rules/property/descriptor_name_set.js +16 -0
  22. package/lib/at-rules/scroll-timeline/collect_features.js +60 -0
  23. package/lib/at-rules/scroll-timeline/descriptor_name_set.js +16 -0
  24. package/lib/collect_features.js +69 -0
  25. package/lib/index.js +5 -0
  26. package/lib/is_supported.js +75 -0
  27. package/lib/options.js +20 -0
  28. package/lib/parse_browserslist_version.js +132 -0
  29. package/lib/properties/-moz-orient/collect_features.js +61 -0
  30. package/lib/properties/-moz-user-input/collect_features.js +71 -0
  31. package/lib/properties/animation-direction/collect_features.js +53 -0
  32. package/lib/properties/animation-timing-function/collect_features.js +51 -0
  33. package/lib/properties/appearance/collect_features.js +76 -0
  34. package/lib/properties/background/background-clip/collect_features.js +59 -0
  35. package/lib/properties/background/background-origin/collect_features.js +59 -0
  36. package/lib/properties/background/background-size/collect_features.js +106 -0
  37. package/lib/properties/background/collect_features.js +104 -0
  38. package/lib/properties/background/multiple_backgrounds/collect_features.js +39 -0
  39. package/lib/properties/background-attachment/collect_features.js +70 -0
  40. package/lib/properties/background-clip/collect_features.js +55 -0
  41. package/lib/properties/background-image/collect_features.js +133 -0
  42. package/lib/properties/background-image/svg_images/collect_features.js +58 -0
  43. package/lib/properties/background-origin/collect_features.js +42 -0
  44. package/lib/properties/background-position/collect_features.js +117 -0
  45. package/lib/properties/background-position-x/collect_features.js +36 -0
  46. package/lib/properties/background-position-y/collect_features.js +36 -0
  47. package/lib/properties/background-repeat/collect_features.js +102 -0
  48. package/lib/properties/background-repeat/round_space/collect_features.js +54 -0
  49. package/lib/properties/background-size/collect_features.js +38 -0
  50. package/lib/properties/block-size/collect_features.js +77 -0
  51. package/lib/properties/border-bottom-left-radius/border-bottom-right-radius/collect_features.js +57 -0
  52. package/lib/properties/border-bottom-left-radius/collect_features.js +57 -0
  53. package/lib/properties/border-bottom-right-radius/collect_features.js +57 -0
  54. package/lib/properties/border-radius/collect_features.js +61 -0
  55. package/lib/properties/border-top-left-radius/collect_features.js +57 -0
  56. package/lib/properties/border-top-right-radius/collect_features.js +57 -0
  57. package/lib/properties/box-shadow/collect_features.js +92 -0
  58. package/lib/properties/box-sizing/collect_features.js +39 -0
  59. package/lib/properties/caption-side/collect_features.js +38 -0
  60. package/lib/properties/clear/collect_features.js +38 -0
  61. package/lib/properties/clip-path/collect_features.js +65 -0
  62. package/lib/properties/collect_features.js +452 -0
  63. package/lib/properties/color-scheme/collect_features.js +52 -0
  64. package/lib/properties/property_name_set.js +16 -0
  65. package/lib/properties/transition/collect_features.js +33 -0
  66. package/lib/properties/transition-property/collect_features.js +38 -0
  67. package/lib/rule.js +125 -0
  68. package/lib/selectors/__attributes/collect_features.js +44 -0
  69. package/lib/selectors/__classes/collect_features.js +23 -0
  70. package/lib/selectors/__combinators/collect_features.js +91 -0
  71. package/lib/selectors/__ids/collect_features.js +23 -0
  72. package/lib/selectors/__pseudos/collect_features.js +228 -0
  73. package/lib/selectors/__pseudos/pseudo_selector_name_set.js +18 -0
  74. package/lib/selectors/__tags/collect_features.js +48 -0
  75. package/lib/selectors/__universal/collect_features.js +37 -0
  76. package/lib/selectors/active/non_a_elements/collect_features.js +38 -0
  77. package/lib/selectors/after/animation_and_transition_support/collect_features.js +43 -0
  78. package/lib/selectors/backdrop/dialog/collect_features.js +38 -0
  79. package/lib/selectors/before/animation_and_transition_support/collect_features.js +43 -0
  80. package/lib/selectors/collect_features.js +120 -0
  81. package/lib/selectors/cue/selector_argument/collect_features.js +26 -0
  82. package/lib/selectors/hostfunction/collect_features.js +26 -0
  83. package/lib/selectors/hover/collect_features.js +61 -0
  84. package/lib/selectors/invalid/collect_features.js +39 -0
  85. package/lib/selectors/marker/animation_and_transition_support/collect_features.js +43 -0
  86. package/lib/selectors/not/selector_list/collect_features.js +31 -0
  87. package/lib/selectors/nth-child/of_syntax/collect_features.js +32 -0
  88. package/lib/selectors/nth-last-child/of_syntax/collect_features.js +32 -0
  89. package/lib/selectors/valid/collect_features.js +39 -0
  90. package/lib/types/__function/collect_features.js +187 -0
  91. package/lib/types/attr/collect_features.js +69 -0
  92. package/lib/types/attr/type_unit_name_map.js +8 -0
  93. package/lib/types/calc/collect_features.js +70 -0
  94. package/lib/types/collect_features.js +139 -0
  95. package/lib/types/color/__alpha_parameter/collect_features.js +37 -0
  96. package/lib/types/color/__float_values/collect_features.js +44 -0
  97. package/lib/types/color/__space_separated_parameters/collect_features.js +37 -0
  98. package/lib/types/color/rgb_hexadecimal_notation/collect_features.js +42 -0
  99. package/lib/types/easing-function/steps/jump/collect_features.js +37 -0
  100. package/lib/types/function_name_map.js +8 -0
  101. package/lib/types/image/gradient/__linear-gradient/collect_features.js +77 -0
  102. package/lib/types/image/gradient/__linear-gradient/doubleposition/collect_features.js +43 -0
  103. package/lib/types/image/gradient/__linear-gradient/interpolation_hints/collect_features.js +42 -0
  104. package/lib/types/image/gradient/__linear-gradient/to/collect_features.js +39 -0
  105. package/lib/types/image/gradient/__linear-gradient/unitless_0_angle/collect_features.js +40 -0
  106. package/lib/types/image/gradient/__radial-gradient/at/collect_features.js +44 -0
  107. package/lib/types/image/gradient/__radial-gradient/collect_features.js +68 -0
  108. package/lib/types/image/gradient/__radial-gradient/doubleposition/collect_features.js +47 -0
  109. package/lib/types/image/gradient/__radial-gradient/interpolation_hints/collect_features.js +42 -0
  110. package/lib/types/image/gradient/conic-gradient/collect_features.js +48 -0
  111. package/lib/types/image/gradient/conic-gradient/doubleposition/collect_features.js +43 -0
  112. package/lib/types/number/scientific_notation/collect_features.js +31 -0
  113. package/lib/types/unit_name_map.js +8 -0
  114. package/lib/types/value_name_map.js +8 -0
  115. package/lib/types.js +5 -0
  116. package/package.json +75 -0
package/lib/rule.js ADDED
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ruleName = exports.plugin = exports.meta = exports.messages = void 0;
7
+
8
+ var _browserCompatData = _interopRequireDefault(require("@mdn/browser-compat-data"));
9
+
10
+ var _browserslist = _interopRequireDefault(require("browserslist"));
11
+
12
+ var _dotProp = _interopRequireDefault(require("dot-prop"));
13
+
14
+ var _stylelint = _interopRequireDefault(require("stylelint"));
15
+
16
+ var _collect_features = require("./collect_features");
17
+
18
+ var _is_supported = require("./is_supported");
19
+
20
+ var _options = require("./options");
21
+
22
+ var _parse_browserslist_version = require("./parse_browserslist_version");
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+
26
+ const ruleName = 'plugin/browser-compat';
27
+ exports.ruleName = ruleName;
28
+
29
+ const messages = _stylelint.default.utils.ruleMessages(ruleName, {
30
+ disallowPrefix: featureName => {
31
+ return `${featureName} with vendor prefix is not allowed by stylelint config.`;
32
+ },
33
+ rejected: (featureName, targets, mdnUrl) => {
34
+ if (mdnUrl) {
35
+ return `${featureName} is not supported in ${targets}. See ${mdnUrl}.`;
36
+ }
37
+
38
+ return `${featureName} is not supported in ${targets}.`;
39
+ }
40
+ });
41
+
42
+ exports.messages = messages;
43
+ const meta = {
44
+ url: 'https://github.com/3846masa/stylelint-browser-compat'
45
+ };
46
+ exports.meta = meta;
47
+
48
+ const ruleFunction = (enabled, passedOptions) => {
49
+ return async (postcssRoot, postcssResult) => {
50
+ if (!enabled) {
51
+ return;
52
+ }
53
+
54
+ const parseOptionsResult = _options.ruleOptionsSchema.safeParse(passedOptions);
55
+
56
+ const validOptions = _stylelint.default.utils.validateOptions(postcssResult, ruleName, {
57
+ actual: passedOptions,
58
+ optional: true,
59
+ possible: () => parseOptionsResult.success
60
+ });
61
+
62
+ if (!validOptions || !parseOptionsResult.success) {
63
+ return;
64
+ }
65
+
66
+ const options = parseOptionsResult.data;
67
+ const versions = (0, _browserslist.default)(options.browserslist ?? null, {});
68
+ const targets = (0, _parse_browserslist_version.parseBrowsersListVersion)(versions);
69
+ const features = await (0, _collect_features.collectFeatures)({
70
+ container: postcssRoot,
71
+ ignoreFeatures: new Set(options.allow.features)
72
+ });
73
+
74
+ for (const feature of features) {
75
+ const compat = _dotProp.default.get(_browserCompatData.default.css, feature.id);
76
+
77
+ if (!(compat !== null && compat !== void 0 && compat.__compat)) {
78
+ continue;
79
+ }
80
+
81
+ const {
82
+ mdn_url: mdnUrl,
83
+ support: supportBlock
84
+ } = compat.__compat;
85
+
86
+ if (options.allow.prefix !== true && feature.prefix != null) {
87
+ _stylelint.default.utils.report({
88
+ endIndex: feature.endIndex,
89
+ index: feature.index,
90
+ message: messages.disallowPrefix(feature.name),
91
+ node: feature.node,
92
+ result: postcssResult,
93
+ ruleName
94
+ });
95
+
96
+ continue;
97
+ }
98
+
99
+ const notSupportedTargets = targets.filter(target => {
100
+ return (0, _is_supported.isSupported)(supportBlock, target, {
101
+ allow: options.allow
102
+ }) === false;
103
+ });
104
+
105
+ if (notSupportedTargets.length === 0) {
106
+ continue;
107
+ }
108
+
109
+ const notSupportedTargetText = notSupportedTargets.map(target => `${target.target.name} ${target.versionString}`).join(', ');
110
+
111
+ _stylelint.default.utils.report({
112
+ endIndex: feature.endIndex,
113
+ index: feature.index,
114
+ message: messages.rejected(feature.name, notSupportedTargetText, mdnUrl ?? ''),
115
+ node: feature.node,
116
+ result: postcssResult,
117
+ ruleName
118
+ });
119
+ }
120
+ };
121
+ };
122
+
123
+ const plugin = _stylelint.default.createPlugin(ruleName, ruleFunction);
124
+
125
+ exports.plugin = plugin;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ const features = [];
13
+ const index = node.sourceIndex;
14
+ const endIndex = index + node.toString().length;
15
+ features.push({
16
+ endIndex,
17
+ id: `selectors.attribute`,
18
+ index,
19
+ name: `Attribute selector`,
20
+ node: parent
21
+ });
22
+
23
+ if (node.insensitive || node.raws.insensitiveFlag === 'i' || node.raws.insensitiveFlag === 'I') {
24
+ features.push({
25
+ endIndex,
26
+ id: `selectors.attribute.case_insensitive_modifier`,
27
+ index,
28
+ name: `Attribute selector with case-insensitive modifier`,
29
+ node: parent
30
+ });
31
+ }
32
+
33
+ if (node.raws.insensitiveFlag === 's' || node.raws.insensitiveFlag === 'S') {
34
+ features.push({
35
+ endIndex,
36
+ id: `selectors.attribute.case_sensitive_modifier`,
37
+ index,
38
+ name: `Attribute selector with case-sensitive modifier`,
39
+ node: parent
40
+ });
41
+ }
42
+
43
+ return features;
44
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ const features = [];
13
+ const index = node.sourceIndex;
14
+ const endIndex = index + node.toString().length;
15
+ features.push({
16
+ endIndex,
17
+ id: `selectors.class`,
18
+ index,
19
+ name: `Class selector`,
20
+ node: parent
21
+ });
22
+ return features;
23
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ const features = [];
13
+ const index = node.sourceIndex;
14
+ const endIndex = index + node.value.length;
15
+
16
+ switch (node.value) {
17
+ case '+':
18
+ {
19
+ features.push({
20
+ endIndex,
21
+ id: `selectors.adjacent_sibling`,
22
+ index,
23
+ name: `Adjacent sibling combinator`,
24
+ node: parent
25
+ });
26
+ break;
27
+ }
28
+
29
+ case '>':
30
+ {
31
+ features.push({
32
+ endIndex,
33
+ id: `selectors.child`,
34
+ index,
35
+ name: `Child combinator`,
36
+ node: parent
37
+ });
38
+ break;
39
+ }
40
+
41
+ case '||':
42
+ {
43
+ features.push({
44
+ endIndex,
45
+ id: `selectors.column`,
46
+ index,
47
+ name: `Column combinator`,
48
+ node: parent
49
+ });
50
+ break;
51
+ }
52
+
53
+ case ' ':
54
+ {
55
+ features.push({
56
+ endIndex,
57
+ id: `selectors.descendant`,
58
+ index,
59
+ name: `Descendant combinator`,
60
+ node: parent
61
+ });
62
+ break;
63
+ }
64
+
65
+ case '>>':
66
+ {
67
+ features.push({
68
+ endIndex,
69
+ id: `selectors.descendant.two_greater_than_syntax`,
70
+ index,
71
+ name: `">>" syntax for descendant combinator`,
72
+ node: parent
73
+ });
74
+ break;
75
+ }
76
+
77
+ case '~':
78
+ {
79
+ features.push({
80
+ endIndex,
81
+ id: `selectors.general_sibling`,
82
+ index,
83
+ name: `General sibling combinator`,
84
+ node: parent
85
+ });
86
+ break;
87
+ }
88
+ }
89
+
90
+ return features;
91
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ const features = [];
13
+ const index = node.sourceIndex;
14
+ const endIndex = index + node.toString().length;
15
+ features.push({
16
+ endIndex,
17
+ id: `selectors.id`,
18
+ index,
19
+ name: `ID selector`,
20
+ node: parent
21
+ });
22
+ return features;
23
+ }
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ var _postcssSelectorParser = require("postcss-selector-parser");
9
+
10
+ var _pseudo_selector_name_set = require("./pseudo_selector_name_set");
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ const PSEUDO_TYPE_CLASS = 'pseudo-class';
17
+ const PSEUDO_TYPE_ELEMENT = 'pseudo-element';
18
+
19
+ async function collectFeatures({
20
+ node,
21
+ parent
22
+ }) {
23
+ const promises = [];
24
+ const pseudoType = (0, _postcssSelectorParser.isPseudoElement)(node) ? PSEUDO_TYPE_ELEMENT : PSEUDO_TYPE_CLASS;
25
+ const index = node.sourceIndex;
26
+ const endIndex = index + node.toString().length;
27
+ const [, vendorPrefix] = /^::?(-(?:webkit|moz|ms|o)-)/.exec(node.value) ?? [];
28
+ const selector = node.value;
29
+ const id = selector.replace(/^::?/, '');
30
+
31
+ if (_pseudo_selector_name_set.pseudoSelectorNameSet.has(id)) {
32
+ promises.push(Promise.resolve([{
33
+ endIndex,
34
+ id: `selectors.${id}`,
35
+ index,
36
+ name: `"${selector}" ${pseudoType}`,
37
+ node: parent
38
+ }]));
39
+ } else if (vendorPrefix != null) {
40
+ const selector = node.value.replace(vendorPrefix, '');
41
+ const id = selector.replace(/^::?/, '');
42
+
43
+ if (_pseudo_selector_name_set.pseudoSelectorNameSet.has(id)) {
44
+ promises.push(Promise.resolve([{
45
+ endIndex,
46
+ id: `selectors.${id}`,
47
+ index,
48
+ name: `"${selector}" ${pseudoType}`,
49
+ node: parent,
50
+ prefix: vendorPrefix
51
+ }]));
52
+ }
53
+ }
54
+
55
+ switch (id) {
56
+ case 'active':
57
+ {
58
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../active/non_a_elements/collect_features"))).then(({
59
+ collectFeatures
60
+ }) => {
61
+ return collectFeatures({
62
+ node,
63
+ parent
64
+ });
65
+ }));
66
+ break;
67
+ }
68
+
69
+ case 'after':
70
+ {
71
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../after/animation_and_transition_support/collect_features"))).then(({
72
+ collectFeatures
73
+ }) => {
74
+ return collectFeatures({
75
+ node,
76
+ parent
77
+ });
78
+ }));
79
+ break;
80
+ }
81
+
82
+ case 'backdrop':
83
+ {
84
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../backdrop/dialog/collect_features"))).then(({
85
+ collectFeatures
86
+ }) => {
87
+ return collectFeatures({
88
+ node,
89
+ parent
90
+ });
91
+ }));
92
+ break;
93
+ }
94
+
95
+ case 'before':
96
+ {
97
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../before/animation_and_transition_support/collect_features"))).then(({
98
+ collectFeatures
99
+ }) => {
100
+ return collectFeatures({
101
+ node,
102
+ parent
103
+ });
104
+ }));
105
+ break;
106
+ }
107
+
108
+ case 'cue':
109
+ {
110
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../cue/selector_argument/collect_features"))).then(({
111
+ collectFeatures
112
+ }) => {
113
+ return collectFeatures({
114
+ node,
115
+ parent
116
+ });
117
+ }));
118
+ break;
119
+ }
120
+
121
+ case 'host':
122
+ {
123
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../hostfunction/collect_features"))).then(({
124
+ collectFeatures
125
+ }) => {
126
+ return collectFeatures({
127
+ node,
128
+ parent
129
+ });
130
+ }));
131
+ break;
132
+ }
133
+
134
+ case 'hover':
135
+ {
136
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../hover/collect_features"))).then(({
137
+ collectFeatures
138
+ }) => {
139
+ return collectFeatures({
140
+ node,
141
+ parent
142
+ });
143
+ }));
144
+ break;
145
+ }
146
+
147
+ case 'invalid':
148
+ {
149
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../invalid/collect_features"))).then(({
150
+ collectFeatures
151
+ }) => {
152
+ return collectFeatures({
153
+ node,
154
+ parent
155
+ });
156
+ }));
157
+ break;
158
+ }
159
+
160
+ case 'marker':
161
+ {
162
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../marker/animation_and_transition_support/collect_features"))).then(({
163
+ collectFeatures
164
+ }) => {
165
+ return collectFeatures({
166
+ node,
167
+ parent
168
+ });
169
+ }));
170
+ break;
171
+ }
172
+
173
+ case 'not':
174
+ {
175
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../not/selector_list/collect_features"))).then(({
176
+ collectFeatures
177
+ }) => {
178
+ return collectFeatures({
179
+ node,
180
+ parent
181
+ });
182
+ }));
183
+ break;
184
+ }
185
+
186
+ case 'nth-child':
187
+ {
188
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../nth-child/of_syntax/collect_features"))).then(({
189
+ collectFeatures
190
+ }) => {
191
+ return collectFeatures({
192
+ node,
193
+ parent
194
+ });
195
+ }));
196
+ break;
197
+ }
198
+
199
+ case 'nth-last-child':
200
+ {
201
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../nth-last-child/of_syntax/collect_features"))).then(({
202
+ collectFeatures
203
+ }) => {
204
+ return collectFeatures({
205
+ node,
206
+ parent
207
+ });
208
+ }));
209
+ break;
210
+ }
211
+
212
+ case 'valid':
213
+ {
214
+ promises.push(Promise.resolve().then(() => _interopRequireWildcard(require("../valid/collect_features"))).then(({
215
+ collectFeatures
216
+ }) => {
217
+ return collectFeatures({
218
+ node,
219
+ parent
220
+ });
221
+ }));
222
+ break;
223
+ }
224
+ }
225
+
226
+ const features = (await Promise.all(promises)).flat();
227
+ return features;
228
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pseudoSelectorNameSet = void 0;
7
+
8
+ var _browserCompatData = _interopRequireDefault(require("@mdn/browser-compat-data"));
9
+
10
+ var _dotProp = _interopRequireDefault(require("dot-prop"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const IGNORE_KEYS = new Set(['adjacent_sibling', 'attribute', 'child', 'class', 'column', 'descendant', 'general_sibling', 'id', 'list', 'namespace', 'type', 'universal', // for @page at-rule
15
+ 'first', // same as :host
16
+ 'hostfunction']);
17
+ const pseudoSelectorNameSet = new Set(Array.from(Object.keys(_dotProp.default.get(_browserCompatData.default.css, 'selectors') ?? {})).filter(k => !IGNORE_KEYS.has(k)));
18
+ exports.pseudoSelectorNameSet = pseudoSelectorNameSet;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ const features = [];
13
+
14
+ if (node.namespace === '*') {
15
+ const namespaceLength = `${node.namespace}|`.length;
16
+ const index = node.sourceIndex - namespaceLength;
17
+ const endIndex = index + namespaceLength;
18
+ features.push({
19
+ endIndex,
20
+ id: `selectors.universal.namespaces`,
21
+ index,
22
+ name: `Universal namespace selector`,
23
+ node: parent
24
+ });
25
+ } else if (node.namespace != null) {
26
+ const namespaceLength = `${node.namespace}|`.length;
27
+ const index = node.sourceIndex - namespaceLength;
28
+ const endIndex = index + namespaceLength;
29
+ features.push({
30
+ endIndex,
31
+ id: `selectors.type.namespaces`,
32
+ index,
33
+ name: `Namespace selector`,
34
+ node: parent
35
+ });
36
+ }
37
+
38
+ const index = node.sourceIndex;
39
+ const endIndex = index + node.value.length;
40
+ features.push({
41
+ endIndex,
42
+ id: `selectors.type`,
43
+ index,
44
+ name: `Type selector`,
45
+ node: parent
46
+ });
47
+ return features;
48
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ const features = [];
13
+
14
+ if (node.namespace === '*') {
15
+ const namespaceLength = `${node.namespace}|`.length;
16
+ const index = node.sourceIndex - namespaceLength;
17
+ const endIndex = index + namespaceLength;
18
+ features.push({
19
+ endIndex,
20
+ id: `selectors.universal.namespaces`,
21
+ index,
22
+ name: `Universal namespace selector`,
23
+ node: parent
24
+ });
25
+ }
26
+
27
+ const index = node.sourceIndex;
28
+ const endIndex = index + node.value.length;
29
+ features.push({
30
+ endIndex,
31
+ id: `selectors.universal`,
32
+ index,
33
+ name: `Universal selector`,
34
+ node: parent
35
+ });
36
+ return features;
37
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectFeatures = collectFeatures;
7
+
8
+ async function collectFeatures({
9
+ node,
10
+ parent
11
+ }) {
12
+ if (node.value !== ':active') {
13
+ return [];
14
+ }
15
+
16
+ const features = [];
17
+ let current = node;
18
+
19
+ while (current = current.prev()) {
20
+ if (['id', 'class', 'attribute', 'tag', 'pseudo'].includes(current.type) !== true) {
21
+ break;
22
+ }
23
+
24
+ if (current.type === 'tag' && current.value !== 'a') {
25
+ const index = node.sourceIndex;
26
+ const endIndex = index + node.value.length;
27
+ features.push({
28
+ endIndex,
29
+ id: `selectors.active.non_a_elements`,
30
+ index,
31
+ name: `":active" pseudo-class with the non-anchor tag`,
32
+ node: parent
33
+ });
34
+ }
35
+ }
36
+
37
+ return features;
38
+ }