MCPcopy Create free account
hub / github.com/Noumena-Network/code / parseImports

Function parseImports

scripts/generate_slash_command_appendix.mjs:345–382  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

343}
344
345function parseImports(source) {
346 const map = new Map()
347
348 for (const match of source.matchAll(
349 /^import\s+([A-Za-z_$][\w$]*)\s+from\s+'(\.\/commands\/[^']+)'/gm,
350 )) {
351 map.set(match[1], { specifier: match[2], gate: 'always', importKind: 'default' })
352 }
353
354 for (const match of source.matchAll(
355 /^import\s+\{([^}]+)\}\s+from\s+'(\.\/commands\/[^']+)'/gm,
356 )) {
357 const names = match[1]
358 .split(',')
359 .map(s => s.trim())
360 .filter(Boolean)
361 .map(s => s.split(/\s+as\s+/)[0].trim())
362 for (const name of names) {
363 map.set(name, { specifier: match[2], gate: 'always', importKind: 'named' })
364 }
365 }
366
367 for (const match of source.matchAll(
368 /^import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s+from\s+'(\.\/commands\/[^']+)'/gm,
369 )) {
370 map.set(match[1], { specifier: match[3], gate: 'always', importKind: 'default' })
371 const names = match[2]
372 .split(',')
373 .map(s => s.trim())
374 .filter(Boolean)
375 .map(s => s.split(/\s+as\s+/)[0].trim())
376 for (const name of names) {
377 map.set(name, { specifier: match[3], gate: 'always', importKind: 'named' })
378 }
379 }
380
381 return map
382}
383
384function parseRelativeImports(source) {
385 const map = new Map()

Calls 1

setMethod · 0.80

Tested by

no test coverage detected