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

[Refactor]: remove unused codes in util/propTypes #2288

Merged
merged 1 commit into from Jan 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/types.d.ts
Expand Up @@ -23,9 +23,8 @@ declare global {
[k in string]: TypeDeclarationBuilder;
};

type UnionTypeDefinitionChildren = unknown[];
type UnionTypeDefinition = {
type: 'union' | 'shape';
children: UnionTypeDefinitionChildren | true;
children: unknown[];
};
}
41 changes: 4 additions & 37 deletions lib/util/propTypes.js
Expand Up @@ -170,22 +170,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
/** @type {UnionTypeDefinition} */
const unionTypeDefinition = {
type: 'union',
children: []
children: annotation.types.map(type => buildTypeAnnotationDeclarationTypes(type, parentName, seen))
};
for (let i = 0, j = annotation.types.length; i < j; i++) {
const type = buildTypeAnnotationDeclarationTypes(annotation.types[i], parentName, seen);
// keep only complex type
Copy link
Member

Choose a reason for hiding this comment

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

can you track down why this was added in the first place? it seems like something that might be important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

children === true comes from b8e0a4e . But it does not help me understand why it is needed.

Copy link
Member

Choose a reason for hiding this comment

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

cc @phpnode any insight here?

Copy link
Contributor

Choose a reason for hiding this comment

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

no recollection, sorry :(

if (type.type) {
if (type.children === true) {
// every child is accepted for one type, abort type analysis
unionTypeDefinition.children = true;
return unionTypeDefinition;
}
}

/** @type {UnionTypeDefinitionChildren} */(unionTypeDefinition.children).push(type);
}
if (/** @type {UnionTypeDefinitionChildren} */(unionTypeDefinition.children).length === 0) {
if (unionTypeDefinition.children.length === 0) {
// no complex type found, simply accept everything
return {};
}
Expand Down Expand Up @@ -419,34 +406,14 @@ module.exports = function propTypesInstructions(context, components, utils) {
/** @type {UnionTypeDefinition} */
const unionTypeDefinition = {
type: 'union',
children: []
children: argument.elements.map(element => buildReactDeclarationTypes(element, parentName))
};
for (let i = 0, j = argument.elements.length; i < j; i++) {
const type = buildReactDeclarationTypes(argument.elements[i], parentName);
// keep only complex type
if (type.type) {
if (type.children === true) {
// every child is accepted for one type, abort type analysis
unionTypeDefinition.children = true;
return unionTypeDefinition;
}
}

/** @type {UnionTypeDefinitionChildren} */(unionTypeDefinition.children).push(type);
}
if (/** @type {UnionTypeDefinitionChildren} */(unionTypeDefinition.children).length === 0) {
if (unionTypeDefinition.children.length === 0) {
// no complex type found, simply accept everything
return {};
}
return unionTypeDefinition;
}
case 'instanceOf':
return {
type: 'instance',
// Accept all children because we can't know what type they are
children: true
};
case 'oneOf':
default:
return {};
}
Expand Down