Home / Function/ processed_tag_to_code() — svelte Function Reference

processed_tag_to_code() — svelte Function Reference

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

Function javascript Compiler Migrator calls 7 called by 1

Entity Profile

Dependency Diagram

graph TD
  860c55db_f911_8bca_7055_338865a9f9b0["processed_tag_to_code()"]
  ccf6927a_1f1b_1dda_8616_80903a72ba16["index.js"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|defined in| ccf6927a_1f1b_1dda_8616_80903a72ba16
  3d6e4414_b36d_fff0_63de_9aea1fab6869["process_tag()"]
  3d6e4414_b36d_fff0_63de_9aea1fab6869 -->|calls| 860c55db_f911_8bca_7055_338865a9f9b0
  f60b5bcd_c389_6937_b4c0_e720a97b643a["from_source()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| f60b5bcd_c389_6937_b4c0_e720a97b643a
  2f8f22ce_6b99_47f9_f47d_9e47a039bde4["slice_source()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| 2f8f22ce_6b99_47f9_f47d_9e47a039bde4
  43e78aae_3ec8_4918_115c_186127bac060["sourcemap_add_offset()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| 43e78aae_3ec8_4918_115c_186127bac060
  0306cc9d_f615_8a46_ac65_f39600cad75c["from_processed()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| 0306cc9d_f615_8a46_ac65_f39600cad75c
  b39edb0f_ea67_1ea3_e86a_954e5131b3cd["parse_attached_sourcemap()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| b39edb0f_ea67_1ea3_e86a_954e5131b3cd
  92d1dbed_c18f_e491_3361_186a20a4d91a["processed_content_to_code()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| 92d1dbed_c18f_e491_3361_186a20a4d91a
  0b0d6cc0_5fd9_5ba4_3426_05a4a4d6e501["concat()"]
  860c55db_f911_8bca_7055_338865a9f9b0 -->|calls| 0b0d6cc0_5fd9_5ba4_3426_05a4a4d6e501
  style 860c55db_f911_8bca_7055_338865a9f9b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/preprocess/index.js lines 137–216

function processed_tag_to_code(
	processed,
	tag_name,
	original_attributes,
	generated_attributes,
	source
) {
	const { file_basename, get_location } = source;

	/**
	 * @param {string} code
	 * @param {number} offset
	 */
	const build_mapped_code = (code, offset) =>
		MappedCode.from_source(slice_source(code, offset, source));

	// To map the open/close tag and content starts positions correctly, we need to
	// differentiate between the original attributes and the generated attributes:
	// `source` contains the original attributes and its get_location maps accordingly.
	const original_tag_open = `<${tag_name}${original_attributes}>`;
	const tag_open = `<${tag_name}${generated_attributes}>`;
	/** @type {MappedCode} */
	let tag_open_code;

	if (original_tag_open.length !== tag_open.length) {
		// Generate a source map for the open tag
		/** @type {DecodedSourceMap['mappings']} */
		const mappings = [
			[
				// start of tag
				[0, 0, 0, 0],
				// end of tag start
				[`<${tag_name}`.length, 0, 0, `<${tag_name}`.length]
			]
		];

		const line = tag_open.split('\n').length - 1;
		const column = tag_open.length - (line === 0 ? 0 : tag_open.lastIndexOf('\n')) - 1;

		while (mappings.length <= line) {
			// end of tag start again, if this is a multi line mapping
			mappings.push([[0, 0, 0, `<${tag_name}`.length]]);
		}

		// end of tag
		mappings[line].push([
			column,
			0,
			original_tag_open.split('\n').length - 1,
			original_tag_open.length - original_tag_open.lastIndexOf('\n') - 1
		]);

		/** @type {DecodedSourceMap} */
		const map = {
			version: 3,
			names: [],
			sources: [file_basename],
			mappings
		};
		sourcemap_add_offset(map, get_location(0), 0);
		tag_open_code = MappedCode.from_processed(tag_open, map);
	} else {
		tag_open_code = build_mapped_code(tag_open, 0);
	}

	const tag_close = `</${tag_name}>`;
	const tag_close_code = build_mapped_code(
		tag_close,
		original_tag_open.length + source.source.length
	);

	parse_attached_sourcemap(processed, tag_name);
	const content_code = processed_content_to_code(
		processed,
		get_location(original_tag_open.length),
		file_basename
	);

	return tag_open_code.concat(content_code).concat(tag_close_code);
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does processed_tag_to_code() do?
processed_tag_to_code() is a function in the svelte codebase, defined in packages/svelte/src/compiler/preprocess/index.js.
Where is processed_tag_to_code() defined?
processed_tag_to_code() is defined in packages/svelte/src/compiler/preprocess/index.js at line 137.
What does processed_tag_to_code() call?
processed_tag_to_code() calls 7 function(s): concat, from_processed, from_source, parse_attached_sourcemap, processed_content_to_code, slice_source, sourcemap_add_offset.
What calls processed_tag_to_code()?
processed_tag_to_code() is called by 1 function(s): process_tag.

Analyze Your Own Codebase

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

Try Supermodel Free