( site: SourceModule, s: MagicString | undefined, created: Creation[], kept: KeptCode, specifier: string, unwrapped: Set<string> )
| 330 | // a site importing what it creates from the flat module, without the |
| 331 | // annotations on what it kept |
| 332 | const flatSiteOf = ( |
| 333 | site: SourceModule, |
| 334 | s: MagicString | undefined, |
| 335 | created: Creation[], |
| 336 | kept: KeptCode, |
| 337 | specifier: string, |
| 338 | unwrapped: Set<string> |
| 339 | ): FlatSite => { |
| 340 | const source = JSON.stringify(specifier) |
| 341 | for (const [start, end] of keptAnnotationsIn(site, kept)) { |
| 342 | if ( |
| 343 | created.some(creation => creation.start <= start && end <= creation.end) |
| 344 | ) |
| 345 | continue |
| 346 | s ??= new MagicString(site.source) |
| 347 | s.remove(start, end) |
| 348 | } |
| 349 | const prefix = prefixOf(site.source, site.id) |
| 350 | for (const { start, end, name, declared } of created) { |
| 351 | s ??= new MagicString(site.source) |
| 352 | // an import, which a bundler doesn't write as a variable holding another |
| 353 | if (declared) { |
| 354 | s.overwrite( |
| 355 | declared.start, |
| 356 | declared.end, |
| 357 | `import { ${name} as ${declared.name} } from ${source}\n${declared.exported ? `export { ${declared.name} }\n` : ""}` |
| 358 | ) |
| 359 | // a read of its one member reads the validator it is |
| 360 | if (unwrapped.has(name)) { |
| 361 | for (const [start, end] of declared.memberReads!.spans) |
| 362 | s.remove(start, end) |
| 363 | } |
| 364 | } else { |
| 365 | const local = `${prefix}_${name}` |
| 366 | s.overwrite(start, end, local) |
| 367 | writeImportsAhead( |
| 368 | s, |
| 369 | site.program, |
| 370 | `\nimport { ${name} as ${local} } from ${source}` |
| 371 | ) |
| 372 | } |
| 373 | } |
| 374 | return s ? |
| 375 | { code: s.toString(), map: s.generateMap({ hires: "boundary" }) } |
| 376 | : { code: site.source, map: undefined } |
| 377 | } |
| 378 | |
| 379 | const unrenamed = (specifier: string) => specifier |
| 380 |
no test coverage detected