From d470dd683ed5446590142f235d7345b8da83eea2 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 14 Mar 2022 17:43:09 +0100 Subject: [PATCH] scripts/api-extractor: add support for @ignore in separate modules Signed-off-by: Patrik Oldsberg --- scripts/api-extractor.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index 0dd8dba6f8..fdcd754b64 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -143,24 +143,35 @@ ApiReportGenerator.generateReviewFileContent = ); } - // NOTE: we limit the @internal functionality to only apply to types that are declared - // in the same module as where they're being referenced from. This limitation makes - // the implementation here simpler but could be revisited if needed. - // The local name of the symbol within the file, rather than the exported name const localName = (sourceFile as any).identifiers?.get(symbolName); if (!localName) { - return true; + throw new Error( + `Unable to find local name of "${symbolName}" in ${sourceFile.fileName}`, + ); } + // The local AST node of the export that we're missing const local = (sourceFile as any).locals?.get(localName); if (!local) { return true; } + // Use the type checker to look up the actual declaration(s) rather than the one in the local file + const type = program.getTypeChecker().getDeclaredTypeOfSymbol(local); + if (!type) { + throw new Error( + `Unable to find type declaration of "${symbolName}" in ${sourceFile.fileName}`, + ); + } + const declarations = type.aliasSymbol?.declarations; + if (!declarations || declarations.length === 0) { + return true; + } + // If any of the TSDoc comments contain a @ignore tag, we ignore this message - const isIgnored = local.declarations.some(declaration => { - const tags = [declaration.jsDoc] + const isIgnored = declarations.some(declaration => { + const tags = [(declaration as any).jsDoc] .flat() .filter(Boolean) .flatMap((tagNode: any) => tagNode.tags);