@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>
30 lines • 1.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeclarationByPath = getDeclarationByPath;
const is_supported_declaration_1 = require("./is-supported-declaration");
/**
*
* @param project
* @param declarationPath
*/
function getDeclarationByPath(project, declarationPath) {
const [sourceFilePath, name] = declarationPath.split('#');
if (!sourceFilePath || !name) {
throw new Error(`Invalid declaration path: ${declarationPath}; expected format: path/to/file.ts#declarationName`);
}
let sourceFile = project.getSourceFile(sourceFilePath);
sourceFile?.refreshFromFileSystemSync();
if (!sourceFile) {
sourceFile = project.addSourceFileAtPath(sourceFilePath);
}
const declarationNodes = sourceFile.getExportedDeclarations().get(name);
const declaration = declarationNodes?.[0];
if (!declarationNodes || !declaration) {
throw new Error(`Declaration not found ("${declarationPath}") make sure it's exported`);
}
if (!(0, is_supported_declaration_1.isSupportedDeclaration)(declaration)) {
throw new Error(`Unsupported declaration type ("${declarationPath}")`);
}
return declaration;
}
//# sourceMappingURL=get-declaration-by-path.js.map
;