Home / Function/ clean() — svelte Function Reference

clean() — svelte Function Reference

Architecture documentation for the clean() function in test.ts from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  a48ae09e_4024_be58_0fa6_568d48cad2b9["clean()"]
  06412a1c_8774_5d98_ab1d_ba86fd568d32["test.ts"]
  a48ae09e_4024_be58_0fa6_568d48cad2b9 -->|defined in| 06412a1c_8774_5d98_ab1d_ba86fd568d32
  style a48ae09e_4024_be58_0fa6_568d48cad2b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/tests/parser-modern/test.ts lines 59–118

function clean(ast: AST.SvelteNode) {
	return walk(ast, null, {
		_(node, context) {
			// @ts-ignore
			delete node.start;
			// @ts-ignore
			delete node.end;
			// @ts-ignore
			delete node.loc;
			// @ts-ignore
			delete node.name_loc;
			// @ts-ignore
			delete node.leadingComments;
			// @ts-ignore
			delete node.trailingComments;

			context.next();
		},
		StyleSheet(node, context) {
			return {
				type: node.type,
				attributes: node.attributes.map((attribute) => context.visit(attribute)),
				children: node.children.map((child) => context.visit(child)),
				content: {}
			} as AST.SvelteNode;
		},
		Fragment(node, context) {
			const nodes: AST.SvelteNode[] = [];

			for (let i = 0; i < node.nodes.length; i += 1) {
				let child = node.nodes[i];

				if (child.type === 'Text') {
					child = {
						...child,
						// trim multiple whitespace to single space
						data: child.data.replace(/[^\S]+/g, ' '),
						raw: child.raw.replace(/[^\S]+/g, ' ')
					};

					if (i === 0) {
						child.data = child.data.trimStart();
						child.raw = child.raw.trimStart();
					}

					if (i === node.nodes.length - 1) {
						child.data = child.data.trimEnd();
						child.raw = child.raw.trimEnd();
					}

					if (child.data === '') continue;
				}

				nodes.push(context.visit(child));
			}

			return { ...node, nodes } as AST.Fragment;
		}
	});
}

Domain

Subdomains

Frequently Asked Questions

What does clean() do?
clean() is a function in the svelte codebase, defined in packages/svelte/tests/parser-modern/test.ts.
Where is clean() defined?
clean() is defined in packages/svelte/tests/parser-modern/test.ts at line 59.

Analyze Your Own Codebase

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

Try Supermodel Free