@miaskiewicz/turbo-dom 0.1.42 → 0.1.44

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.42",
3
+ "version": "0.1.44",
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",
@@ -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 (buf.nodeType(c) === DOCUMENT_FRAGMENT_NODE && buf.tagName(c) === 'content') continue;
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,19 +1403,23 @@ export class Document extends Node {
1402
1403
  }
1403
1404
 
1404
1405
  // nodeAt: one handle per buffer index, memoized → preserves === identity.
1405
- __nodeAt(idx) {
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
- switch (buf.nodeType(idx)) {
1414
+ if (nt === undefined) nt = buf.nodeType(idx);
1415
+ switch (nt) {
1412
1416
  case ELEMENT_NODE: {
1413
- node = new Element(this, buf.tagName(idx), buf.ns(idx));
1417
+ const tag = buf.tagName(idx); // read once (was read twice — ctor + template check)
1418
+ node = new Element(this, tag, buf.ns(idx));
1414
1419
  node.__idx = idx;
1415
1420
  node.__attrIdx = idx; // attrs lazy (constructor left __attrs undefined)
1416
1421
  // template content fragment: a child node typed 11 named "content"
1417
- if (buf.tagName(idx) === 'template') {
1422
+ if (tag === 'template') {
1418
1423
  for (let c = buf.firstChild(idx); c !== -1; c = buf.nextSib(c)) {
1419
1424
  if (buf.nodeType(c) === DOCUMENT_FRAGMENT_NODE && buf.tagName(c) === 'content') {
1420
1425
  node.content = this.__nodeAt(c);