MCPcopy Create free account
hub / github.com/tinyplex/tinybase / getRunnableImport

Function getRunnableImport

test/unit/documentation.test.ts:247–276  ·  view source on GitHub ↗
(
  _: string,
  typeOnly: string | undefined,
  imports: string,
  module: string,
)

Source from the content-addressed store, hash-verified

245 });
246
247const getRunnableImport = (
248 _: string,
249 typeOnly: string | undefined,
250 imports: string,
251 module: string,
252): string => {
253 if (typeOnly != null) {
254 return '';
255 }
256 const moduleExpression = `modules[\`${module}\`]`;
257 const trimmedImports = imports.trim();
258 const defaultAndNamedImports = trimmedImports.match(/^(\w+),\s*({.*})$/s);
259 if (defaultAndNamedImports != null) {
260 return (
261 `const ${defaultAndNamedImports[1]} = ` +
262 `${moduleExpression}.default ?? ${moduleExpression};\n` +
263 `const ${defaultAndNamedImports[2].replace(/\bas\b/g, ':')} = ` +
264 `${moduleExpression};`
265 );
266 }
267 if (trimmedImports.startsWith('{')) {
268 // eslint-disable-next-line max-len
269 return `const ${trimmedImports.replace(/\bas\b/g, ':')} = ${moduleExpression};`;
270 }
271 if (trimmedImports.startsWith('* as ')) {
272 return `const ${trimmedImports.slice(5)} = ${moduleExpression};`;
273 }
274 // eslint-disable-next-line max-len
275 return `const ${trimmedImports} = ${moduleExpression}.default ?? ${moduleExpression};`;
276};
277
278const replaceRunnableImports = (source: string): string =>
279 source.replace(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…