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

Code before:
			return error(
				errorFailedValidation(
					`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`
				)
			);
		}
		const consumedChunk: ConsumedChunk = {
			fileName: emittedChunk.fileName,
			module: null,
			name: emittedChunk.name || emittedChunk.id,
			referenceId: '',
			type: 'chunk'
		};
		this.graph.moduleLoader
			.emitChunk(emittedChunk as unknown as EmittedChunk)
			.then(module => (consumedChunk.module = module))
			.catch(() => {
				// Avoid unhandled Promise rejection as the error will be thrown later
				// once module loading has finished
			});

		return this.assignReferenceId(consumedChunk, emittedChunk.id);
	}

	private emitPrebuiltChunk(
		emitPrebuiltChunk: Omit<EmittedFile, 'fileName' | 'name'> &
			Pick<EmittedPrebuiltChunk, 'exports' | 'map'>
	): string {
		if (typeof emitPrebuiltChunk.code !== 'string') {
			return error(
				errorFailedValidation(
					`Emitted prebuilt chunks need to have a valid string code, received "${emitPrebuiltChunk.code}"`
				)
			);
		}
		if (
			typeof emitPrebuiltChunk.fileName !== 'string' ||
			!(
				typeof emitPrebuiltChunk.fileName === 'string' &&
				!isPathFragment(emitPrebuiltChunk.fileName)
			)
		) {
			return error(
				errorFailedValidation(
					`Emitted prebuilt chunks need to have a valid string fileName and that is neither absolute nor relative paths, received "${emitPrebuiltChunk.fileName}"`
				)
			);
		}
		const consumedPrebuiltChunk: ConsumedPrebuiltChunk = {
			code: emitPrebuiltChunk.code,
			exports: emitPrebuiltChunk.exports,

Review comment (suggestion):
Both validations should be covered in separate `function` tests, cf. e.g. `test/function/samples/emit-file/invalid-asset-name` for where to place them and what they could look like.

Code after:
				)
			);
		}
		const consumedChunk: ConsumedChunk = {
			fileName: emittedChunk.fileName,
			module: null,
			name: emittedChunk.name || emittedChunk.id,
			referenceId: '',
			type: 'chunk'
		};
		this.graph.moduleLoader
			.emitChunk(emittedChunk as unknown as EmittedChunk)
			.then(module => (consumedChunk.module = module))
			.catch(() => {
				// Avoid unhandled Promise rejection as the error will be thrown later
				// once module loading has finished
			});

		return this.assignReferenceId(consumedChunk, emittedChunk.id);
	}

	private emitPrebuiltChunk(
		emitPrebuiltChunk: Omit<EmittedFile, 'fileName' | 'name'> &
			Pick<EmittedPrebuiltChunk, 'exports' | 'map'>
	): string {
		if (typeof emitPrebuiltChunk.code !== 'string') {
			return error(
				errorFailedValidation(
					`Emitted prebuilt chunks need to have a valid string code, received "${emitPrebuiltChunk.code}".`
				)
			);
		}
		if (
			typeof emitPrebuiltChunk.fileName !== 'string' ||
			isPathFragment(emitPrebuiltChunk.fileName)
		) {
			return error(
				errorFailedValidation(
					`The "fileName" property of emitted prebuilt chunks must be strings that are neither absolute nor relative paths, received "${emitPrebuiltChunk.fileName}".`
				)
			);
		}
		const consumedPrebuiltChunk: ConsumedPrebuiltChunk = {
			code: emitPrebuiltChunk.code,
			exports: emitPrebuiltChunk.exports,
			fileName: emitPrebuiltChunk.fileName,
			map: emitPrebuiltChunk.map,
			referenceId: '',
			type: 'prebuilt-chunk'
		};
		const referenceId = this.assignReferenceId(