UNPKG

@jsdocs-io/extractor

Version:

The API extractor for npm packages powering jsdocs.io

21 lines (20 loc) 1.04 kB
import { Node, SyntaxKind } from "ts-morph"; import { docs } from "./docs.js"; import { parseDocComment } from "./parse-doc-comment.js"; /** `isHidden` checks if a declaration is part of a package's private API. */ export function isHidden(node) { // JavaScript private class properties (e.g., `#foo`, `#bar() { ... }`). // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties. if (Node.hasName(node) && Node.isPrivateIdentifier(node.getNameNode())) return true; // TypeScript `private` keyword properties (e.g., `private foo`). // See https://www.typescriptlang.org/docs/handbook/2/classes.html#private. if (Node.isModifierable(node) && node.hasModifier(SyntaxKind.PrivateKeyword)) return true; // TSDoc/JSDoc comment with `@internal` tag. // See https://tsdoc.org/pages/tags/internal. if (docs(node).some((doc) => parseDocComment(doc).modifierTagSet.isInternal())) return true; // Not hidden, part of public API. return false; }