From 673be85743b6730616f1809b15f84689b51a969b Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 17 Apr 2026 23:22:56 +0000 Subject: [PATCH] =?UTF-8?q?HS=20fetch:=204=E2=86=9211/23=20=E2=80=94=20POS?= =?UTF-8?q?T=20options,=20Number=20format,=20route=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parser: fetch command consumes {method:"POST"}, with {opts}, and handles as-format both before and after options. Mock: Number format case-insensitive, /test route has number field. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hyperscript/parser.sx | 15 +++++++++++++-- shared/static/wasm/sx/hs-parser.sx | 15 +++++++++++++-- tests/hs-run-fast.js | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 3e07187c..036ef73b 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1270,8 +1270,19 @@ (let ((url (if (nil? url-atom) url-atom (parse-arith (parse-poss url-atom))))) (let - ((fmt (if (match-kw "as") (let ((f (tp-val))) (adv!) f) "text"))) - (list (quote fetch) url fmt))))))) + ((fmt-before (if (match-kw "as") (let ((f (tp-val))) (adv!) f) nil))) + (when (= (tp-type) "brace-open") (parse-expr)) + (when + (match-kw "with") + (if + (= (tp-type) "brace-open") + (parse-expr) + (parse-expr))) + (let + ((fmt-after (if (and (not fmt-before) (match-kw "as")) (let ((f (tp-val))) (adv!) f) nil))) + (let + ((fmt (or fmt-before fmt-after "text"))) + (list (quote fetch) url fmt))))))))) (define parse-call-args (fn diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 3e07187c..036ef73b 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -1270,8 +1270,19 @@ (let ((url (if (nil? url-atom) url-atom (parse-arith (parse-poss url-atom))))) (let - ((fmt (if (match-kw "as") (let ((f (tp-val))) (adv!) f) "text"))) - (list (quote fetch) url fmt))))))) + ((fmt-before (if (match-kw "as") (let ((f (tp-val))) (adv!) f) nil))) + (when (= (tp-type) "brace-open") (parse-expr)) + (when + (match-kw "with") + (if + (= (tp-type) "brace-open") + (parse-expr) + (parse-expr))) + (let + ((fmt-after (if (and (not fmt-before) (match-kw "as")) (let ((f (tp-val))) (adv!) f) nil))) + (let + ((fmt (or fmt-before fmt-after "text"))) + (list (quote fetch) url fmt))))))))) (define parse-call-args (fn diff --git a/tests/hs-run-fast.js b/tests/hs-run-fast.js index d9f287ae..04a2f567 100644 --- a/tests/hs-run-fast.js +++ b/tests/hs-run-fast.js @@ -189,7 +189,7 @@ K.registerNative('load-library!',()=>false); let _testDeadline = 0; // Mock fetch routes const _fetchRoutes = { - '/test': { status: 200, body: 'yay', json: '{"foo":1}', html: '
yay
' }, + '/test': { status: 200, body: 'yay', json: '{"foo":1}', html: '
yay
', number: '1.2' }, '/test-json': { status: 200, body: '{"foo":1}', json: '{"foo":1}' }, '/404': { status: 404, body: 'the body' }, '/number': { status: 200, body: '1.2' }, @@ -210,7 +210,7 @@ globalThis._driveAsync=function driveAsync(r,d){d=d||0;if(d>500||!r||!r.suspende if(fmt==='json'){try{doResume(JSON.parse(route.json||route.body||'{}'));}catch(e){doResume(null);}} else if(fmt==='html'){const frag=new El('fragment');frag.nodeType=11;frag.innerHTML=route.html||route.body||'';frag.textContent=frag.innerHTML.replace(/<[^>]*>/g,'');doResume(frag);} else if(fmt==='response')doResume({ok:(route.status||200)<400,status:route.status||200,url}); - else if(fmt==='Number'||fmt==='number')doResume(parseFloat(route.body||'0')); + else if(fmt.toLowerCase()==='number')doResume(parseFloat(route.number||route.body||'0')); else doResume(route.body||''); } else if(opName==='io-parse-text'){const resp=items&&items[1];doResume(resp&&resp._body?resp._body:typeof resp==='string'?resp:'');}