HS: computed property names in object literals (+1 test)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

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>
This commit is contained in:
2026-05-06 13:09:17 +00:00
parent 6d8f366439
commit ed42561071
6 changed files with 237 additions and 261 deletions

View File

@@ -2991,6 +2991,22 @@ def generate_eval_only_test(test, idx):
if '_hyperscript.internals.tokenizer' in body:
return generate_tokenizer_test(test, safe_name)
# Special case: computed property names in object literals.
# window.foo="bar", window.bar=fn → {[foo]:true, [bar()]:false} = {bar:true,foo:false}
if test['name'] == 'expressions work in object literal field names':
return (
f' (deftest "{safe_name}"\n'
f' (hs-cleanup!)\n'
f' (assert-equal\n'
f' {{:bar true :foo false}}\n'
f' (hs-strip-order-deep\n'
f' (eval-hs-locals "{{[foo]:true, [bar()]:false}}"\n'
f' (list\n'
f' (list (quote foo) "bar")\n'
f' (list (quote bar) (host-callback (fn () "foo")))))))\n'
f' )'
)
lines.append(f' (deftest "{safe_name}"')
assertions = []