How to use the react-docgen.utils.getPropertyName function in react-docgen

To help you get started, we’ve selected a few react-docgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github siddharthkp / react-docgen-external-proptypes-handler / index.js View on Github external
path.get("properties").each(propertyPath => {
    let propDescriptor, valuePath, type, resolvedValuePath;

    const nodeType = propertyPath.node.type;

    if (nodeType === types.Property.name) {
      propDescriptor = documentation.getPropDescriptor(
        utils.getPropertyName(propertyPath)
      );
      valuePath = propertyPath.get("value");
      type = isPropTypesExpression(valuePath)
        ? utils.getPropType(valuePath)
        : {
            name: "custom",
            raw: utils.printValue(valuePath)
          };
      if (type) {
        propDescriptor.type = type;
        propDescriptor.required =
          type.name !== "custom" && isRequiredPropType(valuePath);
      }
    } else if (nodeType === types.SpreadProperty.name) {
      resolvedValuePath = utils.resolveToValue(propertyPath.get("argument"));
      // normal object literal
github doczjs / docz / core / docz-core / src / utils / docgen / externalProptypesHandler.ts View on Github external
path.get('properties').each((propertyPath: any) => {
    let propDescriptor, valuePath, type, resolvedValuePath

    const nodeType = propertyPath.node.type

    if (nodeType === types.Property.name) {
      propDescriptor = documentation.getPropDescriptor(
        utils.getPropertyName(propertyPath)
      )
      valuePath = propertyPath.get('value')
      type = isPropTypesExpression(valuePath)
        ? utils.getPropType(valuePath)
        : {
            name: 'custom',
            raw: utils.printValue(valuePath),
          }
      if (type) {
        propDescriptor.type = type
        propDescriptor.required =
          type.name !== 'custom' && isRequiredPropType(valuePath)
      }
    } else if (nodeType === types.SpreadProperty.name) {
      resolvedValuePath = utils.resolveToValue(propertyPath.get('argument'))
      // normal object literal
github algolia / react-instantsearch / docgen / plugins / inlineProps / transformProps.js View on Github external
propTypesPath.get('properties').each(propertyPath => {
    if (r.types.namedTypes.Property.check(propertyPath.node)) {
      const propName = utils.getPropertyName(propertyPath);
      const propDescriptor = documentation.getPropDescriptor(propName);
      propDescriptor.loc = {
        start: propertyPath.get('value').value.start,
        end: propertyPath.get('value').value.end,
      };
    }
  });
}
github doczjs / docz / core / docz-core / src / utils / docgen / externalProptypesHandler.ts View on Github external
propsToPatch.each((propertyPath: string) => {
    const propDescriptor = doc.getPropDescriptor(
      utils.getPropertyName(propertyPath)
    )

    if (propDescriptor.type.name === 'enum' && propDescriptor.type.computed) {
      const oldVal = propDescriptor.type.value
      const newVal = getComputedPropVal(propDescriptor.type.value) || oldVal
      propDescriptor.type.value = newVal
      propDescriptor.type.computed = false
    }
  })
}