Skip to content

Commit

Permalink
[Refactor]: remove unused codes in util/propTypes
Browse files Browse the repository at this point in the history
 - remove useless handling of `instanceOf` and `oneOf`

There is no special treatment of `Proptypes.{instanceOf, oneOf}` types
so they might as well be handled as unrecognized types.
  • Loading branch information
golopot authored and ljharb committed May 25, 2019
1 parent 4f3cd90 commit d02bb9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
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
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

0 comments on commit d02bb9a

Please sign in to comment.