Skip to content

Commit ac3173f

Browse files
authored
Use latest babel plugins, and use Annotation and All Resolver on website (#774)
1 parent 7a55943 commit ac3173f

File tree

10 files changed

+2001
-1881
lines changed

10 files changed

+2001
-1881
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"engines": {
44
"node": ">=14.17.0",
5-
"pnpm": "7.30.5"
5+
"pnpm": ">=7.30.3"
66
},
77
"scripts": {
88
"build": "nx run-many --target=build --exclude='@react-docgen-internal/*'",

packages/website/src/components/Select.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function Select({
7878
? 'bg-primary-50 text-primary-600 dark:bg-primary-500/10'
7979
: 'text-gray-800 dark:text-gray-100',
8080
'relative cursor-pointer whitespace-nowrap py-1.5',
81-
'transition-colors ltr:pl-3 ltr:pr-9 rtl:pr-3 rtl:pl-9',
81+
'transition-colors ltr:pl-3 ltr:pr-9 rtl:pl-9 rtl:pr-3',
8282
)
8383
}
8484
>

packages/website/src/components/playground/Panel.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import type { RefObject } from 'react';
21
import { useCallback } from 'react';
32
import { useTheme } from 'next-themes';
43
import CodeMirror from '@uiw/react-codemirror';
54
import { javascript } from '@codemirror/lang-javascript';
6-
import type { EditorMode } from './Playground';
75
import { EditorView } from '@codemirror/view';
86

97
interface PanelProps {
108
codeSample?: string;
11-
mode?: EditorMode;
129
onChange?: (value: string) => void;
1310
readOnly?: boolean;
14-
ref?: RefObject<unknown>;
1511
value: string;
1612
}
1713

packages/website/src/components/playground/Playground.tsx

+31-37
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
import type { RefObject } from 'react';
2-
import { Component, createRef } from 'react';
1+
import { Component } from 'react';
32
import Panel from './Panel';
43
import OptionPanel, { Language } from './OptionPanel';
54
import type { Config } from 'react-docgen';
6-
import { parse } from 'react-docgen';
5+
import { parse, builtinResolvers } from 'react-docgen';
76

87
const defaultPlugins = [
98
'jsx',
10-
'asyncGenerators',
11-
'bigInt',
12-
'classProperties',
13-
'classPrivateProperties',
14-
'classPrivateMethods',
15-
['decorators', { decoratorsBeforeExport: false }],
9+
'asyncDoExpressions',
10+
'decimal',
11+
'decorators',
12+
'decoratorAutoAccessors',
13+
'destructuringPrivate',
1614
'doExpressions',
17-
'dynamicImport',
15+
'explicitResourceManagement',
1816
'exportDefaultFrom',
19-
'exportNamespaceFrom',
2017
'functionBind',
2118
'functionSent',
22-
'importMeta',
23-
'logicalAssignment',
24-
'nullishCoalescingOperator',
25-
'numericSeparator',
26-
'objectRestSpread',
27-
'optionalCatchBinding',
28-
'optionalChaining',
19+
'importAssertions',
20+
'importReflection',
21+
'moduleBlocks',
22+
'partialApplication',
2923
['pipelineOperator', { proposal: 'minimal' }],
24+
'recordAndTuple',
25+
'regexpUnicodeSets',
3026
'throwExpressions',
31-
'topLevelAwait',
3227
];
3328

3429
interface PlaygroundProps {
3530
initialContent: string;
31+
initialLanguage: Language;
3632
}
3733

3834
export type EditorMode = 'application/json' | 'text/jsx' | 'text/plain';
3935

4036
interface PlaygroundState {
4137
value: string;
42-
mode: EditorMode;
4338
content: string;
4439
language: Language;
4540
options: Config;
4641
}
4742

48-
export default class App extends Component<PlaygroundProps, PlaygroundState> {
49-
private _jsonRef: RefObject<unknown>;
43+
const {
44+
ChainResolver,
45+
FindAllDefinitionsResolver,
46+
FindAnnotatedDefinitionsResolver,
47+
} = builtinResolvers;
48+
49+
const resolver = new ChainResolver(
50+
[new FindAnnotatedDefinitionsResolver(), new FindAllDefinitionsResolver()],
51+
{ chainingLogic: ChainResolver.Logic.ALL },
52+
);
5053

54+
export default class App extends Component<PlaygroundProps, PlaygroundState> {
5155
constructor(props: PlaygroundProps) {
5256
super(props);
53-
this._jsonRef = createRef();
5457

55-
const initialLanguage = Language.TYPESCRIPT;
56-
57-
const options = this.buildOptions(initialLanguage);
58+
const options = this.buildOptions(props.initialLanguage);
5859

5960
this.state = {
6061
value: this.compile(props.initialContent, options),
61-
mode: 'application/json',
6262
content: props.initialContent,
63-
language: initialLanguage,
63+
language: props.initialLanguage,
6464
options,
6565
};
6666
}
@@ -71,19 +71,18 @@ export default class App extends Component<PlaygroundProps, PlaygroundState> {
7171

7272
handleChange = (value: string) => {
7373
let result;
74-
let mode: EditorMode = 'text/plain';
7574

7675
try {
7776
result = this.compile(value, this.state.options);
78-
mode = 'application/json';
7977
} catch (err) {
8078
result = String(err);
8179
}
82-
this.setState({ value: result, mode, content: value });
80+
this.setState({ value: result, content: value });
8381
};
8482

8583
buildOptions(language: Language): Config {
8684
const options: Config = {
85+
resolver,
8786
babelOptions: {
8887
babelrc: false,
8988
babelrcRoots: false,
@@ -132,12 +131,7 @@ export default class App extends Component<PlaygroundProps, PlaygroundState> {
132131
/>
133132
</div>
134133
<div className="h-full w-1/2 flex-auto self-auto overflow-hidden">
135-
<Panel
136-
readOnly={true}
137-
ref={this._jsonRef}
138-
value={this.state.value}
139-
mode={this.state.mode}
140-
/>
134+
<Panel readOnly={true} value={this.state.value} />
141135
</div>
142136
</div>
143137
</>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export { default as Playground } from './Playground';
2+
export { Language } from './OptionPanel';
3+
import js from './samples/javascript';
4+
import ts from './samples/typescript';
5+
import flow from './samples/flow';
6+
7+
export const samples = {
8+
flow,
9+
js,
10+
ts,
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default `interface Props {
2+
/** The name to greet */
3+
name: string
4+
}
5+
6+
/**
7+
* Hello world component
8+
*/
9+
const MyComponent = ({name = 'world'}: Props) => {
10+
return <div />;
11+
}`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default `interface Props {
2+
/** The name to greet */
3+
name: string
4+
}
5+
6+
/**
7+
* Hello world component
8+
*/
9+
const MyComponent = ({name = 'world'}: Props) => {
10+
return <div />;
11+
}`;
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Playground from '../components/playground/Playground';
2-
import javaScriptSample from '../components/playground/samples/javascript';
1+
import { Language, Playground, samples } from '../components/playground';
32

4-
<Playground initialContent={javaScriptSample} />
3+
<Playground initialContent={samples.ts} initialLanguage={Language.TYPESCRIPT} />

packages/website/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"incremental": true,
1111
"esModuleInterop": true,
1212
"module": "esnext",
13-
"moduleResolution": "node",
14-
"resolveJsonModule": true,
13+
"moduleResolution": "bundler",
1514
"isolatedModules": true,
1615
"jsx": "preserve"
1716
},

0 commit comments

Comments
 (0)