MCPcopy Create free account
hub / github.com/wailsapp/wails / addField

Method addField

v2/internal/typescriptify/typescriptify.go:954–969  ·  view source on GitHub ↗
(fld, fldType string, isAnyType bool)

Source from the content-addressed store, hash-verified

952}
953
954func (t *typeScriptClassBuilder) addField(fld, fldType string, isAnyType bool) {
955 isOptional := strings.HasSuffix(fld, "?")
956 strippedFieldName := strings.ReplaceAll(fld, "?", "")
957 if !regexp.MustCompile(jsVariableNameRegex).Match([]byte(strippedFieldName)) {
958 fld = fmt.Sprintf(`"%s"`, strippedFieldName)
959 if isOptional {
960 fld += "?"
961 }
962 }
963 if isAnyType {
964 fldType = strings.Split(fldType, ".")[0]
965 t.fields = append(t.fields, fmt.Sprint(t.indent, "// Go type: ", fldType, "\n", t.indent, fld, ": any;"))
966 } else {
967 t.fields = append(t.fields, fmt.Sprint(t.indent, fld, ": ", fldType, ";"))
968 }
969}
970
971func indentLines(str string, i int) string {
972 lines := strings.Split(str, "\n")

Callers 5

AddSimpleArrayFieldMethod · 0.95
AddSimpleFieldMethod · 0.95
AddEnumFieldMethod · 0.95
AddStructFieldMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected