From 36d1b0f3bb5dce4b1df08bb3f9f87739305c7c2b Mon Sep 17 00:00:00 2001 From: Liam Rathke Date: Tue, 29 Jun 2021 17:42:16 -0400 Subject: [PATCH] Fixes generation without recasting component Signed-off-by: Liam Rathke Signed-off-by: Liam Rathke --- pkg/view/tsgen/converter.go | 10 +++++++++- pkg/view/tsgen/model.go | 10 ++++++---- pkg/view/tsgen/tsgen.go | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/view/tsgen/converter.go b/pkg/view/tsgen/converter.go index 9aad349c9e..c33a877664 100644 --- a/pkg/view/tsgen/converter.go +++ b/pkg/view/tsgen/converter.go @@ -52,8 +52,16 @@ func (c *Converter) visit(w *gostrings.Builder, t reflect.Type, depth int) ([]st } componentNames = append(componentNames, names...) case reflect.Map: + var keyString string = t.Key().String() + switch keyString { + // typing for validation steps causes errors with reflection, so we just lock string keys. + case "component.FormValidator": + keyString = "string" + } + // if a map is found, key the key and element to build a typescript object definition. - w.WriteString("{[key:" + t.Key().String() + "]:") + w.WriteString("{[key:" + keyString + "]:") + names, err := c.visit(w, t.Elem(), depth+1) if err != nil { return nil, err diff --git a/pkg/view/tsgen/model.go b/pkg/view/tsgen/model.go index ceb6f0f310..3e9dab7ee6 100644 --- a/pkg/view/tsgen/model.go +++ b/pkg/view/tsgen/model.go @@ -82,10 +82,12 @@ func (c Component) Referenced() []ImportReference { var refs []ImportReference for _, r := range list { - refs = append(refs, ImportReference{ - Name: r, - ImportName: strcase.KebabCase(r), - }) + if c.Name != r { // Prevent nested/recursive component imports + refs = append(refs, ImportReference{ + Name: r, + ImportName: strcase.KebabCase(r), + }) + } } return refs diff --git a/pkg/view/tsgen/tsgen.go b/pkg/view/tsgen/tsgen.go index de94bd1838..4804f4e4ee 100644 --- a/pkg/view/tsgen/tsgen.go +++ b/pkg/view/tsgen/tsgen.go @@ -124,7 +124,7 @@ func (tg *TSGen) Reflect(names []string) (*Model, error) { m := &Model{} if err := gob.NewDecoder(&stdout).Decode(m); err != nil { - return nil, fmt.Errorf("decode reflet model: %w", err) + return nil, fmt.Errorf("decode reflect model: %w", err) } return m, nil