From 68d81f59a61e3715eac3e0cdc4bd340aeacce0c6 Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 26 Apr 2026 22:36:03 +0000 Subject: [PATCH] HS: sourceInfo 4/4 + arrayLiteral 8/8 (+5 tests) - tokenizer hs-emit!: add :end (max pos, start+len(val)) and :line fields to tokens - parser hs-parse-ast: wrap fn body in do so set! hs-span-mode executes - runtime hs-make-object: remove _order key (V8 native insertion order sufficient) --- lib/hyperscript/parser.sx | 7 ++++--- lib/hyperscript/runtime.sx | 11 ++--------- lib/hyperscript/tokenizer.sx | 8 +++++++- shared/static/wasm/sx/hs-parser.sx | 7 ++++--- shared/static/wasm/sx/hs-runtime.sx | 11 ++--------- shared/static/wasm/sx/hs-tokenizer.sx | 8 +++++++- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index f721aa6e..44ae5698 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -2999,6 +2999,7 @@ (define hs-parse-ast (fn (src) - (set! hs-span-mode true) - (let ((result (hs-parse (hs-tokenize src) src))) - (do (set! hs-span-mode false) result)))) + (do + (set! hs-span-mode true) + (let ((result (hs-parse (hs-tokenize src) src))) + (do (set! hs-span-mode false) result))))) diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index ac273fa0..66223707 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -2156,20 +2156,13 @@ (fn (pairs) (let - ((d {}) (order (list))) + ((d {})) (do (for-each (fn (pair) - (let - ((k (first pair))) - (do - (when - (not (dict-has? d k)) - (set! order (append order (list k)))) - (dict-set! d k (nth pair 1))))) + (dict-set! d (first pair) (nth pair 1))) pairs) - (when (not (empty? order)) (dict-set! d "_order" order)) d)))) (define diff --git a/lib/hyperscript/tokenizer.sx b/lib/hyperscript/tokenizer.sx index 8a213ef5..8b3a6a80 100644 --- a/lib/hyperscript/tokenizer.sx +++ b/lib/hyperscript/tokenizer.sx @@ -460,7 +460,13 @@ hs-emit! (fn (type value start) - (append! tokens (hs-make-token type value start)))) + (let + ((tok (hs-make-token type value start)) + (end-pos (max pos (+ start (if (nil? value) 0 (len (str value))))))) + (do + (dict-set! tok "end" end-pos) + (dict-set! tok "line" (len (split (slice src 0 start) "\n"))) + (append! tokens tok))))) (define scan! (fn diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index f721aa6e..44ae5698 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -2999,6 +2999,7 @@ (define hs-parse-ast (fn (src) - (set! hs-span-mode true) - (let ((result (hs-parse (hs-tokenize src) src))) - (do (set! hs-span-mode false) result)))) + (do + (set! hs-span-mode true) + (let ((result (hs-parse (hs-tokenize src) src))) + (do (set! hs-span-mode false) result))))) diff --git a/shared/static/wasm/sx/hs-runtime.sx b/shared/static/wasm/sx/hs-runtime.sx index ac273fa0..66223707 100644 --- a/shared/static/wasm/sx/hs-runtime.sx +++ b/shared/static/wasm/sx/hs-runtime.sx @@ -2156,20 +2156,13 @@ (fn (pairs) (let - ((d {}) (order (list))) + ((d {})) (do (for-each (fn (pair) - (let - ((k (first pair))) - (do - (when - (not (dict-has? d k)) - (set! order (append order (list k)))) - (dict-set! d k (nth pair 1))))) + (dict-set! d (first pair) (nth pair 1))) pairs) - (when (not (empty? order)) (dict-set! d "_order" order)) d)))) (define diff --git a/shared/static/wasm/sx/hs-tokenizer.sx b/shared/static/wasm/sx/hs-tokenizer.sx index 8a213ef5..8b3a6a80 100644 --- a/shared/static/wasm/sx/hs-tokenizer.sx +++ b/shared/static/wasm/sx/hs-tokenizer.sx @@ -460,7 +460,13 @@ hs-emit! (fn (type value start) - (append! tokens (hs-make-token type value start)))) + (let + ((tok (hs-make-token type value start)) + (end-pos (max pos (+ start (if (nil? value) 0 (len (str value))))))) + (do + (dict-set! tok "end" end-pos) + (dict-set! tok "line" (len (split (slice src 0 start) "\n"))) + (append! tokens tok))))) (define scan! (fn