You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement selector expressions with comprehensive tests
Added full support for selector expressions (e.g., e.Target.Value, obj.field)
enabling access to nested object properties in .gx files.
Parser Changes (pkg/ast/ast.go):
- Added Selector type to represent chained field access
- Selector has Base (identifier) and Fields (array of field names)
- Added Selector as alternative in Expr union type
- Supports single field (obj.Name) and chained (e.Target.Value)
Code Generator Changes (pkg/codegen/codegen.go):
- Added generateSelector() to build chained SelectorExpr nodes
- Iterates through fields to create nested Go AST SelectorExpr
- Generates clean, idiomatic Go code (e.g., req.User.Name)
Parser Tests (pkg/parser/parser_test.go):
- TestParseSelector: Verifies e.Target.Value parsing
- TestParseSelectorSingleField: Verifies obj.Name parsing
- Tests verify Base extraction and Fields array
Code Generator Tests (pkg/codegen/codegen_test.go):
- TestGenerateSelector: Verifies e.Target.Value generation
- TestGenerateSelectorSingleField: Verifies obj.Name generation
- TestGenerateSelectorInFunctionCall: Verifies req.User.Name chaining
- Tests verify correct Go selector expression output
Example Usage:
```gx
func Handler(e: Event) {
value := e.Target.Value // Selector expression
name := user.Name // Single field selector
email := req.User.Email // Chained selector
Div { `{value}` }
}
```
All 23 tests passing (7 parser + 16 codegen).
Successfully generated app.gx with selector expressions!
0 commit comments