Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions goblin.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ func AttemptExprAsType(e ast.Expr, fset *token.FileSet) map[string]interface{} {
}
}

if n, ok := e.(*ast.Ellipsis); ok {
return map[string]interface{}{
"kind": "type",
"type": "ellipsis",
"element": DumpExprAsType(n.Elt, fset),
"position": DumpPosition(fset.Position(e.Pos())),
}
}
if n, ok := e.(*ast.InterfaceType); ok {
return map[string]interface{}{
"kind": "type",
Expand Down Expand Up @@ -371,11 +379,15 @@ func DumpExpr(e ast.Expr, fset *token.FileSet) map[string]interface{} {
}

if n, ok := e.(*ast.TypeAssertExpr); ok {
var asserted interface{} = nil
if n.Type != nil {
asserted = DumpExprAsType(n.Type, fset)
}
return map[string]interface{}{
"kind": "expression",
"type": "type-assert",
"target": DumpExpr(n.X, fset),
"asserted": DumpExprAsType(n.Type, fset),
"asserted": asserted,
"position": DumpPosition(fset.Position(e.Pos())),
}
}
Expand Down Expand Up @@ -610,13 +622,12 @@ func DumpGenDecl(decl *ast.GenDecl, fset *token.FileSet) map[string]interface{}
results := make([]interface{}, len(decl.Specs))
switch decl.Tok {
case token.TYPE:
if len(decl.Specs) != 1 {
pos := fset.PositionFor(decl.Pos(), true)
Perish(pos, "syntax_error", "unexpected number of tokens ("+string(len(decl.Specs))+") in type alias (expected 1)")
if len(decl.Specs) == 1 {
return DumpTypeAlias(decl.Specs[0].(*ast.TypeSpec), fset)
}
for i, v := range decl.Specs {
results[i] = DumpTypeAlias(v.(*ast.TypeSpec), fset)
}
// EARLY RETURN
return DumpTypeAlias(decl.Specs[0].(*ast.TypeSpec), fset)

case token.IMPORT:
prettyToken = "import"
for i, v := range decl.Specs {
Expand Down