function resolveImportedValue()

in src/importer/makeFsImporter.ts [28:76]


  function resolveImportedValue(
    path: NodePath,
    name: string,
    seen: Set<string> = new Set(),
  ): NodePath | null {
    // Bail if no filename was provided for the current source file.
    // Also never traverse into react itself.
    const source = path.node.source.value;
    const options = getOptions(path);
    if (!options || !options.filename || source === 'react') {
      return null;
    }

    // Resolve the imported module using the Node resolver
    const basedir = dirname(options.filename);
    let resolvedSource;

    try {
      resolvedSource = lookupModule(source, basedir);
    } catch (err) {
      return null;
    }

    // Prevent recursive imports
    if (seen.has(resolvedSource)) {
      return null;
    }

    seen.add(resolvedSource);

    let nextPath = cache.get(resolvedSource);
    if (!nextPath) {
      // Read and parse the code
      const src = fs.readFileSync(resolvedSource, 'utf8');
      const parseOptions: Options = {
        ...options,
        parserOptions: {},
        filename: resolvedSource,
      };

      const parser = buildParser(parseOptions);
      const ast = parser.parse(src);
      ast.__src = src;
      nextPath = new NodePathConstructor(ast).get('program') as NodePath;
      cache.set(resolvedSource, nextPath);
    }

    return findExportedValue(nextPath, name, seen);
  }