Home / Function/ handle_identifier() — svelte Function Reference

handle_identifier() — svelte Function Reference

Architecture documentation for the handle_identifier() function in index.js from the svelte codebase.

Function javascript Compiler Transformer calls 2 called by 2

Entity Profile

Dependency Diagram

graph TD
  62ad8229_4df7_36d3_2573_07196839bb69["handle_identifier()"]
  cab41022_1b55_3b7a_06c6_b90763bbea47["index.js"]
  62ad8229_4df7_36d3_2573_07196839bb69 -->|defined in| cab41022_1b55_3b7a_06c6_b90763bbea47
  67bd56cb_8c24_e7d8_f5ca_1bc032c1a89b["instance_script.Identifier()"]
  67bd56cb_8c24_e7d8_f5ca_1bc032c1a89b -->|calls| 62ad8229_4df7_36d3_2573_07196839bb69
  73aad8d6_901f_ac43_b6f4_77b2a1ba63e7["template.Identifier()"]
  73aad8d6_901f_ac43_b6f4_77b2a1ba63e7 -->|calls| 62ad8229_4df7_36d3_2573_07196839bb69
  627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"]
  62ad8229_4df7_36d3_2573_07196839bb69 -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098
  8980dd2b_1c7a_2c03_2400_e31c60358534["generate()"]
  62ad8229_4df7_36d3_2573_07196839bb69 -->|calls| 8980dd2b_1c7a_2c03_2400_e31c60358534
  style 62ad8229_4df7_36d3_2573_07196839bb69 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/migrate/index.js lines 1850–1969

function handle_identifier(node, state, path) {
	const parent = path.at(-1);
	if (parent?.type === 'MemberExpression' && parent.property === node) return;

	if (state.analysis.uses_props && node.name !== '$$slots') {
		if (node.name === '$$props' || node.name === '$$restProps') {
			// not 100% correct for $$restProps but it'll do
			state.str.update(
				/** @type {number} */ (node.start),
				/** @type {number} */ (node.end),
				state.names.props
			);
		} else {
			const binding = state.scope.get(node.name);
			if (binding?.kind === 'bindable_prop' && binding.node !== node) {
				state.str.prependLeft(/** @type {number} */ (node.start), `${state.names.props}.`);
			}
		}
	} else if (node.name === '$$restProps' && state.analysis.uses_rest_props) {
		state.str.update(
			/** @type {number} */ (node.start),
			/** @type {number} */ (node.end),
			state.names.rest
		);
	} else if (node.name === '$$slots' && state.analysis.uses_slots) {
		if (parent?.type === 'MemberExpression') {
			if (state.analysis.custom_element) return;

			let name = parent.property.type === 'Literal' ? parent.property.value : parent.property.name;
			let slot_name = name;
			const existing_prop = state.props.find((prop) => prop.slot_name === name);
			if (existing_prop) {
				name = existing_prop.local;
			} else if (name !== 'default') {
				let new_name = state.scope.generate(name);
				if (new_name !== name) {
					throw new MigrationError(
						`This migration would change the name of a slot (${name} to ${new_name}) making the component unusable`
					);
				}
			}

			name = name === 'default' ? 'children' : name;

			if (!existing_prop) {
				state.props.push({
					local: name,
					exported: name,
					init: '',
					bindable: false,
					optional: true,
					slot_name,
					// if it's the first time we encounter this slot
					// we start with any and delegate to when the slot
					// is actually rendered (it might not happen in that case)
					// any is still a safe bet
					type: `import('svelte').Snippet<[any]>`,
					needs_refine_type: true
				});
			}

			state.str.update(
				/** @type {number} */ (node.start),
				parent.property.start,
				state.analysis.uses_props ? `${state.names.props}.` : ''
			);
			state.str.update(parent.property.start, parent.end, name);
		}
		// else passed as identifier, we don't know what to do here, so let it error
	} else if (
		parent?.type === 'TSInterfaceDeclaration' ||
		parent?.type === 'TSTypeAliasDeclaration'
	) {
		const members =
			parent.type === 'TSInterfaceDeclaration' ? parent.body.body : parent.typeAnnotation?.members;
		if (Array.isArray(members)) {
			if (node.name === '$$Props') {
				state.has_type_or_fallback = true;

				for (const member of members) {
					const prop = state.props.find((prop) => prop.exported === member.key.name);

Domain

Subdomains

Frequently Asked Questions

What does handle_identifier() do?
handle_identifier() is a function in the svelte codebase, defined in packages/svelte/src/compiler/migrate/index.js.
Where is handle_identifier() defined?
handle_identifier() is defined in packages/svelte/src/compiler/migrate/index.js at line 1850.
What does handle_identifier() call?
handle_identifier() calls 2 function(s): generate, get.
What calls handle_identifier()?
handle_identifier() is called by 2 function(s): instance_script.Identifier, template.Identifier.

Analyze Your Own Codebase

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

Try Supermodel Free