How to use the react-docgen/dist/utils/resolveToValue.default 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 alfa-laboratory / library-utils / react-doc / create-resolver.js View on Github external
function resolveDefinition(definition, types) {
    if (isReactCreateClassCall(definition)) {
        // return argument
        const resolvedPath = resolveToValue(definition.get('arguments', 0));
        if (types.ObjectExpression.check(resolvedPath.node)) {
            return resolvedPath;
        }
    } else if (isReactComponentClass(definition) || isDecoratedBy(definition, 'cn')) {
        normalizeClassDefinition(definition);
        return definition;
    } else if (isStatelessComponent(definition)) {
        return definition;
    }
    return null;
}
github jamesmfriedman / rmwc / scripts / docgen-resolver.js View on Github external
function resolveDefinition(definition, types) {
  if (isReactCreateClassCall(definition)) {
    // return argument
    var resolvedPath = resolveToValue(definition.get('arguments', 0));
    if (types.ObjectExpression.check(resolvedPath.node)) {
      return resolvedPath;
    }
  } else if (isReactComponentClass(definition)) {
    normalizeClassDefinition(definition);
    return definition;
  } else if (isStatelessComponent(definition)) {
    return definition;
  } else if (isSimpleTag(definition)) {
    var resolvedPath = resolveToValue(definition.get('arguments', 0));
    return resolvedPath;
  } else if (isWithMDC(definition)) {
    var resolvedPath = resolveToValue(definition.get('arguments', 0));
    return resolvedPath;
  }
github jamesmfriedman / rmwc / scripts / docgen-resolver.js View on Github external
function resolveDefinition(definition, types) {
  if (isReactCreateClassCall(definition)) {
    // return argument
    var resolvedPath = resolveToValue(definition.get('arguments', 0));
    if (types.ObjectExpression.check(resolvedPath.node)) {
      return resolvedPath;
    }
  } else if (isReactComponentClass(definition)) {
    normalizeClassDefinition(definition);
    return definition;
  } else if (isStatelessComponent(definition)) {
    return definition;
  } else if (isSimpleTag(definition)) {
    var resolvedPath = resolveToValue(definition.get('arguments', 0));
    return resolvedPath;
  } else if (isWithMDC(definition)) {
    var resolvedPath = resolveToValue(definition.get('arguments', 0));
    return resolvedPath;
  }

  return null;
}
github alfa-laboratory / library-utils / react-doc / create-resolver.js View on Github external
visitAssignmentExpression(path) {
            // Ignore anything that is not `exports.X = ...;` or
            // `module.exports = ...;`
            if (!isExportsOrModuleAssignment(path)) {
                return false;
            }
            // Resolve the value of the right hand side. It should resolve to a call
            // expression, something like React.createClass
            path = resolveToValue(path.get('right'));
            if (!isComponentDefinition(path)) {
                path = resolveToValue(resolveHOC(path));
                if (!isComponentDefinition(path)) {
                    return false;
                }
            }
            if (definition) {
                // If a file exports multiple components, ... complain!
                throw new Error(ERROR_MULTIPLE_DEFINITIONS);
            }
            definition = resolveDefinition(path, types);
            return false;
        }
    });
github alfa-laboratory / library-utils / react-doc / create-resolver.js View on Github external
.reduce((acc, def) => {
                if (isComponentDefinition(def)) {
                    acc.push(def);
                    return acc;
                }

                const resolved = resolveToValue(resolveHOC(def));
                if (isComponentDefinition(resolved)) {
                    acc.push(resolved);
                    return acc;
                }

                if (isDecoratedBy(def, 'cn') && def.get('superClass')) {
                    const superClass = def.get('superClass');
                    if (!originalClassName) { // save original component name and use it to patch parent class
                        originalClassName = def.get('id').value.name;
                    }

                    const src = getSourceFileContent(importedModules[superClass.value.name], filePath);
                    filePath = src.filePath; // update file path, so we can correctly resolve imports
                    linkedFile = recast.parse(src.content, { esprima: babylon });
                    return acc;
                }
github alfa-laboratory / library-utils / react-doc / create-resolver.js View on Github external
visitAssignmentExpression(path) {
            // Ignore anything that is not `exports.X = ...;` or
            // `module.exports = ...;`
            if (!isExportsOrModuleAssignment(path)) {
                return false;
            }
            // Resolve the value of the right hand side. It should resolve to a call
            // expression, something like React.createClass
            path = resolveToValue(path.get('right'));
            if (!isComponentDefinition(path)) {
                path = resolveToValue(resolveHOC(path));
                if (!isComponentDefinition(path)) {
                    return false;
                }
            }
            if (definition) {
                // If a file exports multiple components, ... complain!
                throw new Error(ERROR_MULTIPLE_DEFINITIONS);
            }
            definition = resolveDefinition(path, types);
            return false;
        }
    });
github alfa-laboratory / library-utils / react-doc / docgen / resolve-export-declaration.js View on Github external
    return definitions.map(definition => resolveToValue(definition));
}