From e5e3e90ee771abc6d0a35bd6dd131d1392789ebe Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 14 Apr 2026 19:47:30 +0000 Subject: [PATCH] HS compiler: emit-set handles @attr of target expressions Adds attribute reference case to the 'of' branch in emit-set: (set @bar of #div2 to "foo") now compiles to (dom-set-attr target "bar" "foo") instead of falling through to the broken (set! (host-get ...)) catchall. 417/831 (50.2%), +2 from attr-of fix. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hyperscript/compiler.sx | 16 +++++++++++----- shared/static/wasm/sx/hs-compiler.sx | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 8beb2afe..c09941b9 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -69,14 +69,20 @@ (list (quote host-get) (hs-to-sx obj-ast) (nth base 1)) prop-name value)) - ;; Simple: (ref "prop") of obj → (dom-set-prop (compiled-obj) "prop" value) - (if (and (list? prop-ast) (= (first prop-ast) (quote ref))) - (list (quote dom-set-prop) + ;; (attr "name") of obj → (dom-set-attr (compiled-obj) "name" value) + (if (and (list? prop-ast) (= (first prop-ast) (quote attr))) + (list (quote dom-set-attr) (hs-to-sx obj-ast) (nth prop-ast 1) value) - ;; Fallback - (list (quote set!) (hs-to-sx target) value))))) + ;; Simple: (ref "prop") of obj → (dom-set-prop (compiled-obj) "prop" value) + (if (and (list? prop-ast) (= (first prop-ast) (quote ref))) + (list (quote dom-set-prop) + (hs-to-sx obj-ast) + (nth prop-ast 1) + value) + ;; Fallback + (list (quote set!) (hs-to-sx target) value)))))) (true (list (quote set!) (hs-to-sx target) value))))))) (define emit-on diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index 8beb2afe..c09941b9 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -69,14 +69,20 @@ (list (quote host-get) (hs-to-sx obj-ast) (nth base 1)) prop-name value)) - ;; Simple: (ref "prop") of obj → (dom-set-prop (compiled-obj) "prop" value) - (if (and (list? prop-ast) (= (first prop-ast) (quote ref))) - (list (quote dom-set-prop) + ;; (attr "name") of obj → (dom-set-attr (compiled-obj) "name" value) + (if (and (list? prop-ast) (= (first prop-ast) (quote attr))) + (list (quote dom-set-attr) (hs-to-sx obj-ast) (nth prop-ast 1) value) - ;; Fallback - (list (quote set!) (hs-to-sx target) value))))) + ;; Simple: (ref "prop") of obj → (dom-set-prop (compiled-obj) "prop" value) + (if (and (list? prop-ast) (= (first prop-ast) (quote ref))) + (list (quote dom-set-prop) + (hs-to-sx obj-ast) + (nth prop-ast 1) + value) + ;; Fallback + (list (quote set!) (hs-to-sx target) value)))))) (true (list (quote set!) (hs-to-sx target) value))))))) (define emit-on