Home / Function/ constructor() — svelte Function Reference

constructor() — svelte Function Reference

Architecture documentation for the constructor() function in scope.js from the svelte codebase.

Function javascript Compiler Transformer calls 6 called by 2

Entity Profile

Dependency Diagram

graph TD
  f210eacb_3b9d_eacc_7972_c1f662fc4971["constructor()"]
  75e24897_71a6_47b0_c9ce_ac2a920efd8d["Evaluation"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|defined in| 75e24897_71a6_47b0_c9ce_ac2a920efd8d
  db5e38b6_b71a_4de0_9a78_473b4ad0ae61["constructor()"]
  db5e38b6_b71a_4de0_9a78_473b4ad0ae61 -->|calls| f210eacb_3b9d_eacc_7972_c1f662fc4971
  faf48316_d52b_c5ac_aace_d8f693259b44["constructor()"]
  faf48316_d52b_c5ac_aace_d8f693259b44 -->|calls| f210eacb_3b9d_eacc_7972_c1f662fc4971
  627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098
  bed91719_d047_2256_e199_ee875d5f49b9["get_rune()"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|calls| bed91719_d047_2256_e199_ee875d5f49b9
  c460607c_df6f_f0bc_cf31_b4c25e6d1506["evaluate()"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|calls| c460607c_df6f_f0bc_cf31_b4c25e6d1506
  ba561e41_fdf9_83e5_4af2_dc4ce1c21987["get_global_keypath()"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|calls| ba561e41_fdf9_83e5_4af2_dc4ce1c21987
  96840921_f43d_a26b_1d2e_cd28c0fd6d73["is_rune()"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|calls| 96840921_f43d_a26b_1d2e_cd28c0fd6d73
  db5e38b6_b71a_4de0_9a78_473b4ad0ae61["constructor()"]
  f210eacb_3b9d_eacc_7972_c1f662fc4971 -->|calls| db5e38b6_b71a_4de0_9a78_473b4ad0ae61
  style f210eacb_3b9d_eacc_7972_c1f662fc4971 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/scope.js lines 257–596

	constructor(scope, expression, values) {
		current_evaluations.set(expression, this);

		this.values = values;

		switch (expression.type) {
			case 'Literal': {
				this.values.add(expression.value);
				break;
			}

			case 'Identifier': {
				const binding = scope.get(expression.name);

				if (binding) {
					if (
						binding.initial?.type === 'CallExpression' &&
						get_rune(binding.initial, scope) === '$props.id'
					) {
						this.values.add(STRING);
						break;
					}

					const is_prop =
						binding.kind === 'prop' ||
						binding.kind === 'rest_prop' ||
						binding.kind === 'bindable_prop';

					if (binding.initial?.type === 'EachBlock' && binding.initial.index === expression.name) {
						this.values.add(NUMBER);
						break;
					}

					if (binding.initial?.type === 'SnippetBlock') {
						this.is_defined = true;
						this.is_known = false;
						this.values.add(UNKNOWN);
						break;
					}

					if (!binding.updated && binding.initial !== null && !is_prop) {
						binding.scope.evaluate(/** @type {Expression} */ (binding.initial), this.values);
						break;
					}
				} else if (expression.name === 'undefined') {
					this.values.add(undefined);
					break;
				}

				// TODO glean what we can from reassignments
				// TODO one day, expose props and imports somehow

				this.values.add(UNKNOWN);
				break;
			}

			case 'BinaryExpression': {
				const a = scope.evaluate(/** @type {Expression} */ (expression.left)); // `left` cannot be `PrivateIdentifier` unless operator is `in`
				const b = scope.evaluate(expression.right);

				if (a.is_known && b.is_known) {
					this.values.add(binary[expression.operator](a.value, b.value));
					break;
				}

				switch (expression.operator) {
					case '!=':
					case '!==':
					case '<':
					case '<=':
					case '>':
					case '>=':
					case '==':
					case '===':
					case 'in':
					case 'instanceof':
						this.values.add(true);
						this.values.add(false);
						break;

					case '%':

Domain

Subdomains

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/scope.js.
Where is constructor() defined?
constructor() is defined in packages/svelte/src/compiler/phases/scope.js at line 257.
What does constructor() call?
constructor() calls 6 function(s): constructor, evaluate, get, get_global_keypath, get_rune, is_rune.
What calls constructor()?
constructor() is called by 2 function(s): constructor, constructor.

Analyze Your Own Codebase

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

Try Supermodel Free