(node *ast.Node)
| 13 | type lengthPatcher struct{} |
| 14 | |
| 15 | func (p *lengthPatcher) Visit(node *ast.Node) { |
| 16 | switch n := (*node).(type) { |
| 17 | case *ast.MemberNode: |
| 18 | if prop, ok := n.Property.(*ast.StringNode); ok && prop.Value == "length" { |
| 19 | ast.Patch(node, &ast.BuiltinNode{ |
| 20 | Name: "len", |
| 21 | Arguments: []ast.Node{n.Node}, |
| 22 | }) |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestPatch_length(t *testing.T) { |
| 28 | program, err := expr.Compile( |