diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index c456ad21f47..3186f6912a1 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -1,6 +1,7 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; import { getOrCreate } from './getOrCreate'; +import { concatLazy } from './iterators'; import relativeId from './relativeId'; import { timeEnd, timeStart } from './timers'; @@ -331,15 +332,8 @@ function mergeSignatures(sourceSignature: string, targetSignature: string): stri return signature; } -function* concatLazy(...iterators: Iterable[]) { - for (const iterator of iterators) { - yield* iterator; - } -} - // DEBUGGING HELPERS, REMOVED BY TREE-SHAKING /* eslint-disable @typescript-eslint/no-unused-vars */ - const relativeModuleId = (module: Module) => relativeId(module.id); const printModuleMap = (label: string, map: DependentModuleMap) => diff --git a/src/utils/iterators.ts b/src/utils/iterators.ts new file mode 100644 index 00000000000..afbe9eb1850 --- /dev/null +++ b/src/utils/iterators.ts @@ -0,0 +1,10 @@ +/** + * Concatenate a number of iterables to a new iterable without fully evaluating + * their iterators. Useful when e.g. working with large sets or lists and when + * there is a chance that the iterators will not be fully exhausted. + */ +export function* concatLazy(...iterables: Iterable[]) { + for (const iterable of iterables) { + yield* iterable; + } +}