HS: wait on event basics (+4 tests)

Five parts: (a) tests/hs-run-filtered.js `io-wait-event` mock now
registers a one-shot listener on the target element and resumes with
the event, instead of immediately resuming with nil. (b) Added
hs-wait-for-or runtime form carrying a timeout-ms; mock resumes
immediately when a timeout is present (0ms tests). (c) parser
parse-wait-cmd recognises `wait for EV(v1, v2)` destructure syntax,
emits :destructure list on wait-for AST. (d) compiler emit-wait-for
updated for :from/:or combos; a new `__bind-from-detail__` form
compiles to `(define v (host-get (host-get it "detail") v))`, and the
`do`-sequence handler preprocesses wait-for to splice these synthetic
bindings after the wait. (e) generator extracts `detail: ...` from
`CustomEvent` options so dispatched events carry their payload.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 06:05:53 +00:00
parent e8a89a6ce2
commit f79f96c1c3
9 changed files with 248 additions and 133 deletions

View File

@@ -341,7 +341,23 @@ globalThis._driveAsync=function driveAsync(r,d){d=d||0;if(d>500||!r||!r.suspende
else if(opName==='io-parse-json'){const resp=items&&items[1];try{doResume(JSON.parse(typeof resp==='string'?resp:resp&&resp._json?resp._json:'{}'));}catch(e){doResume(null);}}
else if(opName==='io-parse-html'){const frag=new El('fragment');frag.nodeType=11;doResume(frag);}
else if(opName==='io-settle')doResume(null);
else if(opName==='io-wait-event')doResume(null);
else if(opName==='io-wait-event'){
const target=items&&items[1];
const evName=typeof items[2]==='string'?items[2]:'';
const timeout=items&&items.length>3?items[3]:undefined;
if(typeof timeout==='number'){
// `wait for EV or Nms` — timeout wins immediately in the mock (tests use 0ms)
doResume(null);
} else if(target && target instanceof El && evName){
const handler=function(ev){
target.removeEventListener(evName,handler);
doResume(ev);
};
target.addEventListener(evName,handler);
} else {
doResume(null);
}
}
else if(opName==='io-transition')doResume(null);
};