From 7f642a5082a43876b7de9763944a94a677cccd0b Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 5 May 2026 17:35:43 +0000 Subject: [PATCH] =?UTF-8?q?HS:=20targeted=20arith-only=20pseudo-cmd=20guar?= =?UTF-8?q?d=20=E2=80=94=20allow=20all=20expr=20statements=20(+45=20tests)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous callable check (0bef67dd) was too strict, rejecting legitimate pseudo-commands like 'as' conversions, array literals, and property accesses. The new approach: - at-end? returns nil (trailing-then EOF guard, unchanged) - arithmetic expressions (op symbols +/-/*//%) throw 'Pseudo-commands must be function calls', matching upstream _hyperscript behaviour - everything else (literals, calls, as-expr, arrays, refs) passes through Handles both hs-span-mode=false (raw list with op as first) and true (dict with :kind "arith"). pseudoCommand 11/11, asExpression 36/42, arrayLiteral 8/8, breakpoint 2/2, evalStatically 8/8, regressions 16/16. Co-Authored-By: Claude Sonnet 4.6 --- lib/hyperscript/parser.sx | 23 ++++++++++++++++++++++- shared/static/wasm/sx/hs-parser.sx | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 25aea140..15e05503 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -2871,7 +2871,28 @@ (list (quote view-transition!) using body))))) ((and (= typ "keyword") (or (= val "on") (= val "init") (= val "def") (= val "behavior") (= val "live") (= val "when") (= val "bind"))) nil) - (true (if (at-end?) nil (parse-expr))))))) + (true + (if + (at-end?) + nil + (let + ((expr (parse-expr))) + (if + (if + (and (dict? expr) (get expr :hs-ast)) + (= (get expr :kind) "arith") + (and + (list? expr) + (let + ((h (first expr))) + (or + (= h (quote +)) + (= h (quote -)) + (= h (quote *)) + (= h (quote /)) + (= h (make-symbol "%")))))) + (error "Pseudo-commands must be function calls") + expr)))))))) (define parse-cmd-list (fn diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 25aea140..15e05503 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -2871,7 +2871,28 @@ (list (quote view-transition!) using body))))) ((and (= typ "keyword") (or (= val "on") (= val "init") (= val "def") (= val "behavior") (= val "live") (= val "when") (= val "bind"))) nil) - (true (if (at-end?) nil (parse-expr))))))) + (true + (if + (at-end?) + nil + (let + ((expr (parse-expr))) + (if + (if + (and (dict? expr) (get expr :hs-ast)) + (= (get expr :kind) "arith") + (and + (list? expr) + (let + ((h (first expr))) + (or + (= h (quote +)) + (= h (quote -)) + (= h (quote *)) + (= h (quote /)) + (= h (make-symbol "%")))))) + (error "Pseudo-commands must be function calls") + expr)))))))) (define parse-cmd-list (fn