How to use the react-docgen.utils 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
const setPropDescription = require("react-docgen/dist/utils/setPropDescription")
  .default;
let babylon;
try {
  const buildParser = require("react-docgen/dist/babelParser").default;
  babylon = buildParser();
} catch (e) {
  // Try babylon if requiring babelParser fails, but don't mask Babel config errors
  if (e.message.indexOf("Cannot find module") === -1) {
    throw e;
  }
  // eslint-disable-next-line node/no-missing-require
  babylon = require("react-docgen/dist/babylon").default;
}

const utils = require("react-docgen").utils;
const types = recast.types.namedTypes;
const HOP = Object.prototype.hasOwnProperty;
const createObject = Object.create;

function isPropTypesExpression(path) {
  const moduleName = utils.resolveToModule(path);

  if (moduleName) {
    return (
      utils.isReactModuleName(moduleName) || moduleName === "ReactPropTypes"
    );
  }

  return false;
}
github facebook / react-native / website / server / docgenHelpers.js View on Github external
function deprecatedPropTypeHandler(documentation, path) {
  let propTypesPath = docgen.utils.getMemberValuePath(path, 'propTypes');
  if (!propTypesPath) {
    return;
  }

  propTypesPath = docgen.utils.resolveToValue(propTypesPath);
  if (!propTypesPath || propTypesPath.node.type !== 'ObjectExpression') {
    return;
  }

  // Checks for deprecatedPropType function and add deprecation info.
  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;
github facebook / react-native / website / server / docgenHelpers.js View on Github external
function deprecatedPropTypeHandler(documentation, path) {
  let propTypesPath = docgen.utils.getMemberValuePath(path, 'propTypes');
  if (!propTypesPath) {
    return;
  }

  propTypesPath = docgen.utils.resolveToValue(propTypesPath);
  if (!propTypesPath || propTypesPath.node.type !== 'ObjectExpression') {
    return;
  }

  // Checks for deprecatedPropType function and add deprecation info.
  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.
github facebook / react-360 / website / server / extractDocs.js View on Github external
visitAssignmentExpression: function(astPath) {
        if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
          definition = docgen.utils.resolveToValue(astPath.get('right'));
        }
        return false;
      }
    });
github facebook / react-native / website / server / extractDocs.js View on Github external
visitAssignmentExpression: function(astPath) {
        if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
          definition = docgen.utils.resolveToValue(astPath.get('right'));
        }
        return false;
      }
    });
github styleguidist / react-styleguidist / src / loaders / utils / getProps.js View on Github external
doc.methods = (doc.methods || []).filter(method => {
		const doclets = method.docblock && reactDocs.utils.docblock.getDoclets(method.docblock);
		return doclets && doclets.public;
	});
github ansumanshah / css-in-js / packages / atom-css-in-js / scripts / rn / completions.js View on Github external
visitAssignmentExpression: function(path) {
      if (!objPath && docgen.utils.isExportsOrModuleAssignment(path)) {
        objPath = docgen.utils.resolveToValue(path.get('right'))
      }
      return false
    },
  })
github styleguidist / react-styleguidist / src / loaders / utils / getProps.js View on Github external
const getDocletsObject = string => ({ ...reactDocs.utils.docblock.getDoclets(string) });
github facebook / react-360 / website / server / extractDocs.js View on Github external
visitAssignmentExpression: function(astPath) {
        if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
          definition = docgen.utils.resolveToValue(astPath.get('right'));
        }
        return false;
      }
    });
github ansumanshah / css-in-js / packages / atom-css-in-js / scripts / rn / completions.js View on Github external
visitAssignmentExpression: function(path) {
      if (!objPath && docgen.utils.isExportsOrModuleAssignment(path)) {
        objPath = docgen.utils.resolveToValue(path.get('right'))
      }
      return false
    },
  })