• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

david-luna / csset / 19246794314

10 Nov 2025 09:32PM UTC coverage: 95.408%. Remained the same
19246794314

push

github

david-luna
Merge branch 'main' of github.com:david-luna/csset

386 of 409 branches covered (94.38%)

Branch coverage included in aggregate %.

176 of 176 new or added lines in 8 files covered. (100.0%)

35 existing lines in 3 files now uncovered.

1754 of 1834 relevant lines covered (95.64%)

128.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/lib/parser/parse.js
1
// MIT License
2✔
2

2✔
3
// Copyright (c) 2020 Lea Verou
2✔
4

2✔
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
2✔
6
// of this software and associated documentation files (the "Software"), to deal
2✔
7
// in the Software without restriction, including without limitation the rights
2✔
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2✔
9
// copies of the Software, and to permit persons to whom the Software is
2✔
10
// furnished to do so, subject to the following conditions:
2✔
11

2✔
12
// The above copyright notice and this permission notice shall be included in all
2✔
13
// copies or substantial portions of the Software.
2✔
14

2✔
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2✔
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2✔
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2✔
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2✔
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2✔
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2✔
21
// SOFTWARE.
2✔
22

2✔
23
import { nestTokens } from './nestTokens.js';
2✔
24
import { tokenize } from './tokenize.js';
2✔
25
import { RECURSIVE_PSEUDO_CLASSES, RECURSIVE_PSEUDO_CLASSES_ARGS } from './tokens.js';
2✔
26
import { walk } from './walk.js';
2✔
27

2✔
28
/**
2✔
29
 * @typedef {Object} ParseOptions
2✔
30
 * @property {boolean} recursive Whether to parse the arguments of pseudo-classes like :is(), :has() etc. Defaults to true.
2✔
31
 * @property {boolean} list Whether this can be a selector list (A, B, C etc). Defaults to true.
2✔
32
 */
2✔
33

2✔
34
/** @type {ParseOptions} */
2✔
35
const DEFAULT_PARSE_OPTIONS = {
2✔
36
  recursive: true,
2✔
37
  list: true,
2✔
38
};
2✔
39

2✔
40
/**
2✔
41
 * Parse a CSS selector
2✔
42
 * @param {string} selector The selector to parse
2✔
43
 * @param {Partial<ParseOptions>} options The parse options. Default is {recursive: true, list: true}
2✔
44
 * @returns {AST | null}
2✔
45
 */
2✔
46
export function parse(selector, options = {}) {
2✔
47
  const { recursive, list } = Object.assign({}, DEFAULT_PARSE_OPTIONS, options);
6✔
48
  const tokens = tokenize(selector);
6✔
49

6✔
50
  if (!tokens) {
6!
UNCOV
51
    return null;
×
UNCOV
52
  }
×
53
  // eslint-disable-next-line prettier/prettier
6✔
54
  const ast = nestTokens(/** @type {Array<Token>}*/(tokens), { list });
6✔
55

6✔
56
  if (recursive) {
6✔
57
    walk(ast, (node) => {
6✔
58
      if (node.type === 'pseudo-class' && node.argument) {
32✔
59
        if (RECURSIVE_PSEUDO_CLASSES.has(node.name)) {
6✔
60
          let argument = node.argument;
4✔
61
          const childArg = RECURSIVE_PSEUDO_CLASSES_ARGS[node.name];
4✔
62
          if (childArg) {
4!
UNCOV
63
            const match = childArg.exec(argument);
×
UNCOV
64
            if (!match) {
×
UNCOV
65
              return;
×
UNCOV
66
            }
×
UNCOV
67

×
UNCOV
68
            Object.assign(node, match.groups);
×
UNCOV
69
            argument = match.groups ? match.groups.subtree : '';
×
UNCOV
70
          }
×
71
          if (argument) {
4✔
72
            node.subtree = parse(argument, { recursive: true, list: true });
4✔
73
          }
4✔
74
        }
4✔
75
      }
6✔
76
    });
6✔
77
  }
6✔
78

6✔
79
  return ast;
6✔
80
}
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc