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

Function parsePropertyLike

compiler/companion/src/AST.ts:406–442  ·  view source on GitHub ↗
(
  node: ts.TypeElement | ts.ClassElement,
  references: AST.TypeReferences,
)

Source from the content-addressed store, hash-verified

404}
405
406function parsePropertyLike(
407 node: ts.TypeElement | ts.ClassElement,
408 references: AST.TypeReferences,
409): AST.PropertyLikeDeclaration {
410 const memberName = node.name && getIdentifierString(node.name);
411 const isOptional = !!(node as ts.TypeElement)?.questionToken;
412
413 let type: AST.Type;
414
415 if (ts.isPropertySignature(node) || ts.isPropertyDeclaration(node)) {
416 type = parseType(node.type, references);
417 } else if (
418 ts.isMethodSignature(node) ||
419 ts.isMethodDeclaration(node) ||
420 ts.isGetAccessor(node) ||
421 ts.isGetAccessorDeclaration(node)
422 ) {
423 const functionType = parseFunctionType(node, references);
424 type = {
425 name: 'function',
426 function: functionType,
427 };
428 } else {
429 throw new Error(`Could not resolve kind ${getNodeDebugDescription(node)}`);
430 }
431
432 const result: AST.PropertyLikeDeclaration = {
433 start: node.getStart(),
434 end: node.getEnd(),
435 isOptional,
436 name: memberName ?? '',
437 type,
438 leadingComments: getNodeComments(node),
439 };
440
441 return result;
442}
443
444export interface DumpedRootNode {
445 nodeType: 'enum' | 'function' | 'interface' | 'variable' | 'exportedTypeAlias';

Callers 1

dumpInterfaceFunction · 0.85

Calls 6

getNodeDebugDescriptionFunction · 0.90
getNodeCommentsFunction · 0.90
getIdentifierStringFunction · 0.85
parseTypeFunction · 0.85
parseFunctionTypeFunction · 0.85
getEndMethod · 0.80

Tested by

no test coverage detected