Skip to content

Commit

Permalink
Remove unnecessary Node types
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Apr 29, 2023
1 parent 6d48e10 commit d25ba18
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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, Node } from '@babel/traverse';
import type { NodePath } from '@babel/traverse';
import type { ComponentNode } from '../resolver/index.js';
import type { Handler } from './index.js';

Expand All @@ -21,7 +21,7 @@ function getDocblockFromComponent(path: NodePath): string | null {
}
if (description == null) {
// Find parent statement (e.g. var Component = React.createClass(<path>);)
let searchPath: NodePath<Node> | null = path;
let searchPath: NodePath | null = path;

while (searchPath && !searchPath.isStatement()) {
searchPath = searchPath.parentPath;
Expand Down
3 changes: 1 addition & 2 deletions packages/react-docgen/src/handlers/defaultPropsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type Documentation from '../Documentation.js';
import type { DefaultValueDescriptor } from '../Documentation.js';
import type { NodePath } from '@babel/traverse';
import type {
Node,
ObjectMethod,
ObjectProperty,
RestElement,
Expand Down Expand Up @@ -70,7 +69,7 @@ function getStatelessPropsPath(
function getDefaultPropsPath(
componentDefinition: NodePath<ComponentNode>,
): NodePath | null {
let defaultPropsPath: NodePath<Node> | null = getMemberValuePath(
let defaultPropsPath: NodePath | null = getMemberValuePath(
componentDefinition,
'defaultProps',
);
Expand Down
3 changes: 1 addition & 2 deletions packages/react-docgen/src/handlers/propDocblockHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NodePath } from '@babel/traverse';
import type { Node } from '@babel/types';
import getMemberValuePath from '../utils/getMemberValuePath.js';
import resolveToValue from '../utils/resolveToValue.js';
import setPropDescription from '../utils/setPropDescription.js';
Expand Down Expand Up @@ -33,7 +32,7 @@ const propDocblockHandler: Handler = function (
documentation: Documentation,
componentDefinition: NodePath<ComponentNode>,
): void {
let propTypesPath: NodePath<Node> | null = getMemberValuePath(
let propTypesPath: NodePath | null = getMemberValuePath(
componentDefinition,
'propTypes',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import resolveToModule from '../utils/resolveToModule.js';
import resolveToValue from '../utils/resolveToValue.js';
import type Documentation from '../Documentation.js';
import type { NodePath } from '@babel/traverse';
import type { ObjectExpression, Node } from '@babel/types';
import type { ObjectExpression } from '@babel/types';
import type { Handler } from './index.js';
import type { ComponentNode } from '../resolver/index.js';

Expand Down Expand Up @@ -37,7 +37,7 @@ const propTypeCompositionHandler: Handler = function (
documentation: Documentation,
componentDefinition: NodePath<ComponentNode>,
): void {
let propTypesPath: NodePath<Node> | null = getMemberValuePath(
let propTypesPath: NodePath | null = getMemberValuePath(
componentDefinition,
'propTypes',
);
Expand Down
3 changes: 1 addition & 2 deletions packages/react-docgen/src/handlers/propTypeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import resolveToValue from '../utils/resolveToValue.js';
import type Documentation from '../Documentation.js';
import type { PropDescriptor, PropTypeDescriptor } from '../Documentation.js';
import type { NodePath } from '@babel/traverse';
import type { Node } from '@babel/types';
import type { Handler } from './index.js';
import type { ComponentNode } from '../resolver/index.js';

Expand Down Expand Up @@ -65,7 +64,7 @@ function getPropTypeHandler(propName: string): Handler {
documentation: Documentation,
componentDefinition: NodePath<ComponentNode>,
): void {
let propTypesPath: NodePath<Node> | null = getMemberValuePath(
let propTypesPath: NodePath | null = getMemberValuePath(
componentDefinition,
propName,
);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-docgen/src/utils/expressionTo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*eslint no-loop-func: 0, no-use-before-define: 0*/

import resolveToValue from './resolveToValue.js';
import type { Node, NodePath } from '@babel/traverse';
import type { NodePath } from '@babel/traverse';
import type { Node } from '@babel/types';

/**
* Splits a MemberExpression or CallExpression into parts.
Expand Down
4 changes: 2 additions & 2 deletions packages/react-docgen/src/utils/isRequiredPropType.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Node, NodePath } from '@babel/traverse';
import type { NodePath } from '@babel/traverse';
import getMembers from '../utils/getMembers.js';

/**
* Returns true of the prop is required, according to its type definition
*/
export default function isRequiredPropType(path: NodePath<Node>): boolean {
export default function isRequiredPropType(path: NodePath): boolean {
return getMembers(path).some(
({ computed, path: memberPath }) =>
(!computed && memberPath.isIdentifier({ name: 'isRequired' })) ||
Expand Down

0 comments on commit d25ba18

Please sign in to comment.