Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes #761

Merged
merged 7 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-plants-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-docgen': major
---

Rename `propDocBlockHandler` to `propDocblockHandler` for consistency
5 changes: 5 additions & 0 deletions .changeset/plenty-cooks-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-docgen': patch
---

Fix using react-docgen in browsers
5 changes: 5 additions & 0 deletions .changeset/polite-pandas-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-docgen': patch
---

Add `displayName` and `description` to Documentation type
4 changes: 3 additions & 1 deletion packages/react-docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"type": "module",
"browser": {
"./dist/importer/fsImporter.js": "./dist/importer/ignoreImporter.js",
"./src/importer/fsImporter.ts": "./src/importer/ignoreImporter.ts"
"./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"
Expand Down
9 changes: 6 additions & 3 deletions packages/react-docgen/src/Documentation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export interface DocumentationObject {
props?: Record<string, PropDescriptor>;
context?: Record<string, PropDescriptor>;
childContext?: Record<string, PropDescriptor>;
composes?: string[];
context?: Record<string, PropDescriptor>;
description?: string;
displayName?: string;
methods?: MethodDescriptor[];
props?: Record<string, PropDescriptor>;
}

export interface MethodParameter {
name: string;
type?: TypeDescriptor<FunctionSignatureType> | null;
optional: boolean;
type?: TypeDescriptor<FunctionSignatureType> | null;
}

export interface MethodReturn {
Expand Down Expand Up @@ -162,6 +164,7 @@ export default class Documentation {
this.#data.set(key, value);
}

get<T>(key: string): T | null;
get(key: string): unknown {
return this.#data.get(key);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-docgen/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
contextTypeHandler,
defaultPropsHandler,
displayNameHandler,
propDocBlockHandler,
propDocblockHandler,
propTypeCompositionHandler,
propTypeHandler,
} from './handlers/index.js';
Expand Down Expand Up @@ -52,7 +52,7 @@ export const defaultHandlers: Handler[] = [
contextTypeHandler,
childContextTypeHandler,
propTypeCompositionHandler,
propDocBlockHandler,
propDocblockHandler,
codeTypeHandler,
defaultPropsHandler,
componentDocblockHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Documentation from '../../Documentation';
import type { Importer } from '../../importer';
import type { ComponentNode } from '../../resolver';
import type DocumentationMock from '../../__mocks__/Documentation';
import propDocBlockHandler from '../propDocBlockHandler.js';
import propDocblockHandler from '../propDocblockHandler.js';
import { beforeEach, describe, expect, test, vi } from 'vitest';

vi.mock('../../Documentation.js');

describe('propDocBlockHandler', () => {
describe('propDocblockHandler', () => {
let documentation: Documentation & DocumentationMock;

beforeEach(() => {
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('propDocBlockHandler', () => {
),
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'Foo comment',
Expand All @@ -75,7 +75,7 @@ describe('propDocBlockHandler', () => {
),
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description:
Expand All @@ -102,7 +102,7 @@ describe('propDocBlockHandler', () => {
),
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'Foo comment',
Expand All @@ -126,7 +126,7 @@ describe('propDocBlockHandler', () => {
),
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'Foo comment',
Expand All @@ -150,7 +150,7 @@ describe('propDocBlockHandler', () => {
),
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'Foo comment',
Expand All @@ -169,7 +169,7 @@ describe('propDocBlockHandler', () => {
};
`);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'Foo comment',
Expand All @@ -186,7 +186,7 @@ describe('propDocBlockHandler', () => {
mockImporter,
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'A comment on imported props',
Expand All @@ -210,7 +210,7 @@ describe('propDocBlockHandler', () => {
mockImporter,
);

propDocBlockHandler(documentation, definition);
propDocblockHandler(documentation, definition);
expect(documentation.descriptors).toEqual({
foo: {
description: 'A comment on imported props',
Expand Down Expand Up @@ -263,15 +263,15 @@ describe('propDocBlockHandler', () => {
const definition = parse.expression<ObjectExpression>('{fooBar: 42}');

expect(() =>
propDocBlockHandler(documentation, definition),
propDocblockHandler(documentation, definition),
).not.toThrow();
});

test('ClassDeclaration', () => {
const definition = parse.statement<ClassDeclaration>('class Foo {}');

expect(() =>
propDocBlockHandler(documentation, definition),
propDocblockHandler(documentation, definition),
).not.toThrow();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function merge<T, U>(obj1: T, obj2: U): (T & U) | null {
const componentMethodsJsDocHandler: Handler = function (
documentation: Documentation,
): void {
let methods = documentation.get('methods') as MethodDescriptor[] | null;
let methods = documentation.get<MethodDescriptor[]>('methods');

if (!methods) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-docgen/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { default as componentMethodsJsDocHandler } from './componentMethodsJsDoc
export { default as defaultPropsHandler } from './defaultPropsHandler.js';
export { default as displayNameHandler } from './displayNameHandler.js';
export { default as codeTypeHandler } from './codeTypeHandler.js';
export { default as propDocBlockHandler } from './propDocBlockHandler.js';
export { default as propDocblockHandler } from './propDocblockHandler.js';
export { default as propTypeCompositionHandler } from './propTypeCompositionHandler.js';
export {
propTypeHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function resolveDocumentation(
});
}

const propDocBlockHandler: Handler = function (
const propDocblockHandler: Handler = function (
documentation: Documentation,
componentDefinition: NodePath<ComponentNode>,
): void {
Expand All @@ -49,4 +49,4 @@ const propDocBlockHandler: Handler = function (
resolveDocumentation(documentation, propTypesPath);
};

export default propDocBlockHandler;
export default propDocblockHandler;
8 changes: 3 additions & 5 deletions packages/react-docgen/src/importer/ignoreImporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Importer } from './index.js';
import makeIgnoreImporter from './makeIgnoreImporter.js';

const ignoreImports: Importer = function (): null {
return null;
};
const ignoreImporter = makeIgnoreImporter();

export default ignoreImports;
export default ignoreImporter;
5 changes: 5 additions & 0 deletions packages/react-docgen/src/importer/makeIgnoreImporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Importer } from './index.js';

export default function makeIgnoreImporter(): Importer {
return () => null;
}
3 changes: 3 additions & 0 deletions packages/website/pages/_app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
14 changes: 1 addition & 13 deletions packages/website/pages/docs/reference/cli.mdx
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import Image from 'next/image';

export const whoa = (
<Image
src="/mind-blown-shocked.gif"
alt="whoa"
width={30}
height={50}
style={{ display: 'inline-block' }}
/>
);

# Command Line Interface (CLI) Reference

This is the complete reference of all available options for the CLI. A basic
Expand Down Expand Up @@ -49,7 +37,7 @@ independent of this option.

### `--help`

Displays the help for the command with the current default values. <>{whoa}</>
Displays the help for the command with the current default values.

### `-i, --ignore <globs>`

Expand Down
Binary file removed packages/website/public/mind-blown-shocked.gif
Binary file not shown.