(runtime: RuntimeModule)
| 204 | } |
| 205 | |
| 206 | private link(runtime: RuntimeModule): void { |
| 207 | const { module } = runtime |
| 208 | const add = (specifier: string, edge: ImportEdge) => { |
| 209 | // e.g. `export * as ark from "arktype"`, whose errors class is read unfollowed |
| 210 | if ( |
| 211 | (edge.kind === "whole" || edge.kind === "star") && |
| 212 | isArkSpecifier(specifier) |
| 213 | ) { |
| 214 | this.used.add("errors") |
| 215 | this.used.add("thrown") |
| 216 | } |
| 217 | const id = this.program.resolve(specifier, module.id) |
| 218 | if (id === undefined || !this.program.modules.has(id)) { |
| 219 | if (!isArkSpecifier(specifier)) this.used.add("external") |
| 220 | return |
| 221 | } |
| 222 | const edges = this.edgesByTarget.get(id) |
| 223 | if (edges) edges.push(edge) |
| 224 | else this.edgesByTarget.set(id, [edge]) |
| 225 | } |
| 226 | const noteExternal = (specifier: string) => { |
| 227 | if (isArkSpecifier(specifier)) return |
| 228 | const id = this.program.resolve(specifier, module.id) |
| 229 | if (id === undefined || !this.program.modules.has(id)) |
| 230 | this.used.add("external") |
| 231 | } |
| 232 | for (const statement of module.program.body) { |
| 233 | if (statement.type === "ImportDeclaration") { |
| 234 | if (statement.importKind === "type") continue |
| 235 | if (!statement.specifiers.length) noteExternal(statement.source.value) |
| 236 | for (const specifier of statement.specifiers) { |
| 237 | if ( |
| 238 | specifier.type === "ImportSpecifier" && |
| 239 | specifier.importKind === "type" |
| 240 | ) |
| 241 | continue |
| 242 | const binding = module.scopes.bindingsById.get(specifier.local)! |
| 243 | if (isArkSpecifier(statement.source.value)) { |
| 244 | this.readArkImport( |
| 245 | specifier.type === "ImportSpecifier" ? |
| 246 | exportNameOf(specifier.imported) |
| 247 | : undefined, |
| 248 | binding, |
| 249 | runtime |
| 250 | ) |
| 251 | } |
| 252 | add( |
| 253 | statement.source.value, |
| 254 | specifier.type === "ImportNamespaceSpecifier" ? |
| 255 | { kind: "namespace", binding, importer: runtime } |
| 256 | : { |
| 257 | kind: "named", |
| 258 | name: |
| 259 | specifier.type === "ImportDefaultSpecifier" ? |
| 260 | "default" |
| 261 | : exportNameOf(specifier.imported), |
| 262 | binding, |
| 263 | importer: runtime |
no test coverage detected