deps: Update thema, use CUE fork (#60496)
* deps: Update thema, use CUE fork * Remove superfluous openapi-codegen output * Update thema again to catch cuetsy changes * Rerun codegen with latest * Latest thema, removes cuetsy update * Latest of cuetsy * Update type usage * One last cuetsy rollback * Update playlist summary tests * More lint fixes * Remove TS veneer changes for VariableHide Co-authored-by: Clarity-89 <homes89@ukr.net>
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/dave/dst"
|
||||
"github.com/dave/dst/dstutil"
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/imports"
|
||||
)
|
||||
@@ -163,3 +165,75 @@ func (d prefixmod) do(n *ast.Ident) {
|
||||
n.Name = d.replace
|
||||
}
|
||||
}
|
||||
|
||||
func isSingleTypeDecl(gd *dst.GenDecl) bool {
|
||||
if gd.Tok == token.TYPE && len(gd.Specs) == 1 {
|
||||
_, is := gd.Specs[0].(*dst.TypeSpec)
|
||||
return is
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isAdditionalPropertiesStruct(tspec *dst.TypeSpec) (dst.Expr, bool) {
|
||||
strct, is := tspec.Type.(*dst.StructType)
|
||||
if is && len(strct.Fields.List) == 1 && strct.Fields.List[0].Names[0].Name == "AdditionalProperties" {
|
||||
return strct.Fields.List[0].Type, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func DecoderCompactor() dstutil.ApplyFunc {
|
||||
return func(c *dstutil.Cursor) bool {
|
||||
f, is := c.Node().(*dst.File)
|
||||
if !is {
|
||||
return false
|
||||
}
|
||||
|
||||
compact := make(map[string]bool)
|
||||
// walk the file decls
|
||||
for _, decl := range f.Decls {
|
||||
if fd, is := decl.(*dst.FuncDecl); is {
|
||||
compact[ddepoint(fd.Recv.List[0].Type).(*dst.Ident).Name] = true
|
||||
}
|
||||
}
|
||||
if len(compact) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
replace := make(map[string]dst.Expr)
|
||||
// Walk again, looking for types we found
|
||||
for _, decl := range f.Decls {
|
||||
if gd, is := decl.(*dst.GenDecl); is && isSingleTypeDecl(gd) {
|
||||
if tspec := gd.Specs[0].(*dst.TypeSpec); compact[tspec.Name.Name] {
|
||||
if expr, is := isAdditionalPropertiesStruct(tspec); is {
|
||||
replace[tspec.Name.Name] = expr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dstutil.Apply(f, func(c *dstutil.Cursor) bool {
|
||||
switch x := c.Node().(type) {
|
||||
case *dst.FuncDecl:
|
||||
c.Delete()
|
||||
case *dst.GenDecl:
|
||||
if isSingleTypeDecl(x) && compact[x.Specs[0].(*dst.TypeSpec).Name.Name] {
|
||||
c.Delete()
|
||||
}
|
||||
case *dst.Field:
|
||||
if id, is := x.Type.(*dst.Ident); is {
|
||||
if expr, has := replace[id.Name]; has {
|
||||
x.Type = expr
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}, nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
func ddepoint(e dst.Expr) dst.Expr {
|
||||
if star, is := e.(*dst.StarExpr); is {
|
||||
return star.X
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user