Home / Function/ stringify() — svelte Function Reference

stringify() — svelte Function Reference

Architecture documentation for the stringify() function in template.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  aa03984a_4f5e_a389_0597_87262d57992f["stringify()"]
  c3ec4c82_ce35_6219_c232_12ebeea91443["template.js"]
  aa03984a_4f5e_a389_0597_87262d57992f -->|defined in| c3ec4c82_ce35_6219_c232_12ebeea91443
  d6dfd043_7103_f2c7_aab3_9660fb0a5f75["escape_html()"]
  aa03984a_4f5e_a389_0597_87262d57992f -->|calls| d6dfd043_7103_f2c7_aab3_9660fb0a5f75
  02a8b5a2_13c5_e5b3_1ed2_617763d0904d["is_void()"]
  aa03984a_4f5e_a389_0597_87262d57992f -->|calls| 02a8b5a2_13c5_e5b3_1ed2_617763d0904d
  style aa03984a_4f5e_a389_0597_87262d57992f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/3-transform/client/transform-template/template.js lines 89–116

function stringify(item) {
	if (item.type === 'text') {
		return item.nodes.map((node) => node.raw).join('');
	}

	if (item.type === 'comment') {
		return item.data ? `<!--${item.data}-->` : '<!>';
	}

	let str = `<${item.name}`;

	for (const key in item.attributes) {
		const value = item.attributes[key];

		str += ` ${key}`;
		if (value !== undefined) str += `="${escape_html(value, true)}"`;
	}

	if (is_void(item.name)) {
		str += '/>'; // XHTML compliance
	} else {
		str += `>`;
		str += item.children.map(stringify).join('');
		str += `</${item.name}>`;
	}

	return str;
}

Domain

Subdomains

Frequently Asked Questions

What does stringify() do?
stringify() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/transform-template/template.js.
Where is stringify() defined?
stringify() is defined in packages/svelte/src/compiler/phases/3-transform/client/transform-template/template.js at line 89.
What does stringify() call?
stringify() calls 2 function(s): escape_html, is_void.

Analyze Your Own Codebase

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

Try Supermodel Free