* Returns the target. * @param {ModuleGraph} moduleGraph the module graph * @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target * @param {AlreadyVisitedExportInfo | undefined} alreadyVisited set of already visited export info to avoid circular references
(moduleGraph, resolveTargetFilter, alreadyVisited)
| 1652 | * @returns {TargetItemWithConnection | CIRCULAR | undefined} the target |
| 1653 | */ |
| 1654 | _getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) { |
| 1655 | /** |
| 1656 | * Returns resolved target. |
| 1657 | * @param {TargetItem | undefined | null} inputTarget unresolved target |
| 1658 | * @param {AlreadyVisitedExportInfo} alreadyVisited set of already visited export info to avoid circular references |
| 1659 | * @returns {TargetItemWithConnection | CIRCULAR | null} resolved target |
| 1660 | */ |
| 1661 | const resolveTarget = (inputTarget, alreadyVisited) => { |
| 1662 | if (!inputTarget) return null; |
| 1663 | if (!inputTarget.export) { |
| 1664 | return { |
| 1665 | module: inputTarget.connection.module, |
| 1666 | connection: inputTarget.connection, |
| 1667 | export: undefined |
| 1668 | }; |
| 1669 | } |
| 1670 | /** @type {TargetItemWithConnection} */ |
| 1671 | let target = { |
| 1672 | module: inputTarget.connection.module, |
| 1673 | connection: inputTarget.connection, |
| 1674 | export: inputTarget.export |
| 1675 | }; |
| 1676 | if (!resolveTargetFilter(target)) return target; |
| 1677 | let alreadyVisitedOwned = false; |
| 1678 | for (;;) { |
| 1679 | const exportsInfo = moduleGraph.getExportsInfo(target.module); |
| 1680 | const exportInfo = exportsInfo.getExportInfo( |
| 1681 | /** @type {NonNullable<TargetItemWithConnection["export"]>} */ |
| 1682 | (target.export)[0] |
| 1683 | ); |
| 1684 | if (!exportInfo) return target; |
| 1685 | if (alreadyVisited.has(exportInfo)) return CIRCULAR; |
| 1686 | const newTarget = exportInfo._getTarget( |
| 1687 | moduleGraph, |
| 1688 | resolveTargetFilter, |
| 1689 | alreadyVisited |
| 1690 | ); |
| 1691 | if (newTarget === CIRCULAR) return CIRCULAR; |
| 1692 | if (!newTarget) return target; |
| 1693 | if ( |
| 1694 | /** @type {NonNullable<TargetItemWithConnection["export"]>} */ |
| 1695 | (target.export).length === 1 |
| 1696 | ) { |
| 1697 | target = newTarget; |
| 1698 | if (!target.export) return target; |
| 1699 | } else { |
| 1700 | target = { |
| 1701 | module: newTarget.module, |
| 1702 | connection: newTarget.connection, |
| 1703 | export: newTarget.export |
| 1704 | ? [ |
| 1705 | ...newTarget.export, |
| 1706 | .../** @type {NonNullable<TargetItemWithConnection["export"]>} */ |
| 1707 | (target.export).slice(1) |
| 1708 | ] |
| 1709 | : /** @type {NonNullable<TargetItemWithConnection["export"]>} */ |
| 1710 | (target.export).slice(1) |
| 1711 | }; |
no test coverage detected