Skip to content

Commit 0a2481d

Browse files
authored
Integration updates (#786)
* Rename Documentation to DocumentationBuilder Rename DocumentationObjet to Documentation Rename toObject to build * Re-export types from babel * Remove unnecessary Node types
1 parent 622036f commit 0a2481d

24 files changed

+94
-66
lines changed

.changeset/healthy-moles-explain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-docgen': minor
3+
---
4+
5+
Export the type for the DocumentationBuilder.

.changeset/heavy-plums-repair.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'react-docgen': minor
3+
---
4+
5+
The types `NodePath` and `babelTypes` are now exported.
6+
7+
These types are useful when building integrations in TypeScript.
8+
9+
`babelTypes` includes all types from `@babel/types`.

.changeset/smart-trainers-film.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'react-docgen': major
3+
---
4+
5+
Renamed the method `toObject` to `build` in the DocumentationBuilder.
6+
7+
This method might be used by integrations.

packages/react-docgen/src/Documentation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface DocumentationObject {
1+
export interface Documentation {
22
childContext?: Record<string, PropDescriptor>;
33
composes?: string[];
44
context?: Record<string, PropDescriptor>;
@@ -141,7 +141,7 @@ export interface PropDescriptor {
141141
description?: string;
142142
}
143143

144-
export default class Documentation {
144+
export default class DocumentationBuilder {
145145
#props: Map<string, PropDescriptor>;
146146
#context: Map<string, PropDescriptor>;
147147
#childContext: Map<string, PropDescriptor>;
@@ -199,8 +199,8 @@ export default class Documentation {
199199
return propDescriptor;
200200
}
201201

202-
toObject(): DocumentationObject {
203-
const obj: DocumentationObject = {};
202+
build(): Documentation {
203+
const obj: Documentation = {};
204204

205205
for (const [key, value] of this.#data) {
206206
obj[key] = value;

packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse, makeMockImporter } from '../../../tests/utils';
2-
import Documentation from '../../Documentation';
2+
import DocumentationBuilder from '../../Documentation';
33
import codeTypeHandler from '../codeTypeHandler.js';
44
import type DocumentationMock from '../../__mocks__/Documentation';
55
import type {
@@ -20,10 +20,11 @@ vi.mock('../../utils/getFlowType.js', () => ({
2020
}));
2121

2222
describe('codeTypeHandler', () => {
23-
let documentation: Documentation & DocumentationMock;
23+
let documentation: DocumentationBuilder & DocumentationMock;
2424

2525
beforeEach(() => {
26-
documentation = new Documentation() as Documentation & DocumentationMock;
26+
documentation = new DocumentationBuilder() as DocumentationBuilder &
27+
DocumentationMock;
2728
});
2829

2930
const mockImporter = makeMockImporter({

packages/react-docgen/src/handlers/__tests__/componentDocblockHandler-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeMockImporter, parse } from '../../../tests/utils';
22
import componentDocblockHandler from '../componentDocblockHandler.js';
3-
import Documentation from '../../Documentation';
3+
import DocumentationBuilder from '../../Documentation';
44
import type DocumentationMock from '../../__mocks__/Documentation';
55
import type { NodePath } from '@babel/traverse';
66
import type {
@@ -20,10 +20,11 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
2020
vi.mock('../../Documentation.js');
2121

2222
describe('componentDocblockHandler', () => {
23-
let documentation: Documentation & DocumentationMock;
23+
let documentation: DocumentationBuilder & DocumentationMock;
2424

2525
beforeEach(() => {
26-
documentation = new Documentation() as Documentation & DocumentationMock;
26+
documentation = new DocumentationBuilder() as DocumentationBuilder &
27+
DocumentationMock;
2728
});
2829

2930
function testDockblockHandler(

packages/react-docgen/src/handlers/__tests__/componentMethodsHandler-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parse, makeMockImporter } from '../../../tests/utils';
22
import componentMethodsHandler from '../componentMethodsHandler.js';
3-
import Documentation from '../../Documentation';
3+
import DocumentationBuilder from '../../Documentation';
44
import type DocumentationMock from '../../__mocks__/Documentation';
55
import type {
66
ArrowFunctionExpression,
@@ -18,10 +18,11 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
1818
vi.mock('../../Documentation.js');
1919

2020
describe('componentMethodsHandler', () => {
21-
let documentation: Documentation & DocumentationMock;
21+
let documentation: DocumentationBuilder & DocumentationMock;
2222

2323
beforeEach(() => {
24-
documentation = new Documentation() as Documentation & DocumentationMock;
24+
documentation = new DocumentationBuilder() as DocumentationBuilder &
25+
DocumentationMock;
2526
});
2627

2728
const mockImporter = makeMockImporter({

packages/react-docgen/src/handlers/__tests__/componentMethodsJsDocHandler-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { NodePath } from '@babel/traverse';
2-
import Documentation from '../../Documentation';
2+
import DocumentationBuilder from '../../Documentation';
33
import type { ComponentNode } from '../../resolver';
44
import type DocumentationMock from '../../__mocks__/Documentation';
55
import componentMethodsJsDocHandler from '../componentMethodsJsDocHandler.js';
66
import { beforeEach, describe, expect, test } from 'vitest';
77

88
describe('componentMethodsJsDocHandler', () => {
9-
let documentation: Documentation & DocumentationMock;
9+
let documentation: DocumentationBuilder & DocumentationMock;
1010

1111
beforeEach(() => {
12-
documentation = new Documentation() as Documentation & DocumentationMock;
12+
documentation = new DocumentationBuilder() as DocumentationBuilder &
13+
DocumentationMock;
1314
});
1415

1516
test('stays the same when no docblock is present', () => {

packages/react-docgen/src/handlers/__tests__/defaultPropsHandler-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ import type {
88
VariableDeclaration,
99
} from '@babel/types';
1010
import { parse, makeMockImporter } from '../../../tests/utils';
11-
import Documentation from '../../Documentation';
11+
import DocumentationBuilder from '../../Documentation';
1212
import type DocumentationMock from '../../__mocks__/Documentation';
1313
import defaultPropsHandler from '../defaultPropsHandler.js';
1414
import { beforeEach, describe, expect, test, vi } from 'vitest';
1515

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

1818
describe('defaultPropsHandler', () => {
19-
let documentation: Documentation & DocumentationMock;
19+
let documentation: DocumentationBuilder & DocumentationMock;
2020

2121
beforeEach(() => {
22-
documentation = new Documentation() as Documentation & DocumentationMock;
22+
documentation = new DocumentationBuilder() as DocumentationBuilder &
23+
DocumentationMock;
2324
});
2425

2526
const mockImporter = makeMockImporter({

packages/react-docgen/src/handlers/__tests__/displayNameHandler-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse, makeMockImporter } from '../../../tests/utils';
2-
import Documentation from '../../Documentation';
2+
import DocumentationBuilder from '../../Documentation';
33
import displayNameHandler from '../displayNameHandler.js';
44
import type DocumentationMock from '../../__mocks__/Documentation';
55
import type {
@@ -17,10 +17,11 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
1717
vi.mock('../../Documentation.js');
1818

1919
describe('defaultPropsHandler', () => {
20-
let documentation: Documentation & DocumentationMock;
20+
let documentation: DocumentationBuilder & DocumentationMock;
2121

2222
beforeEach(() => {
23-
documentation = new Documentation() as Documentation & DocumentationMock;
23+
documentation = new DocumentationBuilder() as DocumentationBuilder &
24+
DocumentationMock;
2425
});
2526

2627
const mockImporter = makeMockImporter({

0 commit comments

Comments
 (0)