this repo has no description
0
fork

Configure Feed

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

cmd/cue: reuse astutil.ToFile for --path expressions

The logic is the same, so this saves us a little bit of duplication.
Noticed in passing while investigating a different issue.

While here, add TODOs about these ToFile APIs modifying the input AST.
This could very well be problematic if either func is called
from a public API, as this could affect end users.

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

+3 -7
+1 -7
cmd/cue/cmd/orphans.go
··· 214 214 "recordCount", ast.NewLit(token.INT, strconv.Itoa(len(objs))), 215 215 ) 216 216 } 217 - var f *ast.File 218 - if s, ok := expr.(*ast.StructLit); ok { 219 - f = &ast.File{Decls: s.Elts} 220 - } else { 221 - f = &ast.File{Decls: []ast.Decl{&ast.EmbedDecl{Expr: expr}}} 222 - } 223 - err := astutil.Sanitize(f) 217 + f, err := astutil.ToFile(expr) 224 218 if err != nil { 225 219 return nil, errors.Wrapf(err, token.NoPos, 226 220 "invalid combination of input files")
+1
cue/ast/astutil/file.go
··· 24 24 // references as appropriate. 25 25 func ToFile(x ast.Expr) (*ast.File, error) { 26 26 var f *ast.File 27 + // TODO(mvdan): SetRelPos modifies the input argument; if it's really needed, make a copy 27 28 if st, ok := x.(*ast.StructLit); ok { 28 29 f = &ast.File{Decls: st.Elts} 29 30 } else {
+1
internal/internal.go
··· 249 249 if n == nil { 250 250 return nil 251 251 } 252 + // TODO(mvdan): SetRelPos modifies the input argument; if it's really needed, make a copy 252 253 switch n := n.(type) { 253 254 case *ast.StructLit: 254 255 if preserveStructLit {