Repository: rollup/rollup
File: src/utils/chunkAssignment.ts (TypeScript)

Code before:
		const awaitedDynamicImportsForCurrentEntry = new Set<Module>();
		dynamicImportModulesByEntry[entryIndex] = dynamicImportsForCurrentEntry;
		awaitedDynamicImportModulesByEntry[entryIndex] = awaitedDynamicImportsForCurrentEntry;
		const modulesToHandle = new Set([currentEntry]);
		for (const module of modulesToHandle) {
			getOrCreate(dependentEntriesByModule, module, getNewSet<number>).add(entryIndex);
			for (const dependency of module.getDependenciesToBeIncluded()) {
				if (!(dependency instanceof ExternalModule)) {
					modulesToHandle.add(dependency);
				}
			}
			for (const { resolution } of module.dynamicImports) {
				if (
					resolution instanceof Module &&
					resolution.includedDynamicImporters.length > 0 &&
					!allEntriesSet.has(resolution)
				) {
					dynamicEntryModules.add(resolution);
					allEntriesSet.add(resolution);
					dynamicImportsForCurrentEntry.add(resolution);
					for (const includedDirectTopLevelAwaitingDynamicImporter of resolution.includedDirectTopLevelAwaitingDynamicImporters) {
						if (modulesToHandle.has(includedDirectTopLevelAwaitingDynamicImporter)) {
							awaitedDynamicEntryModules.add(resolution);
							awaitedDynamicImportsForCurrentEntry.add(resolution);
							break;
						}
					}
				}
			}
			for (const dependency of module.implicitlyLoadedBefore) {
				if (!allEntriesSet.has(dependency)) {
					dynamicEntryModules.add(dependency);
					allEntriesSet.add(dependency);
				}
			}
		}
		entryIndex++;
	}
	const allEntries = [...allEntriesSet];
	const {
		awaitedDynamicEntries,
		awaitedDynamicImportsByEntry,
		dynamicEntries,
		dynamicImportsByEntry
	} = getDynamicEntries(
		allEntries,
		dynamicEntryModules,
		dynamicImportModulesByEntry,
		awaitedDynamicEntryModules,
		awaitedDynamicImportModulesByEntry
	);

Review comment (suggestion):
Looks good to me, thanks! I needed to think about this for a moment, maybe we want to rename `modulesToHandle` to something like `staticDependencies`, that would clarify that this is not just a transient Set but really has a meaning. Otherwise, this looks fine to me.

Code after:
		const awaitedDynamicImportsForCurrentEntry = new Set<Module>();
		dynamicImportModulesByEntry[entryIndex] = dynamicImportsForCurrentEntry;
		awaitedDynamicImportModulesByEntry[entryIndex] = awaitedDynamicImportsForCurrentEntry;
		const staticDependencies = new Set([currentEntry]);
		for (const module of staticDependencies) {
			getOrCreate(dependentEntriesByModule, module, getNewSet<number>).add(entryIndex);
			for (const dependency of module.getDependenciesToBeIncluded()) {
				if (!(dependency instanceof ExternalModule)) {
					staticDependencies.add(dependency);
				}
			}
			for (const { resolution } of module.dynamicImports) {
				if (
					resolution instanceof Module &&
					resolution.includedDynamicImporters.length > 0 &&
					!allEntriesSet.has(resolution)
				) {
					dynamicEntryModules.add(resolution);
					allEntriesSet.add(resolution);
					dynamicImportsForCurrentEntry.add(resolution);
					for (const includedDirectTopLevelAwaitingDynamicImporter of resolution.includedDirectTopLevelAwaitingDynamicImporters) {
						if (staticDependencies.has(includedDirectTopLevelAwaitingDynamicImporter)) {
							awaitedDynamicEntryModules.add(resolution);
							awaitedDynamicImportsForCurrentEntry.add(resolution);
							break;
						}
					}
				}
			}
			for (const dependency of module.implicitlyLoadedBefore) {
				if (!allEntriesSet.has(dependency)) {
					dynamicEntryModules.add(dependency);
					allEntriesSet.add(dependency);
				}
			}
		}
		entryIndex++;
	}
	const allEntries = [...allEntriesSet];
	const {
		awaitedDynamicEntries,
		awaitedDynamicImportsByEntry,
		dynamicEntries,
		dynamicImportsByEntry
	} = getDynamicEntries(
		allEntries,
		dynamicEntryModules,
		dynamicImportModulesByEntry,
		awaitedDynamicEntryModules,
		awaitedDynamicImportModulesByEntry
	);