diff --git a/src/compiler/docs/generate-doc-data.ts b/src/compiler/docs/generate-doc-data.ts index f8fc3aa568f4..cc1c18a4fe56 100644 --- a/src/compiler/docs/generate-doc-data.ts +++ b/src/compiler/docs/generate-doc-data.ts @@ -377,7 +377,7 @@ const getUserReadmeContent = async (compilerCtx: d.CompilerCtx, readmePath: stri * @param jsdoc the JSDoc associated with the component's declaration * @returns the generated documentation */ -const generateDocs = (readme: string, jsdoc: d.CompilerJsDoc): string => { +const generateDocs = (readme: string | undefined, jsdoc: d.CompilerJsDoc): string => { const docs = jsdoc.text; if (docs !== '' || !readme) { // just return the existing docs if they exist. these would have been captured earlier in the compilation process. diff --git a/src/compiler/transformers/type-library.ts b/src/compiler/transformers/type-library.ts index 09ee5509d3ee..36bc540d0e9f 100644 --- a/src/compiler/transformers/type-library.ts +++ b/src/compiler/transformers/type-library.ts @@ -104,7 +104,15 @@ export function addFileToLibrary(filePath: string): void { const importPath = node.moduleSpecifier.text; const module = ts.resolveModuleName(importPath, sourceFile.fileName, options, compilerHost); - const exportHomeModule = program.getSourceFile(module.resolvedModule.resolvedFileName); + const resolvedFileName = module?.resolvedModule?.resolvedFileName; + + if (!resolvedFileName) { + return; + } + const exportHomeModule = program.getSourceFile(resolvedFileName); + if (!exportHomeModule) { + return; + } // if there are named exports (like `export { Pie, Cake } from './dessert'`) // we get each export specifier (`Pie`, `Cake`), use the typechecker @@ -112,6 +120,9 @@ export function addFileToLibrary(filePath: string): void { if (node.exportClause && ts.isNamedExports(node.exportClause)) { for (const exportSpecifier of node.exportClause.elements) { const identifier = exportSpecifier.getChildAt(0); + if (!identifier) { + return; + } // if this symbol is being aliased like // // ```ts @@ -120,7 +131,11 @@ export function addFileToLibrary(filePath: string): void { // // this will give us 'Best' as a symbol, letting us look that name up // in the source module, below - const unaliasedSymbol = unalias(checker.getSymbolAtLocation(identifier), checker); + const possiblyAliasedSymbol = checker.getSymbolAtLocation(identifier); + if (!possiblyAliasedSymbol) { + return; + } + const unaliasedSymbol = unalias(possiblyAliasedSymbol, checker); const name = unaliasedSymbol.getName(); ts.forEachChild(exportHomeModule, (child) => { @@ -216,8 +231,10 @@ function isNotPrivate(node: TypeDeclLike): boolean { function getTypeDeclaration(checker: ts.TypeChecker, type: ts.Type): string { const maybeSymbol = getSymbolForType(type); - if (maybeSymbol) { - return maybeSymbol?.declarations?.[0]?.getText(); + const declaration = maybeSymbol?.declarations?.[0]; + + if (declaration) { + return declaration.getText(); } else { // in the case that we couldn't resolve the declaration, `typeToString` // provides a reasonable fallback diff --git a/src/declarations/stencil-public-docs.ts b/src/declarations/stencil-public-docs.ts index 742ecfbf1850..795c3e8c4f67 100644 --- a/src/declarations/stencil-public-docs.ts +++ b/src/declarations/stencil-public-docs.ts @@ -108,7 +108,7 @@ export interface JsonDocsProp { reflectToAttr: boolean; docs: string; docsTags: JsonDocsTag[]; - default: string; + default?: string; deprecation?: string; values: JsonDocsValue[]; optional: boolean;