function stylePropTypeHandler(documentation, path) {
  var propTypesPath = docgen.utils.getMemberValuePath(path, 'propTypes');
  if (!propTypesPath) {
    return;
  }
  propTypesPath = docgen.utils.resolveToValue(propTypesPath);
  if (!propTypesPath || propTypesPath.node.type !== 'ObjectExpression') {
    return;
  }

  // Check if the there is a style prop
  propTypesPath.get('properties').each(function(propertyPath) {
    if (propertyPath.node.type !== 'Property' ||
        docgen.utils.getPropertyName(propertyPath) !== 'style') {
      return;
    }
    var valuePath = docgen.utils.resolveToValue(propertyPath.get('value'));
    // If it's a call to StyleSheetPropType, do stuff
    if (valuePath.node.type !== 'CallExpression' ||
        valuePath.node.callee.name !== 'StyleSheetPropType') {
      return;
    }
    // Get type of style sheet
    var styleSheetModule = docgen.utils.resolveToModule(
      valuePath.get('arguments', 0)
    );
    if (styleSheetModule) {
      var propDescriptor = documentation.getPropDescriptor('style');
      propDescriptor.type = {name: 'stylesheet', value: styleSheetModule};
    }
  });
}
 propTypesPath.get('properties').each(function(propertyPath) {
   if (propertyPath.node.type !== 'Property' ||
       docgen.utils.getPropertyName(propertyPath) !== 'style') {
     return;
   }
   const valuePath = docgen.utils.resolveToValue(propertyPath.get('value'));
   // If it's a call to StyleSheetPropType, do stuff
   if (valuePath.node.type !== 'CallExpression' ||
       valuePath.node.callee.name !== 'StyleSheetPropType') {
     return;
   }
   // Get type of style sheet
   const styleSheetModule = docgen.utils.resolveToModule(
     valuePath.get('arguments', 0)
   );
   if (styleSheetModule) {
     const propDescriptor = documentation.getPropDescriptor('style');
     propDescriptor.type = {name: 'stylesheet', value: styleSheetModule};
   }
 });
  propTypesPath.get('properties').each(function(propertyPath) {
    const valuePath = docgen.utils.resolveToValue(propertyPath.get('value'));
    // If it's a call to deprecatedPropType, do stuff
    if (valuePath.node.type !== 'CallExpression' ||
        valuePath.node.callee.name !== 'deprecatedPropType') {
      return;
    }
    const propDescriptor = documentation.getPropDescriptor(
      docgen.utils.getPropertyName(propertyPath)
    );
    // The 2nd argument of deprecatedPropType is the deprecation message.
    // Used printValue to get the string otherwise there was issues with template
    // strings.
    propDescriptor.deprecationMessage = docgen.utils
      .printValue(valuePath.get('arguments', 1))
      // Remove the quotes printValue adds.
      .slice(1, -1);

    // Get the actual prop type.
    propDescriptor.type = docgen.utils.getPropType(
      valuePath.get('arguments', 0)
    );
  });
function typedefHandler(documentation, path) {
  const declarationPath = path.get('declaration');
  const typePath = declarationPath.get('right');

  // Name, type, description of the typedef
  const name = declarationPath.value.id.name;
  const type = { names: [typePath.node.id ? typePath.node.id.name : typePath.node.type] };
  const description = docgen.utils.docblock.getDocblock(path);

  // Get the properties for the typedef
  let paramsDescriptions = [];
  let paramsTypes;
  if (typePath.node.typeParameters) {
    const paramsPath = typePath.get('typeParameters').get('params', 0);
    if (paramsPath) {
      const properties = paramsPath.get('properties');
      // Get the descriptions inside each property (are inline leading comments)
      paramsDescriptions =
        properties.map(property => docgen.utils.docblock.getDocblock(property));
      // Get the property type info
      paramsTypes = docgen.utils.getFlowType(paramsPath);
    }
  }
  // Get the property type, description and value info
  let values = [];
  if (paramsTypes && paramsTypes.signature && paramsTypes.signature.properties &&
    paramsTypes.signature.properties.length !== 0) {
    values = paramsTypes.signature.properties.map((property, index) => {
      return {
        type: { names: [property.value.name] },
        description: paramsDescriptions[index],
        name: property.key,
      };
    });
  }

  const typedef = {
    name: name,
    description: description,
    type: type,
    values: values,
  };
  documentation.set('typedef', typedef);
}
 visitAssignmentExpression: function(path) {
   if (!objPath && docgen.utils.isExportsOrModuleAssignment(path)) {
     objPath = docgen.utils.resolveToValue(path.get('right'));
   }
   return false;
 }
Beispiel #6
0
 visitAssignmentExpression: function(astPath) {
   if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
     definition = docgen.utils.resolveToValue(astPath.get('right'));
   }
   return false;
 }