MCPcopy Create free account
hub / github.com/Snapchat/Valdi / parseType

Function parseType

compiler/companion/src/AST.ts:306–404  ·  view source on GitHub ↗
(type: ts.TypeNode | undefined, references: AST.TypeReferences)

Source from the content-addressed store, hash-verified

304}
305
306function parseType(type: ts.TypeNode | undefined, references: AST.TypeReferences): AST.Type {
307 if (!type) {
308 return {
309 name: 'void',
310 };
311 }
312
313 const leadingComments = getNodeComments(type);
314
315 if (ts.isFunctionTypeNode(type)) {
316 return {
317 name: 'function',
318 leadingComments,
319 function: parseFunctionType(type, references),
320 };
321 }
322
323 if (ts.isUnionTypeNode(type)) {
324 const unions: AST.Type[] = [];
325 for (const unionType of type.types) {
326 unions.push(parseType(unionType, references));
327 }
328
329 return {
330 name: 'union',
331 leadingComments,
332 unions,
333 };
334 }
335
336 if (ts.isIntersectionTypeNode(type)) {
337 const intersections: AST.Type[] = [];
338 for (const unionType of type.types) {
339 intersections.push(parseType(unionType, references));
340 }
341
342 return {
343 name: 'intersection',
344 leadingComments,
345 intersections,
346 };
347 }
348
349 if (ts.isArrayTypeNode(type)) {
350 return {
351 name: 'array',
352 leadingComments,
353 array: parseType(type.elementType, references),
354 };
355 }
356
357 if (ts.isTypeReferenceNode(type) || ts.isExpressionWithTypeArguments(type)) {
358 const resolvedSymbol = resolveSymbol(type, references.typeChecker);
359 if (!resolvedSymbol) {
360 throw new Error(`Could not resolve symbol ${getNodeDebugDescription(type)}`);
361 }
362
363 return parseTypeFromSymbolGroup(type, resolvedSymbol, leadingComments, references);

Callers 5

parseFunctionTypeFunction · 0.85
parseTypeFromSymbolGroupFunction · 0.85
parsePropertyLikeFunction · 0.85
dumpInterfaceFunction · 0.85
dumpVariableFunction · 0.85

Calls 7

getNodeCommentsFunction · 0.90
getNodeDebugDescriptionFunction · 0.90
parseFunctionTypeFunction · 0.85
resolveSymbolFunction · 0.85
parseTypeFromSymbolGroupFunction · 0.85
getTextMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected