MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / extractExportMetadata

Function extractExportMetadata

packages/vite/hmr/server/websocket.ts:714–749  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

712// Extract a quick set of export names and whether a default export exists from ESM code.
713// This uses conservative regex scanning for metadata only (no code rewriting).
714function extractExportMetadata(code: string): {
715 hasDefault: boolean;
716 named: string[];
717} {
718 const named = new Set<string>();
719 let hasDefault = /\bexport\s+default\b/.test(code);
720 try {
721 // export const foo, export let foo, export function bar, export class Baz
722 for (const m of code.matchAll(/\bexport\s+(?:const|let|var|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/g)) {
723 if (m[1]) named.add(m[1]);
724 }
725 // export { a, b as c }
726 for (const m of code.matchAll(/\bexport\s*\{([^}]+)\}/g)) {
727 const inner = (m[1] || '')
728 .split(',')
729 .map((s) => s.trim())
730 .filter(Boolean);
731 for (const seg of inner) {
732 // forms: name or name as alias or default as name
733 const dm = seg.match(/^([A-Za-z_$][A-Za-z0-9_$]*)(?:\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*))?$/);
734 if (dm) {
735 const base = dm[1];
736 const alias = dm[2];
737 if (base === 'default') {
738 hasDefault = true;
739 continue;
740 }
741 named.add(alias || base);
742 }
743 }
744 }
745 } catch {}
746 // Remove default if accidentally included
747 named.delete('default');
748 return { hasDefault, named: Array.from(named) };
749}
750
751function normalizeImportPath(spec: string, importerDir: string): string | null {
752 if (!spec) return null;

Callers 1

configureServerFunction · 0.85

Calls 6

addMethod · 0.65
mapMethod · 0.65
deleteMethod · 0.65
testMethod · 0.45
filterMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected