MCPcopy Index your code
hub / github.com/processing/p5.js / typeObject

Function typeObject

utils/shared-helpers.mjs:82–123  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

80}
81
82export function typeObject(node) {
83 if (!node) return {};
84
85 if (node.type === 'OptionalType') {
86 return { optional: 1, ...typeObject(node.expression) };
87 } else if (node.type === 'UnionType') {
88 const names = node.elements.map(n => typeObject(n).type);
89 return {
90 type: names.join('|')
91 };
92 } else if (node.type === 'TypeApplication') {
93 const { type: typeName } = typeObject(node.expression);
94 if (
95 typeName === 'Array' &&
96 node.applications.length === 1
97 ) {
98 return {
99 type: `${typeObject(node.applications[0]).type}[]`
100 };
101 }
102 const args = node.applications.map(n => typeObject(n).type);
103 return {
104 type: `${typeName}<${args.join(', ')}>`
105 };
106 } else if (node.type === 'UndefinedLiteral') {
107 return { type: 'undefined' };
108 } else if (node.type === 'FunctionType') {
109 let signature = `function(${node.params.map(p => typeObject(p).type).join(', ')})`;
110 if (node.result) {
111 signature += `: ${typeObject(node.result).type}`;
112 }
113 return { type: signature };
114 } else if (node.type === 'ArrayType') {
115 return { type: `[${node.elements.map(e => typeObject(e).type).join(', ')}]` };
116 } else if (node.type === 'RestType') {
117 return { type: typeObject(node.expression).type, rest: true };
118 } else {
119 // TODO
120 // - handle record types
121 return { type: node.name };
122 }
123}
124
125export function getParams(entry) {
126 // Documentation.js seems to try to grab params from the function itself in

Callers 1

convert.mjsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected