MCPcopy
hub / github.com/xpf0000/FlyEnv / loadRegisteredNamespaces

Function loadRegisteredNamespaces

src/lang/check.mjs:40–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38}
39
40function loadRegisteredNamespaces() {
41 const source = getNamespaceIndexFile()
42 if (!source) {
43 return new Map()
44 }
45
46 const { pack, indexFile } = source
47 const content = fs.readFileSync(indexFile, 'utf8')
48 const importVarToFile = new Map()
49 let importMatch
50
51 while ((importMatch = INDEX_IMPORT_PATTERN.exec(content)) !== null) {
52 importVarToFile.set(importMatch[1], importMatch[2])
53 }
54
55 const namespaceByFile = new Map()
56 const lines = content.split(/\r?\n/)
57 let inPackBlock = false
58
59 for (const rawLine of lines) {
60 const line = rawLine.trim()
61 if (!inPackBlock) {
62 if (line === `${pack}: {`) {
63 inPackBlock = true
64 }
65 continue
66 }
67
68 if (line === '}' || line === '},') {
69 break
70 }
71
72 let entryMatch = line.match(INDEX_ENTRY_PATTERN)
73 if (entryMatch) {
74 const [, , namespace, importVar] = entryMatch
75 const fileName = importVarToFile.get(importVar)
76 if (fileName) {
77 namespaceByFile.set(fileName, namespace)
78 }
79 continue
80 }
81
82 entryMatch = line.match(INDEX_SHORTHAND_PATTERN)
83 if (entryMatch) {
84 const importVar = entryMatch[1]
85 const fileName = importVarToFile.get(importVar)
86 if (fileName) {
87 namespaceByFile.set(fileName, importVar)
88 }
89 }
90 }
91
92 return namespaceByFile
93}
94
95const REGISTERED_NAMESPACE_BY_FILE = loadRegisteredNamespaces()
96

Callers 1

check.mjsFile · 0.85

Calls 4

getNamespaceIndexFileFunction · 0.85
setMethod · 0.80
getMethod · 0.80
execMethod · 0.45

Tested by

no test coverage detected