MCPcopy Index your code
hub / github.com/angular/components / getClassLikeDocsFromType

Function getClassLikeDocsFromType

tools/dgeni/common/class-inheritance.ts:61–109  ·  view source on GitHub ↗

* Gets all class-like Dgeni documents from the given type. e.g. intersection types of * multiple classes will result in multiple Dgeni API documents for each class.

(
  type: ts.Type,
  baseDoc: ClassLikeExportDoc,
  exportSymbolsToDocsMap: Map<ts.Symbol, ClassLikeExportDoc>,
)

Source from the content-addressed store, hash-verified

59 * multiple classes will result in multiple Dgeni API documents for each class.
60 */
61function getClassLikeDocsFromType(
62 type: ts.Type,
63 baseDoc: ClassLikeExportDoc,
64 exportSymbolsToDocsMap: Map<ts.Symbol, ClassLikeExportDoc>,
65): ClassLikeExportDoc[] {
66 let aliasSymbol: ts.Symbol | undefined = undefined;
67 let symbol: ts.Symbol = type.symbol;
68 const typeChecker = baseDoc.typeChecker;
69
70 // Symbols can be aliases of the declaration symbol. e.g. in named import
71 // specifiers. We need to resolve the aliased symbol back to the declaration symbol.
72 if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {
73 aliasSymbol = symbol;
74 symbol = typeChecker.getAliasedSymbol(symbol);
75 }
76
77 // Intersection types are commonly used in TypeScript mixins to express the
78 // class augmentation. e.g. "BaseClass & CanColor".
79 if (type.isIntersection()) {
80 return type.types.reduce(
81 (res, t) => [...res, ...getClassLikeDocsFromType(t, baseDoc, exportSymbolsToDocsMap)],
82 [] as ClassLikeExportDoc[],
83 );
84 } else if (symbol) {
85 // If the given symbol has already been registered within Dgeni, we use the
86 // existing symbol instead of creating a new one. The dgeni typescript package
87 // keeps track of all exported symbols and their corresponding docs. See:
88 // dgeni-packages/blob/master/typescript/src/processors/linkInheritedDocs.ts
89 if (exportSymbolsToDocsMap.has(symbol)) {
90 return [exportSymbolsToDocsMap.get(symbol)!];
91 }
92 let createdDoc: InheritanceCreatedClassLikeDoc | null = null;
93 if ((symbol.flags & ts.SymbolFlags.Class) !== 0) {
94 createdDoc = new ClassExportDoc(baseDoc.host, baseDoc.moduleDoc, symbol, aliasSymbol);
95 } else if ((symbol.flags & ts.SymbolFlags.Interface) !== 0) {
96 createdDoc = new InterfaceExportDoc(baseDoc.host, baseDoc.moduleDoc, symbol, aliasSymbol);
97 }
98
99 if (createdDoc) {
100 // Mark the created document. This allows us to distinguish between documents which
101 // have been resolved by Dgeni automatically, and docs which are manually resolved.
102 createdDoc._inheritanceCreated = true;
103 // If a new document has been created, add it to the shared symbol.
104 exportSymbolsToDocsMap.set(aliasSymbol || symbol, createdDoc);
105 return [createdDoc];
106 }
107 }
108 return [];
109}

Callers 1

getInheritedDocsOfClassFunction · 0.85

Calls 2

setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…