Home / Function/ declare() — svelte Function Reference

declare() — svelte Function Reference

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

Function javascript Compiler Transformer calls 3 called by 2

Entity Profile

Dependency Diagram

graph TD
  44642633_e3c9_8ae1_48af_53507481a2cb["declare()"]
  36ef071d_b929_6d90_0038_9f22de99efbe["Scope"]
  44642633_e3c9_8ae1_48af_53507481a2cb -->|defined in| 36ef071d_b929_6d90_0038_9f22de99efbe
  78a6ba9a_5003_f569_a638_76e4f1977809["analyze_component()"]
  78a6ba9a_5003_f569_a638_76e4f1977809 -->|calls| 44642633_e3c9_8ae1_48af_53507481a2cb
  c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f["create_scopes()"]
  c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 44642633_e3c9_8ae1_48af_53507481a2cb
  627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"]
  44642633_e3c9_8ae1_48af_53507481a2cb -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098
  a860293e_8524_0e18_ab7a_f41e0ba8c116["declaration_duplicate()"]
  44642633_e3c9_8ae1_48af_53507481a2cb -->|calls| a860293e_8524_0e18_ab7a_f41e0ba8c116
  962a9e38_f393_8bb8_8642_fd23c4e768e6["validate_identifier_name()"]
  44642633_e3c9_8ae1_48af_53507481a2cb -->|calls| 962a9e38_f393_8bb8_8642_fd23c4e768e6
  style 44642633_e3c9_8ae1_48af_53507481a2cb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/scope.js lines 667–694

	declare(node, kind, declaration_kind, initial = null) {
		if (this.parent) {
			if (declaration_kind === 'var' && this.#porous) {
				return this.parent.declare(node, kind, declaration_kind);
			}

			if (declaration_kind === 'import') {
				return this.parent.declare(node, kind, declaration_kind, initial);
			}
		}

		if (this.declarations.has(node.name)) {
			const binding = this.declarations.get(node.name);
			if (binding && binding.declaration_kind !== 'var' && declaration_kind !== 'var') {
				// This also errors on function types, but that's arguably a good thing
				// declaring function twice is also caught by acorn in the parse phase
				e.declaration_duplicate(node, node.name);
			}
		}

		const binding = new Binding(this, node, kind, declaration_kind, initial);

		validate_identifier_name(binding, this.function_depth);

		this.declarations.set(node.name, binding);
		this.root.conflicts.add(node.name);
		return binding;
	}

Domain

Subdomains

Frequently Asked Questions

What does declare() do?
declare() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/scope.js.
Where is declare() defined?
declare() is defined in packages/svelte/src/compiler/phases/scope.js at line 667.
What does declare() call?
declare() calls 3 function(s): declaration_duplicate, get, validate_identifier_name.
What calls declare()?
declare() is called by 2 function(s): analyze_component, create_scopes.

Analyze Your Own Codebase

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

Try Supermodel Free