@ng-doc/builder
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
63 lines • 2.43 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTypeAliasProperties = getTypeAliasProperties;
const core_1 = require("@ng-doc/core");
const ts_morph_1 = require("ts-morph");
/**
* Traverse all of the properties of a type alias declaration,
* returning an array of all of the properties.
*
* Specifically, this resolves type alias declarations that resolve to types
* that are "object-like", including:
* - IntersectionTypes,
* - TypeLiterals, and
* - TypeReferences (which resolve to IntersectionTypes or TypeLiterals)
*/
function getTypeAliasProperties(ta) {
const properties = new Map();
const signatures = [];
const getProperties = (typeNode) => {
if (typeNode.isKind(ts_morph_1.SyntaxKind.TypeLiteral)) {
const members = typeNode.getMembers();
members.forEach((member) => {
if (member.isKind(ts_morph_1.SyntaxKind.PropertySignature)) {
signatures.push(member);
}
});
}
else if (typeNode?.isKind(ts_morph_1.SyntaxKind.IntersectionType)) {
const types = typeNode.getTypeNodes();
types.forEach((typ) => {
getProperties(typ);
});
}
else if (typeNode.isKind(ts_morph_1.SyntaxKind.TypeReference)) {
const symbol = typeNode.getTypeName().getSymbol();
if (symbol) {
const declarations = symbol.getDeclarations();
declarations.forEach((decl) => {
if (decl.isKind(ts_morph_1.SyntaxKind.TypeLiteral)) {
getProperties(decl);
}
else if (decl.isKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)) {
const typeNode = decl.getTypeNode();
if (typeNode) {
getProperties(typeNode);
}
}
});
}
}
};
const typeNode = ta.getTypeNode();
if (typeNode) {
getProperties(typeNode);
}
signatures.forEach((property) => {
const name = property.getName();
// this may override the previous value (and we want the last one)
properties.set(name, property);
});
return (0, core_1.asArray)(properties.values());
}
//# sourceMappingURL=get-type-alias-properties.js.map
;