function markPropTypesAsUsed(node,parentNames){parentNames=parentNames||[];var type;var name;var allNames;var properties;switch(node.type){case'MemberExpression':name=getPropertyName(node);if(name){allNames=parentNames.concat(name);if(node.parent.type==='MemberExpression'){markPropTypesAsUsed(node.parent,allNames);}// Do not mark computed props as used.
type=name!=='__COMPUTED_PROP__'?'direct':null;}else if(node.parent.id&&node.parent.id.properties&&node.parent.id.properties.length&&getKeyValue(node.parent.id.properties[0])){type='destructuring';properties=node.parent.id.properties;}break;case'ArrowFunctionExpression':case'FunctionDeclaration':case'FunctionExpression':type='destructuring';properties=node.params[0].properties;break;case'VariableDeclarator':for(var i=0,j=node.id.properties.length;i<j;i++){// let {props: {firstname}} = this
var thisDestructuring=node.id.properties[i].key&&(node.id.properties[i].key.name==='props'||node.id.properties[i].key.value==='props')&&node.id.properties[i].value.type==='ObjectPattern';// let {firstname} = props
var genericDestructuring=isPropAttributeName(node)&&(utils.getParentStatelessComponent()||isInLifeCycleMethod(node));if(thisDestructuring){properties=node.id.properties[i].value.properties;}else if(genericDestructuring){properties=node.id.properties;}else{continue;}type='destructuring';break;}break;default:throw new Error(node.type+' ASTNodes are not handled by markPropTypesAsUsed');}var component=components.get(utils.getParentComponent());var usedPropTypes=component&&component.usedPropTypes||[];var ignorePropsValidation=component&&component.ignorePropsValidation||false;switch(type){case'direct':// Ignore Object methods
if(Object.prototype[name]){break;}usedPropTypes.push({name:name,allNames:allNames});break;case'destructuring':for(var k=0,l=(properties||[]).length;k<l;k++){if(hasSpreadOperator(properties[k])||properties[k].computed){ignorePropsValidation=true;break;}var propName=getKeyValue(properties[k]);var currentNode=node;allNames=[];while(currentNode.property&&currentNode.property.name!=='props'){allNames.unshift(currentNode.property.name);currentNode=currentNode.object;}allNames.push(propName);if(propName){usedPropTypes.push({allNames:allNames,name:propName});}}break;default:break;}components.set(node,{usedPropTypes:usedPropTypes,ignorePropsValidation:ignorePropsValidation});}
Mark a prop type as used
@param {ASTNode} node The AST node being marked.