Home / Function/ from_source() — svelte Function Reference

from_source() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f60b5bcd_c389_6937_b4c0_e720a97b643a["from_source()"]
  fd3be7c7_b876_965d_9025_a9b9bd4c6aaf["MappedCode"]
  f60b5bcd_c389_6937_b4c0_e720a97b643a -->|defined in| fd3be7c7_b876_965d_9025_a9b9bd4c6aaf
  860c55db_f911_8bca_7055_338865a9f9b0["processed_tag_to_code()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| f60b5bcd_c389_6937_b4c0_e720a97b643a
  3d6e4414_b36d_fff0_63de_9aea1fab6869["process_tag()"]
  3d6e4414_b36d_fff0_63de_9aea1fab6869 -->|calls| f60b5bcd_c389_6937_b4c0_e720a97b643a
  248beedc_da17_46c9_c5b6_5da6d39a6912["perform_replacements()"]
  248beedc_da17_46c9_c5b6_5da6d39a6912 -->|calls| f60b5bcd_c389_6937_b4c0_e720a97b643a
  style f60b5bcd_c389_6937_b4c0_e720a97b643a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/utils/mapped_code.js lines 216–248

	static from_source({ source, file_basename, get_location }) {
		/**
		 * @type {{ line: number; column: number; }}
		 */
		let offset = get_location(0);
		if (!offset) offset = { line: 0, column: 0 };

		/**
		 * @type {DecodedSourceMap}
		 */
		const map = { version: 3, names: [], sources: [file_basename], mappings: [] };
		if (source == '') return new MappedCode(source, map);
		// we create a high resolution identity map here,
		// we know that it will eventually be merged with svelte's map,
		// at which stage the resolution will decrease.
		const line_list = source.split('\n');
		for (let line = 0; line < line_list.length; line++) {
			map.mappings.push([]);
			const token_list = line_list[line].split(regex_line_token);
			for (let token = 0, column = 0; token < token_list.length; token++) {
				if (token_list[token] == '') continue;
				map.mappings[line].push([column, 0, offset.line + line, column]);
				column += token_list[token].length;
			}
		}
		// shift columns in first line
		const segment_list = map.mappings[0];
		for (let segment = 0; segment < segment_list.length; segment++) {
			// @ts-ignore
			segment_list[segment][3] += offset.column;
		}
		return new MappedCode(source, map);
	}

Domain

Subdomains

Frequently Asked Questions

What does from_source() do?
from_source() is a function in the svelte codebase, defined in packages/svelte/src/compiler/utils/mapped_code.js.
Where is from_source() defined?
from_source() is defined in packages/svelte/src/compiler/utils/mapped_code.js at line 216.
What calls from_source()?
from_source() is called by 3 function(s): perform_replacements, process_tag, processed_tag_to_code.

Analyze Your Own Codebase

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

Try Supermodel Free