Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 5139f7f

Browse files
committed
Delete unused functions, fix some lints and unnecessary comments
1 parent 9ee4277 commit 5139f7f

File tree

5 files changed

+9
-93
lines changed

5 files changed

+9
-93
lines changed

analyze.go

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,6 @@ func getKindFor(v cue.Value) (TSType, error) {
4646
return TSType(tt), nil
4747
}
4848

49-
func getForceText(v cue.Value) string {
50-
var found bool
51-
var attr cue.Attribute
52-
for _, a := range v.Attributes(cue.ValueAttr) {
53-
if a.Name() == attrname {
54-
found = true
55-
attr = a
56-
}
57-
}
58-
if !found {
59-
return ""
60-
}
61-
62-
ft, found, err := attr.Lookup(0, attrForceText)
63-
if err != nil || !found {
64-
return ""
65-
}
66-
67-
return ft
68-
}
69-
70-
func targetsAnyKind(v cue.Value) bool {
71-
return targetsKind(v)
72-
}
73-
7449
func targetsKind(v cue.Value, kinds ...TSType) bool {
7550
vkind, err := getKindFor(v)
7651
if err != nil {
@@ -88,23 +63,6 @@ func targetsKind(v cue.Value, kinds ...TSType) bool {
8863
return false
8964
}
9065

91-
// containsReference recursively flattens expressions within a Value to find all
92-
// its constituent Values, and checks if any of those Values are references.
93-
//
94-
// It does NOT walk struct fields - only expression structures, as returned from Expr().
95-
// Remember that Expr() _always_ drops values in default branches.
96-
func containsReference(v cue.Value) bool {
97-
if isReference(v) {
98-
return true
99-
}
100-
for _, dv := range flatten(v) {
101-
if isReference(dv) {
102-
return true
103-
}
104-
}
105-
return false
106-
}
107-
10866
// containsCuetsyReference does the same as containsReference, but returns true
10967
// iff at least one referenced node passes the targetsKind predicate check
11068
func containsCuetsyReference(v cue.Value, kinds ...TSType) bool {
@@ -298,19 +256,19 @@ type listField struct {
298256
props listProps
299257
}
300258

301-
func (li *listField) eq(oli *listField) bool {
302-
if li.props.isOpen == oli.props.isOpen && li.props.divergentTypes == oli.props.divergentTypes && li.lenElems == oli.lenElems {
303-
if !li.props.isOpen {
304-
if li.lenElems == 0 {
259+
func (l *listField) eq(oli *listField) bool {
260+
if l.props.isOpen == oli.props.isOpen && l.props.divergentTypes == oli.props.divergentTypes && l.lenElems == oli.lenElems {
261+
if !l.props.isOpen {
262+
if l.lenElems == 0 {
305263
return true
306264
}
307265
p := cue.MakePath(cue.Index(0))
308266
// Sloppy, but enough to cover all but really complicated cases that
309267
// are likely unsupportable anyway
310-
return li.v.LookupPath(p).Equals(oli.v.LookupPath(p))
268+
return l.v.LookupPath(p).Equals(oli.v.LookupPath(p))
311269
}
312270

313-
return li.anyType.Subsume(oli.anyType, cue.Raw(), cue.Schema()) == nil && oli.anyType.Subsume(li.anyType, cue.Raw(), cue.Schema()) == nil
271+
return l.anyType.Subsume(oli.anyType, cue.Raw(), cue.Schema()) == nil && oli.anyType.Subsume(l.anyType, cue.Raw(), cue.Schema()) == nil
314272
}
315273

316274
return false

dobuild.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func doit(conf NewConfig, inst *cue.Instance) (result []tsast.Decl, err error) {
4242
panic("TODO")
4343
}
4444

45-
func (c *buildContext) build(name string, v cue.Value) *tsoutput {
45+
func (b *buildContext) build(name string, v cue.Value) *tsoutput {
4646
// TODO should we let errors escape here? Maybe only unsupported-type ones?
47-
return newTypeBuilder(c).enterGen(nil, name, v)
47+
return newTypeBuilder(b).enterGen(nil, name, v)
4848
}
4949

50-
func (c *buildContext) makeRef(inst *cue.Instance, ref []string) string {
50+
func (b *buildContext) makeRef(inst *cue.Instance, ref []string) string {
5151
ref = append([]string{}, ref...)
5252

5353
// NOTE this is where oapi does things with its NameFunc

generator.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cuetsy
22

33
import (
4-
"bytes"
54
"fmt"
65
"math/bits"
76
"sort"
87
"strings"
9-
"text/template"
108

119
"cuelang.org/go/cue"
1210
"cuelang.org/go/cue/ast"
@@ -17,10 +15,8 @@ import (
1715

1816
const (
1917
attrname = "cuetsy"
20-
attrEnumDefault = "enumDefault"
2118
attrEnumMembers = "memberNames"
2219
attrKind = "kind"
23-
attrForceText = "forceText"
2420
)
2521

2622
// TSType strings indicate the kind of TypeScript declaration to which a CUE
@@ -177,15 +173,6 @@ func (g *generator) addErr(err error) {
177173
}
178174
}
179175

180-
func execGetString(t *template.Template, data interface{}) (string, error) {
181-
var tpl bytes.Buffer
182-
if err := t.Execute(&tpl, data); err != nil {
183-
return "", err
184-
}
185-
result := tpl.String()
186-
return result, nil
187-
}
188-
189176
func (g *generator) decl(name string, v cue.Value) []ts.Decl {
190177
tst, err := getKindFor(v)
191178
if err != nil {
@@ -1024,11 +1011,6 @@ func (g generator) tsPrintDefault(v cue.Value) (bool, ts.Expr, error) {
10241011
// Render a string containing a Typescript semantic equivalent to the provided
10251012
// Value for placement in a single field, if possible.
10261013
func (g generator) tsprintField(v cue.Value, isType bool) (ts.Expr, error) {
1027-
// Let the forceText attribute supersede everything.
1028-
if ft := getForceText(v); ft != "" {
1029-
return ts.Raw(ft), nil
1030-
}
1031-
10321014
if hasEnumReference(v) {
10331015
ref, err := g.genEnumReference(v)
10341016
return ref.T, err
@@ -1325,12 +1307,10 @@ func refAsInterface(v cue.Value) (ts.Expr, error) {
13251307
return ts.Ident(dstr), nil
13261308
}
13271309
case *ast.SelectorExpr:
1328-
// panic("case 2")
13291310
if targetsKind(deref, TypeInterface) {
13301311
return ts.Ident(dstr), nil
13311312
}
13321313
case *ast.Ident:
1333-
// panic("case 3")
13341314
if targetsKind(deref, TypeInterface) {
13351315
str, ok := dvals[0].Source().(fmt.Stringer)
13361316
if !ok {
@@ -1410,12 +1390,10 @@ func referenceValueAs(v cue.Value, kinds ...TSType) (ts.Expr, error) {
14101390
return ts.Ident(dstr), nil
14111391
}
14121392
case *ast.SelectorExpr:
1413-
// panic("case 2")
14141393
if targetsKind(deref, kinds...) {
14151394
return ts.Ident(dstr), nil
14161395
}
14171396
case *ast.Ident:
1418-
// panic("case 3")
14191397
if targetsKind(deref, kinds...) {
14201398
str, ok := dvals[0].Source().(fmt.Stringer)
14211399
if !ok {

ts/ast/ast.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,6 @@ var (
9999
_ Expr = Num{}
100100
)
101101

102-
type Raw struct {
103-
Data string
104-
}
105-
106-
func (r Raw) decl() {}
107-
func (r Raw) expr() {}
108-
func (r Raw) String() string {
109-
return r.Data
110-
}
111-
112102
type Ident struct {
113103
Name string
114104

ts/ts.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ func Union(elems ...Expr) Expr {
4646
return ast.ParenExpr{Expr: U}
4747
}
4848

49-
func Raw(data string) ast.Raw {
50-
// pc, file, no, ok := runtime.Caller(1)
51-
// details := runtime.FuncForPC(pc)
52-
// if ok && details != nil {
53-
// fmt.Printf("fix: ts.Raw used by %s at %s#%d\n", details.Name(), file, no)
54-
// }
55-
56-
return ast.Raw{Data: data}
57-
}
58-
5949
func Object(fields map[string]Expr) Expr {
6050
elems := make([]ast.KeyValueExpr, 0, len(fields))
6151
for k, v := range fields {

0 commit comments

Comments
 (0)