@cosmology/ast
Version:
Cosmos TypeScript AST generation
28 lines (26 loc) • 797 B
text/typescript
import * as t from '@babel/types';
import { ProtoParseContext } from '../../context';
import { ProtoType } from '@cosmology/types';
import { getAminoTypeName, getTypeUrl } from '../../amino';
export const createTypeUrlProperty = (
context: ProtoParseContext,
proto: ProtoType
) => {
const typeUrl = getTypeUrl(context.ref.proto, proto);
if (!typeUrl) return;
return t.objectProperty(
t.identifier('typeUrl'),
t.stringLiteral(typeUrl)
)
};
export const createAminoTypeProperty = (
context: ProtoParseContext,
proto: ProtoType
) => {
const str = getAminoTypeName(context, context.ref.proto, proto);
if (!str || str.startsWith('/')) return;
return t.objectProperty(
t.identifier('aminoType'),
t.stringLiteral(str)
)
};