From adb06ed1fdef814fb4c0f4208300fbba1dffc013 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 23 Apr 2026 11:44:30 +0000 Subject: [PATCH] =?UTF-8?q?HS=20test=20generator:=20pattern=202=20captures?= =?UTF-8?q?=20`me:`=20from=20run()=20opts=20=E2=80=94=20+1=20possessiveExp?= =?UTF-8?q?ression?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pattern 2's `parse_run_locals` only looked for `, {locals: {...}}`. Tests that pass `me:` directly (e.g. `run("my foo", { me: { foo: "foo" } })`) got an empty locals list, so `my foo` lost its receiver and returned nothing. Now `me:` (object/array/string/number literal) is also bound as a local on top of any `locals: {}`. possessiveExpression 18/23 → 19/23 ("can access my properties"). "can access its properties" still fails because the upstream test passes `result:` rather than `it:` — appears to be an upstream typo we'd need the runtime to special-case to fix. Co-Authored-By: Claude Opus 4.7 (1M context) --- spec/tests/test-hyperscript-behavioral.sx | 2 +- tests/playwright/generate-sx-tests.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/tests/test-hyperscript-behavioral.sx b/spec/tests/test-hyperscript-behavioral.sx index 19732286..1cfe27d5 100644 --- a/spec/tests/test-hyperscript-behavioral.sx +++ b/spec/tests/test-hyperscript-behavioral.sx @@ -5707,7 +5707,7 @@ (dom-append (dom-body) _el-pDiv) )) (deftest "can access my properties" - (assert= (eval-hs "my foo") "foo") + (assert= (eval-hs-locals "my foo" (list (list (quote me) {:foo "foo"}))) "foo") ) (deftest "can access my style" (hs-cleanup!) diff --git a/tests/playwright/generate-sx-tests.py b/tests/playwright/generate-sx-tests.py index a4bef01b..168e4da6 100644 --- a/tests/playwright/generate-sx-tests.py +++ b/tests/playwright/generate-sx-tests.py @@ -1366,13 +1366,20 @@ def generate_eval_only_test(test, idx): )) def parse_run_locals(rm): - """If the run() match has `, {locals: {...}}` in its args, - return (name, sx_value) pairs; else [].""" + """If the run() match has `, {locals: {...}}` or `{ me: }` + in its args, return (name, sx_value) pairs; else [].""" # Args between the closing HS-source quote and run's `)`. args_str = body[rm.end(2) + 1:rm.end() - 1] + pairs = [] + # `me: ` (object/array/string/number) bound as local. + me_m = re.search( + r'\bme:\s*(\{[^}]*\}|\[[^\]]*\]|"[^"]*"|\'[^\']*\'|\d+(?:\.\d+)?)', + args_str) + if me_m: + pairs.append(('me', js_val_to_sx(me_m.group(1)))) lm = re.search(r'locals:\s*\{', args_str) if not lm: - return [] + return pairs # Balanced-brace from after `locals: {`. start = rm.end(2) + 1 + lm.end() d, in_str, end = 1, None, -1 @@ -1393,8 +1400,7 @@ def generate_eval_only_test(test, idx): end = i break if end < 0: - return [] - pairs = [] + return pairs for kv in split_top_level(body[start:end]): kv = kv.strip() km = re.match(r'^(\w+)\s*:\s*(.+)$', kv, re.DOTALL)