Home / File/ html_equal.js — svelte Source File

html_equal.js — svelte Source File

Architecture documentation for html_equal.js, a javascript file in the svelte codebase. 2 imports, 5 dependents.

File javascript BuildSystem QualityControl 2 imports 5 dependents 5 functions

Entity Profile

Dependency Diagram

graph LR
  7e13368c_af2f_099c_e7e1_de404629548f["html_equal.js"]
  54c2bfce_50b6_b8cc_4371_e1e14f283fb3["constants"]
  7e13368c_af2f_099c_e7e1_de404629548f --> 54c2bfce_50b6_b8cc_4371_e1e14f283fb3
  b63ddb92_634c_990b_eb1b_0bad8a4d434e["vitest"]
  7e13368c_af2f_099c_e7e1_de404629548f --> b63ddb92_634c_990b_eb1b_0bad8a4d434e
  56007373_5cb4_276b_8066_2e61ad5747d2["test.ts"]
  56007373_5cb4_276b_8066_2e61ad5747d2 --> 7e13368c_af2f_099c_e7e1_de404629548f
  241c2922_c732_530f_f92d_772220952a6f["test.ts"]
  241c2922_c732_530f_f92d_772220952a6f --> 7e13368c_af2f_099c_e7e1_de404629548f
  42f0f097_4458_875b_c920_692659ecc7f1["test-ssr.ts"]
  42f0f097_4458_875b_c920_692659ecc7f1 --> 7e13368c_af2f_099c_e7e1_de404629548f
  2cf8977f_8bb9_9ef1_6e90_d6eea1dac831["shared.ts"]
  2cf8977f_8bb9_9ef1_6e90_d6eea1dac831 --> 7e13368c_af2f_099c_e7e1_de404629548f
  e19cfbe3_ca82_459d_0cfe_63f6bb4739fd["test.ts"]
  e19cfbe3_ca82_459d_0cfe_63f6bb4739fd --> 7e13368c_af2f_099c_e7e1_de404629548f
  style 7e13368c_af2f_099c_e7e1_de404629548f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { COMMENT_NODE, ELEMENT_NODE, TEXT_NODE } from '#client/constants';
import { assert } from 'vitest';

/**
 * @param {Element} node
 * @param {{ preserveComments: boolean }} opts
 */
function clean_children(node, opts) {
	let previous = null;
	let has_element_children = false;
	let template =
		node.nodeName.toUpperCase() === 'TEMPLATE'
			? /** @type {HTMLTemplateElement} */ (node)
			: undefined;

	if (template) {
		const div = document.createElement('div');
		div.append(template.content);
		node = div;
	}

	// sort attributes
	const attributes = Array.from(node.attributes).sort((a, b) => {
		return a.name < b.name ? -1 : 1;
	});

	attributes.forEach((attr) => {
		if (attr.name !== 'xmlns') node.removeAttribute(attr.name);
	});

	attributes.forEach(({ name, value }) => {
		// Strip out the special onload/onerror hydration events from the test output
		if (['onload', 'onerror', 'xmlns'].includes(name) && value === 'this.__e=event') {
			return;
		}

		if (name === 'class') {
			value = value.replace(/svelte-\w+/, 'svelte-xyz123');
		}

		node.setAttribute(name, value);
	});

	for (let child of [...node.childNodes]) {
		if (child.nodeType === TEXT_NODE) {
			let text = /** @type {Text} */ (child);

			if (
				node.namespaceURI === 'http://www.w3.org/2000/svg' &&
				node.tagName !== 'text' &&
				node.tagName !== 'tspan'
			) {
				node.removeChild(child);
				continue;
			}

			text.data = text.data.replace(/[^\S]+/g, ' ');

			if (previous && previous.nodeType === TEXT_NODE) {
				const prev = /** @type {Text} */ (previous);
// ... (133 more lines)

Domain

Subdomains

Dependencies

  • constants
  • vitest

Frequently Asked Questions

What does html_equal.js do?
html_equal.js is a source file in the svelte codebase, written in javascript. It belongs to the BuildSystem domain, QualityControl subdomain.
What functions are defined in html_equal.js?
html_equal.js defines 5 function(s): assert_html_equal, assert_html_equal_with_options, clean_children, normalize_html, normalize_new_line.
What does html_equal.js depend on?
html_equal.js imports 2 module(s): constants, vitest.
What files import html_equal.js?
html_equal.js is imported by 5 file(s): shared.ts, test-ssr.ts, test.ts, test.ts, test.ts.
Where is html_equal.js in the architecture?
html_equal.js is located at packages/svelte/tests/html_equal.js (domain: BuildSystem, subdomain: QualityControl, directory: packages/svelte/tests).

Analyze Your Own Codebase

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

Try Supermodel Free