Home / Function/ combine_sourcemaps() — svelte Function Reference

combine_sourcemaps() — svelte Function Reference

Architecture documentation for the combine_sourcemaps() function in mapped_code.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  c005db55_c14e_aa09_dbae_d0b302ec93df["combine_sourcemaps()"]
  d383a41d_5383_ee86_cab6_03bf1a2daf93["mapped_code.js"]
  c005db55_c14e_aa09_dbae_d0b302ec93df -->|defined in| d383a41d_5383_ee86_cab6_03bf1a2daf93
  d378c79f_a5b8_3e96_866c_2dfa63c43532["to_processed()"]
  d378c79f_a5b8_3e96_866c_2dfa63c43532 -->|calls| c005db55_c14e_aa09_dbae_d0b302ec93df
  75dd917c_6b23_2b41_3ed7_e5aa56348c12["apply_preprocessor_sourcemap()"]
  75dd917c_6b23_2b41_3ed7_e5aa56348c12 -->|calls| c005db55_c14e_aa09_dbae_d0b302ec93df
  style c005db55_c14e_aa09_dbae_d0b302ec93df fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/utils/mapped_code.js lines 265–300

export function combine_sourcemaps(filename, sourcemap_list) {
	if (sourcemap_list.length == 0) return null;
	let map_idx = 1;
	const map =
		sourcemap_list.slice(0, -1).find((m) => m.sources.length !== 1) === undefined
			? remapping(
					// use array interface
					// only the oldest sourcemap can have multiple sources
					sourcemap_list,
					() => null,
					true // skip optional field `sourcesContent`
				)
			: remapping(
					// use loader interface
					sourcemap_list[0], // last map
					(sourcefile) => {
						// TODO the equality check assumes that the preprocessor map has the input file as a relative path in sources,
						// e.g. when the input file is `src/foo/bar.svelte`, then sources is expected to contain just `bar.svelte`.
						// Therefore filename also needs to be the basename of the path. This feels brittle, investigate how we can
						// harden this (without breaking other tooling that assumes this behavior).
						if (sourcefile === filename && sourcemap_list[map_idx]) {
							return sourcemap_list[map_idx++]; // idx 1, 2, ...
							// bundle file = branch node
						} else {
							return null; // source file = leaf node
						}
					},
					true
				);
	if (!map.file) delete map.file; // skip optional field `file`
	// When source maps are combined and the leading map is empty, sources is not set.
	// Add the filename to the empty array in this case.
	// Further improvements to remapping may help address this as well https://github.com/ampproject/remapping/issues/116
	if (!map.sources.length) map.sources = [filename];
	return map;
}

Domain

Subdomains

Frequently Asked Questions

What does combine_sourcemaps() do?
combine_sourcemaps() is a function in the svelte codebase, defined in packages/svelte/src/compiler/utils/mapped_code.js.
Where is combine_sourcemaps() defined?
combine_sourcemaps() is defined in packages/svelte/src/compiler/utils/mapped_code.js at line 265.
What calls combine_sourcemaps()?
combine_sourcemaps() is called by 2 function(s): apply_preprocessor_sourcemap, to_processed.

Analyze Your Own Codebase

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

Try Supermodel Free