@miaskiewicz/turbo-dom 0.1.37 → 0.1.39

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.37",
3
+ "version": "0.1.39",
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",
@@ -240,8 +240,13 @@ export class Node extends EventTarget {
240
240
  }
241
241
 
242
242
  get textContent() {
243
+ const kids = this.__children();
244
+ // hot leaf case (RTL getByText reads textContent on every element): a single
245
+ // text child → return its data directly, skipping the iterator + concat.
246
+ if (kids.length === 1 && kids[0].nodeType === TEXT_NODE) return kids[0].data;
243
247
  let s = '';
244
- for (const c of this.__children()) {
248
+ for (let i = 0; i < kids.length; i++) {
249
+ const c = kids[i];
245
250
  if (c.nodeType === TEXT_NODE) s += c.data;
246
251
  else if (c.nodeType === ELEMENT_NODE || c.nodeType === DOCUMENT_FRAGMENT_NODE) s += c.textContent;
247
252
  }
@@ -25,7 +25,7 @@ export class Event {
25
25
  this.timeStamp = 0;
26
26
  this._stopPropagation = false;
27
27
  this._stopImmediate = false;
28
- this._path = [];
28
+ this._path = null; // set by dispatchEvent; composedPath() reads [] until then
29
29
  this._passiveListener = false;
30
30
  }
31
31
 
@@ -40,7 +40,7 @@ export class Event {
40
40
  get returnValue() { return !this.defaultPrevented; }
41
41
  set returnValue(v) { if (v === false) this.preventDefault(); }
42
42
 
43
- composedPath() { return this._path.slice(); }
43
+ composedPath() { return this._path ? this._path.slice() : []; }
44
44
 
45
45
  // legacy init — react-dom's dev rethrow path uses createEvent('Event')+initEvent
46
46
  initEvent(type, bubbles = false, cancelable = false) {