How to use the react-docgen.utils.resolveToValue 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
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
      if (resolvedValuePath.node.type === types.ObjectExpression.name) {
        amendPropTypes(documentation, resolvedValuePath);
      }
    }

    if (types.Property.check(propertyPath.node)) {
      setPropDescription(documentation, propertyPath);
    }
  });
}
github doczjs / docz / core / docz-core / src / utils / docgen / externalProptypesHandler.ts View on Github external
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
      if (resolvedValuePath.node.type === types.ObjectExpression.name) {
        amendPropTypes(documentation, resolvedValuePath)
      }
    }

    if (types.Property.check(propertyPath.node)) {
      setPropDescription(documentation, propertyPath)
    }
  })
}
github siddharthkp / react-docgen-external-proptypes-handler / index.js View on Github external
return (doc, path) => {
    const root = path.scope.getGlobalScope().node;
    let propTypesPath, propTypesFilePath, propTypesAST;

    propTypesPath = utils.getMemberValuePath(path, "propTypes");
    propTypesAST = root;
    propTypesFilePath = componentPath;

    if (!propTypesPath) {
      return;
    }

    const propsNameIdentifier = propTypesPath.node.name;
    propTypesPath = utils.resolveToValue(propTypesPath);

    if (!propTypesPath) {
      return;
    }

    if (!types.ObjectExpression.check(propTypesPath.node)) {
      //First resolve dependencies against component path
      propTypesFilePath = resolveFilePath(
        componentPath,
        propTypesPath.node.source.value
      );
      const propTypesSrc = getSrc(propTypesFilePath);
      propTypesAST = getAST(propTypesSrc);
      const importedPropTypes = getIdentifiers(propTypesAST)[
        propsNameIdentifier
      ];
github doczjs / docz / core / docz-core / src / utils / docgen / externalProptypesHandler.ts View on Github external
return (doc: any, path: any) => {
    const root = path.scope.getGlobalScope().node
    let propTypesPath, propTypesFilePath, propTypesAST

    propTypesPath = utils.getMemberValuePath(path, 'propTypes')
    propTypesAST = root
    propTypesFilePath = componentPath

    if (!propTypesPath) {
      return
    }

    const propsNameIdentifier = propTypesPath.node.name
    propTypesPath = utils.resolveToValue(propTypesPath)

    if (!propTypesPath) {
      return
    }

    if (!types.ObjectExpression.check(propTypesPath.node)) {
      //First resolve dependencies against component path
      propTypesFilePath = resolveFilePath(
        componentPath,
        propTypesPath.node.source.value
      )
      const propTypesSrc = getSrc(propTypesFilePath)
      propTypesAST = getAST(propTypesSrc)
      const importedPropTypes = getIdentifiers(propTypesAST)[
        propsNameIdentifier
      ]
github doczjs / docz / core / docz-core / src / utils / docgen / externalProptypesHandler.ts View on Github external
//First resolve dependencies against component path
      propTypesFilePath = resolveFilePath(
        componentPath,
        propTypesPath.node.source.value
      )
      const propTypesSrc = getSrc(propTypesFilePath)
      propTypesAST = getAST(propTypesSrc)
      const importedPropTypes = getIdentifiers(propTypesAST)[
        propsNameIdentifier
      ]

      if (!importedPropTypes) {
        return
      }

      propTypesPath = utils.resolveToValue(importedPropTypes.path)

      //updating doc object with external props
      amendPropTypes(doc, propTypesPath)
    }

    const computedPropNames = getComputedPropValuesFromDoc(doc)

    if (!computedPropNames) {
      return
    }

    const importSpecifiers = getImports(propTypesAST)

    if (!importSpecifiers) {
      return
    }
github algolia / react-instantsearch / docgen / plugins / inlineProps / transformProps.js View on Github external
function propLocHandler(documentation, path) {
  let propTypesPath = utils.getMemberValuePath(path, 'propTypes');
  if (!propTypesPath) {
    return;
  }
  propTypesPath = utils.resolveToValue(propTypesPath);
  if (!propTypesPath || !r.types.namedTypes.ObjectExpression.check(propTypesPath.node)) {
    return;
  }

  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 siddharthkp / react-docgen-external-proptypes-handler / index.js View on Github external
//First resolve dependencies against component path
      propTypesFilePath = resolveFilePath(
        componentPath,
        propTypesPath.node.source.value
      );
      const propTypesSrc = getSrc(propTypesFilePath);
      propTypesAST = getAST(propTypesSrc);
      const importedPropTypes = getIdentifiers(propTypesAST)[
        propsNameIdentifier
      ];

      if (!importedPropTypes) {
        return;
      }

      propTypesPath = utils.resolveToValue(importedPropTypes.path);

      //updating doc object with external props
      amendPropTypes(doc, propTypesPath);
    }

    const computedPropNames = getComputedPropValuesFromDoc(doc);

    if (!computedPropNames) {
      return;
    }

    const importSpecifiers = getImports(propTypesAST);

    if (!importSpecifiers) {
      return;
    }