VecFixed now take sub, align ext with UInt (#1909)
* Allow nested definitions for fixed arrays * Comment nested test * Don't import U8aFixed + u8
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '@polkadot/types/create/types';
|
||||
import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -135,9 +135,7 @@ function tsUInt (definitions: object, def: TypeDef, imports: TypeImports): strin
|
||||
|
||||
/** @internal */
|
||||
function tsVec (definitions: object, def: TypeDef, imports: TypeImports): string {
|
||||
const type = def.info === TypeDefInfo.VecFixed
|
||||
? (def.ext as TypeDefExtVecFixed).type
|
||||
: (def.sub as TypeDef).type;
|
||||
const type = (def.sub as TypeDef).type;
|
||||
|
||||
if (def.info === TypeDefInfo.VecFixed && type === 'u8') {
|
||||
setImports(definitions, imports, ['U8aFixed']);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '@polkadot/types/create/types';
|
||||
import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
|
||||
|
||||
import { getTypeDef } from '@polkadot/types/create';
|
||||
import { paramsNotation } from '@polkadot/types/codec/utils';
|
||||
@@ -170,14 +170,17 @@ export function formatType (definitions: object, type: string | TypeDef, imports
|
||||
);
|
||||
}
|
||||
case TypeDefInfo.VecFixed: {
|
||||
if ((typeDef.ext as TypeDefExtVecFixed).type === 'u8') {
|
||||
const type = (typeDef.sub as TypeDef).type;
|
||||
|
||||
if (type === 'u8') {
|
||||
setImports(definitions, imports, ['U8aFixed']);
|
||||
|
||||
return 'U8aFixed';
|
||||
}
|
||||
|
||||
setImports(definitions, imports, ['Vec']);
|
||||
return formatVec(formatType(definitions, (typeDef.ext as TypeDefExtVecFixed).type, imports));
|
||||
|
||||
return formatVec(formatType(definitions, type, imports));
|
||||
}
|
||||
case TypeDefInfo.BTreeMap: {
|
||||
setImports(definitions, imports, ['BTreeMap']);
|
||||
|
||||
@@ -60,7 +60,7 @@ export function setImports (allDefs: object, imports: TypeImports, types: string
|
||||
// TypeDef.sub is a `TypeDef | TypeDef[]`
|
||||
if (Array.isArray(typeDef.sub)) {
|
||||
typeDef.sub.forEach((subType): void => setImports(allDefs, imports, [subType.type]));
|
||||
} else if (typeDef.sub) {
|
||||
} else if (typeDef.sub && (typeDef.info !== TypeDefInfo.VecFixed || typeDef.sub.type !== 'u8')) {
|
||||
// typeDef.sub is a TypeDef in this case
|
||||
setImports(allDefs, imports, [typeDef.sub.type]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user