MCPcopy
hub / github.com/webpack/webpack / resolveTarget

Method resolveTarget

lib/ExportsInfo.js:1661–1720  ·  view source on GitHub ↗
(inputTarget, alreadyVisited)

Source from the content-addressed store, hash-verified

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 };
1712 }
1713 if (!resolveTargetFilter(target)) return target;
1714 if (!alreadyVisitedOwned) {
1715 alreadyVisited = new Set(alreadyVisited);
1716 alreadyVisitedOwned = true;
1717 }
1718 alreadyVisited.add(exportInfo);

Callers

nothing calls this directly

Calls 6

getExportsInfoMethod · 0.80
_getTargetMethod · 0.80
sliceMethod · 0.80
getExportInfoMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected