js-on-sx: for..of / for..in + more Array methods

Parser: jp-parse-for-stmt does 2-token lookahead for (var? ident
(of|in) expr), emits (js-for-of-in kind ident iter body) else
classic (js-for init cond step body).

Transpile: wraps body in (call/cc (__break__) (let items
(for-each (fn (ident) (call/cc (__continue__) body)) items))).

Runtime: js-iterable-to-list normalizes list/string/dict for of
iteration; js-string-to-list expands string to char list.

399/401 unit (+8), 148/148 slice unchanged.
This commit is contained in:
2026-04-23 21:41:52 +00:00
parent ee16e358f3
commit f113b45d48
5 changed files with 120 additions and 14 deletions

View File

@@ -1585,6 +1585,29 @@
(dict-set! p "value" reason)
(js-promise-flush-callbacks! p))))))
(define
js-iterable-to-list
(fn
(v)
(cond
((list? v) v)
((= (type-of v) "string") (js-string-to-list v 0 (list)))
((dict? v)
(let
((result (list)))
(for-each (fn (k) (append! result (get v k))) (keys v))
result))
(else (list)))))
(define
js-string-to-list
(fn
(s i acc)
(if
(>= i (len s))
acc
(begin (append! acc (char-at s i)) (js-string-to-list s (+ i 1) acc)))))
(define
js-object-keys
(fn