Repository: webpack/webpack
File: lib/css/CssGenerator.js (JavaScript)

Code before:
				dependency,
				initFragments,
				source,
				generateContext
			);
		}

		if (module.presentationalDependencies !== undefined) {
			for (const dependency of module.presentationalDependencies) {
				this.sourceDependency(
					module,
					dependency,
					initFragments,
					source,
					generateContext
				);
			}
		}
	}

	/**
	 * @param {NormalModule} module module for which the code should be generated
	 * @param {GenerateContext} generateContext context for generate
	 * @returns {Source | null} generated code
	 */
	generate(module, generateContext) {
		const exportType = /** @type {BuildMeta} */ (module.buildMeta).exportType;
		const source =
			generateContext.type === "javascript"
				? exportType === "link"
					? new ReplaceSource(new RawSource(""))
					: new ReplaceSource(/** @type {Source} */ (module.originalSource()))
				: new ReplaceSource(/** @type {Source} */ (module.originalSource()));

		/** @type {InitFragment<GenerateContext>[]} */
		const initFragments = [];
		/** @type {CssData} */
		const cssData = {
			esModule: /** @type {boolean} */ (this._esModule),
			exports: new Map()
		};

		// TODO avoid multiple rendering
		this.sourceModule(module, initFragments, source, {
			...generateContext,
			cssData
		});

		/**
		 * @returns {string | null} the default export
		 */

Review comment (refactor):
Looks good now, but I think we will need to refactor it after implementation of all export types, maybe simplify it

Code after:
		const isEmpty =
			generateContext.type === "javascript" && exportType === "link";

		if (!this._sourceModuleCache.has(generateContext.runtimeRequirements)) {
			this._sourceModuleCache.set(
				generateContext.runtimeRequirements,
				/** @type {Source[]} */ ([])
			);
		}

		const cachedIndex = isEmpty ? 0 : 1;
		const cachedSource = /** @type {Source[]} */ (
			this._sourceModuleCache.get(generateContext.runtimeRequirements)
		)[cachedIndex];
		if (cachedSource) {
			return /** @type {ReplaceSource} */ (cachedSource);
		}
		const source = isEmpty
			? new ReplaceSource(new RawSource(""))
			: new ReplaceSource(/** @type {Source} */ (module.originalSource()));
		this._sourceModule(module, initFragments, source, generateContext);
		/** @type {Source[]} */ (
			this._sourceModuleCache.get(generateContext.runtimeRequirements)
		)[cachedIndex] = source;
		return source;
	}

	/**
	 * @param {NormalModule} module the module to generate
	 * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
	 * @param {ReplaceSource} source the current replace source which can be modified
	 * @param {GenerateContext & { cssData: CssData }} generateContext the generateContext
	 * @returns {void}
	 */
	_sourceModule(module, initFragments, source, generateContext) {
		for (const dependency of module.dependencies) {
			this.sourceDependency(
				module,
				dependency,
				initFragments,
				source,
				generateContext
			);
		}

		if (module.presentationalDependencies !== undefined) {
			for (const dependency of module.presentationalDependencies) {
				this.sourceDependency(
					module,
					dependency,
					initFragments,