@asamuzakjp/dom-selector 4.4.2 → 4.4.4

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.
package/src/js/parser.js CHANGED
@@ -8,11 +8,12 @@ import { findAll, parse, toPlainObject, walk } from 'css-tree';
8
8
  /* constants */
9
9
  import {
10
10
  BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN,
11
- COMBINATOR, DUO, EMPTY, HEX, REG_CHILD_INDEXED, REG_LOGICAL_COMPLEX_A,
12
- REG_LOGICAL_COMPLEX_B, REG_LOGICAL_COMPOUND, REG_LOGICAL_KEY,
13
- REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR, SELECTOR_ATTR,
14
- SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT,
15
- SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO, U_FFFD
11
+ DUO, EMPTY, HEX, REG_CHILD_INDEXED, REG_HEX, REG_INVALID_SELECTOR,
12
+ REG_LANG_QUOTED, REG_LOGICAL_COMPLEX_A, REG_LOGICAL_COMPLEX_B,
13
+ REG_LOGICAL_COMPOUND, REG_LOGICAL_EMPTY, REG_LOGICAL_KEY, REG_LOGICAL_PSEUDO,
14
+ REG_SHADOW_PSEUDO, SELECTOR, SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID,
15
+ SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SYNTAX_ERR,
16
+ TYPE_FROM, TYPE_TO, U_FFFD
16
17
  } from './constant.js';
17
18
 
18
19
  /**
@@ -29,7 +30,7 @@ export const unescapeSelector = (selector = '') => {
29
30
  if (item === '' && i === l - 1) {
30
31
  item = U_FFFD;
31
32
  } else {
32
- const hexExists = /^([\da-f]{1,6}\s?)/i.exec(item);
33
+ const hexExists = REG_HEX.exec(item);
33
34
  if (hexExists) {
34
35
  const [, hex] = hexExists;
35
36
  let str;
@@ -127,7 +128,7 @@ export const preprocess = (...args) => {
127
128
  export const parseSelector = selector => {
128
129
  selector = preprocess(selector);
129
130
  // invalid selectors
130
- if (/^$|^\s*>|,\s*$/.test(selector)) {
131
+ if (REG_INVALID_SELECTOR.test(selector)) {
131
132
  throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);
132
133
  }
133
134
  let res;
@@ -139,11 +140,10 @@ export const parseSelector = selector => {
139
140
  res = toPlainObject(ast);
140
141
  } catch (e) {
141
142
  const { message } = e;
142
- const regEmptyIs = /(:(is|where)\(\s*\))/;
143
143
  // workaround for https://github.com/csstree/csstree/issues/265
144
- const regLang = /(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;
145
- if (message === 'Identifier is expected' && regLang.test(selector)) {
146
- const [, lang, range] = regLang.exec(selector);
144
+ if (message === 'Identifier is expected' &&
145
+ REG_LANG_QUOTED.test(selector)) {
146
+ const [, lang, range] = REG_LANG_QUOTED.exec(selector);
147
147
  const escapedRange =
148
148
  range.replaceAll('*', '\\*').replace(/^"/, '').replace(/"$/, '');
149
149
  let escapedLang = lang.replace(range, escapedRange);
@@ -151,19 +151,17 @@ export const parseSelector = selector => {
151
151
  escapedLang = `:lang(${EMPTY})`;
152
152
  }
153
153
  res = parseSelector(selector.replace(lang, escapedLang));
154
- } else if ((message === 'Identifier is expected' ||
155
- message === 'Selector is expected') &&
156
- regEmptyIs.test(selector)) {
157
- const [, logic, name] = regEmptyIs.exec(selector);
158
- const emptyIs = `:${name}(${EMPTY})`;
159
- res = parseSelector(selector.replace(logic, emptyIs));
154
+ } else if (/^(?:Identifier|Selector) is expected$/.test(message) &&
155
+ REG_LOGICAL_EMPTY.test(selector)) {
156
+ const [, sel, name] = REG_LOGICAL_EMPTY.exec(selector);
157
+ res = parseSelector(selector.replace(sel, `:${name}(${EMPTY})`));
160
158
  } else if (/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(message) &&
161
159
  !selector.endsWith(']')) {
162
160
  const index = selector.lastIndexOf('[');
163
161
  const sel = selector.substring(index);
164
162
  if (sel.includes('"')) {
165
- const count = sel.match(/"/g).length;
166
- if (count % 2) {
163
+ const quotes = sel.match(/"/g).length;
164
+ if (quotes % 2) {
167
165
  res = parseSelector(`${selector}"]`);
168
166
  } else {
169
167
  res = parseSelector(`${selector}]`);
@@ -183,13 +181,11 @@ export const parseSelector = selector => {
183
181
  /**
184
182
  * walk AST
185
183
  * @param {object} ast - AST
186
- * @param {boolean} check - check selector within logical combinators
187
- * @returns {object} - branches and complex
184
+ * @returns {Array.<object|undefined>} - collection of AST branches
188
185
  */
189
- export const walkAST = (ast = {}, check = false) => {
186
+ export const walkAST = (ast = {}) => {
190
187
  const branches = new Set();
191
188
  let hasPseudoFunc;
192
- let hasComplexSelector;
193
189
  const opt = {
194
190
  enter: node => {
195
191
  if (node.type === SELECTOR) {
@@ -220,17 +216,6 @@ export const walkAST = (ast = {}, check = false) => {
220
216
  // Selector
221
217
  for (const { children: greatGrandChildren } of grandChildren) {
222
218
  if (branches.has(greatGrandChildren)) {
223
- if (check) {
224
- for (const greatGrandChild of greatGrandChildren) {
225
- const { type: greatGrandChildType } = greatGrandChild;
226
- if (greatGrandChildType === COMBINATOR) {
227
- hasComplexSelector = true;
228
- break;
229
- }
230
- }
231
- } else {
232
- hasComplexSelector = false;
233
- }
234
219
  branches.delete(greatGrandChildren);
235
220
  }
236
221
  }
@@ -256,10 +241,7 @@ export const walkAST = (ast = {}, check = false) => {
256
241
  }
257
242
  });
258
243
  }
259
- return {
260
- branches: [...branches],
261
- complex: hasComplexSelector
262
- };
244
+ return [...branches];
263
245
  };
264
246
 
265
247
  /**
@@ -331,6 +313,14 @@ export const filterSelector = (selector, opt = {}) => {
331
313
  if (!selector || typeof selector !== 'string') {
332
314
  return false;
333
315
  }
316
+ // filter missing close square bracket
317
+ if (selector.includes('[')) {
318
+ const index = selector.lastIndexOf('[');
319
+ const sel = selector.substring(index);
320
+ if (sel.lastIndexOf(']') < 0) {
321
+ return false;
322
+ }
323
+ }
334
324
  // filter namespaced selectors, e.g. ns|E, pseudo-element selectors and
335
325
  // attribute selectors with case flag, e.g. [attr i], and unclosed quotes
336
326
  if (/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(selector)) {
@@ -340,6 +330,10 @@ export const filterSelector = (selector, opt = {}) => {
340
330
  if (selector.includes(':')) {
341
331
  let reg;
342
332
  if (REG_LOGICAL_KEY.test(selector)) {
333
+ // filter empty :is() and :where()
334
+ if (REG_LOGICAL_EMPTY.test(selector)) {
335
+ return false;
336
+ }
343
337
  const { complex, descendant } = opt;
344
338
  if (complex && descendant) {
345
339
  reg = REG_LOGICAL_COMPLEX_A;
@@ -41,41 +41,49 @@ export const SHOW_DOCUMENT_FRAGMENT: 1024;
41
41
  export const SHOW_ELEMENT: 1;
42
42
  export const WALKER_FILTER: 1281;
43
43
  export const ALPHA_NUM: "[A-Z\\d]+";
44
+ export const DIGIT: "(?:0|[1-9]\\d*)";
44
45
  export const LANG_PART: "(?:-[A-Z\\d]+)*";
45
46
  export const N_ST: "(?:first|last|only)-(?:child|of-type)";
46
- export const DIGIT: "(?:0|[1-9]\\d*)";
47
47
  export const ANB: "[+-]?(?:(?:0|[1-9]\\d*)n?|n)|(?:[+-]?(?:0|[1-9]\\d*))?n\\s*[+-]\\s*(?:0|[1-9]\\d*)";
48
48
  export const N_TH: "nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\\d*)n?|n)|(?:[+-]?(?:0|[1-9]\\d*))?n\\s*[+-]\\s*(?:0|[1-9]\\d*))\\s*\\)";
49
- export const LOGICAL_KEY: "(?:is|not|where)";
50
49
  export const SUB_TYPE: "\\[[^\\]]+\\]|[#.:][\\w-]+";
51
50
  export const TAG_TYPE: "\\*|[A-Za-z][\\w-]*";
52
- export const COMPOUND_A: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)";
53
- export const NESTED_LOGICAL_A: ":(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\)";
54
- export const COMPOUND_B: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+)";
55
- export const LOGICAL_COMPOUND: "(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+))*\\s*\\)";
51
+ export const TAG_TYPE_I: "\\*|[A-Z][\\w-]*";
52
+ export const LOGICAL_KEY: "(?:is|not|where)";
53
+ export const COMPOUND: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)";
56
54
  export const COMBO_A: "\\s?[\\s>~+]\\s?";
57
- export const COMPLEX_A: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*";
58
- export const NESTED_LOGICAL_B: ":(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*)*\\s*\\)";
59
- export const COMPOUND_C: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|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w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*)*\\s*\\))+))*)*\\s*\\)";
62
55
  export const COMBO_B: "\\s?[~+]\\s?";
56
+ export const COMPLEX_A: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*";
63
57
  export const COMPLEX_B: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*";
58
+ export const NESTED_LOGICAL_A: ":(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\)";
59
+ export const NESTED_LOGICAL_B: ":(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*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*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*)*\\s*\\))+)";
61
+ export const COMPOUND_A: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+)";
62
+ export const COMPOUND_B: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*)*\\s*\\))+)";
63
+ export const COMPOUND_C: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+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za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+))*\\s*\\)";
68
70
  export const REG_ANCHOR: RegExp;
69
71
  export const REG_CHILD_INDEXED: RegExp;
72
+ export const REG_COMPLEX_A: RegExp;
73
+ export const REG_COMPLEX_B: RegExp;
70
74
  export const REG_DIR: RegExp;
71
75
  export const REG_FORM: RegExp;
72
76
  export const REG_FORM_CTRL: RegExp;
73
77
  export const REG_FORM_VALID: RegExp;
78
+ export const REG_HEX: RegExp;
74
79
  export const REG_INTERACT: RegExp;
80
+ export const REG_INVALID_SELECTOR: RegExp;
75
81
  export const REG_LANG: RegExp;
82
+ export const REG_LANG_QUOTED: RegExp;
76
83
  export const REG_LOGICAL_COMPLEX_A: RegExp;
77
84
  export const REG_LOGICAL_COMPLEX_B: RegExp;
78
85
  export const REG_LOGICAL_COMPOUND: RegExp;
86
+ export const REG_LOGICAL_EMPTY: RegExp;
79
87
  export const REG_LOGICAL_KEY: RegExp;
80
88
  export const REG_LOGICAL_PSEUDO: RegExp;
81
89
  export const REG_SHADOW_HOST: RegExp;
@@ -1,7 +1,8 @@
1
1
  export class Finder {
2
- constructor(window: object);
2
+ constructor(window: object, document: object);
3
3
  private _onError;
4
4
  private _setup;
5
+ private _initNwsapi;
5
6
  private _setEvent;
6
7
  private _correspond;
7
8
  private _createTreeWalker;
@@ -1,7 +1,7 @@
1
1
  export function unescapeSelector(selector?: string): string | null;
2
2
  export function preprocess(...args: any[]): string;
3
3
  export function parseSelector(selector: string): object;
4
- export function walkAST(ast?: object, check?: boolean): object;
4
+ export function walkAST(ast?: object): Array<object | undefined>;
5
5
  export function sortAST(asts: Array<object>): Array<object>;
6
6
  export function parseAstName(selector: string): object;
7
7
  export function filterSelector(selector: string, opt?: object): boolean;