123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 'use strict';
- const astUtil = require('./ast');
- function isPropTypesDeclaration(node) {
- if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
-
- if (node.typeAnnotation && node.key.name === 'props') {
- return true;
- }
- }
- return astUtil.getPropertyName(node) === 'propTypes';
- }
- function isContextTypesDeclaration(node) {
- if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
-
- if (node.typeAnnotation && node.key.name === 'context') {
- return true;
- }
- }
- return astUtil.getPropertyName(node) === 'contextTypes';
- }
- function isContextTypeDeclaration(node) {
- return astUtil.getPropertyName(node) === 'contextType';
- }
- function isChildContextTypesDeclaration(node) {
- return astUtil.getPropertyName(node) === 'childContextTypes';
- }
- function isDefaultPropsDeclaration(node) {
- const propName = astUtil.getPropertyName(node);
- return (propName === 'defaultProps' || propName === 'getDefaultProps');
- }
- function isDisplayNameDeclaration(node) {
- switch (node.type) {
- case 'ClassProperty':
- case 'PropertyDefinition':
- return node.key && node.key.name === 'displayName';
- case 'Identifier':
- return node.name === 'displayName';
- case 'Literal':
- return node.value === 'displayName';
- default:
- return false;
- }
- }
- function isRequiredPropType(propTypeExpression) {
- return propTypeExpression.type === 'MemberExpression' && propTypeExpression.property.name === 'isRequired';
- }
- module.exports = {
- isPropTypesDeclaration,
- isContextTypesDeclaration,
- isContextTypeDeclaration,
- isChildContextTypesDeclaration,
- isDefaultPropsDeclaration,
- isDisplayNameDeclaration,
- isRequiredPropType,
- };
|