MCPcopy Create free account
hub / github.com/glideapps/quicktype / processType

Function processType

src/GatherNames.ts:18–55  ·  view source on GitHub ↗
(t: Type, names: OrderedSet<string>, parentNames: OrderedSet<string> | null)

Source from the content-addressed store, hash-verified

16 let processed: Set<Type> = Set();
17
18 function processType(t: Type, names: OrderedSet<string>, parentNames: OrderedSet<string> | null) {
19 if (t.isNamedType()) {
20 const alternatives: string[] = [];
21 names.forEach(name => {
22 if (parentNames !== null) {
23 alternatives.push(...parentNames.map(pn => `${pn}_${name}`).toArray());
24 }
25 alternatives.push(`${name}_${t.kind}`);
26 if (parentNames !== null) {
27 alternatives.push(...parentNames.map(pn => `${pn}_${name}_${t.kind}`).toArray());
28 }
29 });
30 t.addNames({ names, alternatives: OrderedSet(alternatives) }, true);
31 }
32 if (processed.has(t)) return;
33 processed = processed.add(t);
34 matchCompoundType(
35 t,
36 arrayType => {
37 processType(arrayType.items, names.map(pluralize.singular), parentNames);
38 },
39 classType => {
40 const properties = classType.properties.sortBy((_, n) => n);
41 properties.forEach((propertyType, propertyName) => {
42 processType(propertyType, OrderedSet([propertyName]), names);
43 });
44 },
45 mapType => {
46 processType(mapType.values, names.map(pluralize.singular), parentNames);
47 },
48 unionType => {
49 const members = unionType.members.sortBy(member => member.kind);
50 members.forEach(memberType => {
51 processType(memberType, names, parentNames);
52 });
53 }
54 );
55 }
56
57 graph.topLevels.forEach((t, name) => {
58 processType(t, OrderedSet([name]), null);

Callers 1

gatherNamesFunction · 0.85

Calls 3

matchCompoundTypeFunction · 0.90
addMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…