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

Function extractLocalExportAliases

src/resolution/alias-binding.ts:115–151  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

113 * Type-only specifiers are skipped: they carry no runtime call.
114 */
115export function extractLocalExportAliases(content: string): Array<{ exportedName: string; localName: string }> {
116 const out: Array<{ exportedName: string; localName: string }> = [];
117 // `export { … }` NOT followed by `from` — the `from` form is a re-export.
118 const clauseRe = /export\s*\{([^}]*)\}\s*(?!\s*from)[;\n]/g;
119 let clause: RegExpExecArray | null;
120 while ((clause = clauseRe.exec(content)) !== null) {
121 for (const raw of clause[1]!.split(',')) {
122 const specifier = raw.trim();
123 if (!specifier || /^type\s/.test(specifier)) continue;
124 const renamed = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(specifier);
125 if (renamed) {
126 out.push({ localName: renamed[1]!, exportedName: renamed[2]! });
127 continue;
128 }
129 if (/^[A-Za-z_$][\w$]*$/.test(specifier)) {
130 out.push({ localName: specifier, exportedName: specifier });
131 }
132 }
133 }
134 // CommonJS: `exports.setCharset = function setCharset(…)`, `module.exports.x = impl`,
135 // and a named class expression, `exports.Router = class Router {…}` (#2499).
136 const memberRe = /^[ \t]*(?:module\.)?exports\.([A-Za-z_$][\w$]*)\s*=\s*(?:(?:async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)\s*\(|class\s+(?!extends\b)([A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*)\s*;?[ \t]*$)/gm;
137 let member: RegExpExecArray | null;
138 while ((member = memberRe.exec(content)) !== null) {
139 out.push({ exportedName: member[1]!, localName: member[2] ?? member[3] ?? member[4]! });
140 }
141 // `module.exports = { parse, format: formatDate }`.
142 const objectRe = /^[ \t]*module\.exports\s*=\s*\{([^{}]*)\}/gm;
143 let object: RegExpExecArray | null;
144 while ((object = objectRe.exec(content)) !== null) {
145 for (const raw of object[1]!.split(',')) {
146 const entry = /^\s*([A-Za-z_$][\w$]*)\s*(?::\s*([A-Za-z_$][\w$]*)\s*)?$/.exec(raw);
147 if (entry) out.push({ exportedName: entry[1]!, localName: entry[2] ?? entry[1]! });
148 }
149 }
150 return out;
151}
152
153/**
154 * The binding a module's default export is as a whole: `export default

Callers 5

exportedByNameFunction · 0.90
namespaceExportModuleFunction · 0.90
exportsOfFunction · 0.90
ownExportFunction · 0.90
defaultExportBindingFunction · 0.85

Calls 2

pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected