MCPcopy Create free account
hub / github.com/TanStack/ai / importUses

Function importUses

testing/react-native-smoke/scripts/assert-import-surface.ts:131–157  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

129}
130
131function importUses(source: string): Array<SpecifierUse> {
132 const parseSource = stripComments(source)
133 const uses: Array<SpecifierUse> = []
134 const importPattern =
135 /import\s+(?:type\s+)?([\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g
136 const sideEffectPattern = /import\s+['"]([^'"]+)['"]/g
137 const dynamicPattern = /import\(\s*['"]([^'"]+)['"]\s*\)/g
138
139 for (const match of parseSource.matchAll(importPattern)) {
140 const clause = match[1]?.trim() ?? ''
141 const specifier = match[2]
142 if (!specifier) continue
143
144 const named = clause.match(/\{([\s\S]*?)\}/)
145 mergeUse(uses, specifier, named ? parseNames(named[1] ?? '') : undefined)
146 }
147
148 for (const match of parseSource.matchAll(sideEffectPattern)) {
149 if (match[1]) mergeUse(uses, match[1], undefined)
150 }
151
152 for (const match of parseSource.matchAll(dynamicPattern)) {
153 if (match[1]) mergeUse(uses, match[1], undefined)
154 }
155
156 return uses
157}
158
159function exportUsesForNames(
160 source: string,

Callers 1

walkFunction · 0.85

Calls 3

mergeUseFunction · 0.85
parseNamesFunction · 0.85
stripCommentsFunction · 0.70

Tested by

no test coverage detected