Merge pull request #55 from moul/dev/gfanton/add-js-reserved-prefix-helper
Add jsSuffixReservedKeyword helper
This commit is contained in:
commit
21cba66d10
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@ -14,6 +15,8 @@ import (
|
||||
options "google.golang.org/genproto/googleapis/api/annotations"
|
||||
)
|
||||
|
||||
var jsReservedRe *regexp.Regexp = regexp.MustCompile(`(^|[^A-Za-z])(do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)($|[^A-Za-z])`)
|
||||
|
||||
var ProtoHelpersFuncMap = template.FuncMap{
|
||||
"string": func(i interface {
|
||||
String() string
|
||||
@ -66,6 +69,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
||||
"isFieldRepeated": isFieldRepeated,
|
||||
"goType": goType,
|
||||
"jsType": jsType,
|
||||
"jsSuffixReserved": jsSuffixReservedKeyword,
|
||||
"namespacedFlowType": namespacedFlowType,
|
||||
"httpVerb": httpVerb,
|
||||
"httpPath": httpPath,
|
||||
@ -205,6 +209,10 @@ func jsType(f *descriptor.FieldDescriptorProto) string {
|
||||
}
|
||||
}
|
||||
|
||||
func jsSuffixReservedKeyword(s string) string {
|
||||
return jsReservedRe.ReplaceAllString(s, "${1}${2}_${3}")
|
||||
}
|
||||
|
||||
func shortType(s string) string {
|
||||
t := strings.Split(s, ".")
|
||||
return t[len(t)-1]
|
||||
|
Loading…
Reference in New Issue
Block a user