Skip to content

Commit

Permalink
cue/ast/astutil: remove deprecated API usage
Browse files Browse the repository at this point in the history
This removes some deprecated API usages in the astutil package.

While here, fix a typo and some unordered imports.

Updates #2480.

Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Change-Id: I3a4f424379a1bdb7e82c67841f891e292f3f0d09
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194643
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
NoamTD authored and mvdan committed May 13, 2024
1 parent b83ae37 commit 64bbf1b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cue/ast/astutil/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (f *applier) Before(c Cursor) applyVisitor {
node := c.Node()
if f.before == nil || (f.before(c) && node == c.Node()) {
f.commentStack = append(f.commentStack, f.current)
f.current = commentFrame{cg: node.Comments()}
f.current = commentFrame{cg: ast.Comments(node)}
f.visitComments(c, f.current.pos)
return f
}
Expand Down
9 changes: 4 additions & 5 deletions cue/ast/astutil/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/ast/astutil"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/format"
"cuelang.org/go/cue/token"
_ "cuelang.org/go/pkg"
Expand Down Expand Up @@ -80,14 +81,12 @@ func TestToFile(t *testing.T) {
t.Fatal(err)
}

var r cue.Runtime

inst, err := r.CompileFile(f)
if err != nil {
v := cuecontext.New().BuildFile(f)
if err := v.Err(); err != nil {
t.Fatal(err)
}

b, err := format.Node(inst.Value().Syntax(cue.Concrete(true)))
b, err := format.Node(v.Syntax(cue.Concrete(true)))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cue/ast/astutil/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// - change a predeclared identifier reference to use the __ident form,
// instead of introducing an alias.

// Sanitize rewrites File f in place to be well formed after automated
// Sanitize rewrites File f in place to be well-formed after automated
// construction of an AST.
//
// Rewrites:
Expand Down
4 changes: 2 additions & 2 deletions cue/ast/astutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CopyComments(to, from ast.Node) {
if from == nil {
return
}
ast.SetComments(to, from.Comments())
ast.SetComments(to, ast.Comments(from))
}

// CopyPosition sets the position of one node to another.
Expand All @@ -95,7 +95,7 @@ func CopyMeta(to, from ast.Node) ast.Node {
if from == nil {
return to
}
ast.SetComments(to, from.Comments())
ast.SetComments(to, ast.Comments(from))
ast.SetPos(to, from.Pos())
return to
}
Expand Down
3 changes: 2 additions & 1 deletion cue/ast/astutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"path"
"testing"

"cuelang.org/go/cue/ast"
"github.com/google/go-cmp/cmp"

"cuelang.org/go/cue/ast"
)

func TestImportInfo(t *testing.T) {
Expand Down

0 comments on commit 64bbf1b

Please sign in to comment.