Skip to content

Commit

Permalink
Simpler unpackFieldNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Sep 8, 2024
1 parent bb7ee2d commit ef30a9a
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pkg/ast/processing/find_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ func (p *Processor) extractObjectRangesFromDesugaredObjs(desugaredObjs []*ast.De
return ranges, nil
}

fieldNodes, err := p.unpackFieldNodes(foundFields)
if err != nil {
return nil, err
}

fieldNodes := p.unpackFieldNodes(foundFields)
i := 0
for i < len(fieldNodes) {
fieldNode := fieldNodes[i]
Expand Down Expand Up @@ -145,7 +141,7 @@ func (p *Processor) extractObjectRangesFromDesugaredObjs(desugaredObjs []*ast.De
additionalIndexList := append(nodestack.NewNodeStack(fieldNode).BuildIndexList(), indexList...)
result, _ := p.FindRangesFromIndexList(stack, additionalIndexList, partialMatchFields)
if len(result) > 0 {
return result, err
return result, nil
}
}

Expand Down Expand Up @@ -178,7 +174,7 @@ func flattenBinary(node ast.Node) []ast.Node {
// unpackFieldNodes extracts nodes from fields
// - Binary nodes. A field could be either in the left or right side of the binary
// - Self nodes. We want the object self refers to, not the self node itself
func (p *Processor) unpackFieldNodes(fields []*ast.DesugaredObjectField) ([]ast.Node, error) {
func (p *Processor) unpackFieldNodes(fields []*ast.DesugaredObjectField) []ast.Node {
var fieldNodes []ast.Node
for _, foundField := range fields {
switch fieldNode := foundField.Body.(type) {
Expand All @@ -191,7 +187,7 @@ func (p *Processor) unpackFieldNodes(fields []*ast.DesugaredObjectField) ([]ast.
}
}

return fieldNodes, nil
return fieldNodes
}

func findObjectFieldsInObjects(objectNodes []*ast.DesugaredObject, index string, partialMatchFields bool) []*ast.DesugaredObjectField {
Expand Down

0 comments on commit ef30a9a

Please sign in to comment.