@miaskiewicz/turbo-dom 0.1.43 → 0.1.45
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miaskiewicz/turbo-dom",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"description": "Faster, more spec-correct DOM for test runners — native html5ever (Rust/WASM) parser + lazy copy-on-write DOM. A drop-in-style alternative to jsdom/happy-dom for vitest & jest.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
"prepublishOnly": "napi build --platform --release",
|
|
71
71
|
"test:vitest": "vitest run -c test-vitest/vitest.config.mjs",
|
|
72
72
|
"test:jest": "jest -c test-jest/jest.config.cjs",
|
|
73
|
-
"bench:query": "node bench/query.mjs"
|
|
73
|
+
"bench:query": "node bench/query.mjs",
|
|
74
|
+
"bench:scorecard": "node bench/scorecard.mjs"
|
|
74
75
|
},
|
|
75
76
|
"keywords": [
|
|
76
77
|
"dom",
|
package/src/runtime/dom.mjs
CHANGED
|
@@ -98,9 +98,10 @@ export class Node extends EventTarget {
|
|
|
98
98
|
if (this.__idx >= 0 && doc && doc.__buf) {
|
|
99
99
|
const buf = doc.__buf;
|
|
100
100
|
for (let c = buf.firstChild(this.__idx); c !== -1; c = buf.nextSib(c)) {
|
|
101
|
+
const nt = buf.nodeType(c); // read once, pass to __nodeAt (was re-read in its switch)
|
|
101
102
|
// template content fragment is not a child — it's `.content`
|
|
102
|
-
if (
|
|
103
|
-
const child = doc.__nodeAt(c);
|
|
103
|
+
if (nt === DOCUMENT_FRAGMENT_NODE && buf.tagName(c) === 'content') continue;
|
|
104
|
+
const child = doc.__nodeAt(c, nt);
|
|
104
105
|
child.parentNode = this;
|
|
105
106
|
kids.push(child);
|
|
106
107
|
}
|
|
@@ -1402,13 +1403,16 @@ export class Document extends Node {
|
|
|
1402
1403
|
}
|
|
1403
1404
|
|
|
1404
1405
|
// nodeAt: one handle per buffer index, memoized → preserves === identity.
|
|
1405
|
-
|
|
1406
|
+
// `nt` (nodeType) may be passed by callers that already read it (__children),
|
|
1407
|
+
// avoiding a second buffer read; other callers leave it undefined.
|
|
1408
|
+
__nodeAt(idx, nt) {
|
|
1406
1409
|
if (idx < 0) return null;
|
|
1407
1410
|
const cached = this.__cache[idx];
|
|
1408
1411
|
if (cached !== undefined) return cached;
|
|
1409
1412
|
const buf = this.__buf;
|
|
1410
1413
|
let node;
|
|
1411
|
-
|
|
1414
|
+
if (nt === undefined) nt = buf.nodeType(idx);
|
|
1415
|
+
switch (nt) {
|
|
1412
1416
|
case ELEMENT_NODE: {
|
|
1413
1417
|
const tag = buf.tagName(idx); // read once (was read twice — ctor + template check)
|
|
1414
1418
|
node = new Element(this, tag, buf.ns(idx));
|
package/src/runtime/window.mjs
CHANGED
|
@@ -85,6 +85,7 @@ const hostClearTimeout = globalThis.clearTimeout;
|
|
|
85
85
|
// self-replaces onto the per-env base, so each env gets its own instance; only
|
|
86
86
|
// the factory objects/closures are shared, saving ~28 allocations per test file.
|
|
87
87
|
const SHARED_LAZY = {
|
|
88
|
+
customElements: () => makeCustomElements(), // fresh registry per env, built on first access
|
|
88
89
|
localStorage: () => new Storage(),
|
|
89
90
|
sessionStorage: () => new Storage(),
|
|
90
91
|
matchMedia: () => makeMatchMedia(),
|
|
@@ -133,7 +134,8 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
|
|
|
133
134
|
name: '',
|
|
134
135
|
closed: false,
|
|
135
136
|
origin: new URL(url).origin,
|
|
136
|
-
customElements
|
|
137
|
+
// customElements is lazy (SHARED_LAZY) — env-independent + rarely used; building
|
|
138
|
+
// its two Maps eagerly per createWindow was wasted for the typical test.
|
|
137
139
|
Image: function Image(w, h) { const img = document.createElement('img'); if (w != null) img.setAttribute('width', w); if (h != null) img.setAttribute('height', h); return img; },
|
|
138
140
|
Audio: function Audio(src) { const a = document.createElement('audio'); if (src) a.setAttribute('src', src); return a; },
|
|
139
141
|
getSelection: () => document.getSelection(),
|
|
Binary file
|