diff --git a/.changeset/README.md b/.changeset/README.md
deleted file mode 100644
index e5b6d8d6a67..00000000000
--- a/.changeset/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-# Changesets
-
-Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
-with multi-package repos, or single-package repos to help you version and publish your code. You can
-find the full documentation for it [in our repository](https://github.com/changesets/changesets)
-
-We have a quick list of common questions to get you started engaging with this project in
-[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
diff --git a/.changeset/config.json b/.changeset/config.json
deleted file mode 100644
index 0765cca37fb..00000000000
--- a/.changeset/config.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json",
- "changelog": [
- "@changesets/changelog-github",
- { "repo": "reactjs/react-docgen" }
- ],
- "commit": false,
- "fixed": [],
- "linked": [],
- "access": "public",
- "baseBranch": "main",
- "updateInternalDependencies": "patch",
- "ignore": [
- "@react-docgen-internal/benchmark",
- "@react-docgen-internal/website"
- ]
-}
diff --git a/.editorconfig b/.editorconfig
deleted file mode 100644
index 179b45db9a6..00000000000
--- a/.editorconfig
+++ /dev/null
@@ -1,15 +0,0 @@
-root = true
-
-[*]
-end_of_line = lf
-insert_final_newline = true
-charset = utf-8
-
-[*.{js,cjs,mjs,ts,tsx,mts,cts,mdx}]
-indent_style = space
-indent_size = 2
-#indent_style = tab
-
-[**.json]
-indent_style = space
-indent_size = 2
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
deleted file mode 100644
index e090ba84f8b..00000000000
--- a/.github/FUNDING.yml
+++ /dev/null
@@ -1 +0,0 @@
-github: [danez]
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
deleted file mode 100644
index a10a24703a3..00000000000
--- a/.github/workflows/build.yml
+++ /dev/null
@@ -1,117 +0,0 @@
-name: CI
-
-on:
- push:
- branches:
- - main
- - renovate/**
- pull_request:
-
-permissions: {}
-
-env:
- NODE_VERSION: 22
-
-jobs:
- tests:
- strategy:
- matrix:
- node: ['20.9.0', '22', '23']
- os: ['ubuntu']
- include:
- - os: macos
- node: '22'
- - os: windows
- node: '22'
-
- name: Tests (Node.js v${{ matrix.node }}, ${{ matrix.os }})
- runs-on: ${{ matrix.os }}-latest
-
- steps:
- - name: Checkout
- uses: actions/checkout@v5
-
- - name: Install pnpm
- uses: pnpm/action-setup@v4
-
- - name: Setup Node.js
- uses: actions/setup-node@v5
- with:
- node-version: ${{ matrix.node }}
- cache: 'pnpm'
-
- - name: Install dependencies
- run: pnpm install --frozen-lockfile
-
- - name: Unit tests with coverage
- if: '${{ matrix.node == env.NODE_VERSION }}'
- run: pnpm test -- --coverage
-
- - name: Unit tests
- if: '${{ matrix.node != env.NODE_VERSION }}'
- run: pnpm test
-
- - name: Upload coverage
- if: '${{ matrix.node == env.NODE_VERSION }}'
- continue-on-error: true
- uses: coverallsapp/github-action@v2
- with:
- parallel: true
- flag-name: test-${{ matrix.os }}
-
- finish:
- needs: tests
- if: ${{ always() }}
- continue-on-error: true
- runs-on: ubuntu-latest
- steps:
- - name: Close parallel build
- uses: coverallsapp/github-action@v2
- with:
- parallel-finished: true
-
- lint:
- name: Lint
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout
- uses: actions/checkout@v5
-
- - name: Install pnpm
- uses: pnpm/action-setup@v4
-
- - name: Setup Node.js
- uses: actions/setup-node@v5
- with:
- node-version: ${{ env.NODE_VERSION }}
- cache: 'pnpm'
-
- - name: Install dependencies
- run: pnpm install --frozen-lockfile
-
- - name: Lint
- run: pnpm lint
-
- website:
- name: Website test build
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout
- uses: actions/checkout@v5
-
- - name: Install pnpm
- uses: pnpm/action-setup@v4
-
- - name: Setup Node.js
- uses: actions/setup-node@v5
- with:
- node-version: ${{ env.NODE_VERSION }}
- cache: 'pnpm'
-
- - name: Install dependencies
- run: pnpm install --frozen-lockfile
-
- - name: Build
- run: pnpm exec nx run @react-docgen-internal/website:build
diff --git a/.github/workflows/changesets.yml b/.github/workflows/changesets.yml
deleted file mode 100644
index f10c4f56faa..00000000000
--- a/.github/workflows/changesets.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-name: Release
-
-on:
- push:
- branches:
- - main
-
-concurrency: ${{ github.workflow }}-${{ github.ref }}
-
-permissions:
- id-token: write
-
-jobs:
- release:
- name: Release
- runs-on: ubuntu-latest
- steps:
- - name: Checkout
- uses: actions/checkout@v5
- with:
- # Do not persist credentials so changesets can use the provided token
- persist-credentials: false
-
- - name: Install pnpm
- uses: pnpm/action-setup@v4
-
- - name: Setup Node.js
- uses: actions/setup-node@v5
- with:
- node-version: 'lts/*'
- cache: 'pnpm'
-
- - name: Install dependencies
- run: pnpm install --frozen-lockfile
-
- - name: Run Changesets
- id: changesets
- uses: changesets/action@v1
- with:
- publish: pnpm changesets-release
- version: pnpm changesets-version
- title: Packages ready to publish
- commit: Publish new versions
- env:
- GITHUB_TOKEN: ${{ secrets.CHANGESETS_TOKEN }}
- NPM_TOKEN: ${{secrets.NPM_TOKEN}}
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
deleted file mode 100644
index 786b7c0f839..00000000000
--- a/.github/workflows/codeql-analysis.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-name: 'CodeQL'
-
-on:
- push:
- branches: [main]
- pull_request:
- # The branches below must be a subset of the branches above
- branches: [main]
- schedule:
- - cron: '43 16 * * 5'
-
-jobs:
- analyze:
- name: Analyze
- runs-on: ubuntu-latest
- permissions:
- actions: read
- contents: read
- security-events: write
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v5
-
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v3
- with:
- languages: 'javascript'
-
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v3
- with:
- category: "/language:javascript"
diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml
deleted file mode 100644
index 07d14ce49b1..00000000000
--- a/.github/workflows/lock.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-name: 'Lock Threads'
-
-on:
- schedule:
- - cron: '36 4 * * 4'
- workflow_dispatch:
-
-permissions:
- issues: write
- pull-requests: write
- discussions: write
-
-concurrency:
- group: lock
-
-jobs:
- action:
- runs-on: ubuntu-latest
- steps:
- - uses: dessant/lock-threads@v5
- with:
- log-output: true
diff --git a/.github/workflows/ossar-analysis.yml b/.github/workflows/ossar-analysis.yml
deleted file mode 100644
index 212f25b6aad..00000000000
--- a/.github/workflows/ossar-analysis.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-name: OSSAR
-
-on:
- push:
- branches: [main]
- pull_request:
- # The branches below must be a subset of the branches above
- branches: [main]
- schedule:
- - cron: '38 4 * * 1'
-
-permissions:
- contents: read
-
-jobs:
- OSSAR-Scan:
- permissions:
- contents: read # for actions/checkout to fetch code
- security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
- runs-on: windows-latest
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v5
-
- - name: Run OSSAR
- uses: github/ossar-action@v1
- id: ossar
-
- - name: Upload OSSAR results
- uses: github/codeql-action/upload-sarif@v3
- with:
- sarif_file: ${{ steps.ossar.outputs.sarifFile }}
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 7a09e4c990e..00000000000
--- a/.gitignore
+++ /dev/null
@@ -1,10 +0,0 @@
-benchmark/suites/
-dist/
-**/node_modules/*
-!**/__fixtures__/**/node_modules/*
-.idea/
-coverage/
-.nx/cache
-.nx/workspace-data
-.cursor/rules/nx-rules.mdc
-.github/instructions/nx.instructions.md
diff --git a/.gitpod.yml b/.gitpod.yml
deleted file mode 100644
index 320f7b51ffc..00000000000
--- a/.gitpod.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-tasks:
- - init: npm install -g pnpm && pnpm install
-vscode:
- extensions:
- - dbaeumer.vscode-eslint
- - esbenp.prettier-vscode
diff --git a/.npmrc b/.npmrc
deleted file mode 100644
index 75b9f7b1fd7..00000000000
--- a/.npmrc
+++ /dev/null
@@ -1,3 +0,0 @@
-auto-install-peers=true
-link-workspace-packages=false
-provenance=true
diff --git a/.prettierignore b/.prettierignore
deleted file mode 100644
index 7be039621db..00000000000
--- a/.prettierignore
+++ /dev/null
@@ -1,6 +0,0 @@
-benchmark/suites/
-**/__fixtures__/
-**/dist/
-**/node_modules
-/.nx/cache
-/.nx/workspace-data
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index 2f1be750f5b..00000000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# Contributing to react-docgen
-We want to make contributing to this project as easy and transparent as
-possible.
-
-## Our Development Process
-The majority of development on react-docgen will occur through GitHub. Accordingly,
-the process for contributing will follow standard GitHub protocol.
-
-## Pull Requests
-We actively welcome your pull requests.
-1. Fork the repo and create your branch from `main`.
-2. If you've added code that should be tested, add tests
-3. If you've changed APIs, update the documentation.
-4. Ensure the test suite passes.
-5. Make sure your code lints and typechecks.
-6. If you haven't already, complete the Contributor License Agreement ("CLA").
-
-## Issues
-We use GitHub issues to track public bugs. Please ensure your description is
-clear and has sufficient instructions to be able to reproduce the issue.
-
-Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
-disclosure of security bugs. In those cases, please go through the process
-outlined on that page and do not file a public issue.
-
-## License
-react-docgen is [MIT licensed](https://github.com/reactjs/react-docgen/blob/master/LICENSE).
-
-By contributing to react-docgen, you agree that your contributions will be licensed
-under its MIT license.
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index b96dcb0480a..00000000000
--- a/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) Facebook, Inc. and its affiliates.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/README.md b/README.md
deleted file mode 100644
index 41e1dec839f..00000000000
--- a/README.md
+++ /dev/null
@@ -1,25 +0,0 @@
-# react-docgen
-
-[`react-docgen`](./packages/react-docgen/) is a highly customizable library that
-extracts information from [React](https://reactjs.org/) components and returns
-this information in a structured machine readable format from which
-documentations can be generated.
-
-[`@react-docgen/cli`](./packages/react-docgen-cli/) is a cli wrapper around the
-library allowing using `react-docgen` on the command line.
-
-## Typescript
-
-See [this issue](https://github.com/reactjs/react-docgen/issues/1005) about the status of TypeScript.
-
-## Documentation
-
-For version 5.x please checkout the
-[README.md on the 5.x branch](https://github.com/reactjs/react-docgen/blob/5.x/README.md)
-
-For version 6.x and newer please visit
-[react-docgen.dev](https://react-docgen.dev)
-
-## License
-
-This project is licensed under the MIT License.
diff --git a/benchmark/index.mjs b/benchmark/index.mjs
deleted file mode 100644
index 68408bf2844..00000000000
--- a/benchmark/index.mjs
+++ /dev/null
@@ -1,115 +0,0 @@
-import fs from 'fs';
-import path, { dirname } from 'path';
-import { fileURLToPath } from 'url';
-import Table from 'cli-table';
-import glob from 'fast-glob';
-import Benchmark from 'benchmark';
-import { parse } from '../packages/react-docgen/dist/main.js';
-import { parse as parse5 } from 'react-docgen5';
-import { parse as parse6 } from 'react-docgen6';
-
-console.log(`Node: ${process.version}`);
-
-const __dirname = dirname(fileURLToPath(import.meta.url));
-
-const head = ['fixture', 'v5.4.3', 'v6.0.0', 'main'];
-
-process.stdout.write(`Preparing suites ... `);
-
-const suites = [
- {
- name: 'react-bootstrap',
- files: await glob('./suites/react-bootstrap/src/*.tsx', {
- absolute: false,
- cwd: __dirname,
- }),
- },
-];
-
-const table = new Table({
- head,
- style: {
- head: ['bold'],
- },
-});
-
-if (!global.gc) {
- console.error(
- 'Garbage collection unavailable. Pass --expose-gc ' +
- 'when launching node to enable forced garbage collection.',
- );
- process.exit();
-}
-
-const preparedSuites = [];
-
-suites.forEach(({ name, files }) => {
- const suite = new Benchmark.Suite(name);
-
- files.forEach((file) => {
- const code = fs.readFileSync(path.join(__dirname, file), 'utf-8');
- const options = { filename: file, babelrc: false, configFile: false };
- const newOptions = { babelOptions: options };
-
- try {
- // warmup
- parse(code, newOptions);
- parse6(code, newOptions);
- parse5(code, undefined, undefined, options);
- global.gc();
-
- preparedSuites.push({
- code,
- options,
- newOptions,
- });
- } catch {
- // ignore errors
- }
- });
-
- suite.add('v5.4.3', () => {
- for (const { code, options } of preparedSuites) {
- parse5(code, undefined, undefined, options);
- }
- });
- suite.add('v6.0.0-alpha.4', () => {
- for (const { code, newOptions } of preparedSuites) {
- parse6(code, newOptions);
- }
- });
- suite.add('current', () => {
- for (const { code, newOptions } of preparedSuites) {
- parse(code, newOptions);
- }
- });
- const result = [suite.name];
-
- suite.on('cycle', function (event) {
- {
- // separate scope so we can cleanup all this afterwards
- const bench = event.target;
- const factor = bench.hz < 100 ? 100 : 1;
- const msg = `${Math.round(bench.hz * factor) / factor} ops/sec ±${
- Math.round(bench.stats.rme * 100) / 100
- }% (${Math.round(bench.stats.mean * 1000)}ms)`;
-
- result.push(msg);
- }
- global.gc();
- });
- suite.on('complete', function () {
- process.stdout.write(
- '-> Winner: ' + this.filter('fastest').map('name') + '\n',
- );
- });
-
- process.stdout.write(`Done\nRunning benchmark for ${suite.name} ... `);
- global.gc();
- suite.run({ async: false });
- global.gc(); // gc is disabled so ensure we run it
- table.push(result);
-});
-
-global.gc(); // gc is disabled so ensure we run it
-console.log(table.toString());
diff --git a/benchmark/package.json b/benchmark/package.json
deleted file mode 100644
index 60b38cfd15d..00000000000
--- a/benchmark/package.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "name": "@react-docgen-internal/benchmark",
- "version": "0.0.0",
- "private": true,
- "description": "Generate benchmarks for react-docgen",
- "scripts": {
- "setup": "rm -rf ./suites/react-bootstrap/ && git clone --depth=1 --branch=v2.7.0 https://github.com/react-bootstrap/react-bootstrap.git ./suites/react-bootstrap/",
- "start": "node --expose-gc ./index.mjs",
- "debug": "node --inspect-brk --expose-gc ./index.mjs"
- },
- "license": "MIT",
- "dependencies": {
- "benchmark": "2.1.4",
- "cli-table": "0.3.11",
- "fast-glob": "3.3.3",
- "microtime": "3.1.1",
- "react-docgen5": "npm:react-docgen@5.4.3",
- "react-docgen6": "npm:react-docgen@6.0.0"
- }
-}
diff --git a/eslint.config.mjs b/eslint.config.mjs
deleted file mode 100644
index 9804850cdcd..00000000000
--- a/eslint.config.mjs
+++ /dev/null
@@ -1,97 +0,0 @@
-import { globalIgnores } from 'eslint/config';
-import globals from 'globals';
-import js from '@eslint/js';
-import prettierRecommended from 'eslint-plugin-prettier/recommended';
-import tseslint from 'typescript-eslint';
-
-export default tseslint.config([
- globalIgnores([
- 'benchmark/suites/',
- '**/__fixtures__/',
- '**/dist/',
- '**/.nx/',
- '**/coverage',
- '**/node_modules',
- ]),
- js.configs.recommended,
- {
- files: ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts', '**/*.tsx'],
- languageOptions: {
- globals: {
- ...globals.node,
- },
-
- ecmaVersion: 2022,
- sourceType: 'module',
- },
-
- rules: {
- 'no-shadow': 'error',
- 'no-var': 'error',
-
- 'padding-line-between-statements': [
- 'error',
- {
- blankLine: 'always',
- prev: '*',
- next: 'return',
- },
- {
- blankLine: 'always',
- prev: ['const', 'let', 'var'],
- next: '*',
- },
- {
- blankLine: 'any',
- prev: ['const', 'let', 'var'],
- next: ['const', 'let', 'var'],
- },
- {
- blankLine: 'never',
- prev: ['import'],
- next: ['import'],
- },
- ],
-
- 'prefer-const': 'error',
- },
- },
- {
- files: ['**/*.cjs'],
-
- languageOptions: {
- ecmaVersion: 2022,
- sourceType: 'script',
- },
-
- rules: {
- strict: ['error', 'global'],
- },
- },
- {
- files: ['**/*.ts', '**/*.tsx'],
-
- extends: [
- tseslint.configs.recommended,
- tseslint.configs.strict,
- tseslint.configs.stylistic,
- ],
-
- rules: {
- 'no-shadow': 'off',
- '@typescript-eslint/no-shadow': 'error',
-
- '@typescript-eslint/array-type': [
- 'error',
- {
- default: 'array-simple',
- },
- ],
-
- '@typescript-eslint/consistent-type-imports': 'error',
- '@typescript-eslint/no-non-null-assertion': 'off',
- '@typescript-eslint/sort-type-constituents': 'error',
- },
- },
- prettierRecommended,
-]);
diff --git a/index.html b/index.html
new file mode 100644
index 00000000000..30f71bc9195
--- /dev/null
+++ b/index.html
@@ -0,0 +1,12 @@
+
+
+
+
Redirecting…
+
+
+ Redirecting…
+ Click here if you are not redirected.
+
+
diff --git a/nx.json b/nx.json
deleted file mode 100644
index 37510e0d221..00000000000
--- a/nx.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "$schema": "./node_modules/nx/schemas/nx-schema.json",
- "targetDefaults": {
- "build": {
- "dependsOn": ["^build"],
- "outputs": ["{projectRoot}/dist"],
- "cache": true
- },
- "test": {
- "dependsOn": ["build"],
- "cache": true
- }
- },
- "namedInputs": {
- "default": ["{projectRoot}/**/*", "sharedGlobals"],
- "sharedGlobals": [
- "{workspaceRoot}/nx.json",
- "{workspaceRoot}/package.json",
- "{workspaceRoot}/pnpm-lock.yaml",
- "{workspaceRoot}/tsconfig.base.json"
- ],
- "production": ["default"]
- }
-}
diff --git a/package.json b/package.json
deleted file mode 100644
index 948c46a9f1a..00000000000
--- a/package.json
+++ /dev/null
@@ -1,42 +0,0 @@
-{
- "private": true,
- "engines": {
- "node": "^20.9.0 || >=22",
- "pnpm": ">=10.6.2"
- },
- "scripts": {
- "build": "nx run-many --target=build --exclude='@react-docgen-internal/*'",
- "lint": "eslint . --flag unstable_config_lookup_from_file --report-unused-disable-directives --max-warnings=0",
- "fix": "eslint . --flag unstable_config_lookup_from_file --fix --report-unused-disable-directives --max-warnings=0",
- "test": "nx run-many --target=test --exclude='@react-docgen-internal/*' --output-style=stream",
- "copy:changelog:react-docgen": "cp ./packages/react-docgen/CHANGELOG.md ./packages/website/src/pages/docs/release-notes/react-docgen.mdx",
- "copy:changelog:cli": "cp ./packages/react-docgen-cli/CHANGELOG.md ./packages/website/src/pages/docs/release-notes/cli.mdx",
- "changesets-release": "pnpm build && changeset publish",
- "changesets-version": "changeset version && pnpm install --lockfile-only && pnpm copy:changelog:react-docgen && pnpm copy:changelog:cli"
- },
- "license": "MIT",
- "devDependencies": {
- "@changesets/changelog-github": "0.5.1",
- "@changesets/cli": "2.29.7",
- "@eslint/eslintrc": "3.3.1",
- "@eslint/js": "9.36.0",
- "@types/node": "20.19.17",
- "@vitest/coverage-v8": "3.2.4",
- "cpy": "12.0.1",
- "eslint": "9.36.0",
- "eslint-config-next": "15.5.4",
- "eslint-config-prettier": "10.1.8",
- "eslint-plugin-prettier": "5.5.4",
- "execa": "9.6.0",
- "globals": "16.4.0",
- "nx": "21.5.3",
- "prettier": "3.6.2",
- "prettier-plugin-tailwindcss": "0.6.14",
- "rimraf": "6.0.1",
- "tempy": "3.1.0",
- "typescript": "5.9.2",
- "typescript-eslint": "8.44.1",
- "vitest": "3.2.4"
- },
- "packageManager": "pnpm@10.17.1"
-}
diff --git a/packages/react-docgen-cli/CHANGELOG.md b/packages/react-docgen-cli/CHANGELOG.md
deleted file mode 100644
index 8017500ff2a..00000000000
--- a/packages/react-docgen-cli/CHANGELOG.md
+++ /dev/null
@@ -1,508 +0,0 @@
-# Release Notes
-
-## 3.0.3
-
-### Patch Changes
-
-- [`bdfdbac`](https://github.com/reactjs/react-docgen/commit/bdfdbaca3e798be18bab3b499e9b49003b7798d6)
- Thanks [@danez](https://github.com/danez)! - update dependency commander to
- v14.0.1
-
-- [`bdfdbac`](https://github.com/reactjs/react-docgen/commit/bdfdbaca3e798be18bab3b499e9b49003b7798d6)
- Thanks [@danez](https://github.com/danez)! - update dependency debug to v4.4.3
-
-- [`bdfdbac`](https://github.com/reactjs/react-docgen/commit/bdfdbaca3e798be18bab3b499e9b49003b7798d6)
- Thanks [@danez](https://github.com/danez)! - update dependency chalk to v5.6.2
-
-## 3.0.2
-
-### Patch Changes
-
-- [#1017](https://github.com/reactjs/react-docgen/pull/1017)
- [`a818275`](https://github.com/reactjs/react-docgen/commit/a818275de1ba7e616d2ba45d0d2cde4f703b961f)
- Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update
- dependency chalk to v5.6.0
-
-- Updated dependencies
- [[`4c7dd9d`](https://github.com/reactjs/react-docgen/commit/4c7dd9d12ffdb3ac1d6f9663124cc43ec7fabb08)]:
- - react-docgen@8.0.1
-
-## 3.0.1
-
-### Patch Changes
-
-- [#996](https://github.com/reactjs/react-docgen/pull/996)
- [`a9b5ca3`](https://github.com/reactjs/react-docgen/commit/a9b5ca3f5411e876264db716fc4640ad9d4fb928)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- debug to v4.4.1
-
-- [#1000](https://github.com/reactjs/react-docgen/pull/1000)
- [`5cedd84`](https://github.com/reactjs/react-docgen/commit/5cedd84aaf38ec45a08fb673034e0d9ac03df81b)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- commander to v14
-
-## 3.0.0
-
-### Major Changes
-
-- [#942](https://github.com/reactjs/react-docgen/pull/942)
- [`c3dfead`](https://github.com/reactjs/react-docgen/commit/c3dfead6b1cfdd57e34d1689c2b1d1334e9ef328)
- Thanks [@danez](https://github.com/danez)! - Drop support for Node.js 16, 17,
- 18, 19 and 21.
-
- With this `react-docgen` version Node.js support is:
- - Node.js 20.9.0 or newer 20.x versions
- - Node.js 22.0.0 or any newer version
-
-### Patch Changes
-
-- [#961](https://github.com/reactjs/react-docgen/pull/961)
- [`5e2a332`](https://github.com/reactjs/react-docgen/commit/5e2a33202e101e55fc6b0640c1ff6686f8f92189)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- commander to v13
-
-- [#979](https://github.com/reactjs/react-docgen/pull/979)
- [`3486af5`](https://github.com/reactjs/react-docgen/commit/3486af5db316864824fa5f0d86d3a92335b0912f)
- Thanks [@renovate](https://github.com/apps/renovate)! - Fix bug with loading
- CommonJS files
-
-- Updated dependencies
- [[`06c2fae`](https://github.com/reactjs/react-docgen/commit/06c2fae6f0d7f1aea3f23c2bf0dbfdc7b801ccb8),
- [`c3dfead`](https://github.com/reactjs/react-docgen/commit/c3dfead6b1cfdd57e34d1689c2b1d1334e9ef328)]:
- - react-docgen@8.0.0
-
-## 2.0.6
-
-### Patch Changes
-
-- Updated dependencies
- [[`639bf37`](https://github.com/reactjs/react-docgen/commit/639bf3799bd74c46c2163841fefd9f3cc847dce9)]:
- - react-docgen@7.1.1
-
-## 2.0.5
-
-### Patch Changes
-
-- [#960](https://github.com/reactjs/react-docgen/pull/960)
- [`8b1c753`](https://github.com/reactjs/react-docgen/commit/8b1c753a353d1ff44c3eca6c5e391dec1198ab7e)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- chalk to v5.4.1
-
-- [#958](https://github.com/reactjs/react-docgen/pull/958)
- [`f5d644a`](https://github.com/reactjs/react-docgen/commit/f5d644a3041c227c4889059e787fcbaab57ec70e)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- chalk to v5.4.0
-
-- [#954](https://github.com/reactjs/react-docgen/pull/954)
- [`3c0cbb0`](https://github.com/reactjs/react-docgen/commit/3c0cbb0c2869488ac96291f1d491a93c8c1b5b06)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- debug to v4.4.0
-
-- [#963](https://github.com/reactjs/react-docgen/pull/963)
- [`972a1a3`](https://github.com/reactjs/react-docgen/commit/972a1a316affc8164ac957432b177bba09f1e667)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- fast-glob to v3.3.3
-
-## 2.0.4
-
-### Patch Changes
-
-- [#931](https://github.com/reactjs/react-docgen/pull/931)
- [`a10dd0c`](https://github.com/reactjs/react-docgen/commit/a10dd0c782f053b648cf9bab2042a9d31245fc3d)
- Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update
- dependency debug to v4.3.5
-
-- [`f723041`](https://github.com/reactjs/react-docgen/commit/f7230419af3680b9ed87a323c4fdf46ead667459)
- Thanks [@renovate[bot]](https://github.com/renovate%5Bbot%5D)! - fix(deps):
- update dependency debug to v4.3.6
-
-- [#943](https://github.com/reactjs/react-docgen/pull/943)
- [`ef85698`](https://github.com/reactjs/react-docgen/commit/ef8569863974599f51b9c9e1c4b9202144fe7607)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- debug to v4.3.7
-
-- Updated dependencies
- [[`3033ca0`](https://github.com/reactjs/react-docgen/commit/3033ca0908eb53f6ae2ee8a40eb4ef96840ff7ad)]:
- - react-docgen@7.1.0
-
-## 2.0.3
-
-### Patch Changes
-
-- Updated dependencies
- [[`afe8d02`](https://github.com/reactjs/react-docgen/commit/afe8d022d058a5d49c6fc144fb165c02f4a764d9)]:
- - react-docgen@7.0.3
-
-## 2.0.2
-
-### Patch Changes
-
-- Updated dependencies
- [[`64bf1aa`](https://github.com/reactjs/react-docgen/commit/64bf1aa078148b4d44f8634252e5b726e24b8ee5)]:
- - react-docgen@7.0.2
-
-## 2.0.1
-
-### Patch Changes
-
-- [#869](https://github.com/reactjs/react-docgen/pull/869)
- [`6b19e8a`](https://github.com/reactjs/react-docgen/commit/6b19e8a34744d4f3f5c93b96c1258796f440ede1)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- fast-glob to v3.3.2
-
-- Updated dependencies
- [[`2b51bbd`](https://github.com/reactjs/react-docgen/commit/2b51bbd47d14638ff98014a59f52c13a0c88abf9)]:
- - react-docgen@7.0.1
-
-## 2.0.0
-
-### Major Changes
-
-- [#848](https://github.com/reactjs/react-docgen/pull/848)
- [`dda8915`](https://github.com/reactjs/react-docgen/commit/dda8915ce9f8d5065372570d590405f2c2403bd8)
- Thanks [@danez](https://github.com/danez)! - Drop support for Node.js
- version 14.
-
- The minimum supported version is now 16.14.0
-
-### Minor Changes
-
-- [`b0a46e7`](https://github.com/reactjs/react-docgen/commit/b0a46e7429f2a7449eebeff329753b25ac4226c9)
- Thanks [@danez](https://github.com/danez)! - update dependency commander to
- v11
-
-### Patch Changes
-
-- [#859](https://github.com/reactjs/react-docgen/pull/859)
- [`7dd2264`](https://github.com/reactjs/react-docgen/commit/7dd22646877d9a454f7809de5cbbb72499758916)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- commander to v11.1.0
-
-- Updated dependencies
- [[`82154c3`](https://github.com/reactjs/react-docgen/commit/82154c3b59bf22acf3068165f87b089138fdf7ae),
- [`6312f2f`](https://github.com/reactjs/react-docgen/commit/6312f2f47b9f679b5bf923a30855e813193ed4af),
- [`c01d1a0`](https://github.com/reactjs/react-docgen/commit/c01d1a00fdba76cea38eebc953fd3d2dd3f12fbd),
- [`dda8915`](https://github.com/reactjs/react-docgen/commit/dda8915ce9f8d5065372570d590405f2c2403bd8),
- [`62e692f`](https://github.com/reactjs/react-docgen/commit/62e692fcca6f3d17dcf81ce72f2db1a95b2d694b),
- [`74b6680`](https://github.com/reactjs/react-docgen/commit/74b6680910037b1b4b64dd57769b652bf775675e),
- [`0641700`](https://github.com/reactjs/react-docgen/commit/0641700e4425390c0fe50e216a71e5e18322ab3b),
- [`40ebb00`](https://github.com/reactjs/react-docgen/commit/40ebb0010a7a380f89e0c79a4a937cf9a50a3245),
- [`82154c3`](https://github.com/reactjs/react-docgen/commit/82154c3b59bf22acf3068165f87b089138fdf7ae),
- [`3be404e`](https://github.com/reactjs/react-docgen/commit/3be404eee6c8fc7bd867fea9d1987b7f438107d6)]:
- - react-docgen@7.0.0
-
-## 1.0.4
-
-### Patch Changes
-
-- Updated dependencies
- [[`8ba9ac7`](https://github.com/reactjs/react-docgen/commit/8ba9ac74279c74f06803773a1dc5acc50376b5f3)]:
- - react-docgen@6.0.4
-
-## 1.0.3
-
-### Patch Changes
-
-- Updated dependencies
- [[`c3c16e3`](https://github.com/reactjs/react-docgen/commit/c3c16e30ad4cffa7304543ff4bef9b4f13a05683)]:
- - react-docgen@6.0.3
-
-## 1.0.2
-
-### Patch Changes
-
-- [#812](https://github.com/reactjs/react-docgen/pull/812)
- [`0f97ece`](https://github.com/reactjs/react-docgen/commit/0f97ece8ea9cd722b495db67843295b8846bb071)
- Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update
- dependency chalk to v5.3.0
-
-- [#813](https://github.com/reactjs/react-docgen/pull/813)
- [`7aa1e8e`](https://github.com/reactjs/react-docgen/commit/7aa1e8e24d0eb0a0cf36192aa5d00a4944f9844b)
- Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update
- dependency fast-glob to v3.3.0
-
-- Updated dependencies
- [[`ddf4e20`](https://github.com/reactjs/react-docgen/commit/ddf4e20160c41685d81f7d5d8cf21eccb4b41529)]:
- - react-docgen@6.0.2
-
-## 1.0.1
-
-### Patch Changes
-
-- Updated dependencies
- [[`c7e2bd5`](https://github.com/reactjs/react-docgen/commit/c7e2bd5911d660b42bc3bc8b368a7b7cdcf980fd)]:
- - react-docgen@6.0.1
-
-## 1.0.0
-
-### Major Changes
-
-- [#693](https://github.com/reactjs/react-docgen/pull/693)
- [`3b28f6e`](https://github.com/reactjs/react-docgen/commit/3b28f6ee864fddbd872441035b21ad416ae7f417)
- Thanks [@danez](https://github.com/danez)! - Introducing the new CLI package
- `@react-docgen/cli` which was extracted from `react-docgen` and is a complete
- rewrite. Compared to the old CLI these are some of the major differences:
- - Does not support input via stdin anymore
- - The path argument is now a glob
- - `-x, --extension` was removed in favor of globs
- - `-e, --exclude` was removed
- - `-i, --ignore` now accepts a glob
- - `--handler` added
- - `--importer` added
- - `--failOnWarning` added
-
- Check out https://react-docgen.dev/docs/getting-started/cli for the
- documentation.
-
-- [#714](https://github.com/reactjs/react-docgen/pull/714)
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0)
- Thanks [@danez](https://github.com/danez)! - Renamed `--handlers` option to
- `--handler`. This unifies all options to be singular.
-
-### Minor Changes
-
-- [#714](https://github.com/reactjs/react-docgen/pull/714)
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0)
- Thanks [@danez](https://github.com/danez)! - `--resolver` option can now be
- used multiple times.
-
- If used multiple times the resolvers will be chained in the defined order and
- all components from all resolvers will be used.
-
-- [#753](https://github.com/reactjs/react-docgen/pull/753)
- [`217a005`](https://github.com/reactjs/react-docgen/commit/217a00513e2a6554a0ff22ad988fd539fc818921)
- Thanks [@danez](https://github.com/danez)! - Add support for the
- `FindAnnotatedDefinitionsResolver`.
-
- Can be used with
-
- ```
- react-docgen --resolver find-all-annotated-components
- ```
-
-### Patch Changes
-
-- [`ebd9130`](https://github.com/reactjs/react-docgen/commit/ebd9130a583ee3698623205d3393a79ed4ce057b)
- Thanks [@danez](https://github.com/danez)! - Display the correct help info
- when running `react-docgen --help`
-
-- [#782](https://github.com/reactjs/react-docgen/pull/782)
- [`72ac984`](https://github.com/reactjs/react-docgen/commit/72ac9841f02f1f6b925247621bc5aa56d3ba4267)
- Thanks [@renovate](https://github.com/apps/renovate)! - Update dependency
- commander to v10.0.1
-
-- [`050313d`](https://github.com/reactjs/react-docgen/commit/050313d47c3922276e4a06bcf38836f34f9558fb)
- Thanks [@danez](https://github.com/danez)! - Correctly add LICENSE file to
- published packages
-
-- [#792](https://github.com/reactjs/react-docgen/pull/792)
- [`e0999e1`](https://github.com/reactjs/react-docgen/commit/e0999e155fed3b4b2915a26599f475d0884196ca)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- slash to v5.1.0
-
-- [#783](https://github.com/reactjs/react-docgen/pull/783)
- [`fc8a97c`](https://github.com/reactjs/react-docgen/commit/fc8a97c5fb552f5e4d2cbffced6c66f8729d23b6)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- slash to v5.0.1
-
-- [#729](https://github.com/reactjs/react-docgen/pull/729)
- [`5b281f4`](https://github.com/reactjs/react-docgen/commit/5b281f40d4958099d59dc7ce459742516589d0a4)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- commander to v10
-
-- Updated dependencies
- [[`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`8fe3dbf`](https://github.com/reactjs/react-docgen/commit/8fe3dbf510d4d66539bf09db227de5036c125f25),
- [`d7a39af`](https://github.com/reactjs/react-docgen/commit/d7a39af7162c312daba2be428613cb378cce0727),
- [`7c99f15`](https://github.com/reactjs/react-docgen/commit/7c99f156b1cc49da8bc78ca9c7e3bb2da215c49d),
- [`dfc2f85`](https://github.com/reactjs/react-docgen/commit/dfc2f85ae10a668880ed64710a5acd714edf3bf7),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca),
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`caae6bf`](https://github.com/reactjs/react-docgen/commit/caae6bf74ee292a513d6610350d5790c9d23f931),
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`e956802`](https://github.com/reactjs/react-docgen/commit/e956802a26700bb3f827a4500d9fc18a4eed6599),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`a684d82`](https://github.com/reactjs/react-docgen/commit/a684d8281044b3f8c8baecc9148cd4ef2b8fd409),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`cc94da2`](https://github.com/reactjs/react-docgen/commit/cc94da24fc9b2107c7e9df8c680a114038cbb16e),
- [`98a1138`](https://github.com/reactjs/react-docgen/commit/98a113884a2227a89e5aede84ad48238e5f5c4f0),
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0),
- [`3b28f6e`](https://github.com/reactjs/react-docgen/commit/3b28f6ee864fddbd872441035b21ad416ae7f417),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`ea25b16`](https://github.com/reactjs/react-docgen/commit/ea25b16deb721a81e9937a307f88854e4b19f56d),
- [`5a226ac`](https://github.com/reactjs/react-docgen/commit/5a226ac97882378790291cb67b1c0eee471f9def),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`1aa0249`](https://github.com/reactjs/react-docgen/commit/1aa0249f293784091260839377f8204eefb1da23),
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`050313d`](https://github.com/reactjs/react-docgen/commit/050313d47c3922276e4a06bcf38836f34f9558fb),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`5215bab`](https://github.com/reactjs/react-docgen/commit/5215babf11e9c8a672d86816d1250c1e54b22249),
- [`f6e4fe7`](https://github.com/reactjs/react-docgen/commit/f6e4fe75560b1420388119131a8f49abe52757f6),
- [`5215bab`](https://github.com/reactjs/react-docgen/commit/5215babf11e9c8a672d86816d1250c1e54b22249),
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`d4c27d4`](https://github.com/reactjs/react-docgen/commit/d4c27d482e6364c38af2f7c871071f475dc40393),
- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad),
- [`e08e08d`](https://github.com/reactjs/react-docgen/commit/e08e08d6cd56c833fd123019639dca9d819cd7ab)]:
- - react-docgen@6.0.0
-
-## 1.0.0-rc.6
-
-### Patch Changes
-
-- [#792](https://github.com/reactjs/react-docgen/pull/792)
- [`e0999e1`](https://github.com/reactjs/react-docgen/commit/e0999e155fed3b4b2915a26599f475d0884196ca)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- slash to v5.1.0
-
-- Updated dependencies
- [[`7c99f15`](https://github.com/reactjs/react-docgen/commit/7c99f156b1cc49da8bc78ca9c7e3bb2da215c49d)]:
- - react-docgen@6.0.0-rc.9
-
-## 1.0.0-rc.5
-
-### Patch Changes
-
-- Updated dependencies
- [[`5a226ac`](https://github.com/reactjs/react-docgen/commit/5a226ac97882378790291cb67b1c0eee471f9def)]:
- - react-docgen@6.0.0-rc.8
-
-## 1.0.0-rc.4
-
-### Patch Changes
-
-- [#782](https://github.com/reactjs/react-docgen/pull/782)
- [`72ac984`](https://github.com/reactjs/react-docgen/commit/72ac9841f02f1f6b925247621bc5aa56d3ba4267)
- Thanks [@renovate](https://github.com/apps/renovate)! - Update dependency
- commander to v10.0.1
-
-- [#783](https://github.com/reactjs/react-docgen/pull/783)
- [`fc8a97c`](https://github.com/reactjs/react-docgen/commit/fc8a97c5fb552f5e4d2cbffced6c66f8729d23b6)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- slash to v5.0.1
-
-- Updated dependencies
- [[`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca),
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca),
- [`a684d82`](https://github.com/reactjs/react-docgen/commit/a684d8281044b3f8c8baecc9148cd4ef2b8fd409),
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca),
- [`e08e08d`](https://github.com/reactjs/react-docgen/commit/e08e08d6cd56c833fd123019639dca9d819cd7ab)]:
- - react-docgen@6.0.0-rc.7
-
-## 1.0.0-beta.3
-
-### Minor Changes
-
-- 217a005: Add support for the `FindAnnotatedDefinitionsResolver`.
-
- Can be used with
-
- ```
- react-docgen --resolver find-all-annotated-components
- ```
-
-### Patch Changes
-
-- Updated dependencies [dfc2f85]
-- Updated dependencies [cc94da2]
-- Updated dependencies [98a1138]
- - react-docgen@6.0.0-beta.6
-
-## 1.0.0-beta.2
-
-### Major Changes
-
-- 80e4c74: Renamed `--handlers` option to `--handler`. This unifies all options
- to be singular.
-
-### Minor Changes
-
-- 80e4c74: `--resolver` option can now be used multiple times.
-
- If used multiple times the resolvers will be chained in the defined order and
- all components from all resolvers will be used.
-
-### Patch Changes
-
-- ebd9130: Display the correct help info when running `react-docgen --help`
-- 050313d: Correctly add LICENSE file to published packages
-- 5b281f4: update dependency commander to v10
-- Updated dependencies [8fe3dbf]
-- Updated dependencies [d7a39af]
-- Updated dependencies [80e4c74]
-- Updated dependencies [e956802]
-- Updated dependencies [80e4c74]
-- Updated dependencies [ea25b16]
-- Updated dependencies [1aa0249]
-- Updated dependencies [050313d]
-- Updated dependencies [5215bab]
-- Updated dependencies [f6e4fe7]
-- Updated dependencies [5215bab]
-- Updated dependencies [80e4c74]
- - react-docgen@6.0.0-beta.5
-
-## 1.0.0-alpha.1
-
-### Major Changes
-
-- 3b28f6e: Introducing the new CLI package `@react-docgen/cli` which was
- extracted from `react-docgen` and is a complete rewrite. Compared to the old
- CLI these are some of the major differences:
- - Does not support input via stdin anymore
- - The path argument is now a glob
- - `-x, --extension` was removed in favor of globs
- - `-e, --exclude` was removed
- - `-i, --ignore` now accepts a glob
- - `--handler` added
- - `--importer` added
- - `--failOnWarning` added
-
- Check out https://react-docgen.dev/docs/getting-started/cli/ for the
- documentation.
-
-### Patch Changes
-
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [caae6bf]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [3b28f6e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [96d6e9e]
-- Updated dependencies [d4c27d4]
-- Updated dependencies [96d6e9e]
- - react-docgen@6.0.0-alpha.4
diff --git a/packages/react-docgen-cli/README.md b/packages/react-docgen-cli/README.md
deleted file mode 100644
index cb6cdac294e..00000000000
--- a/packages/react-docgen-cli/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# @react-docgen/cli
-
-# Documentation
-
-Please visit https://react-docgen.dev/docs/getting-started/cli/
diff --git a/packages/react-docgen-cli/package.json b/packages/react-docgen-cli/package.json
deleted file mode 100644
index 5c785f9ec88..00000000000
--- a/packages/react-docgen-cli/package.json
+++ /dev/null
@@ -1,44 +0,0 @@
-{
- "name": "@react-docgen/cli",
- "version": "3.0.3",
- "description": "A CLI to extract information from React components for documentation generation.",
- "repository": {
- "type": "git",
- "url": "https://github.com/reactjs/react-docgen.git",
- "directory": "packages/react-docgen-cli"
- },
- "type": "module",
- "bin": {
- "react-docgen": "dist/cli.js"
- },
- "files": [
- "dist"
- ],
- "engines": {
- "node": "^20.9.0 || >=22"
- },
- "scripts": {
- "build": "rimraf dist/ && tsc",
- "test": "vitest run"
- },
- "keywords": [
- "react",
- "cli",
- "documentation-generation"
- ],
- "author": {
- "name": "Daniel Tschinder (http://github.com/danez)"
- },
- "license": "MIT",
- "dependencies": {
- "chalk": "5.6.2",
- "commander": "14.0.1",
- "debug": "4.4.3",
- "fast-glob": "3.3.3",
- "react-docgen": "workspace:8.0.1",
- "slash": "5.1.0"
- },
- "devDependencies": {
- "@types/debug": "4.1.12"
- }
-}
diff --git a/packages/react-docgen-cli/src/cli.ts b/packages/react-docgen-cli/src/cli.ts
deleted file mode 100755
index 392a87af26c..00000000000
--- a/packages/react-docgen-cli/src/cli.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env node
-import { program } from 'commander';
-
-program
- .name('react-docgen')
- .helpOption(false)
- .executableDir('./commands/')
- .command('parse', 'Extract meta information from React components.', {
- isDefault: true,
- executableFile: 'parse/command.js',
- });
-
-program.parse();
diff --git a/packages/react-docgen-cli/src/commands/parse/command.ts b/packages/react-docgen-cli/src/commands/parse/command.ts
deleted file mode 100644
index 6a53701d238..00000000000
--- a/packages/react-docgen-cli/src/commands/parse/command.ts
+++ /dev/null
@@ -1,167 +0,0 @@
-#!/usr/bin/env node
-import glob from 'fast-glob';
-import debugFactory from 'debug';
-import { program } from 'commander';
-import { builtinHandlers, parse } from 'react-docgen';
-import { readFile } from 'fs/promises';
-import outputResult from './output/outputResult.js';
-import loadOptions from './options/loadOptions.js';
-import outputError from './output/outputError.js';
-import { resolve } from 'path';
-import slash from 'slash';
-import type { Documentation } from 'react-docgen';
-import { ResolverConfigs } from './options/loadResolvers.js';
-
-const debug = debugFactory('react-docgen:cli');
-
-const defaultIgnoreGlobs = [
- '**/node_modules/**',
- '**/__tests__/**',
- '**/__mocks__/**',
-];
-
-const defaultHandlers = Object.keys(builtinHandlers);
-const defaultResolvers = ['find-exported-component'];
-
-function collect(value: string, previous: string[]): string[] {
- if (
- !previous ||
- previous === defaultIgnoreGlobs ||
- previous === defaultHandlers ||
- previous === defaultResolvers
- ) {
- previous = [];
- }
-
- const values = value.split(',');
-
- return previous.concat(values);
-}
-
-interface CLIOptions {
- defaultIgnores: boolean;
- failOnWarning: boolean;
- handler?: string[];
- ignore: string[];
- importer?: string;
- out?: string;
- pretty: boolean;
- resolver?: string[];
-}
-
-program
- .name('react-docgen-parse')
- .description(
- 'Extract meta information from React components.\n' +
- 'Either specify a paths to files or a glob pattern that matches multiple files.',
- )
- .option(
- '-o, --out ',
- 'Store extracted information in the specified file instead of printing to stdout. If the file exists it will be overwritten.',
- )
- .option(
- '-i, --ignore ',
- 'Comma separated list of glob patterns which will ignore the paths that match. Can also be used multiple times.',
- collect,
- defaultIgnoreGlobs,
- )
- .option(
- '--no-default-ignores',
- 'Do not ignore the node_modules, __tests__, and __mocks__ directories.',
- )
- .option('--pretty', 'Print the output JSON pretty', false)
- .option(
- '--failOnWarning',
- 'Fail with exit code 2 on react-docgen component warnings. This includes "no component found" and "multiple components found" warnings.',
- false,
- )
- .option(
- '--resolver ',
- `Built-in resolver config (${Object.values(ResolverConfigs).join(
- ', ',
- )}), package name or path to a module that exports a resolver. Can also be used multiple times. When used, no default handlers will be added.`,
- collect,
- defaultResolvers,
- )
- .option(
- '--importer ',
- 'Built-in importer name (fsImport, ignoreImporter), package name or path to a module that exports an importer.',
- 'fsImporter',
- )
- .option(
- '--handler ',
- 'Comma separated list of handlers to use. Can also be used multiple times. When used, no default handlers will be added.',
- collect,
- defaultHandlers,
- )
- .argument('', 'Can be globs or paths to files')
- .action(async (globs: string[], input: CLIOptions) => {
- const {
- defaultIgnores,
- failOnWarning,
- handler,
- ignore,
- importer,
- out: output,
- pretty,
- resolver,
- } = input;
-
- let finalIgnores = ignore;
-
- // Push the default ignores unless the --no-default-ignore is set
- if (defaultIgnores === true && ignore !== defaultIgnoreGlobs) {
- finalIgnores.push(...defaultIgnoreGlobs);
- } else if (defaultIgnores === false && ignore === defaultIgnoreGlobs) {
- finalIgnores = [];
- }
-
- const options = await loadOptions({
- handler,
- importer,
- resolver,
- });
- // we use slash to convert windows backslashes to unix format so fast-glob works
- const files = await glob(globs.map(slash), {
- ignore: finalIgnores?.map((ignorePath) => {
- ignorePath = ignorePath.trim();
- // If the ignore glob starts with a dot we need to resolve the path to an
- // absolute path in order for it to work
- if (ignorePath.startsWith('.')) {
- ignorePath = resolve(process.cwd(), ignorePath);
- }
-
- // we use slash to convert windows backslashes to unix format so fast-glob works
- return slash(ignorePath);
- }),
- });
- const result: Record = {};
- let errorEncountered = false;
-
- await Promise.all(
- files.map(async (path) => {
- debug(`Reading file ${path}`);
- const content = await readFile(path, 'utf-8');
-
- try {
- result[path] = parse(content, {
- filename: path,
- handlers: options.handlers,
- importer: options.importer,
- resolver: options.resolver,
- });
- } catch (error) {
- const isError = outputError(error as Error, path, { failOnWarning });
-
- if (isError) {
- errorEncountered = true;
- }
- }
- }),
- );
- if (!errorEncountered) {
- await outputResult(result, { pretty, output });
- }
- });
-
-program.parse();
diff --git a/packages/react-docgen-cli/src/commands/parse/options/loadOptions.ts b/packages/react-docgen-cli/src/commands/parse/options/loadOptions.ts
deleted file mode 100644
index 3f082a2792e..00000000000
--- a/packages/react-docgen-cli/src/commands/parse/options/loadOptions.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import type { Handler, Importer, Resolver } from 'react-docgen';
-import { builtinHandlers, builtinImporters } from 'react-docgen';
-import loadReactDocgenPlugin from './loadReactDocgenPlugin.js';
-import loadResolvers from './loadResolvers.js';
-
-export default async function loadOptions(input: {
- handler: string[] | undefined;
- importer: string | undefined;
- resolver: string[] | undefined;
-}): Promise<{
- handlers: Handler[] | undefined;
- importer: Importer | undefined;
- resolver: Resolver | undefined;
-}> {
- const importer =
- input.importer && input.importer.length !== 0
- ? await loadReactDocgenPlugin(
- input.importer,
- 'importer',
- builtinImporters,
- )
- : undefined;
-
- const handlers = input.handler
- ? await Promise.all(
- input.handler.map(async (handler) => {
- return await loadReactDocgenPlugin(
- handler,
- 'handler',
- builtinHandlers,
- );
- }),
- )
- : undefined;
-
- return {
- handlers,
- importer,
- resolver: await loadResolvers(input.resolver),
- };
-}
diff --git a/packages/react-docgen-cli/src/commands/parse/options/loadReactDocgenPlugin.ts b/packages/react-docgen-cli/src/commands/parse/options/loadReactDocgenPlugin.ts
deleted file mode 100644
index 37a0bc5a149..00000000000
--- a/packages/react-docgen-cli/src/commands/parse/options/loadReactDocgenPlugin.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { resolve } from 'path';
-import importFile from '../../../utils/importFile.js';
-
-export default async function loadReactDocgenPlugin(
- input: string,
- name: string,
- builtins?: Record,
-): Promise {
- if (builtins?.[input]) {
- return builtins[input]!;
- }
-
- const path = resolve(process.cwd(), input);
- // Maybe it is local path or a package
- const plugin: T | undefined =
- (await importFile(path)) ?? (await importFile(input));
-
- if (plugin) {
- return plugin;
- }
-
- throw new Error(
- `Unknown ${name}: "${input}" is not a built-in ${name}, ` +
- `not a package, and can not be found locally ("${path}")`,
- );
-}
diff --git a/packages/react-docgen-cli/src/commands/parse/options/loadResolvers.ts b/packages/react-docgen-cli/src/commands/parse/options/loadResolvers.ts
deleted file mode 100644
index e9ec06303cb..00000000000
--- a/packages/react-docgen-cli/src/commands/parse/options/loadResolvers.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import type { Resolver } from 'react-docgen';
-import { builtinResolvers } from 'react-docgen';
-import loadReactDocgenPlugin from './loadReactDocgenPlugin.js';
-
-const { ChainResolver } = builtinResolvers;
-
-export enum ResolverConfigs {
- FindAll = 'find-all-components',
- FindAllExported = 'find-all-exported-components',
- FindAllAnnotatedComponents = 'find-all-annotated-components',
- FindExported = 'find-exported-component',
-}
-
-async function loadResolver(input: string): Promise {
- if (input === ResolverConfigs.FindAll) {
- return new builtinResolvers.FindAllDefinitionsResolver();
- } else if (input === ResolverConfigs.FindAllExported) {
- return new builtinResolvers.FindExportedDefinitionsResolver();
- } else if (input === ResolverConfigs.FindAllAnnotatedComponents) {
- return new builtinResolvers.FindAnnotatedDefinitionsResolver();
- } else if (input === ResolverConfigs.FindExported) {
- return new builtinResolvers.FindExportedDefinitionsResolver({
- limit: 1,
- });
- }
-
- const loadedResolver = await loadReactDocgenPlugin(
- input,
- 'resolver',
- );
-
- // Check if it is a class constructor
- // If it is we do not know how to construct the resolver so error instead
- if (
- typeof loadedResolver === 'function' &&
- loadedResolver.toString().startsWith('class ')
- ) {
- throw new Error(
- `The provided resolver '${input}' is not a function or a class instance but instead a class.` +
- ' To solve this please make sure to provide a path to a file that returns a class instance.',
- );
- }
-
- return loadedResolver;
-}
-
-export default async function loadResolvers(
- input: string[] | undefined,
-): Promise {
- if (!input || input.length === 0) {
- return;
- }
-
- if (input.length > 1) {
- return new ChainResolver(await Promise.all(input.map(loadResolver)), {
- chainingLogic: ChainResolver.Logic.ALL,
- });
- }
-
- return loadResolver(input[0]!);
-}
diff --git a/packages/react-docgen-cli/src/commands/parse/output/outputError.ts b/packages/react-docgen-cli/src/commands/parse/output/outputError.ts
deleted file mode 100644
index 708ec76a78f..00000000000
--- a/packages/react-docgen-cli/src/commands/parse/output/outputError.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { relative } from 'path';
-import chalk from 'chalk';
-
-function isReactDocgenError(error: NodeJS.ErrnoException): boolean {
- return Boolean(
- error instanceof Error && error.code?.startsWith('ERR_REACTDOCGEN'),
- );
-}
-
-function outputReactDocgenError(
- error: Error,
- filePath: string,
- { failOnWarning }: { failOnWarning: boolean },
-): boolean {
- let label = 'WARNING';
- let color = chalk.yellow;
- let log = console.warn;
- let isError = false;
-
- if (failOnWarning && isReactDocgenError(error)) {
- process.exitCode = 2;
- isError = true;
- label = 'ERROR';
- color = chalk.red;
- log = console.error;
- }
-
- log(
- color(
- `▶ ${label}: ${error.message} 👀\n in ${chalk.underline(
- relative(process.cwd(), filePath),
- )}\n`,
- ),
- );
-
- return isError;
-}
-
-export default function outputError(
- error: Error,
- filePath: string,
- options: { failOnWarning: boolean },
-): boolean {
- if (isReactDocgenError(error)) {
- return outputReactDocgenError(error, filePath, options);
- } else {
- process.exitCode = 1;
- console.error(error);
-
- return true;
- }
-}
diff --git a/packages/react-docgen-cli/src/commands/parse/output/outputResult.ts b/packages/react-docgen-cli/src/commands/parse/output/outputResult.ts
deleted file mode 100644
index 7b04191f972..00000000000
--- a/packages/react-docgen-cli/src/commands/parse/output/outputResult.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { writeFile } from 'fs/promises';
-import type { Documentation } from 'react-docgen';
-
-export default async function outputResult(
- documentation: Record,
- { pretty = false, output }: { pretty: boolean; output: string | undefined },
-): Promise {
- const result = JSON.stringify(
- documentation,
- undefined,
- pretty ? 2 : undefined,
- );
-
- if (output) {
- await writeFile(output, result, 'utf-8');
- } else {
- process.stdout.write(result + '\n');
- }
-}
diff --git a/packages/react-docgen-cli/src/utils/importFile.ts b/packages/react-docgen-cli/src/utils/importFile.ts
deleted file mode 100644
index c1a44c27a0d..00000000000
--- a/packages/react-docgen-cli/src/utils/importFile.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { createRequire } from 'module';
-import { pathToFileURL } from 'url';
-
-const require = createRequire(import.meta.url);
-const resolveOptions = { paths: [process.cwd()] };
-
-export default async function importFile(
- importSpecifier: string,
-): Promise {
- try {
- const importedFile = await import(
- // need to convert to file:// url as on windows absolute path strings do not work
- pathToFileURL(require.resolve(importSpecifier, resolveOptions)).href
- );
-
- return importedFile.default ? importedFile.default : importedFile;
- } catch (error) {
- if (
- error instanceof Error &&
- (error as NodeJS.ErrnoException).code !== 'ERR_MODULE_NOT_FOUND' &&
- (error as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND'
- ) {
- throw error;
- }
-
- return undefined;
- }
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/basic/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/basic/Component.js
deleted file mode 100644
index d35bc49b9b0..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/basic/Component.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const React = require('react');
-
-// @component
-module.exports = class Component extends React.Component {
- displayName = "Component"
-
- otherMethod() {}
- render() {}
-};
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/basic/NoComponent.js b/packages/react-docgen-cli/tests/integration/__fixtures__/basic/NoComponent.js
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-cjs/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-cjs/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-cjs/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-cjs/handler.cjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-cjs/handler.cjs
deleted file mode 100644
index e9f492ec5cd..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-cjs/handler.cjs
+++ /dev/null
@@ -1,5 +0,0 @@
-const testHandler = function (documentation) {
- documentation.set('displayName', 'testhandler');
-};
-
-module.exports = testHandler;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-esm/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-esm/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-esm/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-esm/handler.mjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-esm/handler.mjs
deleted file mode 100644
index 4c6b55a5dd6..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-esm/handler.mjs
+++ /dev/null
@@ -1,5 +0,0 @@
-const testHandler = function (documentation) {
- documentation.set('displayName', 'testhandler');
-};
-
-export default testHandler;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/node_modules/test-react-docgen-handler/index.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/node_modules/test-react-docgen-handler/index.js
deleted file mode 100644
index e9f492ec5cd..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/node_modules/test-react-docgen-handler/index.js
+++ /dev/null
@@ -1,5 +0,0 @@
-const testHandler = function (documentation) {
- documentation.set('displayName', 'testhandler');
-};
-
-module.exports = testHandler;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/node_modules/test-react-docgen-handler/package.json b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/node_modules/test-react-docgen-handler/package.json
deleted file mode 100644
index a92d0ff2c41..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-handler-npm/node_modules/test-react-docgen-handler/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": "test-react-docgen-handler"
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-esm/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-esm/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-esm/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-esm/importer.mjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-esm/importer.mjs
deleted file mode 100644
index 274ce883f7a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-esm/importer.mjs
+++ /dev/null
@@ -1,15 +0,0 @@
-const testImporter = function (pa, n, file) {
- const newFile = file.parse('("importer")', 'x.js');
-
- let path;
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return path.get('body')[0].get('expression');
-};
-
-export default testImporter;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/node_modules/test-react-docgen-importer/index.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/node_modules/test-react-docgen-importer/index.js
deleted file mode 100644
index d8c52d2585e..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/node_modules/test-react-docgen-importer/index.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const testImporter = function (pa, n, file) {
- const newFile = file.parse('("importer")', 'x.js');
-
- let path;
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return path.get('body')[0].get('expression');
-};
-
-module.exports = testImporter;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/node_modules/test-react-docgen-importer/package.json b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/node_modules/test-react-docgen-importer/package.json
deleted file mode 100644
index 65df75ff836..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/custom-importer-npm/node_modules/test-react-docgen-importer/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": "test-react-docgen-importer"
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/importer.cjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/importer.cjs
deleted file mode 100644
index cc56ed37ee4..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-cjs/importer.cjs
+++ /dev/null
@@ -1,15 +0,0 @@
-const testImporter = function (pa, n, file) {
- const newFile = file.parse('("importer")', 'x.js');
-
- let path;
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return path.get('body')[0].get('expression');
-};
-
-module.exports = testImporter;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-esm/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-esm/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-esm/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-esm/importer.mjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-esm/importer.mjs
deleted file mode 100644
index 274ce883f7a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-esm/importer.mjs
+++ /dev/null
@@ -1,15 +0,0 @@
-const testImporter = function (pa, n, file) {
- const newFile = file.parse('("importer")', 'x.js');
-
- let path;
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return path.get('body')[0].get('expression');
-};
-
-export default testImporter;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/Component.js
deleted file mode 100644
index a3c7eb41603..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/Component.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const React = require('react');
-import x from './other.cjs';
-
-function Component() {
- return ;
-};
-
-Component.displayName = x
-
-module.exports = Component
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/node_modules/test-react-docgen-importer/index.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/node_modules/test-react-docgen-importer/index.js
deleted file mode 100644
index d8c52d2585e..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/node_modules/test-react-docgen-importer/index.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const testImporter = function (pa, n, file) {
- const newFile = file.parse('("importer")', 'x.js');
-
- let path;
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return path.get('body')[0].get('expression');
-};
-
-module.exports = testImporter;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/node_modules/test-react-docgen-importer/package.json b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/node_modules/test-react-docgen-importer/package.json
deleted file mode 100644
index 65df75ff836..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-importer-npm/node_modules/test-react-docgen-importer/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": "test-react-docgen-importer"
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/Component.js
deleted file mode 100644
index 1a0ceba0d5f..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/Component.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const React = require('react');
-
-const Component = React.createClass({
- displayName: 'Component',
- render: function () {},
-});
-
-module.exports = Component;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver-class/index.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver-class/index.js
deleted file mode 100644
index 559f79ff687..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver-class/index.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = class {
- resolve(file) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
- }
-}
-
-module.exports = customResolver;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver-class/package.json b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver-class/package.json
deleted file mode 100644
index 8c629f16740..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver-class/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": "test-react-docgen-resolver-class"
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver/index.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver/index.js
deleted file mode 100644
index a55182ff122..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver/index.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = class {
- resolve(file) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
- }
-}
-
-module.exports = new customResolver();
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver/package.json b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver/package.json
deleted file mode 100644
index 8d3ed80b3d1..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/node_modules/test-react-docgen-resolver/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": "test-react-docgen-resolver"
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/resolver.cjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/resolver.cjs
deleted file mode 100644
index a55182ff122..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/resolver.cjs
+++ /dev/null
@@ -1,23 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = class {
- resolve(file) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
- }
-}
-
-module.exports = new customResolver();
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/resolver.mjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/resolver.mjs
deleted file mode 100644
index 30b014dff87..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-class/resolver.mjs
+++ /dev/null
@@ -1,25 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = class {
- resolve(file) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
- }
-}
-
-const resolver = new customResolver();
-
-export default resolver;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/Component.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/Component.js
deleted file mode 100644
index 1a0ceba0d5f..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/Component.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const React = require('react');
-
-const Component = React.createClass({
- displayName: 'Component',
- render: function () {},
-});
-
-module.exports = Component;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/node_modules/test-react-docgen-resolver/index.js b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/node_modules/test-react-docgen-resolver/index.js
deleted file mode 100644
index 8fcf0e1763a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/node_modules/test-react-docgen-resolver/index.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = function (
- file,
-) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
-};
-
-module.exports = customResolver;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/node_modules/test-react-docgen-resolver/package.json b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/node_modules/test-react-docgen-resolver/package.json
deleted file mode 100644
index 8d3ed80b3d1..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/node_modules/test-react-docgen-resolver/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": "test-react-docgen-resolver"
-}
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/resolver.cjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/resolver.cjs
deleted file mode 100644
index 8fcf0e1763a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/resolver.cjs
+++ /dev/null
@@ -1,23 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = function (
- file,
-) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
-};
-
-module.exports = customResolver;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/resolver.mjs b/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/resolver.mjs
deleted file mode 100644
index d1d89b17efa..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/custom-resolver-function/resolver.mjs
+++ /dev/null
@@ -1,23 +0,0 @@
-const code = `
- ({
- displayName: 'Custom',
- })
-`;
-
-const customResolver = function (
- file,
-) {
- const newFile = file.parse(code, 'x.js');
- let path;
-
- newFile.traverse({
- Program(p) {
- path = p;
- p.stop();
- }
- });
-
- return [path.get('body')[0].get('expression')];
-};
-
-export default customResolver;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/__mocks__/MockComponent.js b/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/__mocks__/MockComponent.js
deleted file mode 100644
index 0858c85792a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/__mocks__/MockComponent.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const React = require('react');
-
-const Component = React.createClass({
- displayName: 'MockComponent',
- render: function () {},
-});
-
-module.exports = Component;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/__tests__/TestComponent.js b/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/__tests__/TestComponent.js
deleted file mode 100644
index de3324c137a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/__tests__/TestComponent.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const React = require('react');
-
-const Component = React.createClass({
- displayName: 'TestComponent',
- render: function () {},
-});
-
-module.exports = Component;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/foo/FooComponent.js b/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/foo/FooComponent.js
deleted file mode 100644
index 4843f1e0d63..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/foo/FooComponent.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const React = require('react');
-
-const Component = React.createClass({
- displayName: 'FooComponent',
- render: function () {},
-});
-
-module.exports = Component;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/node_modules/NodeModulesComponent.js b/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/node_modules/NodeModulesComponent.js
deleted file mode 100644
index 8ee5d6b4f95..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/ignore/node_modules/NodeModulesComponent.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const React = require('react');
-
-const Component = React.createClass({
- displayName: 'NodeModulesComponent',
- render: function () {},
-});
-
-module.exports = Component;
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/multiple/MultipleComponents.js b/packages/react-docgen-cli/tests/integration/__fixtures__/multiple/MultipleComponents.js
deleted file mode 100644
index 23ed1a0b4e0..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/multiple/MultipleComponents.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const React = require('react');
-
-exports.ComponentA = React.createClass({
- displayName: 'ComponentA',
- render: function () {
- // ...
- },
-});
-
-exports.ComponentB = React.createClass({
- displayName: 'ComponentB',
- render: function () {
- // ...
- },
-});
diff --git a/packages/react-docgen-cli/tests/integration/__fixtures__/syntax-error/SyntaxError.js b/packages/react-docgen-cli/tests/integration/__fixtures__/syntax-error/SyntaxError.js
deleted file mode 100644
index 8f7c4dfc85a..00000000000
--- a/packages/react-docgen-cli/tests/integration/__fixtures__/syntax-error/SyntaxError.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports {}
diff --git a/packages/react-docgen-cli/tests/integration/cli-test.ts b/packages/react-docgen-cli/tests/integration/cli-test.ts
deleted file mode 100644
index 17bafe1e8c9..00000000000
--- a/packages/react-docgen-cli/tests/integration/cli-test.ts
+++ /dev/null
@@ -1,213 +0,0 @@
-import { readFile } from 'fs/promises';
-import { join } from 'path';
-import { temporaryFile } from 'tempy';
-import { describe, expect, test } from 'vitest';
-import withFixture from './utils/withFixture';
-
-describe('cli', () => {
- describe('glob', () => {
- test('reads files provided as command line arguments', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- join(dir, `Component.js`),
- join(dir, `NoComponent.js`),
- ]);
-
- expect(stderr).toContain('NoComponent.js');
- expect(stdout).toContain('Component.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('reads absolute globs provided as command line arguments', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([`${dir}/*`]);
-
- expect(stderr).toContain('NoComponent.js');
- expect(stdout).toContain('Component.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('reads relative globs provided as command line arguments', async () => {
- await withFixture('basic', async ({ run }) => {
- const { stdout, stderr } = await run(['./*']);
-
- expect(stderr).toContain('NoComponent.js');
- expect(stdout).toContain('Component.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('ignore', () => {
- test('ignores files in node_modules, __tests__ and __mocks__ by default', async () => {
- await withFixture('ignore', async ({ dir, run }) => {
- const { stdout, stderr } = await run([`${dir}/**/*`]);
-
- expect(stderr).toBe('');
- expect(stdout).not.toContain('MockComponent.js');
- expect(stdout).not.toContain('TestComponent.js');
- expect(stdout).not.toContain('NodeModulesComponent.js');
- expect(stdout).toContain('FooComponent.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('can disable default ignores', async () => {
- await withFixture('ignore', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--no-default-ignores',
- `${dir}/**/*`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('MockComponent.js');
- expect(stdout).toContain('TestComponent.js');
- expect(stdout).toContain('NodeModulesComponent.js');
- expect(stdout).toContain('FooComponent.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('ignores directory defined by glob starting with star', async () => {
- await withFixture('ignore', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--ignore=**/foo/**',
- `${dir}/**/*`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).not.toContain('MockComponent.js');
- expect(stdout).not.toContain('TestComponent.js');
- expect(stdout).not.toContain('NodeModulesComponent.js');
- expect(stdout).not.toContain('FooComponent.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('ignores directory defined by relative path', async () => {
- await withFixture('ignore', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--ignore',
- './foo/**',
- `${dir}/**/*`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).not.toContain('MockComponent.js');
- expect(stdout).not.toContain('TestComponent.js');
- expect(stdout).not.toContain('NodeModulesComponent.js');
- expect(stdout).not.toContain('FooComponent.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('ignores directory with shortcut defined by glob starting with star', async () => {
- await withFixture('ignore', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '-i',
- '**/foo/**',
- `${dir}/**/*`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).not.toContain('MockComponent.js');
- expect(stdout).not.toContain('TestComponent.js');
- expect(stdout).not.toContain('NodeModulesComponent.js');
- expect(stdout).not.toContain('FooComponent.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('ignores directory with shortcut defined by relative path', async () => {
- await withFixture('ignore', async ({ dir, run }) => {
- const { stdout, stderr } = await run(['-i', './foo/**', `${dir}/**/*`]);
-
- expect(stderr).toBe('');
- expect(stdout).not.toContain('MockComponent.js');
- expect(stdout).not.toContain('TestComponent.js');
- expect(stdout).not.toContain('NodeModulesComponent.js');
- expect(stdout).not.toContain('FooComponent.js');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('out', () => {
- test('writes to a file if provided', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const outFile = temporaryFile();
- const { stdout, stderr } = await run([
- `--out=${outFile}`,
- `${dir}/Component.js`,
- ]);
-
- const writtenResult = await readFile(outFile, 'utf-8');
-
- expect(stderr).toBe('');
- expect(writtenResult.length).toBeGreaterThan(4);
- expect(() => JSON.parse(writtenResult)).not.toThrowError();
- expect(stdout).toBe('');
- });
- });
-
- test('writes to a file if provided shortcut', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const outFile = temporaryFile();
- const { stdout, stderr } = await run([
- '-o',
- outFile,
- `${dir}/Component.js`,
- ]);
-
- const writtenResult = await readFile(outFile, 'utf-8');
-
- expect(stderr).toBe('');
- expect(writtenResult.length).toBeGreaterThan(4);
- expect(() => JSON.parse(writtenResult)).not.toThrowError();
- expect(stdout).toBe('');
- });
- });
- });
-
- describe('pretty', () => {
- test('by default does not prettify output', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([join(dir, `Component.js`)]);
-
- expect(stderr).toBe('');
- expect(stdout).not.toContain('\n');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('does prettify output', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--pretty',
- join(dir, `Component.js`),
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('\n');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('error', () => {
- test('does exit with code 2 on warning', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr, exitCode } = await run([
- '--failOnWarning',
- `${dir}/*`,
- ]);
-
- expect(stderr).toContain('NoComponent');
- expect(stdout).toEqual('');
- expect(exitCode).toBe(2);
- });
- });
- });
-});
diff --git a/packages/react-docgen-cli/tests/integration/handler-test.ts b/packages/react-docgen-cli/tests/integration/handler-test.ts
deleted file mode 100644
index f37e3b5934d..00000000000
--- a/packages/react-docgen-cli/tests/integration/handler-test.ts
+++ /dev/null
@@ -1,136 +0,0 @@
-import { join } from 'path';
-import { describe, expect, test } from 'vitest';
-import { builtinHandlers } from 'react-docgen';
-import withFixture from './utils/withFixture';
-
-describe('handler', () => {
- describe('accepts the names of builtin handlers', () => {
- test.each(Object.keys(builtinHandlers))('%s', async (importer) => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--handler=${importer}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Component');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('multiple handlers', () => {
- test('multiple handlers arguments', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--handler=displayNameHandler`,
- `--handler=componentDocblockHandler`,
- `--handler=componentMethodsHandler`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"Component"');
- expect(stdout).toContain('"description":""');
- expect(stdout).toContain('"name":"otherMethod"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('multiple handlers comma separated', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--handler=displayNameHandler,componentDocblockHandler,componentMethodsHandler`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"Component"');
- expect(stdout).toContain('"description":""');
- expect(stdout).toContain('"name":"otherMethod"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('custom handlers', () => {
- test('accepts an absolute local CommonJS path', async () => {
- await withFixture('custom-handler-cjs', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--handler=${join(dir, 'handler.cjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"testhandler"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local CommonJS path', async () => {
- await withFixture('custom-handler-cjs', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--handler',
- './handler.cjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"testhandler"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts an absolute local ESM path', async () => {
- await withFixture('custom-handler-esm', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--handler=${join(dir, 'handler.mjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"testhandler"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local ESM path', async () => {
- await withFixture('custom-handler-esm', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--handler',
- './handler.mjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"testhandler"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a npm package', async () => {
- await withFixture('custom-handler-npm', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--handler=test-react-docgen-handler',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"testhandler"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('throws error when not found', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--handler=does-not-exist',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toContain('Unknown handler: "does-not-exist"');
- expect(stdout).toBe('');
- });
- });
- });
-});
diff --git a/packages/react-docgen-cli/tests/integration/importer-test.ts b/packages/react-docgen-cli/tests/integration/importer-test.ts
deleted file mode 100644
index 19a59852dc3..00000000000
--- a/packages/react-docgen-cli/tests/integration/importer-test.ts
+++ /dev/null
@@ -1,102 +0,0 @@
-import { join } from 'path';
-import { describe, expect, test } from 'vitest';
-import { builtinImporters } from 'react-docgen';
-import withFixture from './utils/withFixture';
-
-describe('importer', () => {
- describe('accepts the names of builtin importers', () => {
- test.each(Object.keys(builtinImporters))('%s', async (importer) => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--importer=${importer}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Component');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('custom importer', () => {
- test('accepts an absolute local CommonJS path', async () => {
- await withFixture('custom-importer-cjs', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--importer=${join(dir, 'importer.cjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"importer"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local CommonJS path', async () => {
- await withFixture('custom-importer-cjs', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--importer',
- './importer.cjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"importer"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts an absolute local ESM path', async () => {
- await withFixture('custom-importer-esm', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--importer=${join(dir, 'importer.mjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"importer"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local ESM path', async () => {
- await withFixture('custom-importer-esm', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--importer',
- './importer.mjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"importer"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a npm package', async () => {
- await withFixture('custom-importer-npm', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--importer=test-react-docgen-importer',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('"displayName":"importer"');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('throws error when not found', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--importer=does-not-exist',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toContain('Unknown importer: "does-not-exist"');
- expect(stdout).toBe('');
- });
- });
- });
-});
diff --git a/packages/react-docgen-cli/tests/integration/resolver-test.ts b/packages/react-docgen-cli/tests/integration/resolver-test.ts
deleted file mode 100644
index 0d6fe8bae13..00000000000
--- a/packages/react-docgen-cli/tests/integration/resolver-test.ts
+++ /dev/null
@@ -1,186 +0,0 @@
-import { join } from 'path';
-import { describe, expect, test } from 'vitest';
-import { ResolverConfigs } from '../../src/commands/parse/options/loadResolvers.js';
-import withFixture from './utils/withFixture';
-
-describe('resolver', () => {
- describe('accepts the names of builtin resolver configs', () => {
- test.each(Object.values(ResolverConfigs))('%s', async (importer) => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--resolver=${importer}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Component');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
-
- describe('custom resolver', () => {
- describe('function', () => {
- test('accepts an absolute local CommonJS path', async () => {
- await withFixture('custom-resolver-function', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--resolver=${join(dir, 'resolver.cjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local CommonJS path', async () => {
- await withFixture('custom-resolver-function', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver',
- './resolver.cjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts an absolute local ESM path', async () => {
- await withFixture('custom-resolver-function', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--resolver=${join(dir, 'resolver.mjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local ESM path', async () => {
- await withFixture('custom-resolver-function', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver',
- './resolver.mjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a npm package', async () => {
- await withFixture('custom-resolver-function', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver=test-react-docgen-resolver',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
- });
- describe('class', () => {
- test('accepts an absolute local CommonJS path', async () => {
- await withFixture('custom-resolver-class', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--resolver=${join(dir, 'resolver.cjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local CommonJS path', async () => {
- await withFixture('custom-resolver-class', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver',
- './resolver.cjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts an absolute local ESM path', async () => {
- await withFixture('custom-resolver-class', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- `--resolver=${join(dir, 'resolver.mjs')}`,
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a relative local ESM path', async () => {
- await withFixture('custom-resolver-class', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver',
- './resolver.mjs',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('accepts a npm package', async () => {
- await withFixture('custom-resolver-class', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver=test-react-docgen-resolver',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toBe('');
- expect(stdout).toContain('Custom');
- expect(() => JSON.parse(stdout)).not.toThrowError();
- });
- });
-
- test('throws if export is not a class instance', async () => {
- await withFixture('custom-resolver-class', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver=test-react-docgen-resolver-class',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toContain(
- "The provided resolver 'test-react-docgen-resolver-class' is not a function or a class instance but instead a class",
- );
- expect(stdout).toBe('');
- });
- });
- });
-
- test('throws error when not found', async () => {
- await withFixture('basic', async ({ dir, run }) => {
- const { stdout, stderr } = await run([
- '--resolver=does-not-exist',
- `${dir}/Component.js`,
- ]);
-
- expect(stderr).toContain('Unknown resolver: "does-not-exist"');
- expect(stdout).toBe('');
- });
- });
- });
-});
diff --git a/packages/react-docgen-cli/tests/integration/utils/withFixture.ts b/packages/react-docgen-cli/tests/integration/utils/withFixture.ts
deleted file mode 100644
index ea401a02b58..00000000000
--- a/packages/react-docgen-cli/tests/integration/utils/withFixture.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { rm, stat } from 'fs/promises';
-import { dirname, join } from 'path';
-import type { ExecaError, ExecaReturnValue } from 'execa';
-import { execaNode } from 'execa';
-import copy from 'cpy';
-import { temporaryDirectory } from 'tempy';
-import { fileURLToPath } from 'url';
-
-const __dir = dirname(fileURLToPath(import.meta.url));
-
-const fixtureDir = join(__dir, '../__fixtures__');
-const cliBinary = join(__dir, '../../../dist/cli.js');
-
-export default async function withFixture(
- fixture: string,
- callback: (api: {
- dir: string;
- run: (
- args: readonly string[],
- ) => Promise<{ stdout: string; stderr: string; exitCode: number }>;
- }) => Promise,
-): Promise {
- const tempDir = temporaryDirectory();
-
- async function run(
- args: readonly string[],
- ): Promise> {
- try {
- return await execaNode(cliBinary, args, {
- cwd: tempDir,
- });
- } catch (error) {
- return error as ExecaError;
- }
- }
-
- await stat(join(fixtureDir, fixture));
-
- await copy(join(fixtureDir, fixture, '**/*'), tempDir, {});
- await callback({ dir: tempDir, run });
- await rm(tempDir, { force: true, recursive: true });
-}
diff --git a/packages/react-docgen-cli/tsconfig.json b/packages/react-docgen-cli/tsconfig.json
deleted file mode 100644
index d6e3d9b995d..00000000000
--- a/packages/react-docgen-cli/tsconfig.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "extends": "../../tsconfig.base.json",
- "compilerOptions": {
- "declaration": false,
- "outDir": "./dist"
- },
- "exclude": ["**/__tests__/**/*", "**/__mocks__/**/*"],
- "include": ["src/**/*"]
-}
diff --git a/packages/react-docgen-cli/vitest.config.ts b/packages/react-docgen-cli/vitest.config.ts
deleted file mode 100644
index 8fa82bbafb9..00000000000
--- a/packages/react-docgen-cli/vitest.config.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { defineConfig } from 'vitest/config';
-
-export default defineConfig({
- test: {
- name: 'cli',
- include: ['**/__tests__/**/*-test.ts', '**/tests/integration/**/*-test.ts'],
- testTimeout: 30_000,
- deps: {
- interopDefault: false,
- },
- coverage: {
- all: true,
- include: ['src/**'],
- provider: 'v8',
- reporter: ['text', 'lcov'],
- },
- },
-});
diff --git a/packages/react-docgen/CHANGELOG.md b/packages/react-docgen/CHANGELOG.md
deleted file mode 100644
index 4451c7ff11d..00000000000
--- a/packages/react-docgen/CHANGELOG.md
+++ /dev/null
@@ -1,870 +0,0 @@
-# Release Notes
-
-## 8.0.1
-
-### Patch Changes
-
-- [#1009](https://github.com/reactjs/react-docgen/pull/1009)
- [`4c7dd9d`](https://github.com/reactjs/react-docgen/commit/4c7dd9d12ffdb3ac1d6f9663124cc43ec7fabb08)
- Thanks [@danez](https://github.com/danez)! - Do not fail on new VoidPattern
- type
-
-## 8.0.0
-
-### Major Changes
-
-- [#942](https://github.com/reactjs/react-docgen/pull/942)
- [`c3dfead`](https://github.com/reactjs/react-docgen/commit/c3dfead6b1cfdd57e34d1689c2b1d1334e9ef328)
- Thanks [@danez](https://github.com/danez)! - Drop support for Node.js 16, 17,
- 18, 19 and 21.
-
- With this `react-docgen` version Node.js support is:
- - Node.js 20.9.0 or newer 20.x versions
- - Node.js 22.0.0 or any newer version
-
-### Patch Changes
-
-- [#993](https://github.com/reactjs/react-docgen/pull/993)
- [`06c2fae`](https://github.com/reactjs/react-docgen/commit/06c2fae6f0d7f1aea3f23c2bf0dbfdc7b801ccb8)
- Thanks [@danez](https://github.com/danez)! - Fixed crash when classes with
- private fields are used
-
-## 7.1.1
-
-### Patch Changes
-
-- [#969](https://github.com/reactjs/react-docgen/pull/969)
- [`639bf37`](https://github.com/reactjs/react-docgen/commit/639bf3799bd74c46c2163841fefd9f3cc847dce9)
- Thanks [@christon88](https://github.com/christon88)! - Expose more TypeScript
- types
-
-## 7.1.0
-
-### Minor Changes
-
-- [#923](https://github.com/reactjs/react-docgen/pull/923)
- [`3033ca0`](https://github.com/reactjs/react-docgen/commit/3033ca0908eb53f6ae2ee8a40eb4ef96840ff7ad)
- Thanks [@rvetere](https://github.com/rvetere)! - Support generic types on
- `React.forwardRef` calls.
-
- Example:
-
- `react-docgen` will now find `IButtonProps`.
-
- ```ts
- export const FullWidthButton = forwardRef(
- () => {},
- );
- ```
-
-## 7.0.3
-
-### Patch Changes
-
-- [#890](https://github.com/reactjs/react-docgen/pull/890)
- [`afe8d02`](https://github.com/reactjs/react-docgen/commit/afe8d022d058a5d49c6fc144fb165c02f4a764d9)
- Thanks [@danez](https://github.com/danez)! - Do not throw error when using
- namespace specifiers in export statements
-
-## 7.0.2
-
-### Patch Changes
-
-- [`64bf1aa`](https://github.com/reactjs/react-docgen/commit/64bf1aa078148b4d44f8634252e5b726e24b8ee5)
- Thanks [@danez](https://github.com/danez)! - Fix handling of template literals
-
-## 7.0.1
-
-### Patch Changes
-
-- [#870](https://github.com/reactjs/react-docgen/pull/870)
- [`2b51bbd`](https://github.com/reactjs/react-docgen/commit/2b51bbd47d14638ff98014a59f52c13a0c88abf9)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- @types/doctrine to ^0.0.9
-
-## 7.0.0
-
-### Major Changes
-
-- [#846](https://github.com/reactjs/react-docgen/pull/846)
- [`82154c3`](https://github.com/reactjs/react-docgen/commit/82154c3b59bf22acf3068165f87b089138fdf7ae)
- Thanks [@danez](https://github.com/danez)! - `getTypeFromReactComponent` now
- returns an array of paths to types instead of just one. This can appear when
- multiple type definitions are found for a component, for example:
-
- ```ts
- const Component: React.FC = (props: { some: string }) => {};
- ```
-
- In this example both the `Props` definition as well as `{ some: string }` are
- now found and used.
-
- Here is a simple diff to illustrate the change when using
- `getTypeFromReactComponent`:
-
- ```diff
-
- const type = getTypeFromReactComponent(path)
-
- -if (type) {
- +if (type.length > 0) {
- // do smth
- }
-
- ```
-
-- [#848](https://github.com/reactjs/react-docgen/pull/848)
- [`dda8915`](https://github.com/reactjs/react-docgen/commit/dda8915ce9f8d5065372570d590405f2c2403bd8)
- Thanks [@danez](https://github.com/danez)! - Drop support for Node.js
- version 14.
-
- The minimum supported version is now 16.14.0
-
-- [#846](https://github.com/reactjs/react-docgen/pull/846)
- [`62e692f`](https://github.com/reactjs/react-docgen/commit/62e692fcca6f3d17dcf81ce72f2db1a95b2d694b)
- Thanks [@danez](https://github.com/danez)! - `resolveToValue` will not resolve
- to `ImportDeclaration` anymore but instead to one of the possible specifiers
- (`ImportSpecifier`, `ImportDefaultSpecifier` or `ImportNamespaceSpecifier`).
- This gives better understanding to which specifier exactly `resolveToValue`
- did resolve a NodePath to.
-
- Here is a possible easy fix for this in a code snippet that uses
- `resolveToValue`
-
- ```diff
- const resolved = resolveToValue(path);
-
- -if (resolved.isImportDeclaration()) {
- +if (resolved.parentPath?.isImportDeclaration()) {
- // do smth
- }
- ```
-
-### Minor Changes
-
-- [#862](https://github.com/reactjs/react-docgen/pull/862)
- [`40ebb00`](https://github.com/reactjs/react-docgen/commit/40ebb0010a7a380f89e0c79a4a937cf9a50a3245)
- Thanks [@danez](https://github.com/danez)! - Support `PropsWithoutRef`,
- `PropsWithRef` and `PropsWithChildren` in TypeScript.
-
- Component props are now detected correctly when these builtin types are used,
- but they do currently not add any props to the documentation.
-
-- [#846](https://github.com/reactjs/react-docgen/pull/846)
- [`82154c3`](https://github.com/reactjs/react-docgen/commit/82154c3b59bf22acf3068165f87b089138fdf7ae)
- Thanks [@danez](https://github.com/danez)! - Add support for `React.FC` in
- TypeScript.
-
-### Patch Changes
-
-- [`6312f2f`](https://github.com/reactjs/react-docgen/commit/6312f2f47b9f679b5bf923a30855e813193ed4af)
- Thanks [@renovate[bot]](https://github.com/renovate%5Bbot%5D)! - update
- dependency @types/doctrine to ^0.0.7
-
-- [#846](https://github.com/reactjs/react-docgen/pull/846)
- [`c01d1a0`](https://github.com/reactjs/react-docgen/commit/c01d1a00fdba76cea38eebc953fd3d2dd3f12fbd)
- Thanks [@danez](https://github.com/danez)! - Fix detection of react class
- components when super class is imported via named import.
-
-- [#861](https://github.com/reactjs/react-docgen/pull/861)
- [`74b6680`](https://github.com/reactjs/react-docgen/commit/74b6680910037b1b4b64dd57769b652bf775675e)
- Thanks [@renovate](https://github.com/apps/renovate)! - update dependency
- @types/doctrine to ^0.0.8
-
-- [#846](https://github.com/reactjs/react-docgen/pull/846)
- [`0641700`](https://github.com/reactjs/react-docgen/commit/0641700e4425390c0fe50e216a71e5e18322ab3b)
- Thanks [@danez](https://github.com/danez)! - Remove unnecessary call to
- `resolveToValue` when trying to find props type from react components.
-
-- [#858](https://github.com/reactjs/react-docgen/pull/858)
- [`3be404e`](https://github.com/reactjs/react-docgen/commit/3be404eee6c8fc7bd867fea9d1987b7f438107d6)
- Thanks [@danez](https://github.com/danez)! - Fix detection of React.Children
- with ESM imports
-
-## 6.0.4
-
-### Patch Changes
-
-- [#838](https://github.com/reactjs/react-docgen/pull/838)
- [`8ba9ac7`](https://github.com/reactjs/react-docgen/commit/8ba9ac74279c74f06803773a1dc5acc50376b5f3)
- Thanks [@danez](https://github.com/danez)! - Support index types correctly in
- flow
-
-## 6.0.3
-
-### Patch Changes
-
-- [#830](https://github.com/reactjs/react-docgen/pull/830)
- [`c3c16e3`](https://github.com/reactjs/react-docgen/commit/c3c16e30ad4cffa7304543ff4bef9b4f13a05683)
- Thanks [@danez](https://github.com/danez)! - Fixed error with object and array
- patterns in function signatures.
-
-## 6.0.2
-
-### Patch Changes
-
-- [#810](https://github.com/reactjs/react-docgen/pull/810)
- [`ddf4e20`](https://github.com/reactjs/react-docgen/commit/ddf4e20160c41685d81f7d5d8cf21eccb4b41529)
- Thanks [@danez](https://github.com/danez)! - Read docblock in nested flow
- object types and use them as descriptions
-
-## 6.0.1
-
-### Patch Changes
-
-- [#806](https://github.com/reactjs/react-docgen/pull/806)
- [`c7e2bd5`](https://github.com/reactjs/react-docgen/commit/c7e2bd5911d660b42bc3bc8b368a7b7cdcf980fd)
- Thanks [@danez](https://github.com/danez)! - Make docblocks for assigned
- methods be correctly detected.
-
-## 6.0.0
-
-### Major Changes
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Rename `flowTypeHandler` to
- `codeTypeHandler` because it handles Flow and TypeScript
-
-- [#719](https://github.com/reactjs/react-docgen/pull/719)
- [`d7a39af`](https://github.com/reactjs/react-docgen/commit/d7a39af7162c312daba2be428613cb378cce0727)
- Thanks [@danez](https://github.com/danez)! - Refactored
- `resolveComponentDefinition` utility.
- - Renamed to `findComponentDefinition`
- - Removed named export `isComponentDefinition`
- - The utility now does a lot more than previously, check out the commit to see
- the changes in detail.
-
-- [#761](https://github.com/reactjs/react-docgen/pull/761)
- [`dfc2f85`](https://github.com/reactjs/react-docgen/commit/dfc2f85ae10a668880ed64710a5acd714edf3bf7)
- Thanks [@danez](https://github.com/danez)! - Renamed `propDocBlockHandler` to
- `propDocblockHandler` for consistency
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Simplify
- `resolveObjectValuesToArray` and remove type handling. None of the code that
- was handling types was used.
-
-- [`caae6bf`](https://github.com/reactjs/react-docgen/commit/caae6bf74ee292a513d6610350d5790c9d23f931)
- Thanks [@danez](https://github.com/danez)! - The return values of
- `resolveObjectValuesToArray` are now in the order they are defined in the
- source code.
-
-- [#744](https://github.com/reactjs/react-docgen/pull/744)
- [`e956802`](https://github.com/reactjs/react-docgen/commit/e956802a26700bb3f827a4500d9fc18a4eed6599)
- Thanks [@danez](https://github.com/danez)! - Removed match utility.
-
- The utility can be replaced by babel helpers and is not needed anymore. Also
- using explicit checks like `path.isMemberExpression()` is better for type
- safety and catching potential bugs.
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Migrate react-docgen to ES
- modules. Please read
- [this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
-
-- [#693](https://github.com/reactjs/react-docgen/pull/693)
- [`3b28f6e`](https://github.com/reactjs/react-docgen/commit/3b28f6ee864fddbd872441035b21ad416ae7f417)
- Thanks [@danez](https://github.com/danez)! - The CLI was removed from
- `react-docgen` into its own package `@react-docgen/cli`.
-
- Check out https://react-docgen.dev/docs/getting-started/cli for the
- documentation.
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - The main `parse` API had some
- breaking changes.
- - The arguments were changed from previously 5 to just 2. The following diff
- illustrates how to migrate:
-
- ```diff
- -parse(src, resolver, handlers, importer, options: { filename, ...babelOptions})
- +parse(src, { resolver, handlers, importer, filename, babelOptions: {} })
- ```
-
- - The return type is now always an array, independent of the resolver, even if
- only one component was found in the file.
-
-- [#786](https://github.com/reactjs/react-docgen/pull/786)
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca)
- Thanks [@danez](https://github.com/danez)! - Renamed the method `toObject` to
- `build` in the DocumentationBuilder.
-
- This method might be used by integrations.
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Renamed some of the main exports
- for clarity.
-
- Renamed `handlers` to `builtinHandlers` Renamed `resolver` to
- `builtinResolvers` Renamed `importers` to `builtinImporters`
-
-- [#743](https://github.com/reactjs/react-docgen/pull/743)
- [`5215bab`](https://github.com/reactjs/react-docgen/commit/5215babf11e9c8a672d86816d1250c1e54b22249)
- Thanks [@danez](https://github.com/danez)! - Removed support for the
- `@extends React.Component` annotation on react class components.
-
- Instead, you can use the new `@component` annotation or define your own
- annotation by creating a custom `FindAnnotatedDefinitionsResolver` instance
-
-- [#714](https://github.com/reactjs/react-docgen/pull/714)
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0)
- Thanks [@danez](https://github.com/danez)! - Renamed and migrated built-in
- resolvers to classes.
- - `findAllComponentDefinitions` was renamed to `FindAllDefinitionsResolver`
- and is now a class.
-
- ```diff
- -const resolver = builtinResolvers.findAllComponentDefinitions
- +const resolver = new builtinResolvers.FindAllDefinitionsResolver()
- ```
-
- - `findAllExportedComponentDefinitions` was renamed to
- `FindExportedDefinitionsResolver` and is now a class.
-
- ```diff
- -const resolver = builtinResolvers.findAllExportedComponentDefinitions
- +const resolver = new builtinResolvers.FindExportedDefinitionsResolver()
- ```
-
- - `findExportedComponentDefinition` was removed. Use
- `FindExportedDefinitionsResolver` with the `limit` option instead.
-
- > This is still the default resolver.
-
- ```diff
- -const resolver = builtinResolvers.findExportedComponentDefinition
- +const resolver = new builtinResolvers.FindExportedDefinitionsResolver({ limit: 1 })
- ```
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Migrated to babel toolchain
-
- This is one of the big changes in this new version of react-docgen. It made
- the code a lot more robust because there are now finally working TypeScript
- types for the ASTs.
-
- Another benefit from this change is that react-docgen is now a lot faster. 🚀
- In some tests an improvement of nearly 50% was seen in comparison to
- version 5.
-
-- [#707](https://github.com/reactjs/react-docgen/pull/707)
- [`d4c27d4`](https://github.com/reactjs/react-docgen/commit/d4c27d482e6364c38af2f7c871071f475dc40393)
- Thanks [@danez](https://github.com/danez)! - Improve performance of file
- system importer.
-
- The file system importer now also caches the resolving of files in addition to
- parsing files. If the importer is used in an environment where files do change
- at runtime (like a watch command) then the caches will need to be cleared on
- every file change.
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Changed the minimum Node.js
- version to 14.18.0
-
-### Minor Changes
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Add support for `.cts` and `.mts`
- extension when using typescript
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Treat functions returning
- `React.Children.map` as components
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Improve performance by creating
- all visitors only once
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Support all possible kinds of
- functions in the `displayNameHandler`
-
-- [#786](https://github.com/reactjs/react-docgen/pull/786)
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca)
- Thanks [@danez](https://github.com/danez)! - Export the type for the
- DocumentationBuilder.
-
-- [#786](https://github.com/reactjs/react-docgen/pull/786)
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca)
- Thanks [@danez](https://github.com/danez)! - The types `NodePath` and
- `babelTypes` are now exported.
-
- These types are useful when building integrations in TypeScript.
-
- `babelTypes` includes all types from `@babel/types`.
-
-- [#714](https://github.com/reactjs/react-docgen/pull/714)
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0)
- Thanks [@danez](https://github.com/danez)! - Add the new ChainResolver which
- allows multiple resolvers to be chained.
-
- ```ts
- import { builtinResolvers } from 'react-docgen';
-
- const { ChainResolver } = builtinResolvers;
- const resolver = new ChainResolver([resolver1, resolver2], {
- chainingLogic: ChainResolver.Logic.ALL, // or ChainResolver.Logic.FIRST_FOUND,
- });
- ```
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Support all literal types in
- typescript
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Support flow qualified type names
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Support class and function
- declarations without identifier
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Support resolving of
- destructuring in `resolveToValue`
-
-- [#714](https://github.com/reactjs/react-docgen/pull/714)
- [`80e4c74`](https://github.com/reactjs/react-docgen/commit/80e4c747c19d80081c162118f9c7110916fc27a0)
- Thanks [@danez](https://github.com/danez)! - Allow resolvers to be classes in
- addition to functions.
-
- ```ts
- import type { ResolverClass, ResolverFunction } from 'react-docgen';
-
- // This was the only option until now
- const functionResolver: ResolverFunction = (file: FileState) => {
- //needs to return array of found components
- };
-
- // This is the new class resolver
- class MyResolver implements ResolverClass {
- resolve(file: FileState) {
- //needs to return array of found components
- }
- }
-
- const classResolver = new MyResolver();
- ```
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Improve performance drastically
- by making changes to AST traversal
-
- Visitors are now pre-exploded and are cached in the module scope instead of
- creating them on every call. This change brought the benchmark from 170ops/s
- to 225ops/sec
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Add codes to errors to be able to
- easily detect them
-
- There is a new export `ERROR_CODES` that contains all possible error codes.
- The two errors that have codes right now are:
- - `MISSING_DEFINITION`: No component found in a file
- - `MULTIPLE_DEFINITIONS`: Multiple components found in one file
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Support handling
- `useImperativeHandle` correctly
-
-- [#743](https://github.com/reactjs/react-docgen/pull/743)
- [`5215bab`](https://github.com/reactjs/react-docgen/commit/5215babf11e9c8a672d86816d1250c1e54b22249)
- Thanks [@danez](https://github.com/danez)! - Added a new resolver that finds
- annotated components. This resolver is also enabled by default.
-
- To use this feature simply annotated a component with `@component`.
-
- ```ts
- // @component
- class MyComponent {}
- ```
-
-### Patch Changes
-
-- [#745](https://github.com/reactjs/react-docgen/pull/745)
- [`8fe3dbf`](https://github.com/reactjs/react-docgen/commit/8fe3dbf510d4d66539bf09db227de5036c125f25)
- Thanks [@danez](https://github.com/danez)! - Fix crash when using TypeScript
- mapped types
-
-- [#789](https://github.com/reactjs/react-docgen/pull/789)
- [`7c99f15`](https://github.com/reactjs/react-docgen/commit/7c99f156b1cc49da8bc78ca9c7e3bb2da215c49d)
- Thanks [@danez](https://github.com/danez)! - Fix TypeScript types when strict
- null checks are disabled
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Handle `React.forwardRef` calls
- without a function
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Fixed the handling of some edge
- cases in resolveToValue
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Remove trailing commas and
- semicolons from raw values in the documentation
-
-- [#767](https://github.com/reactjs/react-docgen/pull/767)
- [`a684d82`](https://github.com/reactjs/react-docgen/commit/a684d8281044b3f8c8baecc9148cd4ef2b8fd409)
- Thanks [@danez](https://github.com/danez)! - Fix handling of `PropTypes.oneOf`
- to handle unresolved imported values correctly
-
-- [#761](https://github.com/reactjs/react-docgen/pull/761)
- [`cc94da2`](https://github.com/reactjs/react-docgen/commit/cc94da24fc9b2107c7e9df8c680a114038cbb16e)
- Thanks [@danez](https://github.com/danez)! - Fix using react-docgen in
- browsers
-
-- [#761](https://github.com/reactjs/react-docgen/pull/761)
- [`98a1138`](https://github.com/reactjs/react-docgen/commit/98a113884a2227a89e5aede84ad48238e5f5c4f0)
- Thanks [@danez](https://github.com/danez)! - Add `displayName` and
- `description` to Documentation type
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Parse jsdoc comments for
- TypeScript structs
-
-- [#748](https://github.com/reactjs/react-docgen/pull/748)
- [`ea25b16`](https://github.com/reactjs/react-docgen/commit/ea25b16deb721a81e9937a307f88854e4b19f56d)
- Thanks [@danez](https://github.com/danez)! - Handle cyclic references in
- PropTypes `shape()` and `exact()` methods.
-
-- [#787](https://github.com/reactjs/react-docgen/pull/787)
- [`5a226ac`](https://github.com/reactjs/react-docgen/commit/5a226ac97882378790291cb67b1c0eee471f9def)
- Thanks [@danez](https://github.com/danez)! - Fix @babel/traverse import to
- work in non ESM environments
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Correctly handle ObjectProperties
- in `isReactComponentMethod`
-
-- [#747](https://github.com/reactjs/react-docgen/pull/747)
- [`1aa0249`](https://github.com/reactjs/react-docgen/commit/1aa0249f293784091260839377f8204eefb1da23)
- Thanks [@danez](https://github.com/danez)! - Handle `typeof import('...')` and
- `typeof MyType.property` correctly in TypeScript
-
-- [`050313d`](https://github.com/reactjs/react-docgen/commit/050313d47c3922276e4a06bcf38836f34f9558fb)
- Thanks [@danez](https://github.com/danez)! - Correctly add LICENSE file to
- published packages
-
-- [`96d6e9e`](https://github.com/reactjs/react-docgen/commit/96d6e9e6003b92604781553f6910812c74c18dad)
- Thanks [@danez](https://github.com/danez)! - Add support for TSAsExpressions
- when trying to stringify expressions
-
-- [#720](https://github.com/reactjs/react-docgen/pull/720)
- [`f6e4fe7`](https://github.com/reactjs/react-docgen/commit/f6e4fe75560b1420388119131a8f49abe52757f6)
- Thanks [@renovate](https://github.com/apps/renovate)! - Update dependency
- strip-indent to v4
-
-- [#769](https://github.com/reactjs/react-docgen/pull/769)
- [`e08e08d`](https://github.com/reactjs/react-docgen/commit/e08e08d6cd56c833fd123019639dca9d819cd7ab)
- Thanks [@danez](https://github.com/danez)! - Correctly resolve the values in
- an `Object.values()` call
-
-## 6.0.0-rc.9
-
-### Patch Changes
-
-- [#789](https://github.com/reactjs/react-docgen/pull/789)
- [`7c99f15`](https://github.com/reactjs/react-docgen/commit/7c99f156b1cc49da8bc78ca9c7e3bb2da215c49d)
- Thanks [@danez](https://github.com/danez)! - Fix TypeScript types when strict
- null checks are disabled
-
-## 6.0.0-rc.8
-
-### Patch Changes
-
-- [#787](https://github.com/reactjs/react-docgen/pull/787)
- [`5a226ac`](https://github.com/reactjs/react-docgen/commit/5a226ac97882378790291cb67b1c0eee471f9def)
- Thanks [@danez](https://github.com/danez)! - Fix @babel/traverse import to
- work in non ESM environments
-
-## 6.0.0-rc.7
-
-### Major Changes
-
-- [#786](https://github.com/reactjs/react-docgen/pull/786)
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca)
- Thanks [@danez](https://github.com/danez)! - Renamed the method `toObject` to
- `build` in the DocumentationBuilder.
-
- This method might be used by integrations.
-
-### Minor Changes
-
-- [#786](https://github.com/reactjs/react-docgen/pull/786)
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca)
- Thanks [@danez](https://github.com/danez)! - Export the type for the
- DocumentationBuilder.
-
-- [#786](https://github.com/reactjs/react-docgen/pull/786)
- [`0a2481d`](https://github.com/reactjs/react-docgen/commit/0a2481df6328bdbe46a01fb25ee9a0966ec023ca)
- Thanks [@danez](https://github.com/danez)! - The types `NodePath` and
- `babelTypes` are now exported.
-
- These types are useful when building integrations in TypeScript.
-
- `babelTypes` includes all types from `@babel/types`.
-
-### Patch Changes
-
-- [#767](https://github.com/reactjs/react-docgen/pull/767)
- [`a684d82`](https://github.com/reactjs/react-docgen/commit/a684d8281044b3f8c8baecc9148cd4ef2b8fd409)
- Thanks [@danez](https://github.com/danez)! - Fix handling of `PropTypes.oneOf`
- to handle unresolved imported values correctly
-
-- [#769](https://github.com/reactjs/react-docgen/pull/769)
- [`e08e08d`](https://github.com/reactjs/react-docgen/commit/e08e08d6cd56c833fd123019639dca9d819cd7ab)
- Thanks [@danez](https://github.com/danez)! - Correctly resolve the values in
- an `Object.values()` call
-
-## 6.0.0-beta.6
-
-### Major Changes
-
-- dfc2f85: Rename `propDocBlockHandler` to `propDocblockHandler` for consistency
-
-### Patch Changes
-
-- cc94da2: Fix using react-docgen in browsers
-- 98a1138: Add `displayName` and `description` to Documentation type
-
-## 6.0.0-beta.5
-
-### Major Changes
-
-- d7a39af: Refactored `resolveComponentDefinition` utility.
- - Renamed to `findComponentDefinition`
- - Removed named export `isComponentDefinition`
- - The utility now does a lot more than previously, check out the commit to see
- the changes in detail.
-
-- e956802: Remove match utility.
-
- The utility can be replaced by babel helpers and is not needed anymore. Also
- using explicit checks like `path.isMemberExpression()` is better for type
- safety and catching potential bugs.
-
-- 5215bab: Removed support for the `@extends React.Component` annotation on
- react class components.
-
- Instead you can use the new `@component` annotation.
-
-- 80e4c74: Renamed and migrated built-in resolvers to classes.
- - `findAllComponentDefinitions` was renamed to `FindAllDefinitionsResolver`
- and is now a class.
-
- ```diff
- -const resolver = builtinResolvers.findAllComponentDefinitions
- +const resolver = new builtinResolvers.FindAllDefinitionsResolver()
- ```
-
- - `findAllExportedComponentDefinitions` was renamed to
- `FindExportedDefinitionsResolver` and is now a class.
-
- ```diff
- -const resolver = builtinResolvers.findAllExportedComponentDefinitions
- +const resolver = new builtinResolvers.FindExportedDefinitionsResolver()
- ```
-
- - `findExportedComponentDefinition` was removed. Use
- `FindExportedDefinitionsResolver` with the `limit` option instead.
-
- > This is still the default resolver.
-
- ```diff
- -const resolver = builtinResolvers.findExportedComponentDefinition
- +const resolver = new builtinResolvers.FindExportedDefinitionsResolver({ limit: 1 })
- ```
-
-### Minor Changes
-
-- 80e4c74: Add the new ChainResolver which allows multiple resolvers to be
- chained.
-
- ```ts
- import { builtinResolvers } from 'react-docgen';
-
- const { ChainResolver } = builtinResolvers;
- const resolver = new ChainResolver([resolver1, resolver2], {
- chainingLogic: ChainResolver.Logic.ALL, // or ChainResolver.Logic.FIRST_FOUND,
- });
- ```
-
-- 80e4c74: Allow resolvers to be classes in addition to functions.
-
- ```ts
- import type { ResolverClass, ResolverFunction } from 'react-docgen';
-
- // This was the only option until now
- const functionResolver: ResolverFunction = (file: FileState) => {
- //needs to return array of found components
- };
-
- // This is the new class resolver
- class MyResolver implements ResolverClass {
- resolve(file: FileState) {
- //needs to return array of found components
- }
- }
-
- const classResolver = new MyResolver();
- ```
-
-- 5215bab: Added a new resolver that finds annotated components. This resolver
- is also enabled by default.
-
- To use this feature simply annotated a component with `@component`.
-
- ```ts
- // @component
- class MyComponent {}
- ```
-
-### Patch Changes
-
-- 8fe3dbf: Fix crash when using TypeScript mapped types
-- ea25b16: Handle cyclic references in PropTypes `shape()` and `exact()`
- methods.
-- 1aa0249: Handle `typeof import('...')` and `typeof MyType.property` correctly
- in TypeScript
-- 050313d: Correctly add LICENSE file to published packages
-- f6e4fe7: Update dependency strip-indent to v4
-
-## 6.0.0-alpha.4
-
-### Major Changes
-
-- 96d6e9e: Rename `flowTypeHandler` to `codeTypeHandler` because it handles Flow
- and TypeScript
-- 96d6e9e: Simplify `resolveObjectValuesToArray` and remove type handling. None
- of the code that was handling types was actually used.
-- caae6bf: The return values of `resolveObjectValuesToArray` are now in the
- order they are defined in the source code.
-- 96d6e9e: Migrate react-docgen to ES modules. Please read
- [this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
-- 3b28f6e: The CLI was removed from `react-docgen` into its own package
- `@react-docgen/cli`.
-
- Check out https://react-docgen.dev/docs/getting-started/cli/ for the
- documentation.
-
-- 96d6e9e: Main `parse` API was changed
-
- The main API changed and now includes only 2 arguments.
-
- ```diff
- -parse(src, resolver, handlers, importer, options)
- +parse(src, { resolver, handlers, importer, ... })
- ```
-
-- 96d6e9e: Renamed some of the main exports for clarity.
-
- Renamed `handlers` to `builtinHandlers` Renamed `resolver` to
- `builtinResolvers` Renamed `importers` to `builtinImporters`
-
-- 96d6e9e: Migrated to babel toolchain
-
- This is one of the big changes in this new version of react-docgen. It made
- the code a lot more robust because there are now finally working TypeScript
- types for the ASTs.
-
- Another benefit from this change that react-docgen is now a lot faster. 🚀 In
- some tests an improvement of nearly 50% was seen in comparison to version 5.
-
-- d4c27d4: Improve performance of file system importer.
-
- The file system importer now also caches resolving of files in addition to
- parsing files. If the importer is used in an environment where files do change
- at runtime (like a watch command) then the caches will need to be cleared on
- every file change.
-
-- 96d6e9e: Changed the minimum Node.js version to 14.18.0
-
-### Minor Changes
-
-- 96d6e9e: Add support for `.cts` and `.mts` extension when using typescript
-- 96d6e9e: Treat functions returning `React.Children.map` as components
-- 96d6e9e: Improve performance by creating all visitors only once
-- 96d6e9e: Support all possible kinds of functions in the `displayNameHandler`
-- 96d6e9e: Support all literal types in typescript
-- 96d6e9e: Support flow qualified type names
-- 96d6e9e: Support class and function declarations without identifier
-- 96d6e9e: Support resolving of destructurings in `resolveToValue`
-- 96d6e9e: Improve performance drastically by making changes to AST traversal
-
- Visitors are now pre-exploded and are cached in the module scope instead of
- creating them on every call. This change brought the benchmark from 170ops/s
- to 225ops/sec
-
-- 96d6e9e: Add codes to errors to be able to easily detect them
-
- There is a new export `ERROR_CODES` that contains all possible error codes.
- The two errors that have codes right now are:
- - `MISSING_DEFINITION`: No component found in file
- - `MULTIPLE_DEFINITIONS`: Multiple components found in one files
-
-- 96d6e9e: Support handling `useImperativeHandle` correctly
-
-### Patch Changes
-
-- 96d6e9e: Handle `React.forwardRef` calls without a function
-- 96d6e9e: Handle some edge cases in resolveToValue
-- 96d6e9e: Remove trailing commas and semicolons from raw values in the
- documentation
-- 96d6e9e: Parse jsdoc comments for TypeScript structs
-- 96d6e9e: Correctly handle ObjectProperties in `isReactComponentMethod`
-- 96d6e9e: Add support for TSAsExpressions when trying to stringify expressions
-
-## [6.0.0-alpha.3](https://github.com/reactjs/react-docgen/compare/v6.0.0-alpha.2...v6.0.0-alpha.3) (2022-06-13)
-
-### Bug Fixes
-
-- Correctly detect index access types in typescript
- ([#400](https://github.com/reactjs/react-docgen/issues/400))
- ([85ea6a5](https://github.com/reactjs/react-docgen/commit/85ea6a518c837e209043d9dac1505f60e8dd33b6))
-- Correctly handle ObjectTypeSpreadProperty in object type annotations
- ([#593](https://github.com/reactjs/react-docgen/issues/593))
- ([395f338](https://github.com/reactjs/react-docgen/commit/395f338ab8aa3f1d9e1c0f5a81dadd0ce00eb7d5))
-- Fix typescript types for parsing
- ([34c55ac](https://github.com/reactjs/react-docgen/commit/34c55ac1d663cc604f4f548018d78e02e081a797))
-- Fix wrong detection of forwardRef in combination with memo
- ([#592](https://github.com/reactjs/react-docgen/issues/592))
- ([ea9cbeb](https://github.com/reactjs/react-docgen/commit/ea9cbebef13de11d591f175438e59b48dbb67025))
-- Handle ObjectTypeSpreadProperties which are not resolvable
- ([4b8b721](https://github.com/reactjs/react-docgen/commit/4b8b721e6332185c0964a35329108ccdb64f8bb8))
-- Ignore methods in `Object.value()` calls
- ([4fc5b21](https://github.com/reactjs/react-docgen/commit/4fc5b21d899990681287c8d9d70771b7361ec41e))
-
-## [6.0.0-alpha.2](https://github.com/reactjs/react-docgen/compare/v6.0.0-alpha.1...v6.0.0-alpha.2) (2022-04-04)
-
-### Bug Fixes
-
-- Change folder name inside the npm package back to `dist`.
- ([5f3da8c](https://github.com/reactjs/react-docgen/commit/5f3da8c892fd052db470d0a44d13c704eef4d011))
- There was no real reason to change this and happened during the TypeScript
- migration.
-
-## 6.0.0-alpha.1 (2022-04-04)
-
-### Bug Fixes
-
-- Fix for expressionTo with Spread and Methods
- ([5f3da8c](https://github.com/reactjs/react-docgen/commit/5f3da8c892fd052db470d0a44d13c704eef4d011))
-- Remove obsolete id check
- ([66961d8](https://github.com/reactjs/react-docgen/commit/66961d868fb09cbf2a96ea5a4edec602602851b3))
-- Remove usage of ast-type builders
- ([17c8a9c](https://github.com/reactjs/react-docgen/commit/17c8a9c123e0b699e96137e8714cd57fe6200e0c))
-
-### Features
-
-- Migrate to TypeScript
- ([7b35e6f](https://github.com/reactjs/react-docgen/commit/7b35e6f1336c6c606b194b2d0e70376e9c1c0a9d))
-- Remove building out of scope AST Nodes from resolveToValue
- ([5bcf56c](https://github.com/reactjs/react-docgen/commit/5bcf56c6f7d2d8118adc1ed80573f2e3555455cb))
-
-### BREAKING CHANGES
-
-- `resolveToValue` will not create a `MemberExpression` for targets ending in
- destructuring. It will now simply resolve to the `Identifier` inside the
- destructuring. Use new helper `isDestructuringAssignment` to further check
- this identifier.
-- The helpers `resolveObjectValuesToArray` and `resolveObjectKeysToArray` return
- now `string[]` instead of a `NodePath`
diff --git a/packages/react-docgen/package.json b/packages/react-docgen/package.json
deleted file mode 100644
index 6391f875432..00000000000
--- a/packages/react-docgen/package.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "name": "react-docgen",
- "version": "8.0.1",
- "description": "A library to extract information from React components for documentation generation.",
- "repository": {
- "type": "git",
- "url": "https://github.com/reactjs/react-docgen.git",
- "directory": "packages/react-docgen"
- },
- "type": "module",
- "browser": {
- "./dist/importer/fsImporter.js": "./dist/importer/ignoreImporter.js",
- "./src/importer/fsImporter.ts": "./src/importer/ignoreImporter.ts",
- "./dist/importer/makeFsImporter.js": "./dist/importer/makeIgnoreImporter.js",
- "./src/importer/makeFsImporter.ts": "./src/importer/makeIgnoreImporter.ts"
- },
- "files": [
- "dist"
- ],
- "engines": {
- "node": "^20.9.0 || >=22"
- },
- "main": "dist/main.js",
- "typings": "dist/main.d.ts",
- "scripts": {
- "build": "rimraf dist/ && tsc",
- "test": "vitest run"
- },
- "keywords": [
- "react",
- "documentation",
- "documentation-generation"
- ],
- "author": {
- "name": "Felix Kling (http://github.com/fkling)"
- },
- "contributors": [
- "Daniel Tschinder (http://github.com/danez)"
- ],
- "license": "MIT",
- "dependencies": {
- "@babel/core": "^7.28.0",
- "@babel/traverse": "^7.28.0",
- "@babel/types": "^7.28.2",
- "@types/babel__core": "^7.20.5",
- "@types/babel__traverse": "^7.20.7",
- "@types/doctrine": "^0.0.9",
- "@types/resolve": "^1.20.2",
- "doctrine": "^3.0.0",
- "resolve": "^1.22.1",
- "strip-indent": "^4.0.0"
- }
-}
diff --git a/packages/react-docgen/src/Documentation.ts b/packages/react-docgen/src/Documentation.ts
deleted file mode 100644
index f6e63d759c5..00000000000
--- a/packages/react-docgen/src/Documentation.ts
+++ /dev/null
@@ -1,244 +0,0 @@
-export interface Documentation {
- childContext?: Record;
- composes?: string[];
- context?: Record;
- description?: string;
- displayName?: string;
- methods?: MethodDescriptor[];
- props?: Record;
-}
-
-export interface MethodParameter {
- name: string;
- description?: string;
- optional: boolean;
- type?: TypeDescriptor | null;
-}
-
-export interface MethodReturn {
- description?: string;
- type: TypeDescriptor | undefined;
-}
-
-export type MethodModifier = 'async' | 'generator' | 'get' | 'set' | 'static';
-
-export interface MethodDescriptor {
- name: string;
- description?: string | null;
- docblock: string | null;
- modifiers: MethodModifier[];
- params: MethodParameter[];
- returns: MethodReturn | null;
-}
-
-export interface PropTypeDescriptor {
- name:
- | 'any'
- | 'array'
- | 'arrayOf'
- | 'bool'
- | 'custom'
- | 'element'
- | 'elementType'
- | 'enum'
- | 'exact'
- | 'func'
- | 'instanceOf'
- | 'node'
- | 'number'
- | 'object'
- | 'objectOf'
- | 'shape'
- | 'string'
- | 'symbol'
- | 'union';
- value?: unknown;
- raw?: string;
- computed?: boolean;
- // These are only needed for shape/exact types.
- // Consider consolidating PropTypeDescriptor and PropDescriptor
- description?: string;
- required?: boolean;
-}
-
-export interface DefaultValueDescriptor {
- value: unknown;
- computed: boolean;
-}
-
-export interface BaseType {
- required?: boolean;
- nullable?: boolean;
- alias?: string;
-}
-
-export interface SimpleType extends BaseType {
- name: string;
- raw?: string;
-}
-
-export interface LiteralType extends BaseType {
- name: 'literal';
- value: string;
-}
-
-export interface ElementsType extends BaseType {
- name: string;
- raw: string;
- elements: Array>;
-}
-
-export interface FunctionArgumentType {
- name: string;
- type?: TypeDescriptor;
- rest?: boolean;
-}
-
-export interface FunctionSignatureType extends BaseType {
- name: 'signature';
- type: 'function';
- raw: string;
- signature: {
- arguments: Array>;
- return?: TypeDescriptor;
- };
-}
-
-export interface TSFunctionSignatureType extends FunctionSignatureType {
- signature: {
- arguments: Array>;
- return?: TypeDescriptor;
- this?: TypeDescriptor;
- };
-}
-
-export interface ObjectSignatureType
- extends BaseType {
- name: 'signature';
- type: 'object';
- raw: string;
- signature: {
- properties: Array<{
- key: TypeDescriptor | string;
- value: TypeDescriptor;
- description?: string;
- }>;
- constructor?: TypeDescriptor;
- };
-}
-
-export type TypeDescriptor =
- | ElementsType
- | LiteralType
- | ObjectSignatureType
- | SimpleType
- | T;
-
-export interface PropDescriptor {
- type?: PropTypeDescriptor;
- flowType?: TypeDescriptor;
- tsType?: TypeDescriptor;
- required?: boolean;
- defaultValue?: DefaultValueDescriptor;
- description?: string;
-}
-
-export default class DocumentationBuilder {
- #props: Map;
- #context: Map;
- #childContext: Map;
- #composes: Set;
- #data: Map;
-
- constructor() {
- this.#props = new Map();
- this.#context = new Map();
- this.#childContext = new Map();
- this.#composes = new Set();
- this.#data = new Map();
- }
-
- addComposes(moduleName: string): void {
- this.#composes.add(moduleName);
- }
-
- set(key: string, value: unknown): void {
- this.#data.set(key, value);
- }
-
- get(key: string): T | null;
- get(key: string): unknown {
- return this.#data.get(key);
- }
-
- getPropDescriptor(propName: string): PropDescriptor {
- let propDescriptor = this.#props.get(propName);
-
- if (!propDescriptor) {
- this.#props.set(propName, (propDescriptor = {}));
- }
-
- return propDescriptor;
- }
-
- getContextDescriptor(propName: string): PropDescriptor {
- let propDescriptor = this.#context.get(propName);
-
- if (!propDescriptor) {
- this.#context.set(propName, (propDescriptor = {}));
- }
-
- return propDescriptor;
- }
-
- getChildContextDescriptor(propName: string): PropDescriptor {
- let propDescriptor = this.#childContext.get(propName);
-
- if (!propDescriptor) {
- this.#childContext.set(propName, (propDescriptor = {}));
- }
-
- return propDescriptor;
- }
-
- build(): Documentation {
- const obj: Documentation = {};
-
- for (const [key, value] of this.#data) {
- // @ts-expect-error custom handlers can add any properties to Documentation
- obj[key] = value;
- }
-
- if (this.#props.size > 0) {
- obj.props = {};
- for (const [propName, propDescriptor] of this.#props) {
- if (Object.keys(propDescriptor).length > 0) {
- obj.props[propName] = propDescriptor;
- }
- }
- }
-
- if (this.#context.size > 0) {
- obj.context = {};
- for (const [contextName, contextDescriptor] of this.#context) {
- if (Object.keys(contextDescriptor).length > 0) {
- obj.context[contextName] = contextDescriptor;
- }
- }
- }
-
- if (this.#childContext.size > 0) {
- obj.childContext = {};
- for (const [childContextName, childContextDescriptor] of this
- .#childContext) {
- obj.childContext[childContextName] = childContextDescriptor;
- }
- }
-
- if (this.#composes.size > 0) {
- obj.composes = Array.from(this.#composes);
- }
-
- return obj;
- }
-}
diff --git a/packages/react-docgen/src/FileState.ts b/packages/react-docgen/src/FileState.ts
deleted file mode 100644
index 239a533e673..00000000000
--- a/packages/react-docgen/src/FileState.ts
+++ /dev/null
@@ -1,93 +0,0 @@
-import type { HubInterface, Scope, Visitor } from '@babel/traverse';
-import babelTraverse, { NodePath } from '@babel/traverse';
-import type { File, Node, Program } from '@babel/types';
-import type { Importer, ImportPath } from './importer/index.js';
-import babelParse from './babelParser.js';
-import type { TransformOptions } from '@babel/core';
-
-// Workaround while babel is not a proper ES module
-const traverse = babelTraverse.default ?? (babelTraverse as never);
-
-export default class FileState {
- opts: TransformOptions;
- path: NodePath;
- ast: File;
- scope: Scope;
- code: string;
-
- #importer: Importer;
-
- hub: HubInterface = {
- // keep it for the usage in babel-core, ex: path.hub.file.opts.filename
- file: this,
- parse: this.parse.bind(this),
- import: this.import.bind(this),
- getCode: () => this.code,
- getScope: () => this.scope,
- addHelper: () => undefined,
- buildError: (
- node: Node,
- msg: string,
- Error: new (message?: string) => E,
- ): E & { node: Node } => {
- const err = new Error(msg);
-
- (err as E & { node: Node }).node = node;
-
- return err as E & { node: Node };
- },
- };
-
- constructor(
- options: TransformOptions,
- { code, ast, importer }: { code: string; ast: File; importer: Importer },
- ) {
- this.opts = options;
- this.code = code;
- this.ast = ast;
- this.#importer = importer;
-
- this.path = NodePath.get({
- hub: this.hub,
- parentPath: null,
- parent: this.ast,
- container: this.ast,
- key: 'program',
- }).setContext() as NodePath;
- this.scope = this.path.scope;
- }
-
- /**
- * Try to resolve and import the ImportPath with the `name`
- */
- import(path: ImportPath, name: string): NodePath | null {
- return this.#importer(path, name, this);
- }
-
- /**
- * Parse the content of a new file
- * The `filename` is required so that potential imports inside the content can be correctly resolved and
- * the correct babel config file could be loaded. `filename` needs to be an absolute path.
- */
- parse(code: string, filename: string): FileState {
- const newOptions = { ...this.opts, filename };
- // We need to build a new parser, because there might be a new
- // babel config file in effect, so we need to load it
- const ast = babelParse(code, newOptions);
-
- return new FileState(newOptions, {
- ast,
- code,
- importer: this.#importer,
- });
- }
-
- traverse(visitors: Visitor, state?: S): void;
- traverse(visitors: Visitor): void;
- /**
- * Traverse the current file
- */
- traverse(visitors: Visitor, state?: unknown): void {
- traverse(this.ast, visitors, this.scope, state);
- }
-}
diff --git a/packages/react-docgen/src/__mocks__/Documentation.ts b/packages/react-docgen/src/__mocks__/Documentation.ts
deleted file mode 100644
index 35a7d20ab07..00000000000
--- a/packages/react-docgen/src/__mocks__/Documentation.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-export default class Documentation {
- [x: string]: unknown;
- composes: string[] = [];
- descriptors: Record = {};
-
- getPropDescriptor(name: string): unknown {
- return this.descriptors[name] || (this.descriptors[name] = {});
- }
- addComposes(name: string): void {
- this.composes.push(name);
- }
- set(key: string, value: unknown): void {
- this[key] = value;
- }
-}
diff --git a/packages/react-docgen/src/__mocks__/FileState.ts b/packages/react-docgen/src/__mocks__/FileState.ts
deleted file mode 100644
index ccd22c0633a..00000000000
--- a/packages/react-docgen/src/__mocks__/FileState.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { file, program } from '@babel/types';
-import FileState from '../FileState.js';
-
-export default class FileStateMock extends FileState {
- constructor() {
- super(
- {},
- {
- code: '',
- ast: file(program([])),
- importer: () => {
- return null;
- },
- },
- );
- }
-}
diff --git a/packages/react-docgen/src/__tests__/__snapshots__/main-test.ts.snap b/packages/react-docgen/src/__tests__/__snapshots__/main-test.ts.snap
deleted file mode 100644
index d7f54074fe9..00000000000
--- a/packages/react-docgen/src/__tests__/__snapshots__/main-test.ts.snap
+++ /dev/null
@@ -1,156 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`main > Class definition > parses with custom handlers 1`] = `
-[
- {
- "description": "Example component description",
- },
-]
-`;
-
-exports[`main > Class definition > parses with default resolver/handlers 1`] = `
-[
- {
- "description": "Example component description",
- "displayName": "ABC",
- "methods": [],
- "props": {
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "true",
- },
- "description": "Example prop description",
- "required": false,
- "type": {
- "name": "bool",
- },
- },
- },
- },
-]
-`;
-
-exports[`main > React.createClass > parses with custom handlers 1`] = `
-[
- {
- "description": "Example component description",
- },
-]
-`;
-
-exports[`main > React.createClass > parses with default resolver/handlers 1`] = `
-[
- {
- "description": "Example component description",
- "displayName": "ABC",
- "methods": [],
- "props": {
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "true",
- },
- "description": "Example prop description",
- "required": false,
- "type": {
- "name": "bool",
- },
- },
- },
- },
-]
-`;
-
-exports[`main > Stateless Component definition: ArrowFunctionExpression > parses with custom handlers 1`] = `
-[
- {
- "description": "Example component description",
- },
-]
-`;
-
-exports[`main > Stateless Component definition: ArrowFunctionExpression > parses with default resolver/handlers 1`] = `
-[
- {
- "description": "Example component description",
- "displayName": "ABC",
- "methods": [],
- "props": {
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "true",
- },
- "description": "Example prop description",
- "required": false,
- "type": {
- "name": "bool",
- },
- },
- },
- },
-]
-`;
-
-exports[`main > Stateless Component definition: FunctionDeclaration > parses with custom handlers 1`] = `
-[
- {
- "description": "Example component description",
- },
-]
-`;
-
-exports[`main > Stateless Component definition: FunctionDeclaration > parses with default resolver/handlers 1`] = `
-[
- {
- "description": "Example component description",
- "displayName": "ABC",
- "methods": [],
- "props": {
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "true",
- },
- "description": "Example prop description",
- "required": false,
- "type": {
- "name": "bool",
- },
- },
- },
- },
-]
-`;
-
-exports[`main > Stateless Component definition: FunctionExpression > parses with custom handlers 1`] = `
-[
- {
- "description": "Example component description",
- },
-]
-`;
-
-exports[`main > Stateless Component definition: FunctionExpression > parses with default resolver/handlers 1`] = `
-[
- {
- "description": "Example component description",
- "displayName": "ABC",
- "methods": [],
- "props": {
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "true",
- },
- "description": "Example prop description",
- "required": false,
- "type": {
- "name": "bool",
- },
- },
- },
- },
-]
-`;
diff --git a/packages/react-docgen/src/__tests__/main-test.ts b/packages/react-docgen/src/__tests__/main-test.ts
deleted file mode 100644
index 4e23ff182c2..00000000000
--- a/packages/react-docgen/src/__tests__/main-test.ts
+++ /dev/null
@@ -1,198 +0,0 @@
-import { builtinHandlers, parse, ERROR_CODES } from '../main.js';
-import { describe, expect, test } from 'vitest';
-
-// TODO make fixtures out of them?
-describe('main', () => {
- function testMain(source: string) {
- test('parses with default resolver/handlers', () => {
- const docs = parse(source);
-
- expect(docs).toMatchSnapshot();
- });
-
- test('parses with custom handlers', () => {
- const docs = parse(source, {
- handlers: [builtinHandlers.componentDocblockHandler],
- });
-
- expect(docs).toMatchSnapshot();
- });
- }
-
- describe('React.createClass', () => {
- testMain(`
- var React = require("react");
- var PropTypes = React.PropTypes;
-
- var defaultProps = {
- foo: true,
- };
- var propTypes = {
- /**
- * Example prop description
- */
- foo: PropTypes.bool
- };
-
- /**
- * Example component description
- */
- var Component = React.createClass({
- displayName: 'ABC',
- propTypes,
- getDefaultProps: function() {
- return defaultProps;
- }
- });
- module.exports = Component
- `);
- });
-
- describe('Class definition', () => {
- testMain(`
- const React = require("react");
- const PropTypes = React.PropTypes;
-
- const defaultProps = {
- foo: true,
- };
- const propTypes = {
- /**
- * Example prop description
- */
- foo: PropTypes.bool
- };
-
- /**
- * Example component description
- */
- export default class Component extends React.Component {
- static propTypes = propTypes;
- // ...
- }
- Component.defaultProps = defaultProps;
- Component.displayName = 'ABC';
- `);
- });
-
- describe('Stateless Component definition: ArrowFunctionExpression', () => {
- testMain(`
- import React, {PropTypes} from "react";
-
- const defaultProps = {
- foo: true,
- };
- const propTypes = {
- /**
- * Example prop description
- */
- foo: PropTypes.bool
- };
-
- /**
- * Example component description
- */
- let Component = props => ;
- Component.displayName = 'ABC';
- Component.defaultProps = defaultProps;
- Component.propTypes = propTypes;
-
- export default Component;
- `);
- });
-
- describe('Stateless Component definition: FunctionDeclaration', () => {
- testMain(`
- import React, {PropTypes} from "react";
-
- const defaultProps = {
- foo: true,
- };
- const propTypes = {
- /**
- * Example prop description
- */
- foo: PropTypes.bool
- };
-
- /**
- * Example component description
- */
- function Component (props) {
- return ;
- }
-
- Component.displayName = 'ABC';
- Component.defaultProps = defaultProps;
- Component.propTypes = propTypes;
-
- export default Component;
- `);
- });
-
- describe('Stateless Component definition: FunctionExpression', () => {
- testMain(`
- import React, {PropTypes} from "react";
-
- const defaultProps = {
- foo: true,
- };
- const propTypes = {
- /**
- * Example prop description
- */
- foo: PropTypes.bool
- };
-
- /**
- * Example component description
- */
- let Component = function(props) {
- return React.createElement('div', null);
- }
-
- Component.displayName = 'ABC';
- Component.defaultProps = defaultProps;
- Component.propTypes = propTypes;
-
- export default Component;
- `);
- });
-
- describe('Stateless Component definition', () => {
- test('is not so greedy', () => {
- const source = `
- import React, {PropTypes} from "react";
-
- /**
- * Example component description
- */
- let NotAComponent = function(props) {
- let HiddenComponent = () => React.createElement('div', null);
-
- return 7;
- }
-
- NotAComponent.displayName = 'ABC';
- NotAComponent.defaultProps = {
- foo: true
- };
-
- NotAComponent.propTypes = {
- /**
- * Example prop description
- */
- foo: PropTypes.bool
- };
-
- export default NotAComponent;
- `;
-
- expect(() => parse(source)).toThrowError(
- expect.objectContaining({
- code: ERROR_CODES.MISSING_DEFINITION,
- }),
- );
- });
- });
-});
diff --git a/packages/react-docgen/src/__tests__/parse-test.ts b/packages/react-docgen/src/__tests__/parse-test.ts
deleted file mode 100644
index 80f3c8a314a..00000000000
--- a/packages/react-docgen/src/__tests__/parse-test.ts
+++ /dev/null
@@ -1,142 +0,0 @@
-import type { ObjectExpression } from '@babel/types';
-import fs from 'fs';
-import { temporaryDirectory } from 'tempy';
-import { parse as testParse, noopImporter } from '../../tests/utils';
-import parse from '../parse.js';
-import { describe, expect, test, vi } from 'vitest';
-import { ERROR_CODES } from '../error';
-import type { ComponentNodePath, ResolverClass } from '../resolver/index.js';
-
-const createEmptyClassResolver = (path?: ComponentNodePath) =>
- new (class implements ResolverClass {
- resolve = vi.fn(() => {
- return path ? [path] : [];
- });
- })();
-
-const createEmptyFunctionResolver = (path?: ComponentNodePath) =>
- vi.fn(() => (path ? [path] : []));
-
-describe('parse', () => {
- describe.each([
- { name: 'function', createEmptyResolver: createEmptyFunctionResolver },
- { name: 'class', createEmptyResolver: createEmptyClassResolver },
- ])('with $name resolver', ({ createEmptyResolver }) => {
- test('allows custom component definition resolvers', () => {
- const path = testParse.expression('{foo: "bar"}');
- const resolver = createEmptyResolver(path);
- const handler = vi.fn();
-
- parse('//empty', {
- resolver,
- handlers: [handler],
- importer: noopImporter,
- babelOptions: {},
- });
-
- expect(
- typeof resolver === 'object' ? resolver.resolve : resolver,
- ).toBeCalled();
- expect(handler.mock.calls[0][1]).toBe(path);
- });
-
- test('errors if component definition is not found', () => {
- const resolver = createEmptyResolver();
-
- expect(() =>
- parse('//empty', {
- resolver,
- handlers: [],
- importer: noopImporter,
- babelOptions: {},
- }),
- ).toThrowError(
- expect.objectContaining({
- code: ERROR_CODES.MISSING_DEFINITION,
- }),
- );
- expect(
- typeof resolver === 'object' ? resolver.resolve : resolver,
- ).toBeCalled();
-
- expect(() =>
- parse('//empty', {
- resolver,
- handlers: [],
- importer: noopImporter,
- babelOptions: {},
- }),
- ).toThrowError(
- expect.objectContaining({
- code: ERROR_CODES.MISSING_DEFINITION,
- }),
- );
- expect(
- typeof resolver === 'object' ? resolver.resolve : resolver,
- ).toBeCalled();
- });
-
- test('uses local babelrc', () => {
- const dir = temporaryDirectory();
-
- try {
- // Write and empty babelrc to override the parser defaults
- fs.writeFileSync(`${dir}/.babelrc`, '{}');
-
- expect(() =>
- parse('const chained = () => a |> b', {
- resolver: createEmptyResolver(),
- handlers: [],
- importer: noopImporter,
- babelOptions: {
- cwd: dir,
- filename: `${dir}/component.js`,
- },
- }),
- ).toThrowError(
- /.*Support for the experimental syntax 'pipelineOperator' isn't currently enabled.*/,
- );
- } finally {
- fs.unlinkSync(`${dir}/.babelrc`);
- fs.rmdirSync(dir);
- }
- });
-
- test('supports custom parserOptions with plugins', () => {
- expect(() =>
- parse('const chained: Type = 1;', {
- resolver: createEmptyResolver(),
- handlers: [],
- importer: noopImporter,
- babelOptions: {
- parserOpts: {
- plugins: [
- // no flow
- 'jsx',
- ],
- },
- },
- }),
- ).toThrowError(/.*\(1:13\).*/);
- });
-
- test('supports custom parserOptions without plugins', () => {
- expect(() =>
- parse('const chained: Type = 1;', {
- resolver: createEmptyResolver(),
- handlers: [],
- importer: noopImporter,
- babelOptions: {
- parserOpts: {
- allowSuperOutsideMethod: true,
- },
- },
- }),
- ).toThrowError(
- expect.objectContaining({
- code: ERROR_CODES.MISSING_DEFINITION,
- }),
- );
- });
- });
-});
diff --git a/packages/react-docgen/src/babelParser.ts b/packages/react-docgen/src/babelParser.ts
deleted file mode 100644
index 8c323c5a99c..00000000000
--- a/packages/react-docgen/src/babelParser.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import type { ParserOptions, TransformOptions } from '@babel/core';
-import { loadPartialConfig, parseSync } from '@babel/core';
-import type { File } from '@babel/types';
-import { extname } from 'path';
-
-const TYPESCRIPT_EXTS = new Set(['.cts', '.mts', '.ts', '.tsx']);
-
-function getDefaultPlugins(
- options: TransformOptions,
-): NonNullable {
- return [
- 'jsx',
- options.filename && TYPESCRIPT_EXTS.has(extname(options.filename))
- ? 'typescript'
- : 'flow',
- 'asyncDoExpressions',
- 'decimal',
- ['decorators', { decoratorsBeforeExport: false }],
- 'decoratorAutoAccessors',
- 'destructuringPrivate',
- 'doExpressions',
- 'exportDefaultFrom',
- 'functionBind',
- 'importAssertions',
- 'moduleBlocks',
- 'partialApplication',
- ['pipelineOperator', { proposal: 'minimal' }],
- ['recordAndTuple', { syntaxType: 'bar' }],
- 'regexpUnicodeSets',
- 'throwExpressions',
- ];
-}
-
-function buildPluginList(
- options: TransformOptions,
-): NonNullable {
- let plugins: NonNullable = [];
-
- if (options.parserOpts?.plugins) {
- plugins = [...options.parserOpts.plugins];
- }
-
- // Let's check if babel finds a config file for this source file
- // If babel does find a config file we do not apply our defaults
- const partialConfig = loadPartialConfig(options);
-
- if (
- plugins.length === 0 &&
- partialConfig &&
- !partialConfig.hasFilesystemConfig()
- ) {
- plugins = getDefaultPlugins(options);
- }
-
- // Ensure that the estree plugin is never active
- // TODO add test
- return plugins.filter((plugin) => plugin !== 'estree');
-}
-
-function buildParserOptions(options: TransformOptions): ParserOptions {
- const plugins = buildPluginList(options);
-
- return {
- sourceType: 'unambiguous',
- ...(options.parserOpts || {}),
- plugins,
- tokens: false,
- };
-}
-
-export default function babelParser(
- src: string,
- options: TransformOptions = {},
-): File {
- const parserOpts = buildParserOptions(options);
- const opts: TransformOptions = {
- ...options,
- parserOpts,
- };
-
- const ast = parseSync(src, opts);
-
- if (!ast) {
- throw new Error('Unable to parse source code.');
- }
-
- return ast as File;
-}
diff --git a/packages/react-docgen/src/config.ts b/packages/react-docgen/src/config.ts
deleted file mode 100644
index 19eb6263210..00000000000
--- a/packages/react-docgen/src/config.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-import type { TransformOptions } from '@babel/core';
-import type { Handler } from './handlers/index.js';
-import {
- childContextTypeHandler,
- codeTypeHandler,
- componentDocblockHandler,
- componentMethodsHandler,
- componentMethodsJsDocHandler,
- contextTypeHandler,
- defaultPropsHandler,
- displayNameHandler,
- propDocblockHandler,
- propTypeCompositionHandler,
- propTypeHandler,
-} from './handlers/index.js';
-import type { Importer } from './importer/index.js';
-import { fsImporter } from './importer/index.js';
-import type { Resolver } from './resolver/index.js';
-import {
- ChainResolver,
- FindAnnotatedDefinitionsResolver,
- FindExportedDefinitionsResolver,
-} from './resolver/index.js';
-
-export interface Config {
- handlers?: Handler[];
- importer?: Importer;
- resolver?: Resolver;
- /**
- * shortcut for `babelOptions.filename`
- * Set to an absolute path (recommended) to the file currently being parsed or
- * to an relative path that is relative to the `babelOptions.cwd`.
- */
- filename?: string;
- babelOptions?: TransformOptions;
-}
-export type InternalConfig = Omit, 'filename'>;
-
-const defaultResolvers: Resolver[] = [
- new FindExportedDefinitionsResolver({
- limit: 1,
- }),
- new FindAnnotatedDefinitionsResolver(),
-];
-const defaultResolver: Resolver = new ChainResolver(defaultResolvers, {
- chainingLogic: ChainResolver.Logic.ALL,
-});
-const defaultImporter: Importer = fsImporter;
-
-export const defaultHandlers: Handler[] = [
- propTypeHandler,
- contextTypeHandler,
- childContextTypeHandler,
- propTypeCompositionHandler,
- propDocblockHandler,
- codeTypeHandler,
- defaultPropsHandler,
- componentDocblockHandler,
- displayNameHandler,
- componentMethodsHandler,
- componentMethodsJsDocHandler,
-];
-
-export function createConfig(inputConfig: Config): InternalConfig {
- const { babelOptions, filename, handlers, importer, resolver } = inputConfig;
-
- const config = {
- babelOptions: { ...babelOptions },
- handlers: handlers ?? defaultHandlers,
- importer: importer ?? defaultImporter,
- resolver: resolver ?? defaultResolver,
- };
-
- if (filename) {
- config.babelOptions.filename = filename;
- }
-
- return config;
-}
diff --git a/packages/react-docgen/src/error.ts b/packages/react-docgen/src/error.ts
deleted file mode 100644
index e6ff30686ed..00000000000
--- a/packages/react-docgen/src/error.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-export enum ERROR_CODES {
- MISSING_DEFINITION = 'ERR_REACTDOCGEN_MISSING_DEFINITION',
- MULTIPLE_DEFINITIONS = 'ERR_REACTDOCGEN_MULTIPLE_DEFINITIONS',
-}
-
-const messages = new Map([
- [ERROR_CODES.MISSING_DEFINITION, 'No suitable component definition found.'],
- [
- ERROR_CODES.MULTIPLE_DEFINITIONS,
- 'Multiple exported component definitions found.',
- ],
-]);
-
-export class ReactDocgenError extends Error {
- code: string | undefined;
- constructor(code: ERROR_CODES) {
- super(messages.get(code));
-
- this.code = code;
- }
-}
diff --git a/packages/react-docgen/src/handlers/__tests__/__snapshots__/codeTypeHandler-test.ts.snap b/packages/react-docgen/src/handlers/__tests__/__snapshots__/codeTypeHandler-test.ts.snap
deleted file mode 100644
index 4f074311341..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/__snapshots__/codeTypeHandler-test.ts.snap
+++ /dev/null
@@ -1,1694 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > special generic type annotations > unwraps $Exact<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition for flow <0.53 > special generic type annotations > unwraps $ReadOnly<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > special generic type annotations > unwraps $Exact<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with State > special generic type annotations > unwraps $ReadOnly<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > special generic type annotations > unwraps $Exact<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition with inline props > special generic type annotations > unwraps $ReadOnly<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > special generic type annotations > unwraps $Exact<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > class definition without State > special generic type annotations > unwraps $ReadOnly<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > special generic type annotations > unwraps $Exact<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (flow) > stateless component > special generic type annotations > unwraps $ReadOnly<...> 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
- "hal": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "boolean",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > special generic type annotations > unwraps $Exact<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with State > special generic type annotations > unwraps $ReadOnly<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
- "hal": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "boolean",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > special generic type annotations > unwraps $Exact<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition with inline props > special generic type annotations > unwraps $ReadOnly<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
- "hal": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "boolean",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > special generic type annotations > unwraps $Exact<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > class definition without State > special generic type annotations > unwraps $ReadOnly<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
- "hal": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "boolean",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > special generic type annotations > unwraps $Exact<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless TS component with Type > special generic type annotations > unwraps $ReadOnly<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > detects intersection types 1`] = `
-{
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > detects types correctly 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
- "hal": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "boolean",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > detects union types 1`] = `
-{
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > detects whether a prop is required 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > ignores hash map entry 1`] = `
-{
- "bar": {
- "description": "",
- "required": false,
- "tsType": {
- "name": "number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > special generic type annotations > unwraps $Exact<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > TypeAlias (ts) > stateless component > special generic type annotations > unwraps $ReadOnly<...> 1`] = `{}`;
-
-exports[`codeTypeHandler > does support utility types inline 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "name": "literal",
- "value": "'fooValue'",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > forwardRef > resolves prop type from function expression 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > forwardRef > resolves when the function is not inline 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > forwardRef > resolves when the function is rebound and not inline 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > imported prop types > imported 1`] = `
-{
- "abc": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "def": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "foobar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > imported prop types > type imported 1`] = `
-{
- "abc": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "string",
- },
- {
- "name": "number",
- },
- ],
- "name": "union",
- "raw": "string | number",
- },
- "required": true,
- },
- "bar": {
- "description": "",
- "flowType": {
- "name": "number",
- },
- "required": false,
- },
- "def": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "literal",
- "value": ""test"",
- },
- {
- "name": "literal",
- "value": "1",
- },
- {
- "name": "literal",
- "value": "true",
- },
- ],
- "name": "union",
- "raw": ""test" | 1 | true",
- },
- "required": true,
- },
- "foo": {
- "description": "",
- "flowType": {
- "name": "string",
- },
- "required": true,
- },
- "foobar": {
- "description": "",
- "flowType": {
- "elements": [
- {
- "name": "Foo",
- },
- {
- "name": "Bar",
- },
- ],
- "name": "intersection",
- "raw": "Foo & Bar",
- },
- "required": true,
- },
- "hal": {
- "description": "",
- "flowType": {
- "name": "boolean",
- },
- "required": true,
- },
-}
-`;
-
-exports[`codeTypeHandler > stateless TS component and variable type takes precedence 1`] = `
-{
- "foo": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "string",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > stateless TS component with 2 definitions 1`] = `
-{
- "additional": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "boolean",
- },
- },
- "bar": {
- "description": "",
- "required": true,
- "tsType": {
- "name": "number",
- },
- },
-}
-`;
-
-exports[`codeTypeHandler > supports intersection proptypes 1`] = `
-{
- "foo": {
- "description": "",
- "flowType": {
- "name": "literal",
- "value": "'bar'",
- },
- "required": true,
- },
-}
-`;
diff --git a/packages/react-docgen/src/handlers/__tests__/__snapshots__/componentMethodsHandler-test.ts.snap b/packages/react-docgen/src/handlers/__tests__/__snapshots__/componentMethodsHandler-test.ts.snap
deleted file mode 100644
index 326ba010fcc..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/__snapshots__/componentMethodsHandler-test.ts.snap
+++ /dev/null
@@ -1,310 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`componentMethodsHandler > function components > finds static methods on a component in a variable declaration 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doFoo",
- "params": [],
- "returns": null,
- },
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doBar",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > function components > finds static methods on a component in an assignment 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doFoo",
- "params": [],
- "returns": null,
- },
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doBar",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > function components > finds static methods on a function declaration 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doFoo",
- "params": [],
- "returns": null,
- },
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doBar",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > function components > resolves imported methods assigned on a component in an assignment 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doFoo",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > function components > resolves imported methods assigned to static properties on a component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doFoo",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > function components > resolves imported methods on a function declaration 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "doFoo",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > resolves imported methods assigned to computed properties 1`] = `
-[
- {
- "docblock": "The foo method",
- "modifiers": [],
- "name": "@computed#foo",
- "params": [
- {
- "name": "bar",
- "optional": false,
- "type": {
- "name": "number",
- },
- },
- ],
- "returns": {
- "type": {
- "name": "number",
- },
- },
- },
-]
-`;
-
-exports[`componentMethodsHandler > should handle and ignore computed methods 1`] = `
-[
- {
- "docblock": "The foo method",
- "modifiers": [],
- "name": "@computed#foo",
- "params": [
- {
- "name": "bar",
- "optional": false,
- "type": {
- "name": "number",
- },
- },
- ],
- "returns": {
- "type": {
- "name": "number",
- },
- },
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > AssignmentExpression and useImperativeHandle 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "other",
- "params": [],
- "returns": null,
- },
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > VariableDeclaration and useImperativeHandle 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [
- "static",
- ],
- "name": "other",
- "params": [],
- "returns": null,
- },
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > assigned ReturnStatement > ArrowFunctionExpression Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > assigned ReturnStatement > FunctionDeclaration Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > assigned ReturnStatement > FunctionExpression Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > direct ObjectExpression > ArrowFunctionExpression Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > direct ObjectExpression > FunctionDeclaration Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > direct ObjectExpression > FunctionExpression Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > regular ReturnStatement > ArrowFunctionExpression Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > regular ReturnStatement > FunctionDeclaration Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
-
-exports[`componentMethodsHandler > useImperativeHandle > regular ReturnStatement > FunctionExpression Component 1`] = `
-[
- {
- "docblock": null,
- "modifiers": [],
- "name": "method",
- "params": [],
- "returns": null,
- },
-]
-`;
diff --git a/packages/react-docgen/src/handlers/__tests__/__snapshots__/componentMethodsJsDocHandler-test.ts.snap b/packages/react-docgen/src/handlers/__tests__/__snapshots__/componentMethodsJsDocHandler-test.ts.snap
deleted file mode 100644
index 15f5b944bf3..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/__snapshots__/componentMethodsJsDocHandler-test.ts.snap
+++ /dev/null
@@ -1,82 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`componentMethodsJsDocHandler > adds descriptions 1`] = `
-[
- {
- "description": "The foo method.",
- "docblock": "
- The foo method.
- @param test The test
- @returns The number
- ",
- "modifiers": [],
- "name": "foo",
- "params": [
- {
- "description": "The test",
- "name": "test",
- "optional": false,
- },
- ],
- "returns": {
- "description": "The number",
- },
- },
-]
-`;
-
-exports[`componentMethodsJsDocHandler > adds js doc types when no flow types 1`] = `
-[
- {
- "description": null,
- "docblock": "
- @param {string} test
- @returns {string}
- ",
- "modifiers": [],
- "name": "foo",
- "params": [
- {
- "name": "test",
- "optional": false,
- "type": {
- "name": "string",
- },
- },
- ],
- "returns": {
- "type": {
- "name": "string",
- },
- },
- },
-]
-`;
-
-exports[`componentMethodsJsDocHandler > keeps flow types over js doc types 1`] = `
-[
- {
- "description": null,
- "docblock": "
- @param {string} test
- @returns {string}
- ",
- "modifiers": [],
- "name": "foo",
- "params": [
- {
- "name": "test",
- "optional": false,
- "type": {
- "name": "number",
- },
- },
- ],
- "returns": {
- "type": {
- "name": "number",
- },
- },
- },
-]
-`;
diff --git a/packages/react-docgen/src/handlers/__tests__/__snapshots__/defaultPropsHandler-test.ts.snap b/packages/react-docgen/src/handlers/__tests__/__snapshots__/defaultPropsHandler-test.ts.snap
deleted file mode 100644
index ad125e9f086..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/__snapshots__/defaultPropsHandler-test.ts.snap
+++ /dev/null
@@ -1,669 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > can resolve default props that are imported given a custom importer 1`] = `
-{
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > resolves imported spreads 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > resolves imported values assigned as default props 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > should find prop default values that are imported variables 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": true,
- "value": "ImportedComponent",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > should find prop default values that are literals 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > should find prop default values that are literals 2`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassDeclaration with static defaultProps > should resolve local spreads 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassExpression with static defaultProps > resolves imported values assigned as default props 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ClassExpression with static defaultProps > should find prop default values that are literals 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > allows imported defaults to be aliased 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > can use imported values as default props 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > overrides with imported defaultProps 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > resolves imported spreads 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > resolves local spreads 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > should find default props that are literals 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > should find prop default values that are imported variables 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": true,
- "value": "ImportedComponent",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > should override with defaultProps if available 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > should work with aliases 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > Functional components with default params > should work with no defaults 1`] = `{}`;
-
-exports[`defaultPropsHandler > ObjectExpression > can resolve declared functions 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > can resolve object methods 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > handles computed properties 1`] = `
-{
- "@computed#bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > handles imported values assigned to computed properties 1`] = `
-{
- "@computed#bar": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > ignores complex computed properties 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > ignores imported values assigned to complex computed properties 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > resolves imported spreads 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > resolves local spreads 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > should find prop default values that are literals 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "bigint": {
- "defaultValue": {
- "computed": false,
- "value": "1n",
- },
- },
- "falseliteral": {
- "defaultValue": {
- "computed": false,
- "value": "false",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
- "nullliteral": {
- "defaultValue": {
- "computed": false,
- "value": "null",
- },
- },
- "regex": {
- "defaultValue": {
- "computed": false,
- "value": "/./",
- },
- },
- "trueliteral": {
- "defaultValue": {
- "computed": false,
- "value": "true",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > ObjectExpression > should find prop default values that are literals from imported functions 1`] = `
-{
- "abc": {
- "defaultValue": {
- "computed": false,
- "value": "{xyz: abc.def, 123: 42}",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "baz": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": ""bar"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > can have an importer that resolves spread properties 1`] = `
-{
- "123": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
- "xyz": {
- "defaultValue": {
- "computed": true,
- "value": "abc.def",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > forwardRef > also resolves imports when the function is not inline 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > forwardRef > resolves default props in the parameters 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "'bar'",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > forwardRef > resolves defaultProps 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "'baz'",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > forwardRef > resolves imported default props in the parameters 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "["foo", "bar"]",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > forwardRef > resolves imported defaultProps 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": ""foo"",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > forwardRef > resolves when the function is not inline 1`] = `
-{
- "foo": {
- "defaultValue": {
- "computed": false,
- "value": "'bar'",
- },
- },
-}
-`;
-
-exports[`defaultPropsHandler > should only consider Property nodes, not e.g. spread properties 1`] = `
-{
- "bar": {
- "defaultValue": {
- "computed": false,
- "value": "42",
- },
- },
-}
-`;
diff --git a/packages/react-docgen/src/handlers/__tests__/__snapshots__/propTypeHandler-test.ts.snap b/packages/react-docgen/src/handlers/__tests__/__snapshots__/propTypeHandler-test.ts.snap
deleted file mode 100644
index 8dbbfe3d37d..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/__snapshots__/propTypeHandler-test.ts.snap
+++ /dev/null
@@ -1,309 +0,0 @@
-// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-
-exports[`propTypeHandler > React.createClass > can resolve individual imported variables assigned to props 1`] = `
-{
- "@computed#bar": {
- "required": false,
- "type": {},
- },
- "baz": {
- "required": false,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
- "foo": {
- "required": false,
- "type": {},
- },
- "simple_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > React.createClass > handles computed properties 1`] = `
-{
- "@computed#foo": {
- "required": true,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > React.createClass > ignores complex computed properties 1`] = `
-{
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > React.createClass > passes the correct argument to getPropType 1`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "bool",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > React.createClass > passes the correct argument to getPropType 2`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "xyz",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > class definition > class property > can resolve individual imported variables assigned to props 1`] = `
-{
- "@computed#bar": {
- "required": false,
- "type": {},
- },
- "baz": {
- "required": false,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
- "foo": {
- "required": false,
- "type": {},
- },
- "simple_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > class definition > class property > handles computed properties 1`] = `
-{
- "@computed#foo": {
- "required": true,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > class definition > class property > ignores complex computed properties 1`] = `
-{
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > class definition > class property > passes the correct argument to getPropType 1`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "bool",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > class definition > class property > passes the correct argument to getPropType 2`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "xyz",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > class definition > static getter > can resolve individual imported variables assigned to props 1`] = `
-{
- "@computed#bar": {
- "required": false,
- "type": {},
- },
- "baz": {
- "required": false,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
- "foo": {
- "required": false,
- "type": {},
- },
- "simple_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > class definition > static getter > handles computed properties 1`] = `
-{
- "@computed#foo": {
- "required": true,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > class definition > static getter > ignores complex computed properties 1`] = `
-{
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > class definition > static getter > passes the correct argument to getPropType 1`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "bool",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > class definition > static getter > passes the correct argument to getPropType 2`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "xyz",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > stateless component > can resolve individual imported variables assigned to props 1`] = `
-{
- "@computed#bar": {
- "required": false,
- "type": {},
- },
- "baz": {
- "required": false,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
- "foo": {
- "required": false,
- "type": {},
- },
- "simple_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > stateless component > handles computed properties 1`] = `
-{
- "@computed#foo": {
- "required": true,
- "type": {},
- },
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > stateless component > ignores complex computed properties 1`] = `
-{
- "complex_prop": {
- "required": true,
- "type": {},
- },
-}
-`;
-
-exports[`propTypeHandler > stateless component > passes the correct argument to getPropType 1`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "bool",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
-
-exports[`propTypeHandler > stateless component > passes the correct argument to getPropType 2`] = `
-Node {
- "computed": false,
- "object": Node {
- "name": "PropTypes",
- "type": "Identifier",
- },
- "property": Node {
- "name": "xyz",
- "type": "Identifier",
- },
- "type": "MemberExpression",
-}
-`;
diff --git a/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts
deleted file mode 100644
index 633350c9530..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts
+++ /dev/null
@@ -1,446 +0,0 @@
-import { parse, makeMockImporter, parseTypescript } from '../../../tests/utils';
-import DocumentationBuilder from '../../Documentation';
-import codeTypeHandler from '../codeTypeHandler.js';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import type {
- VariableDeclaration,
- ArrowFunctionExpression,
- CallExpression,
- ClassDeclaration,
- ExportNamedDeclaration,
- ObjectExpression,
-} from '@babel/types';
-import type { NodePath } from '@babel/traverse';
-import type { ComponentNode } from '../../resolver';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-
-describe('codeTypeHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- something: (stmtLast) =>
- stmtLast(`
- export type Props = {
- foo: string,
- bar?: number,
- hal: boolean,
- [key: string]: string,
- abc: string | number,
- def: "test" | 1 | true,
- foobar: Foo & Bar,
- };
- `).get('declaration') as NodePath,
- });
-
- function template(src: string, typeObject: string): string {
- return `
- ${src}
- var React = require('React');
- var Component = React.Component;
-
- type Props = ${typeObject};
- `;
- }
-
- function testCodeTypeHandler(
- getSrc: (src: string) => NodePath,
- ) {
- test('detects types correctly', () => {
- const flowTypesSrc = `
- {
- foo: string,
- bar: number,
- hal: boolean,
- }
- `;
- const definition = getSrc(flowTypesSrc);
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('detects whether a prop is required', () => {
- const flowTypesSrc = `
- {
- foo: string,
- bar?: number,
- }
- `;
- const definition = getSrc(flowTypesSrc);
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('ignores hash map entry', () => {
- const flowTypesSrc = `
- {
- [key: string]: string,
- bar?: number,
- }
- `;
- const definition = getSrc(flowTypesSrc);
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('detects union types', () => {
- const flowTypesSrc = `
- {
- foo: string | number,
- bar: "test" | 1 | true,
- }
- `;
- const definition = getSrc(flowTypesSrc);
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('detects intersection types', () => {
- const flowTypesSrc = `
- {
- foo: Foo & Bar,
- }
- `;
- const definition = getSrc(flowTypesSrc);
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- describe('special generic type annotations', () => {
- ['$ReadOnly', '$Exact'].forEach((annotation) => {
- test(`unwraps ${annotation}<...>`, () => {
- const flowTypesSrc = `
- ${annotation}<{
- foo: string | number,
- }>
- `;
-
- const definition = getSrc(flowTypesSrc);
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
- });
- }
-
- describe.each([
- ['flow', parse],
- ['ts', parseTypescript],
- ])('TypeAlias (%s)', (name, parseFunc) => {
- describe.runIf(name === 'flow')('class definition for flow <0.53', () => {
- testCodeTypeHandler((propTypesSrc) =>
- parseFunc.statement(
- template(
- 'class Foo extends Component {}',
- propTypesSrc,
- ),
- ),
- );
- });
-
- describe('class definition without State', () => {
- testCodeTypeHandler((propTypesSrc) =>
- parseFunc.statement(
- template('class Foo extends Component {}', propTypesSrc),
- ),
- );
- });
-
- describe('class definition with State', () => {
- testCodeTypeHandler((propTypesSrc) =>
- parseFunc.statement(
- template(
- 'class Foo extends Component {}',
- propTypesSrc,
- ),
- ),
- );
- });
-
- describe('class definition with inline props', () => {
- testCodeTypeHandler((propTypesSrc) =>
- parseFunc.statement(
- template(
- 'class Foo extends Component { props: Props; }',
- propTypesSrc,
- ),
- ),
- );
- });
-
- describe('stateless component', () => {
- testCodeTypeHandler(
- (propTypesSrc) =>
- parseFunc
- .statement(template('(props: Props) => null;', propTypesSrc))
- .get('expression') as NodePath,
- );
- });
-
- describe.runIf(name === 'ts')('stateless TS component with Type', () => {
- testCodeTypeHandler(
- (propTypesSrc) =>
- parseFunc
- .statement(
- template(
- 'const MyComponent:React.FC = (props) => null;',
- propTypesSrc,
- ),
- )
- .get('declarations')[0]
- .get('init') as NodePath,
- );
- });
- });
-
- describe('does not error if flowTypes cannot be found', () => {
- test('ObjectExpression', () => {
- const definition = parse.expression('{fooBar: 42}');
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- });
-
- test('ClassDeclaration', () => {
- const definition = parse.statement(
- 'class Foo extends Component {}',
- );
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- });
-
- test('ArrowFunctionExpression', () => {
- const definition =
- parse.statement('() => ');
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- });
- });
-
- test('supports intersection proptypes', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- import type Imported from 'something';
- type Props = Imported & { foo: 'bar' };`,
- )
- .get('expression') as NodePath;
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('does support utility types inline', () => {
- const definition = parse
- .statement(
- `(props: $ReadOnly) => ;
- var React = require('React');
- type Props = { foo: 'fooValue' };`,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('does not support union proptypes', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- import type Imported from 'something';
- type Other = { bar: 'barValue' };
- type Props = Imported | Other | { foo: 'fooValue' };`,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toEqual({});
- });
-
- describe('imported prop types', () => {
- test('does not resolve type included by require', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- var Component = React.Component;
- var Props = require('something');`,
- mockImporter,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toEqual({});
- });
-
- test('imported', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- var Component = React.Component;
- import { Props } from 'something';`,
- mockImporter,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('type not imported', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- var Component = React.Component;
- import type { Props } from 'something';`,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toEqual({});
- });
-
- test('type imported', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- var Component = React.Component;
- import type { Props } from 'something';`,
- mockImporter,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('does not resolve types not in scope', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- var Component = React.Component;`,
- mockImporter,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toEqual({});
- });
-
- test('does not resolve types not in scope', () => {
- const definition = parse
- .statement(
- `(props: Props) => ;
- var React = require('React');
- var Component = React.Component;`,
- mockImporter,
- )
- .get('expression') as NodePath;
-
- expect(() => codeTypeHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toEqual({});
- });
- });
-
- describe('forwardRef', () => {
- test('resolves prop type from function expression', () => {
- const src = `
- import React from 'react';
- type Props = { foo: string };
- React.forwardRef((props: Props, ref) => {props.foo}
);
- `;
-
- codeTypeHandler(documentation, parse.expressionLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves when the function is not inline', () => {
- const src = `
- import React from 'react';
- type Props = { foo: string };
- const ComponentImpl = (props: Props, ref) => {props.foo}
;
- React.forwardRef(ComponentImpl);
- `;
-
- codeTypeHandler(documentation, parse.expressionLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves when the function is rebound and not inline', () => {
- const src = `
- import React from 'react';
- type Props = { foo: string };
- let Component = (props: Props, ref) => {props.foo}
;
- Component = React.forwardRef(Component);
- `;
-
- codeTypeHandler(
- documentation,
- parse.expressionLast(src).get('right') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
-
- test('stateless TS component with 2 definitions', () => {
- const definition = parseTypescript
- .statement(
- `
- const MyComponent: React.FC<{ additional: boolean }> = (props: Props) => null;
- var React = require('React');
- var Component = React.Component;
-
- type Props = { bar: number };
- `,
- )
- .get('declarations')[0]
- .get('init') as NodePath;
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('stateless TS component and variable type takes precedence', () => {
- const definition = parseTypescript
- .statement(
- `
- const MyComponent: React.FC<{ foo: string }> = (props: Props) => null;
- var React = require('React');
- var Component = React.Component;
-
- type Props = { foo: number };
- `,
- )
- .get('declarations')[0]
- .get('init') as NodePath;
-
- codeTypeHandler(documentation, definition);
-
- expect(documentation.descriptors).toMatchSnapshot();
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/componentDocblockHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/componentDocblockHandler-test.ts
deleted file mode 100644
index 4683bb64dac..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/componentDocblockHandler-test.ts
+++ /dev/null
@@ -1,455 +0,0 @@
-import { makeMockImporter, parse } from '../../../tests/utils';
-import componentDocblockHandler from '../componentDocblockHandler.js';
-import DocumentationBuilder from '../../Documentation';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import type { NodePath } from '@babel/traverse';
-import type {
- ArrowFunctionExpression,
- CallExpression,
- ClassDeclaration,
- ClassExpression,
- ExportDefaultDeclaration,
- FunctionDeclaration,
- FunctionExpression,
- ObjectExpression,
- VariableDeclaration,
-} from '@babel/types';
-import type { ComponentNode } from '../../resolver';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-
-describe('componentDocblockHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- function testDockblockHandler(
- definitionSrc: string,
- parseFunc: (src: string) => NodePath,
- ) {
- test('finds docblocks for component definitions', () => {
- const definition = parseFunc(`
- import something from 'somewhere';
-
- /**
- * Component description
- */
- ${definitionSrc}
- `);
-
- componentDocblockHandler(documentation, definition);
- expect(documentation.description).toBe('Component description');
- });
-
- test('ignores other types of comments', () => {
- let definition = parseFunc(`
- import something from 'somewhere';
-
- /*
- * This is not a docblock',
- */
- ${definitionSrc}
- `);
-
- componentDocblockHandler(documentation, definition);
- expect(documentation.description).toBe('');
-
- definition = parseFunc(`
- // Inline comment'
- ${definitionSrc}
- `);
-
- componentDocblockHandler(documentation, definition);
- expect(documentation.description).toBe('');
- });
-
- test('only considers the docblock directly above the definition', () => {
- const definition = parseFunc(`
- import something from 'somewhere';
-
- /**
- * This is the wrong docblock
- */
- var something_else = "foo";
- ${definitionSrc}
- `);
-
- componentDocblockHandler(documentation, definition);
- expect(documentation.description).toBe('');
- });
- }
-
- /**
- * Decorates can only be assigned to class and therefore only make sense for
- * class declarations and export declarations.
- */
- function testDecorators(
- classSrc: string,
- parseFunc: (src: string) => NodePath,
- exportSrc = '',
- ) {
- describe('decorators', () => {
- test("uses the docblock above the decorator if it's the only one", () => {
- const definition = parseFunc(`
- import something from 'somewhere';
- /**
- * Component description
- */
- ${exportSrc}
- @Decorator1
- @Decorator2
- ${classSrc}
- `);
-
- componentDocblockHandler(documentation, definition);
- expect(documentation.description).toBe('Component description');
- });
-
- test('uses the component docblock if present', () => {
- const definition = parseFunc(`
- import something from 'somewhere';
-
- ${exportSrc}
- /**
- * Decorator description
- */
- @Decorator1
- @Decorator2
- /**
- * Component description
- */
- ${classSrc}
- `);
-
- componentDocblockHandler(documentation, definition);
- expect(documentation.description).toBe('Component description');
- });
- });
- }
-
- function testImports(
- exportSrc: string,
- importName: string,
- useDefault = false,
- ) {
- const importDef = useDefault ? `${importName}` : `{ ${importName} }`;
-
- const mockImporter = makeMockImporter({
- test1: (stmtLast) =>
- stmtLast(
- `
- /**
- * Component description
- */
- ${exportSrc}
- `,
- false,
- 0,
- ).get('declaration') as NodePath,
-
- test2: (stmtLast) =>
- stmtLast(`
- import ${importDef} from 'test1';
- export default ${importName};
- `).get('declaration'),
- });
-
- describe('imports', () => {
- test('can use a custom importer to resolve docblocks on imported components', () => {
- const program = parse
- .statementLast(
- `import ${importDef} from 'test1';
- export default ${importName};`,
- mockImporter,
- )
- .get('declaration') as NodePath;
-
- componentDocblockHandler(documentation, program);
- expect(documentation.description).toBe('Component description');
- });
- });
-
- test('traverses multiple imports', () => {
- const program = parse
- .statementLast(
- `import ${importDef} from 'test2';
- export default ${importName};`,
- mockImporter,
- )
- .get('declaration') as NodePath;
-
- componentDocblockHandler(documentation, program);
- expect(documentation.description).toBe('Component description');
- });
- }
-
- describe('React.createClass', () => {
- testDockblockHandler(
- 'var Component = React.createClass({})',
- (src) =>
- parse
- .statementLast(src)
- .get('declarations.0.init.arguments.0') as NodePath,
- );
- testImports('export var Component = React.createClass({})', 'Component');
- });
-
- describe('ClassDeclaration', () => {
- testDockblockHandler('class Component {}', (src) =>
- parse.statementLast(src),
- );
- testDecorators('class Component {}', (src) => parse.statementLast(src));
- testImports('export class Component {}', 'Component');
- });
-
- describe('ClassExpression', () => {
- testDockblockHandler(
- 'var Component = class {};',
- (src) =>
- parse
- .statementLast(src)
- .get('declarations.0.init') as NodePath,
- );
- testImports('export var Component = class {};', 'Component');
- });
-
- describe('Stateless functions', () => {
- testDockblockHandler('function Component() {}', (src) =>
- parse.statementLast(src),
- );
- testImports('export function Component() {}', 'Component');
- testDockblockHandler(
- 'var Component = function () {};',
- (src) =>
- parse
- .statementLast(src)
- .get('declarations.0.init') as NodePath,
- );
- testImports('export var Component = function () {};', 'Component');
- testDockblockHandler(
- 'var Component = () => {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declarations.0.init') as NodePath,
- );
- testImports('export var Component = () => {}', 'Component');
- });
-
- describe('ESM default export', () => {
- describe('Default React.createClass export', () => {
- testDockblockHandler(
- 'export default React.createClass({});',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration.arguments.0') as NodePath,
- );
- });
-
- describe('Default class declaration export', () => {
- testDockblockHandler(
- 'export default class Component {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- testDecorators(
- 'class Component {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- 'export default',
- );
- });
-
- describe('Default class expression export', () => {
- testDockblockHandler(
- 'export default class {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- testDecorators(
- 'class {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- 'export default',
- );
- });
-
- describe('Default stateless function export', () => {
- describe('named function', () => {
- testDockblockHandler(
- 'export default function Component() {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- });
-
- describe('anonymous function', () => {
- testDockblockHandler(
- 'export default function() {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- });
-
- describe('arrow function', () => {
- testDockblockHandler(
- 'export default () => {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- });
- });
- });
-
- describe('ESM named export', () => {
- describe('Named React.createClass export', () => {
- testDockblockHandler(
- 'export var Component = React.createClass({});',
- (src) =>
- parse
- .statementLast(src)
- .get(
- 'declaration.declarations.0.init.arguments.0',
- ) as NodePath,
- );
- });
-
- describe('Named class declaration export', () => {
- testDockblockHandler(
- 'export class Component {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- testDecorators(
- 'class Component {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- 'export',
- );
- });
-
- describe('Named stateless function', () => {
- describe('named function', () => {
- testDockblockHandler(
- 'export function Component() {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- });
-
- describe('anonymous function', () => {
- testDockblockHandler(
- 'export var Component = function() {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- });
-
- describe('arrow function', () => {
- testDockblockHandler(
- 'export var Component = () => {}',
- (src) =>
- parse
- .statementLast(src)
- .get('declaration') as NodePath,
- );
- });
- });
- });
-
- describe('forwardRef', () => {
- const useDefault = true;
-
- describe('inline implementation', () => {
- testDockblockHandler(
- `
- React.forwardRef((props, ref) => {});
- import React from "react";`,
- (src) =>
- parse
- .statement(src, -2)
- .get('expression') as NodePath,
- );
-
- testImports(
- `import React from 'react';
- export default React.forwardRef((props, ref) => {});`,
- 'RefComponent',
- useDefault,
- );
- });
-
- describe('inline implementation with memo', () => {
- testDockblockHandler(
- `
- React.memo(React.forwardRef((props, ref) => {}));
- import React from "react";
- `,
- (src) =>
- parse
- .statement(src, -2)
- .get('expression') as NodePath,
- );
-
- testImports(
- `
- export default React.memo(React.forwardRef((props, ref) => {}));
- import React from 'react';
- `,
- 'RefComponent',
- useDefault,
- );
- });
-
- describe('out of line implementation', () => {
- testDockblockHandler(
- `
- let Component = (props, ref) => {};
- React.forwardRef(Component);
- import React from "react";
- `,
- (src) =>
- parse
- .statement(src, -2)
- .get('expression') as NodePath,
- );
-
- testImports(
- `
- let Component = (props, ref) => {};
- export default React.forwardRef(Component);
- import React from 'react';
- `,
- `RefComponent`,
- useDefault,
- );
- });
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/componentMethodsHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/componentMethodsHandler-test.ts
deleted file mode 100644
index 8e67cd1164b..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/componentMethodsHandler-test.ts
+++ /dev/null
@@ -1,524 +0,0 @@
-import { parse, makeMockImporter } from '../../../tests/utils';
-import componentMethodsHandler from '../componentMethodsHandler.js';
-import DocumentationBuilder from '../../Documentation';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import type {
- ArrowFunctionExpression,
- AssignmentExpression,
- ClassDeclaration,
- ExportDefaultDeclaration,
- FunctionDeclaration,
- FunctionExpression,
- VariableDeclaration,
-} from '@babel/types';
-import type { NodePath } from '@babel/traverse';
-import type { ComponentNode } from '../../resolver';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-
-describe('componentMethodsHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- baz: (stmtLast) =>
- stmtLast(`
- export default (foo: string): string => {};
- `).get('declaration'),
-
- foo: (stmtLast) =>
- stmtLast(`
- export default function(bar: number): number {
- return bar;
- }
- `).get('declaration'),
-
- doFoo: (stmtLast) =>
- stmtLast(`
- export default () => {};
- `).get('declaration'),
- });
-
- function testMethodsHandler(definition) {
- componentMethodsHandler(documentation, definition);
- expect(documentation.methods).toEqual([
- {
- name: 'foo',
- docblock: 'The foo method',
- modifiers: [],
- returns: {
- type: { name: 'number' },
- },
- params: [
- {
- name: 'bar',
- optional: false,
- type: { name: 'number' },
- },
- ],
- },
- {
- name: 'baz',
- docblock: '"arrow function method"',
- modifiers: [],
- returns: {
- type: { name: 'string' },
- },
- params: [
- {
- name: 'foo',
- optional: false,
- type: { name: 'string' },
- },
- ],
- },
- {
- name: 'bar',
- docblock: 'Static function',
- modifiers: ['static'],
- returns: null,
- params: [],
- },
- ]);
- }
-
- describe('useImperativeHandle', () => {
- // Other cases BlockScopeBody with return, both assigned and useImperativeHandles
-
- const methodDefinitions = {
- 'direct ObjectExpression': '({ method: () => {} })',
- 'regular ReturnStatement': '{x; return { method: () => {} };}',
- 'assigned ReturnStatement': '{const r = { method: () => {} }; return r;}',
- };
-
- Object.entries(methodDefinitions).forEach(([name, code]) => {
- describe(name, () => {
- test('FunctionExpression Component', () => {
- const definition = parse.expressionLast(
- `import { useImperativeHandle } from 'react';
- (function () {
- useImperativeHandle(ref, () => ${code});
- return ;
- });`,
- );
-
- componentMethodsHandler(documentation, definition);
-
- expect(documentation.methods).toHaveLength(1);
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('FunctionDeclaration Component', () => {
- const definition = parse.statementLast(
- `import { useImperativeHandle } from 'react';
- function Component() {
- useImperativeHandle(ref, () => ${code});
- return ;
- }`,
- );
-
- componentMethodsHandler(documentation, definition);
-
- expect(documentation.methods).toHaveLength(1);
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('ArrowFunctionExpression Component', () => {
- const definition = parse.expressionLast(
- `import { useImperativeHandle } from 'react';
- (() => {
- useImperativeHandle(ref, () => ${code});
- return ;
- });`,
- );
-
- componentMethodsHandler(documentation, definition);
-
- expect(documentation.methods).toHaveLength(1);
- expect(documentation.methods).toMatchSnapshot();
- });
- });
- });
-
- test('AssignmentExpression and useImperativeHandle', () => {
- const definition = parse
- .statement(
- `import { useImperativeHandle } from 'react';
- let Component;
- Component = function () {
- test();
- useImperativeHandle(ref, () => ({ method: () => {} }));
-
- return ;
- };
- Component.other = () => {};
- `,
- -2,
- )
- .get('expression.right') as NodePath;
-
- componentMethodsHandler(documentation, definition);
-
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('VariableDeclaration and useImperativeHandle', () => {
- const definition = parse
- .statement(
- `import { useImperativeHandle } from 'react';
- let Component = function () {
- test();
- useImperativeHandle(ref, () => ({ method: () => {} }));
-
- return ;
- };
- Component.other = () => {};
- `,
- -2,
- )
- .get('declarations.0.init') as NodePath;
-
- componentMethodsHandler(documentation, definition);
-
- expect(documentation.methods).toMatchSnapshot();
- });
- });
-
- test('extracts the documentation for an ObjectExpression', () => {
- const src = `
- {
- /**
- * The foo method
- */
- foo(bar: number): number {
- return bar;
- },
- /**
- * "arrow function method"
- */
- baz: (foo: string): string => {},
- statics: {
- /**
- * Static function
- */
- bar() {}
- },
- state: {
- foo: 'foo',
- },
- componentDidMount() {},
- render() {
- return null;
- },
- }
- `;
-
- testMethodsHandler(parse.expression(src));
- });
-
- test('can resolve an imported method on an ObjectExpression', () => {
- const src = `
- import baz from 'baz';
- ({
- /**
- * The foo method
- */
- foo(bar: number): number {
- return bar;
- },
- /**
- * "arrow function method"
- */
- baz: baz,
- statics: {
- /**
- * Static function
- */
- bar() {}
- },
- state: {
- foo: 'foo',
- },
- componentDidMount() {},
- render() {
- return null;
- },
- })
- `;
-
- testMethodsHandler(parse.expressionLast(src, mockImporter));
- });
-
- test('extracts the documentation for a ClassDeclaration', () => {
- const src = `
- class Test extends React.Component {
- /**
- * The foo method
- */
- foo(bar: number): number {
- return bar;
- }
-
- /**
- * "arrow function method"
- */
- baz = (foo: string): string => {};
-
- /**
- * Static function
- */
- static bar() {}
-
- state = {
- foo: 'foo',
- };
-
- componentDidMount() {}
-
- render() {
- return null;
- }
- }
- `;
-
- testMethodsHandler(parse.statement(src));
- });
-
- test('can resolve an imported method on a ClassDeclaration', () => {
- const src = `
- import baz from 'baz';
- class Test extends React.Component {
- /**
- * The foo method
- */
- foo(bar: number): number {
- return bar;
- }
-
- /**
- * "arrow function method"
- */
- baz = baz;
-
- /**
- * Static function
- */
- static bar() {}
-
- state = {
- foo: 'foo',
- };
-
- componentDidMount() {}
-
- render() {
- return null;
- }
- }
- `;
-
- testMethodsHandler(parse.statementLast(src, mockImporter));
- });
-
- test('should handle and ignore computed methods', () => {
- const src = `
- class Test extends React.Component {
- /**
- * The foo method
- */
- [foo](bar: number): number {
- return bar;
- }
-
- /**
- * Should not show up
- */
- [() => {}](bar: number): number {
- return bar;
- }
-
- componentDidMount() {}
-
- render() {
- return null;
- }
- }
- `;
-
- componentMethodsHandler(
- documentation,
- parse.statement(src),
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('resolves imported methods assigned to computed properties', () => {
- const src = `
- import foo from 'foo';
- class Test extends React.Component {
- /**
- * The foo method
- */
- [foo] = foo;
-
- /**
- * Should not show up
- */
- [() => {}](bar: number): number {
- return bar;
- }
-
- componentDidMount() {}
-
- render() {
- return null;
- }
- }
- `;
-
- componentMethodsHandler(
- documentation,
- parse.statementLast(src, mockImporter),
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('should handle and ignore private properties', () => {
- const src = `
- class Test extends React.Component {
- #privateProperty = () => {
- console.log('Do something');
- }
-
- componentDidMount() {}
-
- render() {
- return null;
- }
- }
- `;
-
- componentMethodsHandler(
- documentation,
- parse.statement(src),
- );
- expect((documentation.methods as unknown[]).length).toBe(0);
- });
-
- describe('function components', () => {
- test('no methods', () => {
- const src = `
- (props) => {}
- `;
-
- const definition = parse
- .statement(src)
- .get('expression') as NodePath;
-
- componentMethodsHandler(documentation, definition);
- expect(documentation.methods).toEqual([]);
- });
-
- test('finds static methods on a component in a variable declaration', () => {
- const src = `
- const Test = (props) => {};
- Test.doFoo = () => {};
- Test.doBar = () => {};
- Test.displayName = 'Test'; // Not a method
- `;
-
- componentMethodsHandler(
- documentation,
- parse
- .statement(src)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('resolves imported methods assigned to static properties on a component', () => {
- const src = `
- const Test = (props) => {};
- import doFoo from 'doFoo';
- Test.doFoo = doFoo;
- `;
-
- componentMethodsHandler(
- documentation,
- parse
- .statement(src, mockImporter)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('finds static methods on a component in an assignment', () => {
- const src = `
- let Test;
- Test = (props) => {};
- Test.doFoo = () => {};
- Test.doBar = () => {};
- Test.displayName = 'Test'; // Not a method
- `;
-
- componentMethodsHandler(
- documentation,
- parse
- .statement(src, 1)
- .get('expression.right') as NodePath,
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('resolves imported methods assigned on a component in an assignment', () => {
- const src = `
- let Test;
- Test = (props) => {};
- import doFoo from 'doFoo';
- Test.doFoo = doFoo;
- `;
-
- componentMethodsHandler(
- documentation,
- parse
- .statement(src, mockImporter, 1)
- .get('expression.right') as NodePath,
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('finds static methods on a function declaration', () => {
- const src = `
- function Test(props) {}
- Test.doFoo = () => {};
- Test.doBar = () => {};
- Test.displayName = 'Test'; // Not a method
- `;
-
- componentMethodsHandler(
- documentation,
- parse.statement(src),
- );
- expect(documentation.methods).toMatchSnapshot();
- });
-
- test('resolves imported methods on a function declaration', () => {
- const src = `
- function Test(props) {}
- import doFoo from 'doFoo';
- Test.doFoo = doFoo;
- `;
-
- componentMethodsHandler(
- documentation,
- parse.statement(src, mockImporter),
- );
- expect(documentation.methods).toMatchSnapshot();
- });
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/componentMethodsJsDocHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/componentMethodsJsDocHandler-test.ts
deleted file mode 100644
index c1ab2dc5db0..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/componentMethodsJsDocHandler-test.ts
+++ /dev/null
@@ -1,105 +0,0 @@
-import type { NodePath } from '@babel/traverse';
-import DocumentationBuilder from '../../Documentation';
-import type { ComponentNode } from '../../resolver';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import componentMethodsJsDocHandler from '../componentMethodsJsDocHandler.js';
-import { beforeEach, describe, expect, test } from 'vitest';
-
-describe('componentMethodsJsDocHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- test('stays the same when no docblock is present', () => {
- const methods = [
- {
- name: 'foo',
- docblock: null,
- modifiers: [],
- returns: null,
- params: [
- {
- name: 'test',
- type: null,
- },
- ],
- },
- ];
-
- documentation.set('methods', methods);
- componentMethodsJsDocHandler(documentation, {} as NodePath);
- expect(documentation.get('methods')).toEqual(methods);
- });
-
- test('adds js doc types when no flow types', () => {
- documentation.set('methods', [
- {
- name: 'foo',
- docblock: `
- @param {string} test
- @returns {string}
- `,
- modifiers: [],
- returns: null,
- params: [
- {
- name: 'test',
- type: null,
- },
- ],
- },
- ]);
- componentMethodsJsDocHandler(documentation, {} as NodePath);
- expect(documentation.get('methods')).toMatchSnapshot();
- });
-
- test('keeps flow types over js doc types', () => {
- documentation.set('methods', [
- {
- name: 'foo',
- docblock: `
- @param {string} test
- @returns {string}
- `,
- modifiers: [],
- returns: {
- type: { name: 'number' },
- },
- params: [
- {
- name: 'test',
- type: { name: 'number' },
- },
- ],
- },
- ]);
- componentMethodsJsDocHandler(documentation, {} as NodePath);
- expect(documentation.get('methods')).toMatchSnapshot();
- });
-
- test('adds descriptions', () => {
- documentation.set('methods', [
- {
- name: 'foo',
- docblock: `
- The foo method.
- @param test The test
- @returns The number
- `,
- modifiers: [],
- returns: null,
- params: [
- {
- name: 'test',
- type: null,
- },
- ],
- },
- ]);
- componentMethodsJsDocHandler(documentation, {} as NodePath);
- expect(documentation.get('methods')).toMatchSnapshot();
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/defaultPropsHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/defaultPropsHandler-test.ts
deleted file mode 100644
index 5675a16494e..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/defaultPropsHandler-test.ts
+++ /dev/null
@@ -1,702 +0,0 @@
-import type { NodePath } from '@babel/traverse';
-import type {
- ArrowFunctionExpression,
- CallExpression,
- ClassDeclaration,
- ClassExpression,
- ObjectExpression,
- VariableDeclaration,
-} from '@babel/types';
-import { parse, makeMockImporter } from '../../../tests/utils';
-import DocumentationBuilder from '../../Documentation';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import defaultPropsHandler from '../defaultPropsHandler.js';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-
-describe('defaultPropsHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- getDefaultProps: (stmtLast) =>
- stmtLast(`
- import baz from 'baz';
- export default function() {
- return {
- foo: "bar",
- bar: 42,
- baz: baz,
- abc: {xyz: abc.def, 123: 42}
- };
- }
- `).get('declaration'),
-
- baz: (stmtLast) =>
- stmtLast(`
- export default ["foo", "bar"];
- `).get('declaration'),
-
- other: (stmtLast) =>
- stmtLast(`
- export default { bar: "foo" };
- `).get('declaration'),
-
- defaultProps: (stmtLast) =>
- stmtLast(`
- export default {
- foo: "bar",
- bar: 42,
- baz: ["foo", "bar"],
- abc: {xyz: abc.def, 123: 42}
- };
- `).get('declaration'),
- });
-
- describe('ObjectExpression', () => {
- test('should find prop default values that are literals', () => {
- const src = `
- {
- getDefaultProps: function() {
- return {
- foo: "bar",
- bar: 42,
- falseliteral: false,
- trueliteral: true,
- nullliteral: null,
- regex: /./,
- bigint: 1n,
- baz: ["foo", "bar"],
- abc: {xyz: abc.def, 123: 42}
- };
- }
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expression(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('can resolve object methods', () => {
- const src = `
- {
- getDefaultProps() {
- return {
- foo: "bar",
- };
- }
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expression(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('can resolve declared functions', () => {
- const src = `
- function getDefaultProps() {
- return {
- foo: "bar",
- bar: 42,
- baz: ["foo", "bar"],
- abc: {xyz: abc.def, 123: 42}
- };
- }
- ({
- getDefaultProps: getDefaultProps
- })
- `;
-
- defaultPropsHandler(documentation, parse.expressionLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should find prop default values that are literals from imported functions', () => {
- const src = `
- import getDefaultProps from 'getDefaultProps';
-
- ({
- getDefaultProps: getDefaultProps
- })
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('handles computed properties', () => {
- const src = `
- {
- getDefaultProps: function() {
- return {
- foo: "bar",
- [bar]: 42,
- };
- }
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expression(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('handles imported values assigned to computed properties', () => {
- const src = `
- import baz from 'baz';
- ({
- getDefaultProps: function() {
- return {
- foo: "bar",
- [bar]: baz,
- };
- }
- })
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('ignores complex computed properties', () => {
- const src = `
- ({
- getDefaultProps: function() {
- return {
- foo: "bar",
- [() => {}]: 42,
- };
- }
- })
- `;
-
- defaultPropsHandler(documentation, parse.expressionLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('ignores imported values assigned to complex computed properties', () => {
- const src = `
- import baz from 'baz';
- ({
- getDefaultProps: function() {
- return {
- foo: "bar",
- [() => {}]: baz,
- };
- }
- })
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves local spreads', () => {
- const src = `
- const other = { bar: "foo" };
-
- ({
- getDefaultProps: function() {
- return {
- foo: "bar",
- ...other,
- };
- }
- })
- `;
-
- defaultPropsHandler(documentation, parse.expressionLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported spreads', () => {
- const src = `
- import other from 'other';
- ({
- getDefaultProps: function() {
- return {
- foo: "bar",
- ...other,
- };
- }
- })
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
-
- describe('ClassDeclaration with static defaultProps', () => {
- test('should find prop default values that are literals', () => {
- const src = `
- class Foo {
- static defaultProps = {
- foo: "bar",
- bar: 42,
- baz: ["foo", "bar"],
- abc: {xyz: abc.def, 123: 42}
- };
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.statement(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should find prop default values that are literals', () => {
- const src = `
- class Foo {
- static get defaultProps() {
- return {
- foo: "bar",
- };
- }
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.statement(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported values assigned as default props', () => {
- const src = `
- import defaultProps from 'defaultProps';
- class Foo {
- static defaultProps = defaultProps;
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.statementLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should resolve local spreads', () => {
- const src = `
- const other = { bar: "foo" };
-
- class Foo {
- static defaultProps = {
- foo: "bar",
- ...other
- };
- }
- `;
-
- defaultPropsHandler(documentation, parse.statementLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported spreads', () => {
- const src = `
- import other from 'other';
- class Foo {
- static defaultProps = {
- foo: "bar",
- ...other
- };
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.statementLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should find prop default values that are imported variables', () => {
- const src = `
- import ImportedComponent from './ImportedComponent.js';
-
- class Foo {
- static defaultProps = {
- foo: ImportedComponent,
- };
- }
- `;
-
- defaultPropsHandler(documentation, parse.statementLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('can resolve default props that are imported given a custom importer', () => {
- const src = `
- import baz from 'baz';
-
- class Foo {
- static defaultProps = {
- baz: baz,
- };
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse.statementLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
-
- describe('ClassExpression with static defaultProps', () => {
- test('should find prop default values that are literals', () => {
- const src = `
- var Bar = class {
- static defaultProps = {
- foo: "bar",
- bar: 42,
- baz: ["foo", "bar"],
- abc: {xyz: abc.def, 123: 42}
- };
- }`;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported values assigned as default props', () => {
- const src = `
- import defaultProps from 'defaultProps';
- var Bar = class {
- static defaultProps = defaultProps;
- }
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statementLast(src, mockImporter)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
-
- test('should only consider Property nodes, not e.g. spread properties', () => {
- const src = `
- {
- getDefaultProps: function() {
- return {
- ...Foo.bar,
- bar: 42,
- };
- }
- }
- `;
- const definition = parse.expression(src);
-
- expect(() => defaultPropsHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('can have an importer that resolves spread properties', () => {
- const src = `
- import Props from 'defaultProps';
- ({
- getDefaultProps: function() {
- return {
- ...Props.abc,
- bar: 42,
- };
- }
- })
- `;
- const definition = parse.expressionLast(
- src,
- mockImporter,
- );
-
- expect(() => defaultPropsHandler(documentation, definition)).not.toThrow();
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- describe('Functional components with default params', () => {
- test('should find default props that are literals', () => {
- const src = `
- ({
- foo = "bar",
- bar = 42,
- baz = ["foo", "bar"],
- abc = {xyz: abc.def, 123: 42}
- }) =>
- `;
-
- defaultPropsHandler(documentation, parse.expressionLast(src));
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('can use imported values as default props', () => {
- const src = `
- import baz from 'baz';
- ({
- bar = baz,
- }) =>
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should override with defaultProps if available', () => {
- const src = `
- var Foo = ({
- foo = "bar",
- bar = 42,
- baz = ["foo", "bar"],
- abc = 'test'
- }) =>
- Foo.defaultProps = { abc: {xyz: abc.def, 123: 42} };
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('overrides with imported defaultProps', () => {
- const src = `
- import other from 'other';
- var Foo = ({
- bar = 42,
- }) =>
- Foo.defaultProps = other;
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src, mockImporter, 1)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves local spreads', () => {
- const src = `
- const other = { bar: "foo" };
- var Foo = (props) =>
- Foo.defaultProps = { foo: "bar", ...other };
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src, 1)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported spreads', () => {
- const src = `
- import other from 'other';
- var Foo = (props) =>
- Foo.defaultProps = { foo: "bar", ...other };
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src, mockImporter, 1)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should work with aliases', () => {
- const src = `
- ({
- foo = "bar",
- bar = 42,
- baz = ["foo", "bar"],
- abc: defg = {xyz: abc.def, 123: 42}
- }) =>
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('allows imported defaults to be aliased', () => {
- const src = `
- import baz from 'baz';
- ({
- foo: bar = baz,
- }) =>
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should find prop default values that are imported variables', () => {
- const src = `
- import ImportedComponent from './ImportedComponent.js';
-
- ({
- foo = ImportedComponent,
- }) =>
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('should work with no defaults', () => {
- const src = `({ foo }) => `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
-
- describe('forwardRef', () => {
- test('resolves default props in the parameters', () => {
- const src = `
- import React from 'react';
- React.forwardRef(({ foo = 'bar' }, ref) => {foo}
);
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported default props in the parameters', () => {
- const src = `
- import baz from 'baz';
- import React from 'react';
- React.forwardRef(({ bar = baz }, ref) => {bar}
);
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves defaultProps', () => {
- const src = `
- import React from 'react';
- const Component = React.forwardRef(({ foo }, ref) => {foo}
);
- Component.defaultProps = { foo: 'baz' };
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src, 1)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves imported defaultProps', () => {
- const src = `
- import other from 'other';
- import React from 'react';
- const Component = React.forwardRef(({ bar }, ref) => {bar}
);
- Component.defaultProps = other;
- `;
-
- defaultPropsHandler(
- documentation,
- parse
- .statement(src, mockImporter, 2)
- .get('declarations.0.init') as NodePath,
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('resolves when the function is not inline', () => {
- const src = `
- import React from 'react';
- const ComponentImpl = ({ foo = 'bar' }, ref) => {foo}
;
- React.forwardRef(ComponentImpl);
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('also resolves imports when the function is not inline', () => {
- const src = `
- import baz from 'baz';
- import React from 'react';
- const ComponentImpl = ({ bar = baz }, ref) => {bar}
;
- React.forwardRef(ComponentImpl);
- `;
-
- defaultPropsHandler(
- documentation,
- parse.expressionLast(src, mockImporter),
- );
- expect(documentation.descriptors).toMatchSnapshot();
- });
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/displayNameHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/displayNameHandler-test.ts
deleted file mode 100644
index d1ea7485d01..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/displayNameHandler-test.ts
+++ /dev/null
@@ -1,649 +0,0 @@
-import { parse, makeMockImporter } from '../../../tests/utils';
-import DocumentationBuilder from '../../Documentation';
-import displayNameHandler from '../displayNameHandler.js';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import type {
- ArrowFunctionExpression,
- ClassDeclaration,
- ExportDefaultDeclaration,
- FunctionDeclaration,
- FunctionExpression,
- ObjectExpression,
- VariableDeclaration,
-} from '@babel/types';
-import type { NodePath } from '@babel/traverse';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-
-describe('defaultPropsHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- foobarbaz: (stmt) =>
- stmt(`
- export default "FooBarBaz"
- `).get('declaration'),
-
- foo: (stmt) =>
- stmt(`
- export default {bar: 'baz'};
- `).get('declaration'),
-
- bar: (stmt) =>
- stmt(`
- export default {baz: 'foo'};
- `).get('declaration'),
- });
-
- test('extracts the displayName', () => {
- const definition = parse.expression(
- '{displayName: "FooBar"}',
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBar');
- });
-
- test('extracts the imported displayName', () => {
- const definition = parse.expressionLast(
- `import foobarbaz from 'foobarbaz';
- ({displayName: foobarbaz});`,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves identifiers', () => {
- const definition = parse.expressionLast(
- `var name = 'abc';
- ({displayName: name})`,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('abc');
- });
-
- test('resolves imported identifiers', () => {
- const definition = parse.expressionLast(
- `import foobarbaz from 'foobarbaz';
- var name = foobarbaz;
- ({displayName: name})`,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('can resolve non-literal names with appropriate importer', () => {
- const definition = parse.expressionLast(
- `import foo from 'foo';
- ({displayName: foo.bar});`,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('baz');
- });
-
- test('ignores non-literal names', () => {
- const definition = parse.expression(
- '{displayName: foo.bar}',
- );
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).not.toBeDefined();
- });
-
- describe('ClassDeclaration', () => {
- test('considers the class name', () => {
- const definition = parse.statement(`class Foo {}`);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('does not crash if no name', () => {
- const definition = parse
- .statement(`export default class {}`)
- .get('declaration') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBeUndefined();
- });
-
- test('resolves identifiers', () => {
- const definition = parse.statement(`
- class Foo {
- static displayName = name;
- }
- var name = 'xyz';
- `);
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('xyz');
- });
-
- test('resolves imported identifiers', () => {
- const definition = parse.statement(
- `
- class Foo {
- static displayName = name;
- }
- import foobarbaz from 'foobarbaz';
- var name = foobarbaz;
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves imported displayName', () => {
- const definition = parse.statement(
- `
- class Foo {
- static displayName = foobarbaz;
- }
- import foobarbaz from 'foobarbaz';
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('ignores non-literal names', () => {
- const definition = parse.statement(`
- class Foo {
- static displayName = foo.bar;
- }
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBeUndefined();
- });
-
- test('can resolve non-literal names with appropriate importer', () => {
- const definition = parse.statement(
- `
- class Foo {
- static displayName = bar.baz;
- }
- import bar from 'bar';
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('foo');
- });
-
- test('considers a static displayName class property', () => {
- const definition = parse.statement(`
- class Foo {
- static displayName = 'foo';
- }
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('foo');
- });
-
- test('considers static displayName getter', () => {
- const definition = parse.statement(`
- class Foo {
- static get displayName() {
- return 'foo';
- }
- }
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('foo');
- });
-
- test('considers static displayName property with function expression', () => {
- const definition = parse.statement(`
- class Foo {
- static displayName = function() {
- return 'foo';
- }
- }
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('foo');
- });
-
- test('considers static displayName property with function declaration', () => {
- const definition = parse.statement(`
- class Foo {
- static displayName = displayName;
- }
- function displayName() {
- return 'foo';
- }
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('foo');
- });
-
- test('resolves variables in displayName getter', () => {
- const definition = parse.statement(`
- class Foo {
- static get displayName() {
- return abc;
- }
- }
- const abc = 'bar';
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('bar');
- });
-
- test('resolves imported Identifier in displayName getter', () => {
- const definition = parse.statement(
- `
- class Foo {
- static get displayName() {
- return foobarbaz;
- }
- }
- import foobarbaz from 'foobarbaz';
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves imported MemberExpression in displayName getter', () => {
- const definition = parse.statement(
- `
- class Foo {
- static get displayName() {
- return foo.bar;
- }
- }
- import foo from 'foo';
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('baz');
- });
- });
-
- describe('FunctionDeclaration', () => {
- test('considers the function name', () => {
- const definition =
- parse.statement('function Foo () {}');
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('does not crash if no name', () => {
- const definition = parse
- .statement(`export default function () {}`)
- .get('declaration') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBeUndefined();
- });
-
- test('considers a static displayName object property', () => {
- const definition = parse.statement(`
- function Foo () {}
- Foo.displayName = 'Bar';
- `);
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves variable assigned to displayName object property', () => {
- const definition = parse.statement(`
- function Foo () {}
- Foo.displayName = bar;
- var bar = 'Bar';
- `);
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves imported Identifier assigned to displayName object property', () => {
- const definition = parse.statement(
- `
- function Foo () {}
- import foobarbaz from 'foobarbaz';
- Foo.displayName = foobarbaz;
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves imported MemberExpression assigned to displayName object property', () => {
- const definition = parse.statement(
- `
- function Foo () {}
- import foo from 'foo';
- Foo.displayName = foo.bar;
- `,
- mockImporter,
- );
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('baz');
- });
- });
-
- describe('FunctionExpression', () => {
- test('considers the variable name', () => {
- const definition = parse
- .statement('var Foo = function () {};')
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers the variable name on assign', () => {
- const definition = parse
- .statement('Foo = function () {};')
- .get('expression.right') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers a static displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = function () {};
- Foo.displayName = 'Bar';
- `,
- )
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves variable assigned to displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = function () {};
- Foo.displayName = bar;
- var bar = 'Bar';
- `,
- )
- .get('declarations.0.init') as NodePath;
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves imported Identifier assigned to displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = function () {};
- import foobarbaz from 'foobarbaz';
- Foo.displayName = foobarbaz;
- `,
- mockImporter,
- )
- .get('declarations.0.init') as NodePath;
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves imported MemberExpression assigned to displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = function () {};
- import foo from 'foo';
- Foo.displayName = foo.bar;
- `,
- mockImporter,
- )
- .get('declarations.0.init') as NodePath;
-
- displayNameHandler(documentation, definition);
- expect(documentation.displayName).toBe('baz');
- });
- });
-
- describe('ArrowFunctionExpression', () => {
- test('considers the variable name', () => {
- const definition = parse
- .statement('var Foo = () => {};')
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers the variable name even if wrapped', () => {
- const definition = parse
- .statement('var Foo = React.forwardRef(() => {});')
- .get(
- 'declarations.0.init.arguments.0',
- ) as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers the variable name when handling forwardRef', () => {
- const definition = parse
- .statement(
- `
- var Foo = React.forwardRef(() => {});
- import React from "react";
- `,
- )
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers the variable name on assign', () => {
- const definition = parse
- .statement('Foo = () => {};')
- .get('expression.right') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers the variable name on assign even if wrapped', () => {
- const definition = parse
- .statement('Foo = React.forwardRef(() => {});')
- .get(
- 'expression.right.arguments.0',
- ) as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers the variable name on assign when handling forwardRef call', () => {
- const definition = parse
- .statement(
- `
- Foo = React.forwardRef(() => {});
- import React from "react";
- `,
- )
- .get('expression.right') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Foo');
- });
-
- test('considers a static displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = () => {};
- Foo.displayName = 'Bar';
- `,
- )
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves a variable assigned to displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = () => {};
- Foo.displayName = bar;
- var bar = 'Bar';
- `,
- )
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves imported Identifier assigned to displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = () => {};
- import foobarbaz from 'foobarbaz';
- Foo.displayName = foobarbaz;
- `,
- mockImporter,
- )
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves imported MemberExpression assigned to displayName object property over variable name', () => {
- const definition = parse
- .statement(
- `
- var Foo = () => {};
- import foo from 'foo';
- Foo.displayName = foo.bar;
- `,
- mockImporter,
- )
- .get('declarations.0.init') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('baz');
- });
-
- test('considers a static displayName object property over variable name even if wrapped', () => {
- const definition = parse
- .statement(
- `
- var Foo = React.forwardRef(() => {});
- Foo.displayName = 'Bar';
- `,
- )
- .get(
- 'declarations.0.init.arguments.0',
- ) as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves a variable assigned to displayName object property over variable name even if wrapped', () => {
- const definition = parse
- .statement(
- `
- var Foo = React.forwardRef(() => {});
- Foo.displayName = bar;
- var bar = 'Bar';
- `,
- )
- .get(
- 'declarations.0.init.arguments.0',
- ) as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('Bar');
- });
-
- test('resolves imported Identifier assigned to displayName object property over variable name even if wrapped', () => {
- const definition = parse
- .statement(
- `
- var Foo = React.forwardRef(() => {});
- import foobarbaz from 'foobarbaz';
- Foo.displayName = foobarbaz;
- `,
- mockImporter,
- )
- .get(
- 'declarations.0.init.arguments.0',
- ) as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('FooBarBaz');
- });
-
- test('resolves imported MemberExpression assigned to displayName object property over variable name even if wrapped', () => {
- const definition = parse
- .statement(
- `
- var Foo = React.forwardRef(() => {});
- import foo from 'foo';
- Foo.displayName = foo.bar;
- `,
- mockImporter,
- )
- .get(
- 'declarations.0.init.arguments.0',
- ) as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).toBe('baz');
- });
-
- test('ignores assignment to non-literal/identifier', () => {
- const definition = parse
- .statement('Foo.Bar = () => {};')
- .get('expression.right') as NodePath;
-
- expect(() => displayNameHandler(documentation, definition)).not.toThrow();
- expect(documentation.displayName).not.toBeDefined();
- });
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/propDocblockHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/propDocblockHandler-test.ts
deleted file mode 100644
index 278dc78cdee..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/propDocblockHandler-test.ts
+++ /dev/null
@@ -1,279 +0,0 @@
-import type { NodePath } from '@babel/traverse';
-import type { ClassDeclaration, ObjectExpression } from '@babel/types';
-import { parse, makeMockImporter, noopImporter } from '../../../tests/utils';
-import DocumentationBuilder from '../../Documentation';
-import type { Importer } from '../../importer';
-import type { ComponentNode } from '../../resolver';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import propDocblockHandler from '../propDocblockHandler.js';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-
-describe('propDocblockHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- props: (stmtLast) =>
- stmtLast(`
- export default {
- /**
- * A comment on imported props
- */
- foo: Prop.bool,
- };
- `).get('declaration'),
- });
-
- function testDocBlockHandler(
- getSrc: (src: string) => string,
- parseSrc: (src: string, importer?: Importer) => NodePath,
- ) {
- test('finds docblocks for prop types', () => {
- const definition = parseSrc(
- getSrc(
- `{
- /**
- * Foo comment
- */
- foo: Prop.bool,
- /**
- * Bar comment
- */
- bar: Prop.bool,
- }`,
- ),
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'Foo comment',
- },
- bar: {
- description: 'Bar comment',
- },
- });
- });
-
- test('can handle multline comments', () => {
- const definition = parseSrc(
- getSrc(
- `{
- /**
- * Foo comment with
- * many lines!
- *
- * even with empty lines in between
- */
- foo: Prop.bool,
- }`,
- ),
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description:
- 'Foo comment with\nmany lines!\n\neven with empty lines in between',
- },
- });
- });
-
- test('ignores non-docblock comments', () => {
- const definition = parseSrc(
- getSrc(
- `{
- /**
- * Foo comment
- */
- // TODO: remove this comment
- foo: Prop.bool,
- /**
- * Bar comment
- */
- /* This is not a doc comment */
- bar: Prop.bool,
- }`,
- ),
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'Foo comment',
- },
- bar: {
- description: 'Bar comment',
- },
- });
- });
-
- test('only considers the comment with the property below it', () => {
- const definition = parseSrc(
- getSrc(
- `{
- /**
- * Foo comment
- */
- foo: Prop.bool,
- bar: Prop.bool,
- }`,
- ),
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'Foo comment',
- },
- bar: {
- description: '',
- },
- });
- });
-
- test('understands and ignores the spread operator', () => {
- const definition = parseSrc(
- getSrc(
- `{
- ...Bar.propTypes,
- /**
- * Foo comment
- */
- foo: Prop.bool,
- }`,
- ),
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'Foo comment',
- },
- });
- });
-
- test('resolves variables', () => {
- const definition = parseSrc(`
- ${getSrc('Props')}
- var Props = {
- /**
- * Foo comment
- */
- foo: Prop.bool,
- };
- `);
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'Foo comment',
- },
- });
- });
-
- test('resolves imported variables', () => {
- const definition = parseSrc(
- `
- ${getSrc('Props')}
- import Props from 'props';
- `,
- mockImporter,
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'A comment on imported props',
- },
- });
- });
-
- test('resolves imported variables that are spread', () => {
- const definition = parseSrc(
- `
- ${getSrc('Props')}
- import ExtraProps from 'props';
- var Props = {
- ...ExtraProps,
- /**
- * Bar comment
- */
- bar: Prop.bool,
- }
- `,
- mockImporter,
- );
-
- propDocblockHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- description: 'A comment on imported props',
- },
- bar: {
- description: 'Bar comment',
- },
- });
- });
- }
-
- describe('React.createClass', () => {
- testDocBlockHandler(
- (propTypesSrc) => `({propTypes: ${propTypesSrc}})`,
- (src, importer = noopImporter) =>
- parse
- .statement(src, importer)
- .get('expression') as NodePath,
- );
- });
-
- describe('ClassDefinition', () => {
- describe('class property', () => {
- testDocBlockHandler(
- (propTypesSrc) => `
- class Foo{
- static propTypes = ${propTypesSrc};
- }
- `,
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
-
- describe('static getter', () => {
- testDocBlockHandler(
- (propTypesSrc) => `
- class Foo{
- static get propTypes() {
- return ${propTypesSrc};
- }
- }
- `,
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
- });
-
- describe('does not error if propTypes cannot be found', () => {
- test('ObjectExpression', () => {
- const definition = parse.expression('{fooBar: 42}');
-
- expect(() =>
- propDocblockHandler(documentation, definition),
- ).not.toThrow();
- });
-
- test('ClassDeclaration', () => {
- const definition = parse.statement('class Foo {}');
-
- expect(() =>
- propDocblockHandler(documentation, definition),
- ).not.toThrow();
- });
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/propTypeCompositionHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/propTypeCompositionHandler-test.ts
deleted file mode 100644
index c527a8cb028..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/propTypeCompositionHandler-test.ts
+++ /dev/null
@@ -1,175 +0,0 @@
-import { parse, makeMockImporter, noopImporter } from '../../../tests/utils';
-import propTypeCompositionHandler from '../propTypeCompositionHandler.js';
-import DocumentationBuilder from '../../Documentation';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import type { NodePath } from '@babel/traverse';
-import type { Importer } from '../../importer';
-import type { ClassDeclaration, ObjectExpression } from '@babel/types';
-import type { ComponentNode } from '../../resolver';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-vi.mock('../../Documentation.js');
-vi.mock('../../utils/getPropType.js', () => () => ({}));
-
-describe('propTypeCompositionHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- 'Foo.react': (stmtLast) =>
- stmtLast(`
- function Component() {}
- Component.propTypes = {
- foo: 'bar'
- };
- export default Component;
- `).get('declaration'),
-
- SharedProps: (stmtLast) =>
- stmtLast(`
- export default {
- bar: 'baz'
- };
- `).get('declaration'),
- });
-
- function testCompositionHandler(
- getSrc: (src: string) => string,
- parseSrc: (src: string, importer?: Importer) => NodePath,
- ) {
- test('understands assignment from module', () => {
- let definition = parseSrc(`
- ${getSrc('Foo.propTypes')}
- var Foo = require("Foo.react");
- `);
-
- propTypeCompositionHandler(documentation, definition);
- expect(documentation.composes).toEqual(['Foo.react']);
-
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- definition = parseSrc(`
- ${getSrc('SharedProps')}
- var SharedProps = require("SharedProps");
- `);
-
- propTypeCompositionHandler(documentation, definition);
- expect(documentation.composes).toEqual(['SharedProps']);
- });
-
- test('understands the spread operator', () => {
- const definitionSrc = getSrc(
- `{
- ...Foo.propTypes,
- ...SharedProps,
- }`,
- );
- const definition = parseSrc(`
- ${definitionSrc}
- var Foo = require("Foo.react");
- var SharedProps = require("SharedProps");
- `);
-
- propTypeCompositionHandler(documentation, definition);
- expect(documentation.composes).toEqual(['Foo.react', 'SharedProps']);
- });
-
- test('does not add any composes if spreads can be fully resolved with the importer', () => {
- const definitionSrc = getSrc(
- `{
- ...Foo.propTypes,
- ...SharedProps,
- }`,
- );
- const definition = parseSrc(
- `
- ${definitionSrc}
- import Foo from "Foo.react";
- import SharedProps from "SharedProps";
- `,
- mockImporter,
- );
-
- propTypeCompositionHandler(documentation, definition);
- expect(documentation.composes).toEqual([]);
- });
-
- test('still adds a composes if the importer cannot resolve a value', () => {
- const definitionSrc = getSrc(
- `{
- ...Foo.propTypes,
- ...NotFound,
- }`,
- );
- const definition = parseSrc(
- `
- ${definitionSrc}
- import Foo from "Foo.react";
- import NotFound from "NotFound";
- `,
- mockImporter,
- );
-
- propTypeCompositionHandler(documentation, definition);
- expect(documentation.composes).toEqual(['NotFound']);
- });
- }
-
- describe('React.createClass', () => {
- testCompositionHandler(
- (propTypesSrc) => `({propTypes: ${propTypesSrc}})`,
- (src, importer = noopImporter) =>
- parse
- .statement(src, importer)
- .get('expression') as NodePath,
- );
- });
-
- describe('class definition', () => {
- describe('class properties', () => {
- testCompositionHandler(
- (propTypesSrc) => `
- class Component {
- static propTypes = ${propTypesSrc};
- }
- `,
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
-
- describe('static getter', () => {
- testCompositionHandler(
- (propTypesSrc) => `
- class Component {
- static get propTypes() {
- return ${propTypesSrc};
- }
- }
- `,
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
- });
-
- describe('does not error if propTypes cannot be found', () => {
- test('ObjectExpression', () => {
- const definition = parse.expression('{fooBar: 42}');
-
- expect(() =>
- propTypeCompositionHandler(documentation, definition),
- ).not.toThrow();
- });
-
- test('ClassDeclaration', () => {
- const definition = parse.statement('class Foo {}');
-
- expect(() =>
- propTypeCompositionHandler(documentation, definition),
- ).not.toThrow();
- });
- });
-});
diff --git a/packages/react-docgen/src/handlers/__tests__/propTypeHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/propTypeHandler-test.ts
deleted file mode 100644
index 37faedb700a..00000000000
--- a/packages/react-docgen/src/handlers/__tests__/propTypeHandler-test.ts
+++ /dev/null
@@ -1,365 +0,0 @@
-import { parse, makeMockImporter, noopImporter } from '../../../tests/utils';
-import DocumentationBuilder from '../../Documentation';
-import type DocumentationMock from '../../__mocks__/Documentation';
-import { propTypeHandler } from '../propTypeHandler.js';
-import getPropType from '../../utils/getPropType';
-import type { NodePath } from '@babel/traverse';
-import type { Importer } from '../../importer';
-import type {
- ArrowFunctionExpression,
- ClassDeclaration,
- FunctionDeclaration,
- ObjectExpression,
-} from '@babel/types';
-import type { ComponentNode } from '../../resolver';
-import { beforeEach, describe, expect, test, vi } from 'vitest';
-
-const getPropTypeMock = vi.mocked(getPropType);
-
-vi.mock('../../Documentation.js');
-vi.mock('../../utils/getPropType.js', () => ({ default: vi.fn(() => ({})) }));
-
-describe('propTypeHandler', () => {
- let documentation: DocumentationBuilder & DocumentationMock;
-
- beforeEach(() => {
- documentation = new DocumentationBuilder() as DocumentationBuilder &
- DocumentationMock;
- });
-
- const mockImporter = makeMockImporter({
- props: (stmtLast) =>
- stmtLast(`
- import { PropTypes } from 'react';
- export default {bar: PropTypes.bool};
- `).get('declaration'),
-
- simpleProp: (stmtLast) =>
- stmtLast(`
- import { PropTypes } from 'react';
- export default PropTypes.array.isRequired;
- `).get('declaration'),
-
- complexProp: (stmtLast) =>
- stmtLast(`
- var prop = PropTypes.oneOfType([PropTypes.number, PropTypes.bool]).isRequired;
- import { PropTypes } from 'react';
- export default prop;
- `).get('declaration'),
-
- foo: (stmtLast) =>
- stmtLast(`
- import { PropTypes } from 'react';
- export default PropTypes.bool;
- `).get('declaration'),
-
- bar: (stmtLast) =>
- stmtLast(`
- import { PropTypes } from 'react';
- export default PropTypes.bool;
- `).get('declaration'),
-
- baz: (stmtLast) =>
- stmtLast(`
- import { PropTypes as OtherPropTypes } from 'react';
- export default OtherPropTypes.bool;
- `).get('declaration'),
- });
-
- function template(src: string) {
- return `
- ${src}
- var React = require('React');
- var PropTypes = React.PropTypes;
- var {PropTypes: OtherPropTypes} = React;
- `;
- }
-
- function testPropTypes(
- getSrc: (src: string) => string,
- parseSrc: (src: string, importer?: Importer) => NodePath,
- ) {
- test('passes the correct argument to getPropType', () => {
- const propTypesSrc = `{
- foo: PropTypes.bool,
- abc: PropTypes.xyz,
- }`;
- const definition = parseSrc(getSrc(propTypesSrc));
-
- propTypeHandler(documentation, definition);
-
- expect(getPropTypeMock.mock.calls[0][0]).toMatchSnapshot();
- expect(getPropTypeMock.mock.calls[1][0]).toMatchSnapshot();
- });
-
- test('finds definitions via React.PropTypes', () => {
- const definition = parseSrc(
- getSrc(
- `{
- foo: PropTypes.bool,
- bar: require("react").PropTypes.bool,
- baz: OtherPropTypes.bool,
- }`,
- ),
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- type: {},
- required: false,
- },
- bar: {
- type: {},
- required: false,
- },
- baz: {
- type: {},
- required: false,
- },
- });
- });
-
- test('finds definitions via the ReactPropTypes module', () => {
- const definition = parseSrc(
- getSrc(
- `{
- foo: require("ReactPropTypes").bool,
- }`,
- ),
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- foo: {
- type: {},
- required: false,
- },
- });
- });
-
- test('detects whether a prop is required', () => {
- const definition = parseSrc(
- getSrc(
- `{
- simple_prop: PropTypes.array.isRequired,
- complex_prop:
- PropTypes.oneOfType([PropTypes.number, PropTypes.bool]).isRequired,
- }`,
- ),
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- simple_prop: {
- type: {},
- required: true,
- },
- complex_prop: {
- type: {},
- required: true,
- },
- });
- });
-
- test('handles computed properties', () => {
- const definition = parseSrc(
- getSrc(
- `{
- [foo]: PropTypes.array.isRequired,
- complex_prop:
- PropTypes.oneOfType([PropTypes.number, PropTypes.bool]).isRequired,
- }`,
- ),
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('ignores complex computed properties', () => {
- const definition = parseSrc(
- getSrc(
- `{
- [() => {}]: PropTypes.array.isRequired,
- complex_prop:
- PropTypes.oneOfType([PropTypes.number, PropTypes.bool]).isRequired,
- }`,
- ),
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toMatchSnapshot();
- });
-
- test('only considers definitions from React or ReactPropTypes', () => {
- const definition = parseSrc(
- getSrc(
- `{
- custom_propA: PropTypes.bool,
- custom_propB: Prop.bool.isRequired,
- }`,
- ),
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- custom_propA: {
- type: {},
- required: false,
- },
- custom_propB: {
- type: {
- name: 'custom',
- raw: 'Prop.bool.isRequired',
- },
- required: false,
- },
- });
- });
-
- test('resolves variables', () => {
- const definitionSrc = getSrc('props');
- const definition = parseSrc(`
- ${definitionSrc}
- var props = {bar: PropTypes.bool};
- `);
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- bar: {
- type: {},
- required: false,
- },
- });
- });
-
- test('resolves imported variables', () => {
- const definitionSrc = getSrc('props');
- const definition = parseSrc(
- `
- ${definitionSrc}
- import props from 'props';
- `,
- mockImporter,
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toEqual({
- bar: {
- type: {},
- required: false,
- },
- });
- });
-
- test('can resolve individual imported variables assigned to props', () => {
- const definitionSrc = getSrc(`{
- foo: foo,
- [bar]: bar,
- baz: baz,
- simple_prop: simpleProp,
- complex_prop: complexProp,
- }`);
- const definition = parseSrc(
- `
- ${definitionSrc}
- import foo from 'foo';
- import bar from 'bar';
- import baz from 'baz';
- import simpleProp from 'simpleProp';
- import complexProp from 'complexProp';
- `,
- mockImporter,
- );
-
- propTypeHandler(documentation, definition);
- expect(documentation.descriptors).toMatchSnapshot();
- });
- }
-
- describe('React.createClass', () => {
- testPropTypes(
- (propTypesSrc) => template(`({propTypes: ${propTypesSrc}})`),
- (src, importer = noopImporter) =>
- parse
- .statement(src, importer)
- .get('expression') as NodePath,
- );
- });
-
- describe('class definition', () => {
- describe('class property', () => {
- testPropTypes(
- (propTypesSrc) =>
- template(`
- class Component {
- static propTypes = ${propTypesSrc};
- }
- `),
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
-
- describe('static getter', () => {
- testPropTypes(
- (propTypesSrc) =>
- template(`
- class Component {
- static get propTypes() {
- return ${propTypesSrc};
- }
- }
- `),
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
- });
-
- describe('stateless component', () => {
- testPropTypes(
- (propTypesSrc) =>
- template(`
- var Component = (props) => ;
- Component.propTypes = ${propTypesSrc};
- `),
- (src, importer = noopImporter) => parse.statement(src, importer),
- );
- });
-
- describe('does not error if propTypes cannot be found', () => {
- test('ObjectExpression', () => {
- const definition = parse.expression('{fooBar: 42}');
-
- expect(() => propTypeHandler(documentation, definition)).not.toThrow();
- });
-
- test('ClassDeclaration', () => {
- const definition = parse.statement('class Foo {}');
-
- expect(() => propTypeHandler(documentation, definition)).not.toThrow();
- });
-
- test('FunctionDeclaration', () => {
- const definition =
- parse.statement('function Foo() {}');
-
- expect(() => propTypeHandler(documentation, definition)).not.toThrow();
- });
-
- test('ArrowFunctionExpression', () => {
- const definition = parse.expression('() => {}');
-
- expect(() => propTypeHandler(documentation, definition)).not.toThrow();
- });
- });
-
- // This case is handled by propTypeCompositionHandler
- test('does not error if propTypes is a member expression', () => {
- const definition = parse.expression(
- '{propTypes: Foo.propTypes}',
- );
-
- expect(() => propTypeHandler(documentation, definition)).not.toThrow();
- });
-});
diff --git a/packages/react-docgen/src/handlers/codeTypeHandler.ts b/packages/react-docgen/src/handlers/codeTypeHandler.ts
deleted file mode 100644
index 75310b4b3d8..00000000000
--- a/packages/react-docgen/src/handlers/codeTypeHandler.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-import type Documentation from '../Documentation.js';
-import { unwrapUtilityType } from '../utils/flowUtilityTypes.js';
-import getFlowType from '../utils/getFlowType.js';
-import getTypeFromReactComponent, {
- applyToTypeProperties,
-} from '../utils/getTypeFromReactComponent.js';
-import getPropertyName from '../utils/getPropertyName.js';
-import getTSType from '../utils/getTSType.js';
-import type { TypeParameters } from '../utils/getTypeParameters.js';
-import resolveToValue from '../utils/resolveToValue.js';
-import setPropDescription from '../utils/setPropDescription.js';
-import type { NodePath } from '@babel/traverse';
-import type { FlowType } from '@babel/types';
-import type { ComponentNode } from '../resolver/index.js';
-import type { Handler } from './index.js';
-
-function setPropDescriptor(
- documentation: Documentation,
- path: NodePath,
- typeParams: TypeParameters | null,
-): void {
- if (path.isObjectTypeSpreadProperty()) {
- const argument = unwrapUtilityType(
- path.get('argument'),
- ) as NodePath;
-
- if (argument.isObjectTypeAnnotation()) {
- applyToTypeProperties(
- documentation,
- argument,
- (propertyPath, innerTypeParams) => {
- setPropDescriptor(documentation, propertyPath, innerTypeParams);
- },
- typeParams,
- );
-
- return;
- }
-
- const id = argument.get('id') as NodePath;
-
- if (!id.hasNode() || !id.isIdentifier()) {
- return;
- }
- const resolvedPath = resolveToValue(id);
-
- if (resolvedPath.isTypeAlias()) {
- const right = resolvedPath.get('right');
-
- applyToTypeProperties(
- documentation,
- right,
- (propertyPath, innerTypeParams) => {
- setPropDescriptor(documentation, propertyPath, innerTypeParams);
- },
- typeParams,
- );
- } else if (!argument.has('typeParameters')) {
- documentation.addComposes(id.node.name);
- }
- } else if (path.isObjectTypeProperty()) {
- const type = getFlowType(path.get('value'), typeParams);
- const propName = getPropertyName(path);
-
- if (!propName) return;
-
- const propDescriptor = documentation.getPropDescriptor(propName);
-
- propDescriptor.required = !path.node.optional;
- propDescriptor.flowType = type;
-
- // We are doing this here instead of in a different handler
- // to not need to duplicate the logic for checking for
- // imported types that are spread in to props.
- setPropDescription(documentation, path);
- } else if (path.isTSPropertySignature()) {
- const typeAnnotation = path.get('typeAnnotation');
-
- if (!typeAnnotation.hasNode()) {
- return;
- }
- const type = getTSType(typeAnnotation, typeParams);
-
- const propName = getPropertyName(path);
-
- if (!propName) return;
-
- const propDescriptor = documentation.getPropDescriptor(propName);
-
- propDescriptor.required = !path.node.optional;
- propDescriptor.tsType = type;
-
- // We are doing this here instead of in a different handler
- // to not need to duplicate the logic for checking for
- // imported types that are spread in to props.
- setPropDescription(documentation, path);
- }
-}
-
-/**
- * This handler tries to find flow and TS Type annotated react components and extract
- * its types to the documentation. It also extracts docblock comments which are
- * inlined in the type definition.
- */
-const codeTypeHandler: Handler = function (
- documentation: Documentation,
- componentDefinition: NodePath,
-): void {
- const typePaths = getTypeFromReactComponent(componentDefinition);
-
- if (typePaths.length === 0) {
- return;
- }
-
- for (const typePath of typePaths) {
- applyToTypeProperties(
- documentation,
- typePath,
- (propertyPath, typeParams) => {
- setPropDescriptor(documentation, propertyPath, typeParams);
- },
- null,
- );
- }
-};
-
-export default codeTypeHandler;
diff --git a/packages/react-docgen/src/handlers/componentDocblockHandler.ts b/packages/react-docgen/src/handlers/componentDocblockHandler.ts
deleted file mode 100644
index 3720f247ea4..00000000000
--- a/packages/react-docgen/src/handlers/componentDocblockHandler.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import type Documentation from '../Documentation.js';
-import { getDocblock } from '../utils/docblock.js';
-import isReactForwardRefCall from '../utils/isReactForwardRefCall.js';
-import resolveToValue from '../utils/resolveToValue.js';
-import type { NodePath } from '@babel/traverse';
-import type { ComponentNode } from '../resolver/index.js';
-import type { Handler } from './index.js';
-import type { Decorator } from '@babel/types';
-
-function getDocblockFromComponent(path: NodePath): string | null {
- let description: string | null = null;
-
- if (path.isClassDeclaration() || path.isClassExpression()) {
- const decorators = path.get('decorators') as
- | Array>
- | null
- | undefined;
-
- // If we have a class declaration or expression, then the comment might be
- // attached to the last decorator instead as trailing comment.
- if (decorators && decorators.length > 0) {
- description = getDocblock(decorators[decorators.length - 1]!, true);
- }
- }
- if (description == null) {
- // Find parent statement (e.g. var Component = React.createClass();)
- let searchPath: NodePath | null = path;
-
- while (searchPath && !searchPath.isStatement()) {
- searchPath = searchPath.parentPath;
- }
- if (searchPath) {
- // If the parent is an export statement, we have to traverse one more up
- if (
- searchPath.parentPath.isExportNamedDeclaration() ||
- searchPath.parentPath.isExportDefaultDeclaration()
- ) {
- searchPath = searchPath.parentPath;
- }
- description = getDocblock(searchPath);
- }
- }
- if (!description) {
- const searchPath = isReactForwardRefCall(path)
- ? path.get('arguments')[0]!
- : path;
- const inner = resolveToValue(searchPath);
-
- if (inner.node !== path.node) {
- return getDocblockFromComponent(inner);
- }
- }
-
- return description;
-}
-
-/**
- * Finds the nearest block comment before the component definition.
- */
-const componentDocblockHandler: Handler = function (
- documentation: Documentation,
- componentDefinition: NodePath,
-): void {
- documentation.set(
- 'description',
- getDocblockFromComponent(componentDefinition) || '',
- );
-};
-
-export default componentDocblockHandler;
diff --git a/packages/react-docgen/src/handlers/componentMethodsHandler.ts b/packages/react-docgen/src/handlers/componentMethodsHandler.ts
deleted file mode 100644
index bc1bdf2f30d..00000000000
--- a/packages/react-docgen/src/handlers/componentMethodsHandler.ts
+++ /dev/null
@@ -1,271 +0,0 @@
-import getMemberValuePath from '../utils/getMemberValuePath.js';
-import type { MethodNodePath } from '../utils/getMethodDocumentation.js';
-import getMethodDocumentation from '../utils/getMethodDocumentation.js';
-import isReactComponentClass from '../utils/isReactComponentClass.js';
-import isReactComponentMethod from '../utils/isReactComponentMethod.js';
-import type Documentation from '../Documentation.js';
-import { shallowIgnoreVisitors } from '../utils/traverse.js';
-import resolveToValue from '../utils/resolveToValue.js';
-import type { NodePath, Scope } from '@babel/traverse';
-import { visitors } from '@babel/traverse';
-import type {
- AssignmentExpression,
- BlockStatement,
- Identifier,
- ObjectExpression,
-} from '@babel/types';
-import type { ComponentNode } from '../resolver/index.js';
-import type { Handler } from './index.js';
-import {
- isReactBuiltinCall,
- isReactForwardRefCall,
- isStatelessComponent,
- findFunctionReturn,
-} from '../utils/index.js';
-
-/**
- * The following values/constructs are considered methods:
- *
- * - Method declarations in classes (except "constructor" and React lifecycle
- * methods
- * - Public class fields in classes whose value are a functions
- * - Object properties whose values are functions
- */
-function isMethod(path: NodePath): path is MethodNodePath {
- let isProbablyMethod =
- (path.isClassMethod() && path.node.kind !== 'constructor') ||
- path.isObjectMethod();
-
- if (
- !isProbablyMethod &&
- (path.isClassProperty() || path.isObjectProperty())
- ) {
- const value = resolveToValue(path.get('value') as NodePath);
-
- isProbablyMethod = value.isFunction();
- }
-
- return isProbablyMethod && !isReactComponentMethod(path);
-}
-
-interface TraverseState {
- readonly scope: Scope | undefined;
- readonly name: string;
- methods: Array>;
-}
-
-const explodedVisitors = visitors.explode({
- ...shallowIgnoreVisitors,
-
- AssignmentExpression: {
- enter: function (assignmentPath, state) {
- const { name, scope } = state;
- const left = assignmentPath.get('left');
- const binding = assignmentPath.scope.getBinding(name);
-
- if (
- binding &&
- left.isMemberExpression() &&
- left.get('object').isIdentifier({ name }) &&
- binding.scope === scope &&
- resolveToValue(assignmentPath.get('right')).isFunction()
- ) {
- state.methods.push(assignmentPath);
- }
- assignmentPath.skip();
- },
- },
-});
-
-interface MethodDefinition {
- path: MethodNodePath;
- isStatic?: boolean;
-}
-
-interface TraverseImperativeHandleState {
- results: MethodNodePath[];
-}
-
-function isObjectExpression(
- path: NodePath,
-): path is NodePath {
- return path.isObjectExpression();
-}
-
-const explodedImperativeHandleVisitors =
- visitors.explode({
- ...shallowIgnoreVisitors,
-
- CallExpression: {
- enter: function (path, state) {
- if (!isReactBuiltinCall(path, 'useImperativeHandle')) {
- return path.skip();
- }
-
- // useImperativeHandle(ref, () => ({ name: () => {}, ...}))
- const arg = path.get('arguments')[1];
-
- if (!arg || !arg.isFunction()) {
- return path.skip();
- }
-
- const body = resolveToValue(arg.get('body') as NodePath);
-
- let definition: NodePath | undefined;
-
- if (body.isObjectExpression()) {
- definition = body;
- } else {
- definition = findFunctionReturn(arg, isObjectExpression);
- }
-
- // We found the object body, now add all of the properties as methods.
- definition?.get('properties').forEach((p) => {
- if (isMethod(p)) {
- state.results.push(p);
- }
- });
-
- path.skip();
- },
- },
- });
-
-function findStatelessComponentBody(
- componentDefinition: NodePath,
-): NodePath | undefined {
- if (isStatelessComponent(componentDefinition)) {
- const body = componentDefinition.get('body');
-
- if (body.isBlockStatement()) {
- return body;
- }
- } else if (isReactForwardRefCall(componentDefinition)) {
- const inner = resolveToValue(componentDefinition.get('arguments')[0]!);
-
- return findStatelessComponentBody(inner);
- }
-
- return undefined;
-}
-
-function findImperativeHandleMethods(
- componentDefinition: NodePath,
-): MethodDefinition[] {
- const body = findStatelessComponentBody(componentDefinition);
-
- if (!body) {
- return [];
- }
-
- const state: TraverseImperativeHandleState = { results: [] };
-
- body.traverse(explodedImperativeHandleVisitors, state);
-
- return state.results.map((p) => ({ path: p }));
-}
-
-function findAssignedMethods(
- path: NodePath,
- idPath: NodePath,
-): MethodDefinition[] {
- if (!idPath.hasNode() || !idPath.isIdentifier()) {
- return [];
- }
-
- const name = idPath.node.name;
- const binding = idPath.scope.getBinding(name);
-
- if (!binding) {
- return [];
- }
-
- const scope = binding.scope;
- const state: TraverseState = {
- scope,
- name,
- methods: [],
- };
-
- path.traverse(explodedVisitors, state);
-
- return state.methods.map((p) => ({ path: p }));
-}
-
-/**
- * Extract all flow types for the methods of a react component. Doesn't
- * return any react specific lifecycle methods.
- */
-const componentMethodsHandler: Handler = function (
- documentation: Documentation,
- componentDefinition: NodePath,
-): void {
- // Extract all methods from the class or object.
- let methodPaths: MethodDefinition[] = [];
- const parent = componentDefinition.parentPath;
-
- if (isReactComponentClass(componentDefinition)) {
- methodPaths = (
- componentDefinition
- .get('body')
- .get('body')
- .filter(isMethod) as MethodNodePath[]
- ).map((p) => ({ path: p }));
- } else if (componentDefinition.isObjectExpression()) {
- methodPaths = (
- componentDefinition.get('properties').filter(isMethod) as MethodNodePath[]
- ).map((p) => ({ path: p }));
-
- // Add the statics object properties.
- const statics = getMemberValuePath(componentDefinition, 'statics');
-
- if (statics && statics.isObjectExpression()) {
- statics.get('properties').forEach((property) => {
- if (isMethod(property)) {
- methodPaths.push({
- path: property,
- isStatic: true,
- });
- }
- });
- }
- } else if (
- parent.isVariableDeclarator() &&
- parent.node.init === componentDefinition.node &&
- parent.get('id').isIdentifier()
- ) {
- methodPaths = findAssignedMethods(
- parent.scope.path,
- parent.get('id') as NodePath