5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-01 15:10:48 +08:00

postfix [] in instance is element accessor, not array type declaration

This commit is contained in:
joshuapare 2025-04-10 08:35:49 -05:00
parent 194b0586ba
commit bc7b816c37
No known key found for this signature in database
3 changed files with 19 additions and 18 deletions

View File

@ -63,18 +63,18 @@ export namespace binding_test {
DoubleFour: number[][];
Triple: number[][][];
SingleMap: Record<string, number>;
SliceMap: Record<string, number[]>;
DoubleSliceMap: Record<string, number[][]>;
ArrayMap: Record<string, number[]>;
DoubleArrayMap1: Record<string, number[][]>;
DoubleArrayMap2: Record<string, number[][]>;
DoubleArrayMap3: Record<string, number[][]>;
SliceMap: Record<string, Array<number>>;
DoubleSliceMap: Record<string, Array<Array<number>>>;
ArrayMap: Record<string, Array<number>>;
DoubleArrayMap1: Record<string, Array<Array<number>>>;
DoubleArrayMap2: Record<string, Array<Array<number>>>;
DoubleArrayMap3: Record<string, Array<Array<number>>>;
OneStructs: DeepMessage[];
TwoStructs: DeepMessage[][];
ThreeStructs: DeepMessage[][][];
MapStructs: Record<string, DeepMessage[]>;
MapTwoStructs: Record<string, DeepMessage[][]>;
MapThreeStructs: Record<string, DeepMessage[][][]>;
MapStructs: Record<string, Array<DeepMessage>>;
MapTwoStructs: Record<string, Array<Array<DeepMessage>>>;
MapThreeStructs: Record<string, Array<Array<Array<DeepMessage>>>>;
static createFrom(source: any = {}) {
return new DeepElements(source);
@ -97,9 +97,9 @@ export namespace binding_test {
this.OneStructs = this.convertValues(source["OneStructs"], DeepMessage);
this.TwoStructs = this.convertValues(source["TwoStructs"], DeepMessage);
this.ThreeStructs = this.convertValues(source["ThreeStructs"], DeepMessage);
this.MapStructs = this.convertValues(source["MapStructs"], DeepMessage[], true);
this.MapTwoStructs = this.convertValues(source["MapTwoStructs"], DeepMessage[][], true);
this.MapThreeStructs = this.convertValues(source["MapThreeStructs"], DeepMessage[][][], true);
this.MapStructs = this.convertValues(source["MapStructs"], Array<DeepMessage>, true);
this.MapTwoStructs = this.convertValues(source["MapTwoStructs"], Array<Array<DeepMessage>>, true);
this.MapThreeStructs = this.convertValues(source["MapThreeStructs"], Array<Array<Array<DeepMessage>>>, true);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {

View File

@ -40,9 +40,7 @@ const (
jsVariableNameRegex = `^([A-Z]|[a-z]|\$|_)([A-Z]|[a-z]|[0-9]|\$|_)*$`
)
var (
jsVariableUnsafeChars = regexp.MustCompile(`[^A-Za-z0-9_]`)
)
var jsVariableUnsafeChars = regexp.MustCompile(`[^A-Za-z0-9_]`)
func nameTypeOf(typeOf reflect.Type) string {
tname := typeOf.Name()
@ -277,6 +275,7 @@ func (t *typeScriptClassBuilder) AddMapField(fieldName string, field reflect.Str
valueType := field.Type.Elem()
valueTypeName := nameTypeOf(valueType)
valueTypeSuffix := ""
valueTypePrefix := ""
if valueType.Kind() == reflect.Ptr {
valueType = valueType.Elem()
valueTypeName = nameTypeOf(valueType)
@ -289,7 +288,8 @@ func (t *typeScriptClassBuilder) AddMapField(fieldName string, field reflect.Str
}
valueType = valueType.Elem()
valueTypeName = nameTypeOf(valueType)
valueTypeSuffix = strings.Repeat("[]", arrayDepth)
valueTypeSuffix = strings.Repeat(">", arrayDepth)
valueTypePrefix = strings.Repeat("Array<", arrayDepth)
}
if valueType.Kind() == reflect.Ptr {
valueType = valueType.Elem()
@ -325,10 +325,10 @@ func (t *typeScriptClassBuilder) AddMapField(fieldName string, field reflect.Str
fieldName = fmt.Sprintf(`"%s"?`, strippedFieldName)
}
}
t.fields = append(t.fields, fmt.Sprintf("%s%s: Record<%s, %s>;", t.indent, fieldName, keyTypeStr, valueTypeName+valueTypeSuffix))
t.fields = append(t.fields, fmt.Sprintf("%s%s: Record<%s, %s>;", t.indent, fieldName, keyTypeStr, valueTypePrefix+valueTypeName+valueTypeSuffix))
if valueType.Kind() == reflect.Struct {
t.constructorBody = append(t.constructorBody, fmt.Sprintf("%s%sthis%s = this.convertValues(source[\"%s\"], %s, true);",
t.indent, t.indent, dotField, strippedFieldName, t.prefix+valueTypeName+valueTypeSuffix+t.suffix))
t.indent, t.indent, dotField, strippedFieldName, t.prefix+valueTypePrefix+valueTypeName+valueTypeSuffix+t.suffix))
} else {
t.constructorBody = append(t.constructorBody, fmt.Sprintf("%s%sthis%s = source[\"%s\"];",
t.indent, t.indent, dotField, strippedFieldName))

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `-skipembedcreate` flag to build and dev command to improve compile and recompile speed [#4143](https://github.com/wailsapp/wails/pull/4143) by @josStorer
### Fixed
- Fixed typescript generation of maps with key of array of structs by @joshuapare in [#4209](https://github.com/wailsapp/wails/pull/4209)
- Fixed -m build flag for dev command not working when recompiling in [#4141](https://github.com/wailsapp/wails/pull/4141) by @josStorer
- Fixed window restoration behavior after minimization by @superDingda in [#4109](https://github.com/wailsapp/wails/issues/4109)
- Fixed excessive console logging after updating to v2.10.1 by @superDingda in [#4111](https://github.com/wailsapp/wails/issues/4111)