Home / Function/ objectify() — svelte Function Reference

objectify() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  0fd55df7_d42b_749b_3540_f01acd512085["objectify()"]
  c3ec4c82_ce35_6219_c232_12ebeea91443["template.js"]
  0fd55df7_d42b_749b_3540_f01acd512085 -->|defined in| c3ec4c82_ce35_6219_c232_12ebeea91443
  eb20d11e_39a8_398a_4e2c_12accd39ccdd["fix_attribute_casing()"]
  0fd55df7_d42b_749b_3540_f01acd512085 -->|calls| eb20d11e_39a8_398a_4e2c_12accd39ccdd
  style 0fd55df7_d42b_749b_3540_f01acd512085 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/3-transform/client/transform-template/template.js lines 119–162

function objectify(item) {
	if (item.type === 'text') {
		return b.literal(item.nodes.map((node) => node.data).join(''));
	}

	if (item.type === 'comment') {
		return item.data ? b.array([b.literal(`// ${item.data}`)]) : null;
	}

	const element = b.array([b.literal(item.name)]);

	const attributes = b.object([]);

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

		attributes.properties.push(
			b.prop(
				'init',
				b.key(fix_attribute_casing(key)),
				value === undefined ? b.void0 : b.literal(value)
			)
		);
	}

	if (attributes.properties.length > 0 || item.children.length > 0) {
		element.elements.push(attributes.properties.length > 0 ? attributes : b.null);
	}

	if (item.children.length > 0) {
		const children = item.children.map(objectify);
		element.elements.push(...children);

		// special case — strip leading newline from `<pre>` and `<textarea>`
		if (item.name === 'pre' || item.name === 'textarea') {
			const first = children[0];
			if (first?.type === 'Literal') {
				first.value = /** @type {string} */ (first.value).replace(regex_starts_with_newline, '');
			}
		}
	}

	return element;
}

Domain

Subdomains

Frequently Asked Questions

What does objectify() do?
objectify() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/transform-template/template.js.
Where is objectify() defined?
objectify() is defined in packages/svelte/src/compiler/phases/3-transform/client/transform-template/template.js at line 119.
What does objectify() call?
objectify() calls 1 function(s): fix_attribute_casing.

Analyze Your Own Codebase

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

Try Supermodel Free