diff --git a/Source/buildimplementationjs.go b/Source/buildimplementationjs.go index ed980d85..06aa9026 100644 --- a/Source/buildimplementationjs.go +++ b/Source/buildimplementationjs.go @@ -477,11 +477,14 @@ func buildJSInjectionClass(component ComponentDefinition, subComponent Component } if readOnly { cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s);", getter.PropertyGet, class.ClassName, getter.MethodName) + cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s);", camelize(getter.PropertyGet), class.ClassName, getter.MethodName) } else { cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s, Cv8%s::v8%s);", setter.PropertySet, class.ClassName, getter.MethodName, class.ClassName, setter.MethodName) + cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s, Cv8%s::v8%s);", camelize(setter.PropertySet), class.ClassName, getter.MethodName, class.ClassName, setter.MethodName) } } else { cppw.Writeln(" Cv8toolsUtils::Set_proto_method(localClassTemplate, \"%s\", Cv8%s::v8%s);", method.MethodName, class.ClassName, method.MethodName) + cppw.Writeln(" Cv8toolsUtils::Set_proto_method(localClassTemplate, \"%s\", Cv8%s::v8%s);", camelize(method.MethodName), class.ClassName, method.MethodName) } } cppw.Writeln("") diff --git a/Source/buildimplementationts.go b/Source/buildimplementationts.go index 4dfb7810..dd18a2c0 100644 --- a/Source/buildimplementationts.go +++ b/Source/buildimplementationts.go @@ -37,8 +37,9 @@ import ( "errors" "log" "path" + "regexp" "strings" - "unicode" + "unicode/utf8" ) type TypeScriptOptions struct { @@ -57,7 +58,7 @@ func BuildImplementationTS( log.Printf("Creating TypeScript Implementation") options := TypeScriptOptions{ - Camelize: false, + Camelize: true, JsArrays: false, LineLength: 80, } @@ -106,11 +107,11 @@ func writeTypescriptEnum( writer LanguageWriter, options TypeScriptOptions, ) error { - writer.Writeln("const enum %s {", getId(enum.Name, options)) + writer.Writeln("const enum %s {", getTypeId(enum.Name, options)) writer.Indentation++ for _, option := range enum.Options { writeCommentEnumOption(option, writer, options) - identifier := getId(option.Name, options) + identifier := getTypeId(option.Name, options) value := option.Value writer.Writeln("%s = %d,", identifier, value) } @@ -140,7 +141,7 @@ func writeTypescriptInterface( options TypeScriptOptions, ) error { writeCommentClass(class, writer, options) - identifier := getId(class.ClassName, options) + identifier := getTypeId(class.ClassName, options) extends := "" if class.ParentClass != "" { extends = "extends " + class.ParentClass + " " @@ -178,18 +179,18 @@ func writeTypescriptMethod( writer.Writeln("") writeCommentMethod(class, method, writer, options) writer.BeginLine() - writer.Printf("%s: (", getId(method.MethodName, options)) + writer.Printf("%s(", getName(method.MethodName, options)) for i, param := range inParams { if param.ParamOptional == "true" { writer.Printf( "%s?: %s", - getId(param.ParamName, options), + getName(param.ParamName, options), getType(param, options), ) } else { writer.Printf( "%s: %s", - getId(param.ParamName, options), + getName(param.ParamName, options), getType(param, options), ) } @@ -197,14 +198,14 @@ func writeTypescriptMethod( writer.Printf(", ") } } - writer.Printf(") => ") + writer.Printf("): ") if len(outParams) > 0 { writer.Printf("[") for i, param := range outParams { writer.Printf( "%s: %s", - getId(param.ParamName, options), + getName(param.ParamName, options), getType(param, options), ) if i+1 < len(outParams) { @@ -258,7 +259,7 @@ func writeTypescriptProperty( writer.Writeln( "%s%s: %s;", readOnly, - getId(getter.PropertyGet, options), + getName(getter.PropertyGet, options), getType(returnParams[0], options), ) return nil @@ -287,7 +288,11 @@ func filterOptional(params []ComponentDefinitionParam) []ComponentDefinitionPara return result } -func getId(identifier string, options TypeScriptOptions) string { +func getTypeId(identifier string, options TypeScriptOptions) string { + return identifier +} + +func getName(identifier string, options TypeScriptOptions) string { if options.Camelize { return camelize(identifier) } @@ -327,13 +332,24 @@ func getTypeString( return paramType } -func camelize(identifier string) string { - if len(identifier) == 0 { - return identifier +func camelize(str string) string { + r, _ := regexp.Compile("^([A-Z]+)([A-Z])(.*)") + result := r.FindStringSubmatch(str) + + if len(result) > 0 { + if len(result) > 1 { + if len(result) == 4 && result[3] == "" { + str = strings.ToLower(str) + } else { + str = strings.ToLower(result[1]) + strings.Join(result[2:], "") + } + } + } else { + r, _ := utf8.DecodeRuneInString(str) + str = strings.ToLower(string(r)) + str[len(string(r)):] } - result := []rune(identifier) - result[0] = unicode.ToLower(result[0]) - return string(result) + + return str } func writeCommentEnumOption( @@ -407,7 +423,7 @@ func writeCommentInParams( ) { for _, param := range params { prefix := " * @param {" + getType(param, options) + "} " + - getId(param.ParamName, options) + " " + getName(param.ParamName, options) + " " lines := getCommentLines(prefix, param.ParamDescription, writer, options) if len(lines) > 0 { writer.Writeln(prefix + lines[0]) @@ -427,7 +443,7 @@ func writeCommentOutParams( ) { for _, param := range params { prefix := " * @returns {" + getType(param, options) + "} " - prefix2 := prefix + getId(param.ParamName, options) + " " + prefix2 := prefix + getName(param.ParamName, options) + " " lines := getCommentLines(prefix2, param.ParamDescription, writer, options) if len(lines) > 0 { writer.Writeln(prefix2 + lines[0])