diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 6a47db8e..912ac999 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -999,7 +999,23 @@ (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 + (= (len compiled) 1) + (first compiled) + (let + ((last-cmd (nth compiled (- (len compiled) 1))) + (init-cmds (reverse (rest (reverse compiled))))) + (reduce + (fn + (body cmd) + (list + (quote let) + (list (list (quote it) cmd)) + body)) + last-cmd + (reverse init-cmds)))))) ((= 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 23462934..45c695b3 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1270,7 +1270,7 @@ (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) "json"))) + ((fmt (if (match-kw "as") (let ((f (tp-val))) (adv!) f) "text"))) (list (quote fetch) url fmt))))))) (define parse-call-args diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index 7379936e..2b157b2a 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -285,13 +285,7 @@ hs-fetch (fn (url format) - (let - ((response (perform (list (quote io-fetch) url)))) - (cond - ((= format "json") (perform (list (quote io-parse-json) response))) - ((= format "text") (perform (list (quote io-parse-text) response))) - ((= format "html") (perform (list (quote io-parse-html) response))) - (true response))))) + (perform (list "io-fetch" url (if format format "text"))))) (define hs-coerce diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index 6a47db8e..912ac999 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -999,7 +999,23 @@ (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 + (= (len compiled) 1) + (first compiled) + (let + ((last-cmd (nth compiled (- (len compiled) 1))) + (init-cmds (reverse (rest (reverse compiled))))) + (reduce + (fn + (body cmd) + (list + (quote let) + (list (list (quote it) cmd)) + body)) + last-cmd + (reverse init-cmds)))))) ((= head (quote wait)) (list (quote hs-wait) (nth ast 1))) ((= head (quote wait-for)) (emit-wait-for ast)) ((= head (quote log)) diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 23462934..45c695b3 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -1270,7 +1270,7 @@ (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) "json"))) + ((fmt (if (match-kw "as") (let ((f (tp-val))) (adv!) f) "text"))) (list (quote fetch) url fmt))))))) (define parse-call-args diff --git a/shared/static/wasm/sx/hs-runtime.sx b/shared/static/wasm/sx/hs-runtime.sx index 7379936e..2b157b2a 100644 --- a/shared/static/wasm/sx/hs-runtime.sx +++ b/shared/static/wasm/sx/hs-runtime.sx @@ -285,13 +285,7 @@ hs-fetch (fn (url format) - (let - ((response (perform (list (quote io-fetch) url)))) - (cond - ((= format "json") (perform (list (quote io-parse-json) response))) - ((= format "text") (perform (list (quote io-parse-text) response))) - ((= format "html") (perform (list (quote io-parse-html) response))) - (true response))))) + (perform (list "io-fetch" url (if format format "text"))))) (define hs-coerce diff --git a/tests/hs-run-fast.js b/tests/hs-run-fast.js index 1c25ffe9..d9f287ae 100644 --- a/tests/hs-run-fast.js +++ b/tests/hs-run-fast.js @@ -192,6 +192,8 @@ const _fetchRoutes = { '/test': { status: 200, body: 'yay', json: '{"foo":1}', html: '