( moduleAndSpecifiers, exportsInfo, runtime, runtimeTemplate, dependencyMeta, concatenationScope )
| 565 | * @returns {SourceData} the generated source |
| 566 | */ |
| 567 | const getSourceForModuleExternal = ( |
| 568 | moduleAndSpecifiers, |
| 569 | exportsInfo, |
| 570 | runtime, |
| 571 | runtimeTemplate, |
| 572 | dependencyMeta, |
| 573 | concatenationScope |
| 574 | ) => { |
| 575 | const phase = dependencyMeta && dependencyMeta.phase; |
| 576 | /** @type {Imported} */ |
| 577 | let imported = true; |
| 578 | if (concatenationScope) { |
| 579 | const usedExports = exportsInfo.getUsedExports(runtime); |
| 580 | switch (usedExports) { |
| 581 | case true: |
| 582 | case null: |
| 583 | // unknown exports |
| 584 | imported = true; |
| 585 | break; |
| 586 | case false: |
| 587 | // no used exports |
| 588 | imported = []; |
| 589 | break; |
| 590 | default: |
| 591 | imported = [...usedExports.entries()]; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if (!Array.isArray(moduleAndSpecifiers)) { |
| 596 | moduleAndSpecifiers = [moduleAndSpecifiers]; |
| 597 | } |
| 598 | |
| 599 | // Return to `namespace` when the external request includes a specific export |
| 600 | if (moduleAndSpecifiers.length > 1) { |
| 601 | imported = true; |
| 602 | } |
| 603 | |
| 604 | // `import defer …` is only valid as `import defer * as ns from "…"`, so |
| 605 | // keep the namespace form even if usage analysis would otherwise narrow |
| 606 | // the import down to specific names. Defer + concatenation is semantically |
| 607 | // at odds (lazy vs. eager), so we preserve the user-written shape here. |
| 608 | if (ImportPhaseUtils.isDefer(phase)) { |
| 609 | imported = true; |
| 610 | } |
| 611 | |
| 612 | const initFragment = new ModuleExternalInitFragment( |
| 613 | moduleAndSpecifiers[0], |
| 614 | imported, |
| 615 | undefined, |
| 616 | dependencyMeta, |
| 617 | runtimeTemplate.outputOptions.hashFunction |
| 618 | ); |
| 619 | const normalizedImported = initFragment.getImported(); |
| 620 | |
| 621 | const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess( |
| 622 | moduleAndSpecifiers, |
| 623 | 1 |
| 624 | )}`; |
no test coverage detected