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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ import (
|
|||||||
options "google.golang.org/genproto/googleapis/api/annotations"
|
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{
|
var ProtoHelpersFuncMap = template.FuncMap{
|
||||||
"string": func(i interface {
|
"string": func(i interface {
|
||||||
String() string
|
String() string
|
||||||
@ -66,6 +69,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
"isFieldRepeated": isFieldRepeated,
|
"isFieldRepeated": isFieldRepeated,
|
||||||
"goType": goType,
|
"goType": goType,
|
||||||
"jsType": jsType,
|
"jsType": jsType,
|
||||||
|
"jsSuffixReserved": jsSuffixReservedKeyword,
|
||||||
"namespacedFlowType": namespacedFlowType,
|
"namespacedFlowType": namespacedFlowType,
|
||||||
"httpVerb": httpVerb,
|
"httpVerb": httpVerb,
|
||||||
"httpPath": httpPath,
|
"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 {
|
func shortType(s string) string {
|
||||||
t := strings.Split(s, ".")
|
t := strings.Split(s, ".")
|
||||||
return t[len(t)-1]
|
return t[len(t)-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user