@asamuzakjp/dom-selector 7.0.3 → 7.0.5

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/package.json CHANGED
@@ -32,24 +32,25 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/css-tree": "^2.3.11",
35
+ "@types/node": "^25.5.2",
35
36
  "benchmark": "^2.1.4",
36
37
  "c8": "^11.0.0",
37
38
  "chai": "^6.2.2",
38
39
  "commander": "^14.0.3",
39
40
  "eslint": "^9.39.4",
40
41
  "eslint-config-prettier": "^10.1.8",
41
- "eslint-plugin-jsdoc": "^62.8.0",
42
+ "eslint-plugin-jsdoc": "^62.9.0",
42
43
  "eslint-plugin-prettier": "^5.5.5",
43
44
  "eslint-plugin-regexp": "^3.1.0",
44
- "eslint-plugin-unicorn": "^63.0.0",
45
+ "eslint-plugin-unicorn": "^64.0.0",
45
46
  "globals": "^17.4.0",
46
- "jsdom": "^28.1.0",
47
+ "jsdom": "^29.0.1",
47
48
  "mocha": "^11.7.5",
48
49
  "neostandard": "^0.13.0",
49
50
  "prettier": "^3.8.1",
50
- "sinon": "^21.0.2",
51
- "typescript": "^5.9.3",
52
- "wpt-runner": "^6.1.0"
51
+ "sinon": "^21.0.3",
52
+ "typescript": "^6.0.2",
53
+ "wpt-runner": "^7.0.0"
53
54
  },
54
55
  "overrides": {
55
56
  "c8": {
@@ -71,5 +72,5 @@
71
72
  "engines": {
72
73
  "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
73
74
  },
74
- "version": "7.0.3"
75
+ "version": "7.0.5"
75
76
  }
package/src/js/finder.js CHANGED
@@ -368,6 +368,7 @@ export class Finder {
368
368
  ast = item.ast;
369
369
  this.#descendant = item.descendant;
370
370
  this.#invalidate = item.invalidate;
371
+ this.#selectorAST = item.selectorAST;
371
372
  }
372
373
  }
373
374
  if (ast) {
@@ -403,7 +404,8 @@ export class Finder {
403
404
  cachedItem.set(`${selector}`, {
404
405
  ast,
405
406
  descendant: this.#descendant,
406
- invalidate: this.#invalidate
407
+ invalidate: this.#invalidate,
408
+ selectorAST: this.#selectorAST
407
409
  });
408
410
  this.#documentCache.set(this.#document, cachedItem);
409
411
  // Initialize nodes array for each branch.
package/src/js/matcher.js CHANGED
@@ -526,15 +526,17 @@ export const matchTypeSelector = (ast, node, opt = {}) => {
526
526
  astName,
527
527
  node
528
528
  );
529
+ const isHTML =
530
+ node.ownerDocument.contentType === 'text/html' &&
531
+ (!namespaceURI || namespaceURI === 'http://www.w3.org/1999/xhtml');
532
+ if (isHTML && localName === astLocalName && !astName.includes('|')) {
533
+ return true;
534
+ }
529
535
  const firstChar = localName.charCodeAt(0);
530
536
  const isAlphabet =
531
537
  (firstChar >= 65 && firstChar <= 90) ||
532
538
  (firstChar >= 97 && firstChar <= 122);
533
- if (
534
- node.ownerDocument.contentType === 'text/html' &&
535
- (!namespaceURI || namespaceURI === 'http://www.w3.org/1999/xhtml') &&
536
- isAlphabet
537
- ) {
539
+ if (isHTML && isAlphabet) {
538
540
  astPrefix = astPrefix.toLowerCase();
539
541
  astLocalName = astLocalName.toLowerCase();
540
542
  }
package/src/js/utility.js CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  RULE,
33
33
  SCOPE,
34
34
  SELECTOR_LIST,
35
+ TAG_TYPE,
35
36
  TARGET_ALL,
36
37
  TARGET_FIRST,
37
38
  TEXT_NODE,
@@ -58,7 +59,8 @@ const KEYS_NODE_FOCUSABLE_SVG = new Set([
58
59
  'symbol',
59
60
  'title'
60
61
  ]);
61
- const REG_ATTR_SIMPLE = /^\[[A-Z\d-]{1,255}="?[A-Z\d\s-]{1,255}"?\]$/i;
62
+ const REG_ATTR_SIMPLE = /^\[[A-Z\d-]{1,255}(?:="?[A-Z\d\s-]{1,255}"?)?\]$/i;
63
+ const REG_TAG_SIMPLE = new RegExp(`^(?:${TAG_TYPE})$`);
62
64
  const REG_EXCLUDE_BASIC =
63
65
  /[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/;
64
66
  const REG_COMPLEX = new RegExp(`${COMPOUND_I}${COMBO}${COMPOUND_I}`, 'i');
@@ -1067,6 +1069,12 @@ export const filterSelector = (selector, target) => {
1067
1069
  }
1068
1070
  return false;
1069
1071
  }
1072
+
1073
+ // Exclude simple tag selector for TARGET_ALL
1074
+ if (target === TARGET_ALL && REG_TAG_SIMPLE.test(selector)) {
1075
+ return false;
1076
+ }
1077
+
1070
1078
  // Exclude various complex or unsupported selectors.
1071
1079
  // - selectors containing '/'
1072
1080
  // - namespaced selectors
@@ -1,12 +1,12 @@
1
1
  export class Finder {
2
2
  constructor(window: object);
3
3
  onError: (e: Error, opt?: {
4
- noexcept?: boolean;
4
+ noexcept?: boolean | undefined;
5
5
  }) => void;
6
6
  setup: (selector: string, node: object, opt?: {
7
- check?: boolean;
8
- noexcept?: boolean;
9
- warn?: boolean;
7
+ check?: boolean | undefined;
8
+ noexcept?: boolean | undefined;
9
+ warn?: boolean | undefined;
10
10
  }) => object;
11
11
  clearResults: (all?: boolean) => void;
12
12
  private _handleFocusEvent;
@@ -1,16 +1,16 @@
1
1
  export function matchPseudoElementSelector(astName: string, astType: string, opt?: {
2
- forgive?: boolean;
3
- warn?: boolean;
2
+ forgive?: boolean | undefined;
3
+ warn?: boolean | undefined;
4
4
  }): void;
5
5
  export function matchDirectionPseudoClass(ast: object, node: object): boolean;
6
6
  export function matchLanguagePseudoClass(ast: object, node: object): boolean;
7
7
  export function matchDisabledPseudoClass(astName: string, node: object): boolean;
8
8
  export function matchReadOnlyPseudoClass(astName: string, node: object): boolean;
9
9
  export function matchAttributeSelector(ast: object, node: object, opt?: {
10
- check?: boolean;
11
- forgive?: boolean;
10
+ check?: boolean | undefined;
11
+ forgive?: boolean | undefined;
12
12
  }): boolean;
13
13
  export function matchTypeSelector(ast: object, node: object, opt?: {
14
- check?: boolean;
15
- forgive?: boolean;
14
+ check?: boolean | undefined;
15
+ forgive?: boolean | undefined;
16
16
  }): boolean;
@@ -6,7 +6,7 @@ export function findLogicalWithNestedHas(leaf: object): object | null;
6
6
  export function filterNodesByAnB(nodes: Array<object>, anb: {
7
7
  a: number;
8
8
  b: number;
9
- reverse?: boolean;
9
+ reverse?: boolean | undefined;
10
10
  }): Array<object>;
11
11
  export function resolveContent(node: object): Array<object | boolean>;
12
12
  export function traverseNode(node: object, walker: object, force?: boolean): object | null;