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:
@@ -1027,6 +1027,14 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 2104)
|
||||
(eval "(js-eval \"[1,2,1,2].indexOf(2, 2)\")")
|
||||
|
||||
;; ── Phase 11.forofin: for..of / for..in ─────────────────────────
|
||||
(epoch 2200)
|
||||
(eval "(js-eval \"var s=0; for (var x of [1,2,3]) s=s+x; s\")")
|
||||
(epoch 2201)
|
||||
(eval "(js-eval \"var r=''; for (var k in {a:1, b:2}) r=r+k; r.length\")")
|
||||
(epoch 2202)
|
||||
(eval "(js-eval \"var s=''; for (var c of 'abc') s=s+c; s\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
|
||||
@@ -1578,6 +1586,11 @@ check 2102 "fill(0)" '"0,0,0"'
|
||||
check 2103 "fill(0,1,3)" '"1,0,0,4"'
|
||||
check 2104 "indexOf with start" '3'
|
||||
|
||||
# ── Phase 11.forofin ───────────────────────────────────────────
|
||||
check 2200 "for-of array" '6'
|
||||
check 2201 "for-in object keys count" '2'
|
||||
check 2202 "for-of string" '"abc"'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user