Home / Function/ preprocess() — svelte Function Reference

preprocess() — svelte Function Reference

Architecture documentation for the preprocess() function in index.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  a7a70deb_64ca_bb14_028e_9cb3aec87b0f["preprocess()"]
  ccf6927a_1f1b_1dda_8616_80903a72ba16["index.js"]
  a7a70deb_64ca_bb14_028e_9cb3aec87b0f -->|defined in| ccf6927a_1f1b_1dda_8616_80903a72ba16
  eb4cb57f_c661_15ec_a226_3092a5663cd9["update_source()"]
  a7a70deb_64ca_bb14_028e_9cb3aec87b0f -->|calls| eb4cb57f_c661_15ec_a226_3092a5663cd9
  73c08b55_6e10_e124_8f2b_318220995bf0["process_markup()"]
  a7a70deb_64ca_bb14_028e_9cb3aec87b0f -->|calls| 73c08b55_6e10_e124_8f2b_318220995bf0
  3d6e4414_b36d_fff0_63de_9aea1fab6869["process_tag()"]
  a7a70deb_64ca_bb14_028e_9cb3aec87b0f -->|calls| 3d6e4414_b36d_fff0_63de_9aea1fab6869
  d378c79f_a5b8_3e96_866c_2dfa63c43532["to_processed()"]
  a7a70deb_64ca_bb14_028e_9cb3aec87b0f -->|calls| d378c79f_a5b8_3e96_866c_2dfa63c43532
  style a7a70deb_64ca_bb14_028e_9cb3aec87b0f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/preprocess/index.js lines 338–368

export default async function preprocess(source, preprocessor, options) {
	/**
	 * @type {string | undefined}
	 */
	const filename = (options && options.filename) || /** @type {any} */ (preprocessor).filename; // legacy
	const preprocessors = preprocessor
		? Array.isArray(preprocessor)
			? preprocessor
			: [preprocessor]
		: [];
	const result = new PreprocessResult(source, filename);

	// TODO keep track: what preprocessor generated what sourcemap?
	// to make debugging easier = detect low-resolution sourcemaps in fn combine_mappings
	for (const preprocessor of preprocessors) {
		if (preprocessor.markup) {
			// @ts-expect-error TODO there might be a bug in hiding here
			result.update_source(await process_markup(preprocessor.markup, result));
		}
		if (preprocessor.script) {
			// @ts-expect-error TODO there might be a bug in hiding here
			result.update_source(await process_tag('script', preprocessor.script, result));
		}
		if (preprocessor.style) {
			// @ts-expect-error TODO there might be a bug in hiding here
			result.update_source(await process_tag('style', preprocessor.style, result));
		}
	}

	return result.to_processed();
}

Domain

Subdomains

Frequently Asked Questions

What does preprocess() do?
preprocess() is a function in the svelte codebase, defined in packages/svelte/src/compiler/preprocess/index.js.
Where is preprocess() defined?
preprocess() is defined in packages/svelte/src/compiler/preprocess/index.js at line 338.
What does preprocess() call?
preprocess() calls 4 function(s): process_markup, process_tag, to_processed, update_source.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free