From f85004c8a2c1006389f72b460b3f778ec5fbfdfa Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 17 Apr 2026 23:13:49 +0000 Subject: [PATCH] =?UTF-8?q?HS:=20targeted=20IO=20let/it=20chaining=20?= =?UTF-8?q?=E2=80=94=20fetch=20tests=200=E2=86=924/23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compiler: do-blocks containing IO commands (hs-fetch, hs-wait, perform) are compiled as (let ((it cmd1)) (let ((it cmd2)) ...)) to chain the it variable through IO suspensions. Non-IO do-blocks stay as plain (do cmd1 cmd2). This enables fetch X then put it into me pattern. Parser: then-separator handled via __then__ markers (stripped in output). fetch URL /path parsing. Default format "text". Runtime: hs-fetch simplified to single perform (io-fetch url format). Test runner: mock fetch routes with format-specific responses. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hyperscript/compiler.sx | 26 +++++++++++++++++++++++++- lib/hyperscript/parser.sx | 8 ++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 6a47db8e..d0ac73a9 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -999,7 +999,31 @@ (hs-to-sx (nth ast 1)) (hs-to-sx (nth ast 2))))) ((= head (quote do)) - (cons (quote do) (map hs-to-sx (rest ast)))) + (let + ((compiled (map hs-to-sx (rest ast)))) + (if + (and + (> (len compiled) 1) + (some + (fn + (c) + (and + (list? c) + (or + (= (first c) (quote hs-fetch)) + (= (first c) (quote hs-wait)) + (= (first c) (quote perform))))) + compiled)) + (reduce + (fn + (body cmd) + (list + (quote let) + (list (list (quote it) cmd)) + body)) + (nth compiled (- (len compiled) 1)) + (reverse (rest (reverse compiled)))) + (cons (quote do) compiled)))) ((= head (quote wait)) (list (quote hs-wait) (nth ast 1))) ((= head (quote wait-for)) (emit-wait-for ast)) ((= head (quote log)) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 45c695b3..3e07187c 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1859,7 +1859,8 @@ (let ((acc2 (append acc (list cmd)))) (cond - ((match-kw "then") (cl-collect acc2)) + ((match-kw "then") + (cl-collect (append acc2 (list (quote __then__))))) ((and (not (at-end?)) (= (tp-type) "keyword") (cmd-kw? (tp-val))) (cl-collect acc2)) (true acc2))))))) @@ -1868,7 +1869,10 @@ (cond ((= (len cmds) 0) nil) ((= (len cmds) 1) (first cmds)) - (true (cons (quote do) cmds)))))) + (true + (cons + (quote do) + (filter (fn (c) (not (= c (quote __then__)))) cmds))))))) (define parse-on-feat (fn