HS generator+runtime: nth() dispatch+expect, dom-query-all SX-list passthrough, nth-of-type selector

- generate-sx-tests.py: add_action/add_assertion accept .nth(N) in PW-body
  tests so 'find(sel).nth(1).dispatchEvent(...)' lands as a dispatch on
  the Nth matching element, and assertions target that same element.
- shared/static/wasm/sx/dom.sx: dom-query-all hands through an already-SX
  list unchanged — the bridge often pre-converts NodeLists/arrays to SX
  lists, so the host-get 'length' / host-call 'item' loop was returning
  empty. Guards node-list=nil and non-list types too.
- tests/hs-run-filtered.js (mock DOM): fnd() understands
  ':nth-of-type(N)', ':first-of-type', ':last-of-type' by matching the
  stripped base selector and returning the correct-indexed sibling.
  Covers upstream tests that write 'find("div:nth-of-type(2)")' to
  pick the HS-owning element.
- Runtime runtime.sx: hs-sorted-by, hs-fetch format normalizer (JSON/
  Object/etc.), nil-safe hs-joined-by/hs-split-by, emit-fetch chain sets
  the-result when wrapped in let((it …)).

Net: take 0→6, hide 11→12, show 15→16, fetch 11→15,
collectionExpressions 13→15 (remaining are a WASM JIT bug on
{…} literals inside arrays).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-23 16:41:47 +00:00
parent 5b100cac17
commit 3528cef35a
6 changed files with 150 additions and 30 deletions

View File

@@ -195,19 +195,22 @@
"Query DOM and return an SX list (not a host NodeList)."
(let
((node-list (if (nil? sel) (host-call (dom-document) "querySelectorAll" root) (host-call root "querySelectorAll" sel))))
(if
(nil? node-list)
(list)
(let
((n (host-get node-list "length")) (result (list)))
(cond
((nil? node-list) (list))
((list? node-list) node-list)
(true
(let
loop
((i 0))
((n (host-get node-list "length")) (result (list)))
(when
(< i n)
(append! result (host-call node-list "item" i))
(loop (+ i 1))))
result)))))
(not (nil? n))
(let
loop
((i 0))
(when
(< i n)
(append! result (host-call node-list "item" i))
(loop (+ i 1)))))
result))))))
(define
dom-query-by-id
(fn (id) (host-call (dom-document) "getElementById" id)))