@asamuzakjp/dom-selector 8.1.4 → 8.2.0
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 +7 -7
- package/src/index.js +15 -32
- package/src/js/evaluator.js +2149 -0
- package/src/js/finder.js +477 -2572
- package/src/js/nwsapi.js +1 -1
- package/src/js/selector.js +11 -3
- package/src/js/utility.js +0 -37
- package/types/js/evaluator.d.ts +58 -0
- package/types/js/finder.d.ts +4 -43
- package/types/js/utility.d.ts +0 -5
package/package.json
CHANGED
|
@@ -32,22 +32,22 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/css-tree": "^2.3.11",
|
|
35
|
-
"@types/node": "^26.0.
|
|
35
|
+
"@types/node": "^26.0.1",
|
|
36
36
|
"c8": "^11.0.0",
|
|
37
37
|
"chai": "^6.2.2",
|
|
38
38
|
"commander": "^15.0.0",
|
|
39
39
|
"eslint": "^9.39.4",
|
|
40
40
|
"eslint-config-prettier": "^10.1.8",
|
|
41
|
-
"eslint-plugin-jsdoc": "^63.0.
|
|
41
|
+
"eslint-plugin-jsdoc": "^63.0.10",
|
|
42
42
|
"eslint-plugin-prettier": "^5.5.6",
|
|
43
|
-
"eslint-plugin-regexp": "^3.1.
|
|
43
|
+
"eslint-plugin-regexp": "^3.1.1",
|
|
44
44
|
"eslint-plugin-unicorn": "^65.0.1",
|
|
45
|
-
"globals": "^17.
|
|
45
|
+
"globals": "^17.7.0",
|
|
46
46
|
"jsdom": "^29.1.1",
|
|
47
47
|
"mitata": "^1.0.34",
|
|
48
48
|
"mocha": "^11.7.6",
|
|
49
49
|
"neostandard": "^0.13.0",
|
|
50
|
-
"prettier": "^3.
|
|
50
|
+
"prettier": "^3.9.1",
|
|
51
51
|
"sinon": "^22.0.0",
|
|
52
52
|
"tinybench": "^6.0.2",
|
|
53
53
|
"typescript": "^6.0.3",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"bench:ps-has": "node --expose-gc benchmark/bench-has.js",
|
|
77
77
|
"bench:ps-nth": "node --expose-gc benchmark/bench-nth-child.js && node --expose-gc benchmark/bench-nth-of-type.js",
|
|
78
78
|
"bench:ps-traverse": "node --expose-gc benchmark/bench-dir.js && node --expose-gc benchmark/bench-lang.js",
|
|
79
|
-
"bench:
|
|
79
|
+
"bench:tl": "node --expose-gc benchmark/bench-testing-library.js",
|
|
80
80
|
"bench:universal": "node --expose-gc benchmark/bench-universal.js",
|
|
81
81
|
"build": "npm run tsc && npm run lint && npm test",
|
|
82
82
|
"lint": "eslint --fix .",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"engines": {
|
|
89
89
|
"node": "^22.13.0 || >=24.0.0"
|
|
90
90
|
},
|
|
91
|
-
"version": "8.
|
|
91
|
+
"version": "8.2.0"
|
|
92
92
|
}
|
package/src/index.js
CHANGED
|
@@ -19,11 +19,8 @@ import { collectAllDescendants, getType } from './js/utility.js';
|
|
|
19
19
|
|
|
20
20
|
/* constants */
|
|
21
21
|
import {
|
|
22
|
-
ATTR_TYPE,
|
|
23
|
-
COMBO,
|
|
24
22
|
DOCUMENT_NODE,
|
|
25
23
|
ELEMENT_NODE,
|
|
26
|
-
TAG_TYPE_WO_UNIVERSAL,
|
|
27
24
|
TARGET_ALL,
|
|
28
25
|
TARGET_FIRST,
|
|
29
26
|
TARGET_LINEAL,
|
|
@@ -33,9 +30,6 @@ const CACHE_SIZE = 2048;
|
|
|
33
30
|
|
|
34
31
|
/* regexp */
|
|
35
32
|
const REG_SELECTOR = /[[\]():\\"'`]/;
|
|
36
|
-
const REG_TEST_LIB = new RegExp(
|
|
37
|
-
`^(?:${TAG_TYPE_WO_UNIVERSAL}|[*]?${ATTR_TYPE}(?:\\s*,\\s*${TAG_TYPE_WO_UNIVERSAL}${COMBO}${TAG_TYPE_WO_UNIVERSAL})?)$`
|
|
38
|
-
);
|
|
39
33
|
const REG_UNIVERSAL = /^(?:\*\|)?\*$/;
|
|
40
34
|
|
|
41
35
|
/**
|
|
@@ -351,13 +345,11 @@ export class DOMSelector {
|
|
|
351
345
|
if (REG_UNIVERSAL.test(selector)) {
|
|
352
346
|
return node.firstElementChild;
|
|
353
347
|
}
|
|
348
|
+
// Only enabled when debugging.
|
|
354
349
|
/*
|
|
355
350
|
const document =
|
|
356
351
|
node.nodeType === DOCUMENT_NODE ? node : node.ownerDocument;
|
|
357
|
-
if (
|
|
358
|
-
(node === this.#document || REG_TEST_LIB.test(selector)) &&
|
|
359
|
-
this.#canUseNwsapi(document)
|
|
360
|
-
) {
|
|
352
|
+
if (node === this.#document && this.#canUseNwsapi(document)) {
|
|
361
353
|
const cacheKey = `querySelector_${selector}`;
|
|
362
354
|
let filterMatches = this.#cache.get(cacheKey);
|
|
363
355
|
if (filterMatches === undefined) {
|
|
@@ -404,33 +396,24 @@ export class DOMSelector {
|
|
|
404
396
|
if (document && REG_UNIVERSAL.test(selector)) {
|
|
405
397
|
return collectAllDescendants(node, document);
|
|
406
398
|
}
|
|
399
|
+
// Only enabled when debugging.
|
|
400
|
+
/*
|
|
407
401
|
if (this.#canUseNwsapi(document)) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
isTestLib = REG_TEST_LIB.test(selector);
|
|
414
|
-
this.#cache.set(testCacheKey, isTestLib);
|
|
415
|
-
}
|
|
416
|
-
routeToNwsapi = isTestLib;
|
|
402
|
+
const cacheKey = `querySelectorAll_${selector}`;
|
|
403
|
+
let filterMatches = this.#cache.get(cacheKey);
|
|
404
|
+
if (filterMatches === undefined) {
|
|
405
|
+
filterMatches = filterSelector(selector, TARGET_ALL);
|
|
406
|
+
this.#cache.set(cacheKey, filterMatches);
|
|
417
407
|
}
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this.#cache.set(cacheKey, filterMatches);
|
|
424
|
-
}
|
|
425
|
-
if (filterMatches) {
|
|
426
|
-
try {
|
|
427
|
-
return this.#nwsapi.select(selector, this.#wrapNode(node));
|
|
428
|
-
} catch (e) {
|
|
429
|
-
// fall through
|
|
430
|
-
}
|
|
408
|
+
if (filterMatches) {
|
|
409
|
+
try {
|
|
410
|
+
return this.#nwsapi.select(selector, this.#wrapNode(node));
|
|
411
|
+
} catch (e) {
|
|
412
|
+
// fall through
|
|
431
413
|
}
|
|
432
414
|
}
|
|
433
415
|
}
|
|
416
|
+
*/
|
|
434
417
|
try {
|
|
435
418
|
const nodes = this.#finder
|
|
436
419
|
.setup(selector, this.#wrapNode(node), opt)
|