this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/format: simplify label replacement without astutil.Apply

Since we already know the label is a *ast.BasicLit, we can inline
the replacement logic directly rather than using astutil.Apply,
which is overkill for this simple case.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I52ec664cc1a4e80d030c5df46c69dadc4b2d422a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1229773
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+5 -14
+5 -14
cue/format/simplify.go
··· 18 18 "strconv" 19 19 20 20 "cuelang.org/go/cue/ast" 21 - "cuelang.org/go/cue/ast/astutil" 22 21 ) 23 22 24 23 // labelSimplifier rewrites string labels to identifiers if ··· 51 50 for _, d := range decls { 52 51 switch x := d.(type) { 53 52 case *ast.Field: 54 - if _, ok := x.Label.(*ast.BasicLit); ok { 55 - x.Label = astutil.Apply(x.Label, nil, sc.replace).(ast.Label) 53 + if bl, ok := x.Label.(*ast.BasicLit); ok { 54 + str, err := strconv.Unquote(bl.Value) 55 + if err == nil && sc.scope[str] { 56 + x.Label = ast.NewIdent(str) 57 + } 56 58 } 57 59 } 58 60 } ··· 101 103 } 102 104 return true 103 105 } 104 - 105 - func (s *labelSimplifier) replace(c astutil.Cursor) bool { 106 - switch x := c.Node().(type) { 107 - case *ast.BasicLit: 108 - str, err := strconv.Unquote(x.Value) 109 - if err == nil && s.scope[str] { 110 - c.Replace(ast.NewIdent(str)) 111 - } 112 - } 113 - return false 114 - }