MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / valueLoader

Function valueLoader

src/resolution/frameworks/react.ts:747–757  ·  view source on GitHub ↗

* The module a value's initializer hands a lazy loader, and the export the * loader resolves to — `default` unless it picks one: `lazy(() => * import('./x'))`, wrapped or not (`Loadable(lazy(…))`, `loadable(…)`, * `dynamic(…, { ssr: false })`, `Loadable({ loader: () => import(…) })`), * `dynamic

(declaration: Node, context: ResolutionContext)

Source from the content-addressed store, hash-verified

745 * what it returns renders, and what it imports is its own business.
746 */
747function valueLoader(declaration: Node, context: ResolutionContext): { spec: string; member: string } | null {
748 const code = stripCommentsForRegex(declarationText(declaration, context), 'typescript');
749 const init = initializerAt(code, declaration.name.length);
750 const loader = init < 0 ? null : loaderOf(code.slice(init));
751 if (!loader) return null;
752 const page = loadedPage(loaderValue(loader, new Map()));
753 if (page) return page;
754 const fn = functionParts(loader);
755 const spec = fn && !fn.block ? FIRST_IMPORT.exec(fn.body)?.[1] : undefined;
756 return spec ? { spec, member: 'default' } : null;
757}
758
759/**
760 * The loader function an initializer hands a lazy wrapper: the first function

Callers 3

declaredComponentFunction · 0.85
declaredLoaderFunction · 0.85
lazyValueModulesFunction · 0.85

Calls 8

stripCommentsForRegexFunction · 0.90
initializerAtFunction · 0.85
loaderOfFunction · 0.85
loadedPageFunction · 0.85
loaderValueFunction · 0.85
functionPartsFunction · 0.85
declarationTextFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected