1 Commits
Author SHA1 Message Date
Aaron SinclairandClaude e09a6dedc8 Add component props and lambda event handlers (TDD)
Implements two major features using Test-Driven Development:

1. Component Props/Parameters:
   - Components can accept parameters: @component def Button(label)
   - Arguments passed when yielding: yield Button("Click me")
   - Default values supported: def Tabs(orientation=0)
   - Codegen passes arguments correctly to render functions

2. Lambda Event Handlers:
   - Support onclick=lambda: function_call() syntax
   - Parser converts lambdas to synthetic functions
   - Synthetic functions auto-named: _lambda_0_ComponentName
   - Codegen emits lambda functions as event handlers
   - Clean syntax vs set_tab_0/1/2 boilerplate

Implementation:
   - Added _process_lambdas_in_component() to scan & convert
   - Lambda detection in _transform_expr()
   - "expr" statement type for lambda bodies
   - Component argument passing in _emit_yield_component()
   - Constants vs variables handled correctly in args

Tests (TDD Style):
   - test_component_props.py (8 tests) - all passing
   - test_lambda_simple.py (3 tests) - all passing
   - 46 total tests passing

Examples:
   # Before (verbose)
   def set_tab_0(): tab = 0
   def set_tab_1(): tab = 1
   with Button(onclick=set_tab_0): yield "Tab 0"

   # After (clean)
   with Button(onclick=lambda: set_tab(0)): yield "Tab 0"
   with Button(onclick=lambda: set_tab(1)): yield "Tab 1"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 10:45:17 -08:00