Smarter implicit then: only before command keywords — 341/831 (41%)
Fixed then insertion to only trigger before known HS command keywords (set, put, add, remove, toggle, etc.) via lookahead regex, instead of on all multi-space sequences. Prevents breaking single-command expressions with wide spacing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -432,11 +432,16 @@ def emit_element_setup(lines, elements, var_names):
|
||||
if el['hs']:
|
||||
hs_val = el['hs']
|
||||
hs_val = hs_val.replace('\\', '')
|
||||
# Newlines in _hyperscript act as implicit 'then' separators
|
||||
hs_val = re.sub(r'\s*\n\s*', ' then ', hs_val)
|
||||
# Collapse multiple spaces (from HTML formatting)
|
||||
hs_val = re.sub(r'\s{2,}', ' then ', hs_val)
|
||||
hs_val = re.sub(r'(then\s*)+then', 'then', hs_val) # dedupe
|
||||
# Newlines/tabs in _hyperscript act as implicit 'then' separators.
|
||||
# Only insert 'then' before command keywords, not within expressions.
|
||||
cmd_kws = r'(?:set|put|get|add|remove|toggle|hide|show|if|repeat|for|wait|send|trigger|log|call|take|throw|return|append|tell|go|halt|settle|increment|decrement|fetch|make|install|measure|empty|reset|swap|default|morph|render|scroll|focus|select|pick|beep!)'
|
||||
# Replace multi-whitespace before a command keyword with ' then '
|
||||
hs_val = re.sub(r'\s{2,}(?=' + cmd_kws + r'\b)', ' then ', hs_val)
|
||||
# Also handle actual newlines
|
||||
hs_val = re.sub(r'\s*[\n\r]\s*', ' then ', hs_val)
|
||||
# Clean up: collapse spaces, dedupe then
|
||||
hs_val = re.sub(r'\s+', ' ', hs_val)
|
||||
hs_val = re.sub(r'(then\s*)+then', 'then', hs_val)
|
||||
hs_val = hs_val.strip()
|
||||
if not hs_val:
|
||||
lines.append(f' (dom-append (dom-body) {var})')
|
||||
|
||||
Reference in New Issue
Block a user