MCPcopy
hub / github.com/webpack/webpack / getChildrenOfTypeInOrder

Method getChildrenOfTypeInOrder

lib/Chunk.js:849–889  ·  view source on GitHub ↗

* Gets children of type in order. * @param {ChunkGraph} chunkGraph the chunk graph * @param {string} type option name * @returns {ChunkChildOfTypeInOrder[] | undefined} referenced chunks for a specific type

(chunkGraph, type)

Source from the content-addressed store, hash-verified

847 * @returns {ChunkChildOfTypeInOrder[] | undefined} referenced chunks for a specific type
848 */
849 getChildrenOfTypeInOrder(chunkGraph, type) {
850 /** @type {{ order: number, group: ChunkGroup, childGroup: ChunkGroup }[]} */
851 const list = [];
852 for (const group of this.groupsIterable) {
853 for (const childGroup of group.childrenIterable) {
854 const edgeOptions = group.getChildOrderOptions(childGroup, chunkGraph);
855 const order = edgeOptions[type];
856 if (order === undefined) continue;
857 list.push({
858 order,
859 group,
860 childGroup
861 });
862 }
863 }
864 if (list.length === 0) return;
865 list.sort((a, b) => {
866 const cmp = b.order - a.order;
867 if (cmp !== 0) return cmp;
868 return a.group.compareTo(chunkGraph, b.group);
869 });
870 /** @type {ChunkChildOfTypeInOrder[]} */
871 const result = [];
872 /** @type {undefined | ChunkChildOfTypeInOrder} */
873 let lastEntry;
874 for (const { group, childGroup } of list) {
875 if (lastEntry && lastEntry.onChunks === group.chunks) {
876 for (const chunk of childGroup.chunks) {
877 lastEntry.chunks.add(chunk);
878 }
879 } else {
880 result.push(
881 (lastEntry = {
882 onChunks: group.chunks,
883 chunks: new Set(childGroup.chunks)
884 })
885 );
886 }
887 }
888 return result;
889 }
890
891 /**
892 * Gets child ids by orders map.

Callers 1

applyMethod · 0.80

Calls 5

getChildOrderOptionsMethod · 0.80
sortMethod · 0.80
pushMethod · 0.45
compareToMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected