Parser: limit `from SOURCE` to parse-collection/cmp/arith/poss/atom
(stops before parse-logical so `or` is not consumed as binary op),
then collect `or EVENT from SOURCE` pairs via recursive collect-ors!.
Adds :or-sources key to the on-feature parts list.
Compiler: scan-on gains or-sources param (11th); new :or-sources cond
clause extracts the list; terminal `true` branch wraps on-call in
(do on-call (hs-on target event handler) ...) for each extra source.
Test: "can handle an or after a from clause" moved from skip-list to
MANUAL_TEST_BODIES and now passes (1478/1496).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Parser: bracket-open in obj-collect key cond → (computed-key expr).
Compiler: detect computed-key list at object-literal pair key and compile
the inner expression instead of emitting a literal string.
Generator: special case for 'expressions work in object literal field names'
using eval-hs-locals with host-callback so hs-win-call can find the fn.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Parser: add 'the ...' as a recognized transition target in parse-transition-cmd's
tgt cond, enabling 'transition the next <div/>'s *width from A to B'.
Generator MANUAL_TEST_BODIES for 4 previously-SKIP tests:
- can transition on query ref with possessive (transition suite, 17/17)
- can write to next element with put command (relativePositionalExpression, 23/23)
- parse error at EOF on trailing newline does not crash (core/parser, 13/14)
- halt works outside of event context (halt suite, 7/7)
Also fix hs-kernel-eval.js navigator assignment for Node.js v22 (read-only global).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
parse-feat true fallback now routes directly to parse-cmd-list when the first
token is a keyword (e.g. "add - to"), so command-keyword scripts always produce
parse errors rather than being treated as subtraction expressions. Non-keyword
tokens (numbers, identifiers, paren-open) still try expression-first.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three parse-cmd / parse-feat refinements:
1. Remove dict-branch from arith guard: span-mode=true produces dict nodes
with :kind "arith", not lists. The guard only needs the list-branch (for
span-mode=false). Without this, hs-src "x + y" threw a parse error.
2. parse-feat top-level expression-first fallback: when no feature keyword is
found, try parse-expr first. If it fully consumes the input (at-end?),
return the expression directly — bypassing parse-cmd and its arith guard.
This matches upstream _hyperscript("1 + 1") which evaluates as an
expression, not a pseudo-command.
3. paren-close exception in arith guard: when the token after the arithmetic
expression is ")", we are inside a parenthesised context (e.g. "(0+1) em"
string-postfix). Allow it through without the pseudo-command error.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 <noreply@anthropic.com>
The callable check added in 0bef67dd rejected legitimate expression
statements (as-conversions, array literals, property access, breakpoint)
because they produce non-call AST nodes. The at-end? guard already handles
the trailing-then EOF case; the callable check is redundant and wrong.
Removing it restores the original open fallback: any parse-expr result is
a valid command. arrayLiteral 8/8, breakpoint 2/2, asExpression +35,
evalStatically +5, regressions +3.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parser.sx: parse-cmd true-fallback returns nil when at-end? instead of
calling parse-expr at EOF — fixes trailing 'then' causing compilation
error for 'on ... then' terminated handlers
- compiler.sx: catch-without-finally branch wraps guard+reraise in do so
both expressions are sequenced inside the let binding
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
In span mode (hs-parse-ast), parse-cmd is used to extract source info from
arbitrary expressions like literals and property access — not just callables.
Guard the "expected function call" error with hs-span-mode so span mode
passes all expression types through, while execution mode still rejects
non-callable expressions.
Also handle span mode's hs-ast dict nodes (kind="call") in the callable?
check, since method calls are wrapped in span mode.
The (true ...) fallback in parse-cmd previously accepted any expression
as a command. Now it checks that the parsed expression's head is `call`
or `method-call` — the only valid forms for pseudo-commands (foo() or
foo.bar()). Any other expression (e.g. foo.bar + bar) raises a parse
error instead of silently becoming a no-op.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
match-kw only matches tokens of type "keyword", but ] tokenizes as
bracket-close. This left the ] unconsumed after remove [@foo], causing
the attribute to never be removed. Use (when (= (tp-type) "bracket-close") (adv!))
matching the same pattern parse-add-cmd uses for [attr=val].
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
parse-repeat-cmd fallback called parse-expr on the next token, which
parse-atom would consume any keyword as (ref val). For bare `repeat`
followed by a command like `set`, this ate the `set` token so the loop
body started from the wrong position.
Fix: only attempt to parse a count expression when the next token is
a number, ident, or paren-open — the types that can form a numeric
count. Any keyword (set, put, if, end, …) means bare repeat-forever.
Fixes "repeat forever works w/o keyword" (+1 test).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parse-log-cmd now collects comma-separated args: log a, b, c
previously only consumed the first arg, causing the rest to be
standalone statement-commands that failed to parse
- compiler log case emits (do (console-log a) (console-log b) ...)
since console-log is single-arg
- hs-put! accepts before/after/start/end as aliases for the
beforebegin/afterend/afterbegin/beforeend positions
- hs-sender uses (get detail "sender") — direct SX dict lookup
instead of host-get round-trip through JS
Fixes "can reference sender in events" test: 8/8 hs-upstream-send
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- install BehaviorName: parse-set-cmd handles `element` separately so
`element's foo` after `set` invokes parse-poss rather than parse-expr,
fixing `set element's bar["count"] to X` inside behavior bodies
- parse-poss-tail ident case: call parse-poss (handles `[`) instead of
parse-prop-chain (does not) when next token is bracket-open
- hs-activate!: replace (handler el) with host-call-fn safe wrapper so
native OCaml "Undefined symbol" throws (which bypass SX guard frames)
are caught at the JS api_call_fn boundary rather than propagating
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three-part fix for element-scoped reactive expressions:
1. Parser: add when/bind to parse-cmd's feature-keyword nil set so
`... then when X changes ...` is parsed as a new feature, not absorbed
into the preceding on-handler body as a (ref "when") expression.
2. Parser: parse-when-feat now recognises local (:var) token type so
`when :count changes ...` dispatches to the when-changes branch.
3. Runtime + compiler: hs-scoped-set! now fires hs-scoped-fire-watchers!
on change; new hs-scoped-watch! / hs-scoped-fire-watchers! registry;
compiler emits (hs-scoped-watch! me name (fn (it) body)) for local
expressions in when-changes AST nodes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add `bind` keyword to tokenizer, parse-bind-feat to parser, and
bind-feat no-op case to compiler. Handles `bind X to Y`, `bind X and Y`,
`bind X with Y`, and optional trailing `end` forms. All 43/44 bind tests
pass (1 is an explicit skip).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
parse-feat's paren-open handler stripped the grouping parens and
returned the inner feature, leaving any trailing ident (like `em`)
as a separate top-level feature. After consuming the closing paren,
now checks if the next token is a non-keyword ident or `%` op and
wraps as (string-postfix inner unit), making `(0 + 1) em` → "1em".
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When parse-feat returns nil but the token stream is not at EOF,
coll-feats now throws a parse error ('Unexpected token X') instead
of silently returning the partial result. Fixes 'extra chars cause
error when evaling': eval-hs("1!") now correctly throws because '!'
is left over after parsing the number expression.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parse-on-feat: event-vars paren check now restores position and returns empty
list when the first token after '(' is a keyword (command starter). Previously
'(log me)' was consumed as event variable names instead of a parenthesized
command, silently dropping the command body and returning empty innerHTML.
Fixes 'can support parenthesized commands and features'.
- parse-add-cmd: true-fallback now throws instead of returning nil when no 'to'
keyword follows the expression. Makes 'add - to' and similar invalid add forms
throw a parse error, satisfying assert-throws in 'basic parse error messages
work' and '_hyperscript() evaluate API still throws on first error'.
- read-class-name: '(' and ')' now only allowed inside '[...]' bracket groups
(depth > 0). Previously allowing them at top level caused '.innerHTML)' at the
end of a possessive expression to be consumed into the class token, producing
'innerHTML))' as a bogus property name. Tailwind classes like
'group-[:nth-of-type(3)_&]:block' still tokenize correctly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parser: `toggle $var between v1 and v2 ...` → `(toggle-var-cycle $var (v1 v2 ...))`
- compiler: emit `(hs-toggle-var-cycle! win var-name values)` for new AST node
- runtime: `hs-toggle-var-cycle!` cycles through a list of values on a variable
- parser: `closest .sel to .target` / `closest #id to .target` / `closest sel to .target`
now consumes the `to` keyword and parses the target expr instead of defaulting to beingTold
- tokenizer: `read-class-name` handles backslash escapes and allows `(`, `)`, `&`
chars so Tailwind classes like `group-[:nth-of-type(3)_&]:block` tokenize correctly
- platform.py: `domListen` drives async result via `_driveAsync` after `cekCall`
- test: fixed-time toggle asserts `.foo` IS present after click (toggle started, 10ms window open)
- generate-sx-tests.py: aligned MANUAL_TEST_BODIES for timed toggle with corrected assertion
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parse-halt-cmd: after consuming 'the event's', check for 'bubbling'
token and return "bubbling" mode instead of "the-event"
- parse-wait-cmd: skip article words (a/an/the) before reading event
name, so 'wait for a customEvent' works correctly
- parse-on-feat: parse optional (vars) paren group before flt and
consume-having!, so 'on intersection(intersecting) having ...' works;
inject event-var refs into body for compiler's event-refs mechanism
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parser: nil return in parse-cmd for feature keywords (on/init/def/behavior/live)
so "then on click" correctly hands off to outer coll-feats loop
- compiler: cek-try wrap for undefined variable refs in coll-where compilation
so "doesNotExist where it > 1" returns nil instead of throwing
- integration: hs-activate! detects script[type=text/hyperscript-template] and
applies handler to DOM instances via hs-query-all(component attr) not to script el
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parser.sx: parse-logical now rejects mixed and/or without parens
- parser.sx: parse-arith now rejects mixed +/-/* //%/mod without parens
- generate-sx-tests.py: MANUAL_TEST_BODIES for short-circuit and/or,
typecheck (direct hs-type-assert calls), template string test
- generate-sx-tests.py: Pattern 5 for error("expr") -> assert-throws
- hs-run-filtered.js: redefine try-call to _run-test-thunk after loading
so assert-throws actually catches exceptions (was always {ok true})
- hs-run-filtered.js: clear __hs_deadline immediately after test eval
to prevent cascading timeout fires in result inspection K.eval calls
- hs-run-filtered.js: typecheck suite in _NO_STEP_LIMIT_SUITES and
_SLOW_DEADLINE_SUITES (hs-type-assert JIT is slow on first call)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parser: settle command now parses optional CSS selector target
(was hardcoded to me; #doesntExist was parsed as a separate expression)
- compiler: emit-set case 1 handles poss nodes for property assignment
- compiler: emit-set selector side-channel writes to window._hs_last_query_sel
via host-set! (was dead SX variable set!)
- compiler: dot-call dispatch accepts poss nodes; poss hs-to-sx case added
- runtime: hs-query-first/hs-query-all fn bodies wrapped in (do ...) so
host-set! _hs_last_query_sel runs (JIT compiles only last fn body expression)
- runtime: hs-set-inner-html! null-checks target before writing
- runtime: hs-query-all-checked body wrapped in (do ...) so hs-empty-raise!
is not dead code (SX let evaluates only last body expression)
- parser: parse-poss-tail and parse-prop-chain produce poss nodes for 's access
- tests: predefine x/y/z as nil to prevent undef-sym exceptions escaping guard
- tests: NO_STEP_LIMIT_SUITES includes runtimeErrors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
parse-on-feat now skips 'queue MODE' tokens before parsing the body,
so 'on foo queue first ...' and 'on foo queue last ...' parse correctly.
Compiler ignores queue mode (catch-all drops unknown parts).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Parser: parse-set-cmd now emits (set-el! target value) when target is
a query node (e.g. #id, .class), keeping (set! ...) for all other
targets.
Compiler: add (set-el! ...) handler that calls hs-set-element!; revert
emit-set for query targets back to hs-set-inner-html! so that
put "x" into #target keeps setting innerHTML rather than replacing
the element.
Runtime: hs-set-element! new function — parses value as HTML into a
temp div; if it contains element children, replaces the target element
via replaceChild and boots hyperscript on the new element; otherwise
falls through to hs-set-inner-html!. Removes the spurious
host-to-list wrapper that was causing len() to always return 0.
Result: all 8 assignableElements tests pass (set #id / set .class /
set closest / swap, plus put-into-still-works-as-innerHTML).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parse-atom: unrecognized keywords (e.g. index) fall back to ref,
fixing 'set index to N' parse failure
- hs-set-inner-html!: join list values as "" so 'put [A,C] into el'
concatenates strings not [object Object]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
collect-pairs! in parse-add-cmd now skips the semicolon op token
between CSS properties, so add {color: red; font-family: monospace}
compiles to two dom-set-style calls instead of three malformed ones.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Parser: parse-cmd-list now skips a leading 'then' token so that
'on click from #bar then add .clicked' compiles correctly instead
of producing nil as the body.
Bootstrap tests: fix two broken tests whose assertions were
incomplete or contradictory:
- "cleanup removes event listeners" — deactivate + re-click to
verify listener is gone
- "reinitializes if script attribute changes" — actually change
the _ attribute before re-activating and re-clicking
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
parser.sx: detect bare ident "initial" after "to" in parse-one-transition,
emit string sentinel instead of (ref "initial") which evaluated to nil.
runtime.sx: hs-transition stores pre-first-transition style as
data-hs-init-{prop}; restores it when value=="initial".
Also commits E37 tokenizer and E40 fetch test implementations that
accumulated in the working tree but weren't staged in prior commits.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements hs-tokens-of, hs-stream-token, hs-stream-consume,
hs-stream-has-more, hs-token-type, hs-token-value, hs-token-op?,
hs-raw->api-token, hs-eof-sentinel in runtime.sx.
Tokenizer emits whitespace tokens after the first content token;
stream functions skip them for look-ahead and consume. Parser
filters whitespace tokens at hs-parse entry. Dot/hash after close
brackets split into PERIOD/POUND + IDENTIFIER. Template escape \$
produces literal $.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- hs-id= uses JS === for DOM elements (hs-ref-eq), = for scalars
- != operator now uses hs-id= for structural correctness
- compound tag[attr=val] selector matching in test runner
- dom-query-all replaces host-call querySelectorAll
- DOM tree structure corrected in 4 generated tests (elements were
appended to wrong parents)
Parser: parse-js-block extracts raw JS source by character positions.
Compiler: js-block AST → hs-js-exec call, stores result in it.
Runtime: hs-js-exec creates JS Function, handles promise rejection.
Test runner: host-new-function/host-promise-state natives + promise monkey-patch.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
${}{"val"} pattern in add {prop: ${}{"val"}} uses two consecutive brace
groups: empty ${} followed by {"val"} for the actual expression. The prior
fix called parse-expr when already at the brace-close of the empty group,
returning nil. New fix: detect empty ${} (brace-open then brace-close),
skip the close, then read the actual value from the following {…} block.
Also handles non-empty ${expr} directly as before.
Suite hs-upstream-add: 17/19 → 18/19. Smoke 0-195: 174/195 → 175/195.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tell now rebinds beingTold/you/yourself without overwriting me.
Parser implicit targets use beingTold; handler wrapper seeds beingTold=me.
Fixes: attributes refer to the thing being told, does not overwrite me,
your symbol represents the thing being told.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`1 in [1, 2, 3]` must return (list 1) not true. Root cause: in? compiled
to hs-contains? which returns boolean for scalar items. Fix: new hs-in?
returns filtered list; new in-bool? operator for is/am-in comparison
contexts so those still return boolean. Parser generates in-bool? for
`X is in Y` / `X am in Y`; plain `in` keeps in? → list return.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three orthogonal fixes that pick up tests now unblocked by earlier
cluster-34 (count filters) and cluster-35 (hs-method-call fallback) work:
(1) parser.sx parse-hide-cmd / parse-show-cmd — added `on` to the keyword
list that signals an implicit-`me` target. Without this, `on click 1
hide on click 2 show` silently parsed as `(hide nil)` because parse-expr
greedily started consuming `on` and returned nil. With the bail-out,
hide/show default to me when the next token is `on` (a sibling feature).
(2) runtime.sx hs-method-call fallback — when method isn't a built-in
collection op, look up obj[method] via host-get; if it's an SX-callable
(lambda) use apply, but if it's a JS-native function (e.g. cookies.clear
on the cookies Proxy) dispatch via `(apply host-call (cons obj (cons
method args)))` so the JS native receives the args correctly. SX
callable? returns false for JS-native function values, hence the split.
(3) generator hs-cleanup! — wrapped body in begin (fn body evaluates
only the last expression) and reset two pieces of mutable global runtime
state between tests: hs-set-default-hide-strategy! nil and
hs-set-log-all! false. The prior `can set default to custom strategy`
test (cluster 11) was leaking _hs-default-hide-strategy to subsequent
tests, breaking `hide element then show element retains original
display` because hs-hide-one! resolved its "display" strategy through
the leaked override.
Also added cluster-33 hand-roll for `basic clear cookie values work`
(uses the new method-call fallback to dispatch cookies.clear via
host-call).
hs-upstream-hide: 15/16 → 16/16. hs-upstream-expressions/cookies: 3/5
→ 4/5. Smoke 0-195 unchanged at 172/195.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>