Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public typeDefFromMetaType (metaType: MetaType, typeIndex?: TypeIndex): TypeDef {
return withTypeString({
info: TypeDefInfo.Null,
type: '',
...this.typeDefDefFields(metaType, typeIndex),
...this.typeDefIdFields(metaType)
}) as TypeDef;
}
private typeDefForTupleStruct (def: MetaTypeDefTupleStruct | MetaTypeDefEnumVariantTupleStruct): Pick {
const tupleStructTypes = (def as MetaTypeDefTupleStruct)['tuple_struct.types'] || (def as MetaTypeDefEnumVariantTupleStruct)['tuple_struct_variant.types'];
const tupleStructNameIndex = (def as MetaTypeDefEnumVariantTupleStruct)['tuple_struct_variant.name'];
return withTypeString({
info: TypeDefInfo.Tuple,
...(tupleStructNameIndex
? { name: this.stringAt(tupleStructNameIndex) }
: {}
),
sub: tupleStructTypes.map((fieldIndex: number, index: number): TypeDef => ({
...this.typeDefFromMetaTypeAt(fieldIndex),
index
}))
});
}
}
public typeDefForStruct (def: MetaTypeDefStruct | MetaTypeDefEnumVariantStruct): Pick {
const structFields = (def as MetaTypeDefStruct)['struct.fields'] || (def as MetaTypeDefEnumVariantStruct)['struct_variant.fields'];
const structNameIndex = (def as MetaTypeDefEnumVariantStruct)['struct_variant.name'];
return withTypeString({
info: TypeDefInfo.Struct,
...(structNameIndex
? { name: this.stringAt(structNameIndex) }
: {}
),
sub: structFields.map((field: MetaTypeDefStructField): TypeDef => ({
...this.typeDefFromMetaTypeAt(field.type),
name: this.stringAt(field.name)
}))
});
}