go/ast/astutil: support Go 1.8 type aliases

Change-Id: I67d561755c1c06c0438f2b42e6a13efb024558c4
Reviewed-on: https://go-review.googlesource.com/32732
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2016-11-03 17:52:54 -04:00
parent 9a286cdc33
commit 50193ec1c5
1 changed files with 7 additions and 1 deletions

View File

@ -200,6 +200,11 @@ func childrenOf(n ast.Node) []ast.Node {
// Then add fake Nodes for bare tokens. // Then add fake Nodes for bare tokens.
switch n := n.(type) { switch n := n.(type) {
case *ast.AliasSpec:
// TODO(adonovan): AliasSpec.{Doc,Comment}?
// Guess position of "=>" assuming well-formattedness.
children = append(children, tok(n.Orig.Pos()-token.Pos(len("=> ")), len("=>")))
case *ast.ArrayType: case *ast.ArrayType:
children = append(children, children = append(children,
tok(n.Lbrack, len("[")), tok(n.Lbrack, len("[")),
@ -623,7 +628,8 @@ func NodeDescription(n ast.Node) string {
return fmt.Sprintf("unary %s operation", n.Op) return fmt.Sprintf("unary %s operation", n.Op)
case *ast.ValueSpec: case *ast.ValueSpec:
return "value specification" return "value specification"
case *ast.AliasSpec:
return "alias specification"
} }
panic(fmt.Sprintf("unexpected node type: %T", n)) panic(fmt.Sprintf("unexpected node type: %T", n))
} }