bundle({
           bundleGraph,
           options
         }) {
    let bundleRoots = new Map();
    let bundlesByEntryAsset = new Map();
    let siblingBundlesByAsset = new Map(); // Step 1: create bundles for each of the explicit code split points.

    bundleGraph.traverse({
      enter: (node, context) => {
        if (node.type !== 'dependency') {
          var _bundlesByEntryAsset$;

          return {
            ...context,
            bundleGroup: context === null || context === void 0 ? void 0 : context.bundleGroup,
            bundleByType: context === null || context === void 0 ? void 0 : context.bundleByType,
            bundleGroupDependency: context === null || context === void 0 ? void 0 : context.bundleGroupDependency,
            parentNode: node,
            parentBundle: (_bundlesByEntryAsset$ = bundlesByEntryAsset.get(node.value)) !== null && _bundlesByEntryAsset$ !== void 0 ? _bundlesByEntryAsset$ : context === null || context === void 0 ? void 0 : context.parentBundle,
          };
        }

        let dependency = node.value;
        let assets = bundleGraph.getDependencyAssets(dependency);
        let resolution = bundleGraph.getDependencyResolution(dependency);

        if (dependency.isEntry && resolution || dependency.isAsync && resolution || (resolution === null || resolution === void 0 ? void 0 : resolution.isIsolated) || (resolution === null || resolution === void 0 ? void 0 : resolution.isInline) || (resolution === null || resolution === void 0 ? void 0 : resolution.filePath.endsWith("local.js"))) {
          var _dependency$target, _context$bundleGroup;

          let bundleGroup = bundleGraph.createBundleGroup(dependency, (0, _nullthrows.default)((_dependency$target = dependency.target) !== null && _dependency$target !== void 0 ? _dependency$target : context === null || context === void 0 ? void 0 : (_context$bundleGroup = context.bundleGroup) === null || _context$bundleGroup === void 0 ? void 0 : _context$bundleGroup.target));
          let bundleByType = new Map();

          for (let asset of assets) {
            let bundle = bundleGraph.createBundle({
              entryAsset: asset,
              isEntry: asset.isIsolated ? false : Boolean(dependency.isEntry),
              isInline: asset.isInline,
              target: bundleGroup.target,
            });
            bundleByType.set(bundle.type, bundle);
            bundleRoots.set(bundle, [asset]);
            bundlesByEntryAsset.set(asset, bundle);
            siblingBundlesByAsset.set(asset.id, []);
            bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
          }

          return {
            bundleGroup,
            bundleByType,
            bundleGroupDependency: dependency,
            parentNode: node,
            parentBundle: context === null || context === void 0 ? void 0 : context.parentBundle,
          };
        }

        (0, _assert.default)(context != null);
        (0, _assert.default)(context.parentNode.type === 'asset');
        (0, _assert.default)(context.parentBundle != null);
        let parentAsset = context.parentNode.value;
        let parentBundle = context.parentBundle;
        let bundleGroup = (0, _nullthrows.default)(context.bundleGroup);
        let bundleGroupDependency = (0, _nullthrows.default)(context.bundleGroupDependency);
        let bundleByType = (0, _nullthrows.default)(context.bundleByType);
        let siblingBundles = (0, _nullthrows.default)(siblingBundlesByAsset.get(parentAsset.id));
        let allSameType = assets.every(a => a.type === parentAsset.type);

        for (let asset of assets) {
          let siblings = siblingBundlesByAsset.get(asset.id);

          if (parentAsset.type === asset.type) {
            if (allSameType && siblings) {
              // If any sibling bundles were created for this asset or its subtree previously,
              // add them all to the current bundle group as well. This fixes cases where two entries
              // depend on a shared asset which has siblings. Due to DFS, the subtree of the shared
              // asset is only processed once, meaning any sibling bundles created due to type changes
              // would only be connected to the first bundle group. To work around this, we store a list
              // of sibling bundles for each asset in the graph, and when we re-visit a shared asset, we
              // connect them all to the current bundle group as well.
              for (let bundle of siblings) {
                bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
              }
            } else if (!siblings) {
              // Propagate the same siblings further if there are no bundles being created in this
              // asset group, otherwise start a new set of siblings.
              siblingBundlesByAsset.set(asset.id, allSameType ? siblingBundles : []);
            }

            continue;
          }

          let existingBundle = bundleByType.get(asset.type);

          if (existingBundle) {
            // If a bundle of this type has already been created in this group,
            // merge this subgraph into it.
            (0, _nullthrows.default)(bundleRoots.get(existingBundle)).push(asset);
            bundleGraph.createAssetReference(dependency, asset);
          } else {
            let bundle = bundleGraph.createBundle({
              entryAsset: asset,
              target: bundleGroup.target,
              isEntry: bundleGroupDependency.isEntry,
              isInline: asset.isInline,
            });
            bundleByType.set(bundle.type, bundle);
            siblingBundles.push(bundle);
            bundleRoots.set(bundle, [asset]);
            bundlesByEntryAsset.set(asset, bundle);
            bundleGraph.createAssetReference(dependency, asset);
            bundleGraph.createBundleReference(parentBundle, bundle);
            bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
          }

          if (!siblings) {
            siblingBundlesByAsset.set(asset.id, []);
          }
        }

        return {
          ...context,
          parentNode: node,
        };
      },
    });

    for (let [bundle, rootAssets] of bundleRoots) {
      for (let asset of rootAssets) {
        bundleGraph.addAssetGraphToBundle(asset, bundle);
      }
    }
  }
// 6. If two assets are always seen together, put them in the same extracted bundle
6. If two assets are always seen together, put them in the same extracted bundle
6 . If two assets are always seen together put them in the same extracted bundle
bundle({
           bundleGraph,
           options
         }) {
    let bundleRoots = new Map();
    let bundlesByEntryAsset = new Map();
    let siblingBundlesByAsset = new Map(); 
    bundleGraph.traverse({
      enter: (node, context) => {
        if (node.type !== 'dependency') {
          var _bundlesByEntryAsset$;
          return {
            ...context,
            bundleGroup: context === null || context === void 0 ? void 0 : context.bundleGroup,
            bundleByType: context === null || context === void 0 ? void 0 : context.bundleByType,
            bundleGroupDependency: context === null || context === void 0 ? void 0 : context.bundleGroupDependency,
            parentNode: node,
            parentBundle: (_bundlesByEntryAsset$ = bundlesByEntryAsset.get(node.value)) !== null && _bundlesByEntryAsset$ !== void 0 ? _bundlesByEntryAsset$ : context === null || context === void 0 ? void 0 : context.parentBundle,
          };
        }
        let dependency = node.value;
        let assets = bundleGraph.getDependencyAssets(dependency);
        let resolution = bundleGraph.getDependencyResolution(dependency);
        if (dependency.isEntry && resolution || dependency.isAsync && resolution || (resolution === null || resolution === void 0 ? void 0 : resolution.isIsolated) || (resolution === null || resolution === void 0 ? void 0 : resolution.isInline) || (resolution === null || resolution === void 0 ? void 0 : resolution.filePath.endsWith("local.js"))) {
          var _dependency$target, _context$bundleGroup;
          let bundleGroup = bundleGraph.createBundleGroup(dependency, (0, _nullthrows.default)((_dependency$target = dependency.target) !== null && _dependency$target !== void 0 ? _dependency$target : context === null || context === void 0 ? void 0 : (_context$bundleGroup = context.bundleGroup) === null || _context$bundleGroup === void 0 ? void 0 : _context$bundleGroup.target));
          let bundleByType = new Map();
          for (let asset of assets) {
            let bundle = bundleGraph.createBundle({
              entryAsset: asset,
              isEntry: asset.isIsolated ? false : Boolean(dependency.isEntry),
              isInline: asset.isInline,
              target: bundleGroup.target,
            });
            bundleByType.set(bundle.type, bundle);
            bundleRoots.set(bundle, [asset]);
            bundlesByEntryAsset.set(asset, bundle);
            siblingBundlesByAsset.set(asset.id, []);
            bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
          }
          return {
            bundleGroup,
            bundleByType,
            bundleGroupDependency: dependency,
            parentNode: node,
            parentBundle: context === null || context === void 0 ? void 0 : context.parentBundle,
          };
        }
        (0, _assert.default)(context != null);
        (0, _assert.default)(context.parentNode.type === 'asset');
        (0, _assert.default)(context.parentBundle != null);
        let parentAsset = context.parentNode.value;
        let parentBundle = context.parentBundle;
        let bundleGroup = (0, _nullthrows.default)(context.bundleGroup);
        let bundleGroupDependency = (0, _nullthrows.default)(context.bundleGroupDependency);
        let bundleByType = (0, _nullthrows.default)(context.bundleByType);
        let siblingBundles = (0, _nullthrows.default)(siblingBundlesByAsset.get(parentAsset.id));
        let allSameType = assets.every(a => a.type === parentAsset.type);
        for (let asset of assets) {
          let siblings = siblingBundlesByAsset.get(asset.id);
          if (parentAsset.type === asset.type) {
            if (allSameType && siblings) {
              for (let bundle of siblings) {
                bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
              }
            } else if (!siblings) {
              siblingBundlesByAsset.set(asset.id, allSameType ? siblingBundles : []);
            }
            continue;
          }
          let existingBundle = bundleByType.get(asset.type);
          if (existingBundle) {
            (0, _nullthrows.default)(bundleRoots.get(existingBundle)).push(asset);
            bundleGraph.createAssetReference(dependency, asset);
          } else {
            let bundle = bundleGraph.createBundle({
              entryAsset: asset,
              target: bundleGroup.target,
              isEntry: bundleGroupDependency.isEntry,
              isInline: asset.isInline,
            });
            bundleByType.set(bundle.type, bundle);
            siblingBundles.push(bundle);
            bundleRoots.set(bundle, [asset]);
            bundlesByEntryAsset.set(asset, bundle);
            bundleGraph.createAssetReference(dependency, asset);
            bundleGraph.createBundleReference(parentBundle, bundle);
            bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
          }
          if (!siblings) {
            siblingBundlesByAsset.set(asset.id, []);
          }
        }
        return {
          ...context,
          parentNode: node,
        };
      },
    });
    for (let [bundle, rootAssets] of bundleRoots) {
      for (let asset of rootAssets) {
        bundleGraph.addAssetGraphToBundle(asset, bundle);
      }
    }
  }
bundle ( { bundleGraph , options } ) { let bundleRoots = new Map ( ) ; let bundlesByEntryAsset = new Map ( ) ; let siblingBundlesByAsset = new Map ( ) ; bundleGraph . traverse ( { enter : ( node , context ) => { if ( node . type !== 'dependency' ) { var _bundlesByEntryAsset$ ; return { ... context , bundleGroup : context === null || context === void 0 ? void 0 : context . bundleGroup , bundleByType : context === null || context === void 0 ? void 0 : context . bundleByType , bundleGroupDependency : context === null || context === void 0 ? void 0 : context . bundleGroupDependency , parentNode : node , parentBundle : ( _bundlesByEntryAsset$ = bundlesByEntryAsset . get ( node . value ) ) !== null && _bundlesByEntryAsset$ !== void 0 ? _bundlesByEntryAsset$ : context === null || context === void 0 ? void 0 : context . parentBundle , } ; } let dependency = node . value ; let assets = bundleGraph . getDependencyAssets ( dependency ) ; let resolution = bundleGraph . getDependencyResolution ( dependency ) ; if ( dependency . isEntry && resolution || dependency . isAsync && resolution || ( resolution === null || resolution === void 0 ? void 0 : resolution . isIsolated ) || ( resolution === null || resolution === void 0 ? void 0 : resolution . isInline ) || ( resolution === null || resolution === void 0 ? void 0 : resolution . filePath . endsWith ( "local.js" ) ) ) { var _dependency$target , _context$bundleGroup ; let bundleGroup = bundleGraph . createBundleGroup ( dependency , ( 0 , _nullthrows . default ) ( ( _dependency$target = dependency . target ) !== null && _dependency$target !== void 0 ? _dependency$target : context === null || context === void 0 ? void 0 : ( _context$bundleGroup = context . bundleGroup ) === null || _context$bundleGroup === void 0 ? void 0 : _context$bundleGroup . target ) ) ; let bundleByType = new Map ( ) ; for ( let asset of assets ) { let bundle = bundleGraph . createBundle ( { entryAsset : asset , isEntry : asset . isIsolated ? false : Boolean ( dependency . isEntry ) , isInline : asset . isInline , target : bundleGroup . target , } ) ; bundleByType . set ( bundle . type , bundle ) ; bundleRoots . set ( bundle , [ asset ] ) ; bundlesByEntryAsset . set ( asset , bundle ) ; siblingBundlesByAsset . set ( asset . id , [ ] ) ; bundleGraph . addBundleToBundleGroup ( bundle , bundleGroup ) ; } return { bundleGroup , bundleByType , bundleGroupDependency : dependency , parentNode : node , parentBundle : context === null || context === void 0 ? void 0 : context . parentBundle , } ; } ( 0 , _assert . default ) ( context != null ) ; ( 0 , _assert . default ) ( context . parentNode . type === 'asset' ) ; ( 0 , _assert . default ) ( context . parentBundle != null ) ; let parentAsset = context . parentNode . value ; let parentBundle = context . parentBundle ; let bundleGroup = ( 0 , _nullthrows . default ) ( context . bundleGroup ) ; let bundleGroupDependency = ( 0 , _nullthrows . default ) ( context . bundleGroupDependency ) ; let bundleByType = ( 0 , _nullthrows . default ) ( context . bundleByType ) ; let siblingBundles = ( 0 , _nullthrows . default ) ( siblingBundlesByAsset . get ( parentAsset . id ) ) ; let allSameType = assets . every ( a => a . type === parentAsset . type ) ; for ( let asset of assets ) { let siblings = siblingBundlesByAsset . get ( asset . id ) ; if ( parentAsset . type === asset . type ) { if ( allSameType && siblings ) { for ( let bundle of siblings ) { bundleGraph . addBundleToBundleGroup ( bundle , bundleGroup ) ; } } else if ( ! siblings ) { siblingBundlesByAsset . set ( asset . id , allSameType ? siblingBundles : [ ] ) ; } continue ; } let existingBundle = bundleByType . get ( asset . type ) ; if ( existingBundle ) { ( 0 , _nullthrows . default ) ( bundleRoots . get ( existingBundle ) ) . push ( asset ) ; bundleGraph . createAssetReference ( dependency , asset ) ; } else { let bundle = bundleGraph . createBundle ( { entryAsset : asset , target : bundleGroup . target , isEntry : bundleGroupDependency . isEntry , isInline : asset . isInline , } ) ; bundleByType . set ( bundle . type , bundle ) ; siblingBundles . push ( bundle ) ; bundleRoots . set ( bundle , [ asset ] ) ; bundlesByEntryAsset . set ( asset , bundle ) ; bundleGraph . createAssetReference ( dependency , asset ) ; bundleGraph . createBundleReference ( parentBundle , bundle ) ; bundleGraph . addBundleToBundleGroup ( bundle , bundleGroup ) ; } if ( ! siblings ) { siblingBundlesByAsset . set ( asset . id , [ ] ) ; } } return { ... context , parentNode : node , } ; } , } ) ; for ( let [ bundle , rootAssets ] of bundleRoots ) { for ( let asset of rootAssets ) { bundleGraph . addAssetGraphToBundle ( asset , bundle ) ; } } }
6.
6 .
// Step 1: create bundles for each of the explicit code split points. // If any sibling bundles were created for this asset or its subtree previously, // add them all to the current bundle group as well. This fixes cases where two entries // depend on a shared asset which has siblings. Due to DFS, the subtree of the shared // asset is only processed once, meaning any sibling bundles created due to type changes // would only be connected to the first bundle group. To work around this, we store a list // of sibling bundles for each asset in the graph, and when we re-visit a shared asset, we // connect them all to the current bundle group as well. // Propagate the same siblings further if there are no bundles being created in this // asset group, otherwise start a new set of siblings. // If a bundle of this type has already been created in this group, // merge this subgraph into it.