Home / File/ clone.js — svelte Source File

clone.js — svelte Source File

Architecture documentation for clone.js, a javascript file in the svelte codebase. 3 imports, 6 dependents.

File javascript SharedInternal BitFlags 3 imports 6 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  258b696c_d923_7010_457a_b58908a057b0["clone.js"]
  91a92bf8_dda4_0433_1381_bfdc545a4813["warnings.js"]
  258b696c_d923_7010_457a_b58908a057b0 --> 91a92bf8_dda4_0433_1381_bfdc545a4813
  cb946435_ce66_d1e8_6bee_287bdb07e7c5["utils.js"]
  258b696c_d923_7010_457a_b58908a057b0 --> cb946435_ce66_d1e8_6bee_287bdb07e7c5
  c9866d91_a204_fa55_a9e3_6bcc6aaaec1e["esm-env"]
  258b696c_d923_7010_457a_b58908a057b0 --> c9866d91_a204_fa55_a9e3_6bcc6aaaec1e
  2c4e51a4_95e5_a6e4_6aca_e064c05b4c52["console-log.js"]
  2c4e51a4_95e5_a6e4_6aca_e064c05b4c52 --> 258b696c_d923_7010_457a_b58908a057b0
  fc525dc9_b57a_8bf5_77df_6fcfa5373180["debug.js"]
  fc525dc9_b57a_8bf5_77df_6fcfa5373180 --> 258b696c_d923_7010_457a_b58908a057b0
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c["inspect.js"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 258b696c_d923_7010_457a_b58908a057b0
  2696eb67_452f_4c32_3e13_ee172192b366["tracing.js"]
  2696eb67_452f_4c32_3e13_ee172192b366 --> 258b696c_d923_7010_457a_b58908a057b0
  2a3905a9_9aed_830f_4ef5_b2f016321df1["clone.test.ts"]
  2a3905a9_9aed_830f_4ef5_b2f016321df1 --> 258b696c_d923_7010_457a_b58908a057b0
  4469324d_0988_ea58_7534_0c58bd171620["test.ts"]
  4469324d_0988_ea58_7534_0c58bd171620 --> 258b696c_d923_7010_457a_b58908a057b0
  style 258b696c_d923_7010_457a_b58908a057b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Snapshot } from './types' */
import { DEV } from 'esm-env';
import * as w from './warnings.js';
import { get_prototype_of, is_array, object_prototype } from './utils.js';

/**
 * In dev, we keep track of which properties could not be cloned. In prod
 * we don't bother, but we keep a dummy array around so that the
 * signature stays the same
 * @type {string[]}
 */
const empty = [];

/**
 * @template T
 * @param {T} value
 * @param {boolean} [skip_warning]
 * @param {boolean} [no_tojson]
 * @returns {Snapshot<T>}
 */
export function snapshot(value, skip_warning = false, no_tojson = false) {
	if (DEV && !skip_warning) {
		/** @type {string[]} */
		const paths = [];

		const copy = clone(value, new Map(), '', paths, null, no_tojson);
		if (paths.length === 1 && paths[0] === '') {
			// value could not be cloned
			w.state_snapshot_uncloneable();
		} else if (paths.length > 0) {
			// some properties could not be cloned
			const slice = paths.length > 10 ? paths.slice(0, 7) : paths.slice(0, 10);
			const excess = paths.length - slice.length;

			let uncloned = slice.map((path) => `- <value>${path}`).join('\n');
			if (excess > 0) uncloned += `\n- ...and ${excess} more`;

			w.state_snapshot_uncloneable(uncloned);
		}

		return copy;
	}

	return clone(value, new Map(), '', empty, null, no_tojson);
}

/**
 * @template T
 * @param {T} value
 * @param {Map<T, Snapshot<T>>} cloned
 * @param {string} path
 * @param {string[]} paths
 * @param {null | T} [original] The original value, if `value` was produced from a `toJSON` call
 * @param {boolean} [no_tojson]
 * @returns {Snapshot<T>}
 */
function clone(value, cloned, path, paths, original = null, no_tojson = false) {
	if (typeof value === 'object' && value !== null) {
		var unwrapped = cloned.get(value);
		if (unwrapped !== undefined) return unwrapped;
// ... (78 more lines)

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does clone.js do?
clone.js is a source file in the svelte codebase, written in javascript. It belongs to the SharedInternal domain, BitFlags subdomain.
What functions are defined in clone.js?
clone.js defines 2 function(s): clone, snapshot.
What does clone.js depend on?
clone.js imports 3 module(s): esm-env, utils.js, warnings.js.
What files import clone.js?
clone.js is imported by 6 file(s): clone.test.ts, console-log.js, debug.js, inspect.js, test.ts, tracing.js.
Where is clone.js in the architecture?
clone.js is located at packages/svelte/src/internal/shared/clone.js (domain: SharedInternal, subdomain: BitFlags, directory: packages/svelte/src/internal/shared).

Analyze Your Own Codebase

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

Try Supermodel Free