From e195b5bd72b5e6193bdf4dd4c7e3514b3c8192de Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 23 Apr 2026 21:28:47 +0000 Subject: [PATCH] =?UTF-8?q?HS:=20element=20=E2=86=92=20HTML=20via=20outerH?= =?UTF-8?q?TML=20(+1=20test)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an `outerHTML` getter to the mock `El` class. Builds `inner` by merging `.id` / `.className` (set as direct properties via host-set!) with the `.attributes` bag, and falling back to `innerText` / `textContent` when there are no children or innerHTML. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/hs-run-filtered.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/hs-run-filtered.js b/tests/hs-run-filtered.js index 8e122561..4b44be5d 100755 --- a/tests/hs-run-filtered.js +++ b/tests/hs-run-filtered.js @@ -99,6 +99,31 @@ class El { if (!('_origDefault' in this)) { this.defaultValue = this.textContent; this._origDefault = true; } } } + get outerHTML() { + const tag = this.tagName.toLowerCase(); + // Merge .id / .className (set directly) into attribute output. + const attrOrder = []; + const attrMap = {}; + if (this.id) { attrMap['id'] = this.id; attrOrder.push('id'); } + if (this.className) { attrMap['class'] = this.className; attrOrder.push('class'); } + for (const k of Object.keys(this.attributes)) { + if (!(k in attrMap)) { attrMap[k] = this.attributes[k]; attrOrder.push(k); } + else attrMap[k] = this.attributes[k]; // prefer explicit attr value when set + } + const attrs = attrOrder.map(k => ` ${k}="${String(attrMap[k]).replace(/"/g, '"')}"`).join(''); + if (VOID_TAGS.has(tag)) return `<${tag}${attrs}>`; + let inner = ''; + if (this.children && this.children.length) { + inner = this.children.map(c => c.outerHTML || c.textContent || '').join(''); + } else if (this.innerHTML) { + inner = this.innerHTML; + } else if (this.innerText !== undefined && this.innerText !== '') { + inner = this.innerText; + } else if (this.textContent) { + inner = this.textContent; + } + return `<${tag}${attrs}>${inner}`; + } get firstElementChild() { return this.children[0]||null; } get lastElementChild() { return this.children[this.children.length-1]||null; } get nextElementSibling() { if(!this.parentElement)return null; const i=this.parentElement.children.indexOf(this); return this.parentElement.children[i+1]||null; }