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

[docs] Remove dead generatePropTypeDescription method #25188

Merged
merged 4 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
95 changes: 1 addition & 94 deletions docs/scripts/buildApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import muiDefaultPropsHandler from 'docs/src/modules/utils/defaultPropsHandler';
import muiFindAnnotatedComponentsResolver from 'docs/src/modules/utils/findAnnotatedComponentsResolver';
import { LANGUAGES, LANGUAGES_IN_PROGRESS } from 'docs/src/modules/constants';
import parseTest from 'docs/src/modules/utils/parseTest';
import generatePropTypeDescription, { escapeCell, isElementTypeAcceptingRefProp, isElementAcceptingRefProp} from 'docs/src/modules/utils/generatePropTypeDescription';
import { findPages, findPagesMarkdown, findComponents } from 'docs/src/modules/utils/find';
import {
getHeaders,
Expand Down Expand Up @@ -109,100 +110,6 @@ function getChained(type: PropTypeDescriptor): false | PropDescriptor {
return false;
}

function escapeCell(value: string): string {
// As the pipe is use for the table structure
return value.replace(/</g, '&lt;').replace(/`&lt;/g, '`<').replace(/\|/g, '\\|');
}

function isElementTypeAcceptingRefProp(type: PropTypeDescriptor): boolean {
return type.raw === 'elementTypeAcceptingRef';
}

function isRefType(type: PropTypeDescriptor): boolean {
return type.raw === 'refType';
}

function isElementAcceptingRefProp(type: PropTypeDescriptor): boolean {
return /^elementAcceptingRef/.test(type.raw);
}

function generatePropTypeDescription(type: PropTypeDescriptor): string | undefined {
switch (type.name) {
case 'custom': {
if (isElementTypeAcceptingRefProp(type)) {
return `element type`;
}
if (isElementAcceptingRefProp(type)) {
return `element`;
}
if (isRefType(type)) {
return `ref`;
}
if (type.raw === 'HTMLElementType') {
return `HTML element`;
}

const deprecatedInfo = getDeprecatedInfo(type);
if (deprecatedInfo !== false) {
return generatePropTypeDescription({
// eslint-disable-next-line react/forbid-foreign-prop-types
name: deprecatedInfo.propTypes,
} as any);
}

const chained = getChained(type);
if (chained !== false) {
return generatePropTypeDescription(chained.type);
}

return type.raw;
}

case 'shape':
return `{ ${Object.keys(type.value)
.map((subValue) => {
const subType = type.value[subValue];
return `${subValue}${subType.required ? '' : '?'}: ${generatePropTypeDescription(
subType,
)}`;
})
.join(', ')} }`;

case 'union':
return (
type.value
.map((type2) => {
return generatePropTypeDescription(type2);
})
// Display one value per line as it's better for visibility.
.join('<br>&#124;&nbsp;')
);
case 'enum':
return (
type.value
.map((type2) => {
return escapeCell(type2.value);
})
// Display one value per line as it's better for visibility.
.join('<br>&#124;&nbsp;')
);

case 'arrayOf': {
return `Array&lt;${generatePropTypeDescription(type.value)}&gt;`;
}

case 'instanceOf': {
if (type.value.startsWith('typeof')) {
return /typeof (.*) ===/.exec(type.value)![1];
}
return type.value;
}

default:
return type.name;
}
}

/**
* Returns `null` if the prop should be ignored.
* Throws if it is invalid.
Expand Down
13 changes: 10 additions & 3 deletions docs/src/modules/utils/generatePropTypeDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ function getChained(type: PropTypeDescriptor) {
return false;
}

function escapeCell(value: string): string {
export function escapeCell(value: string): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an export here because the "buildApi" file duplicated these functions.
I deleted the duplicates, exported them from here, and used them there.

// As the pipe is use for the table structure
return value.replace(/</g, '&lt;').replace(/`&lt;/g, '`<').replace(/\|/g, '\\|');
}

function isElementTypeAcceptingRefProp(type: PropTypeDescriptor): boolean {
function isIntegerPropType(type: PropTypeDescriptor): boolean {
return type.raw === 'integerPropType';
}

oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
export function isElementTypeAcceptingRefProp(type: PropTypeDescriptor): boolean {
return type.raw === 'elementTypeAcceptingRef';
}

function isRefType(type: PropTypeDescriptor): boolean {
return type.raw === 'refType';
}

function isElementAcceptingRefProp(type: PropTypeDescriptor): boolean {
export function isElementAcceptingRefProp(type: PropTypeDescriptor): boolean {
return /^elementAcceptingRef/.test(type.raw);
}

Expand All @@ -73,6 +77,9 @@ export default function generatePropTypeDescription(type: PropTypeDescriptor): s
if (isElementAcceptingRefProp(type)) {
return `element`;
}
if (isIntegerPropType(type)) {
return `integer`;
}
if (isRefType(type)) {
return `ref`;
}
Expand Down