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:
Jaco Greeff
2020-02-20 21:36:12 +01:00
committed by GitHub
parent dd0a31803f
commit 1c1bfb295d
9 changed files with 62 additions and 39 deletions
+2 -4
View File
@@ -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']);
+6 -3
View File
@@ -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']);
+1 -1
View File
@@ -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]);
}