Home / Function/ visit_event_attribute() — svelte Function Reference

visit_event_attribute() — svelte Function Reference

Architecture documentation for the visit_event_attribute() function in events.js from the svelte codebase.

Function javascript Compiler Transformer calls 4 called by 2

Entity Profile

Dependency Diagram

graph TD
  e35222ea_3daa_de5e_3d5f_66469f2fb218["visit_event_attribute()"]
  c5a9d025_4aac_a689_1a38_c0fce5e694c0["events.js"]
  e35222ea_3daa_de5e_3d5f_66469f2fb218 -->|defined in| c5a9d025_4aac_a689_1a38_c0fce5e694c0
  94712346_c9d5_2339_ffd0_ba77be0c95e6["Attribute()"]
  94712346_c9d5_2339_ffd0_ba77be0c95e6 -->|calls| e35222ea_3daa_de5e_3d5f_66469f2fb218
  1e3b81f2_cd53_e5a5_0140_a9af38facf99["RegularElement()"]
  1e3b81f2_cd53_e5a5_0140_a9af38facf99 -->|calls| e35222ea_3daa_de5e_3d5f_66469f2fb218
  414b9ea2_b052_6759_fdfb_f4cabf75669c["is_capture_event()"]
  e35222ea_3daa_de5e_3d5f_66469f2fb218 -->|calls| 414b9ea2_b052_6759_fdfb_f4cabf75669c
  cd53dd1a_8bd9_06e2_6bfe_ed90344d0b28["build_event_handler()"]
  e35222ea_3daa_de5e_3d5f_66469f2fb218 -->|calls| cd53dd1a_8bd9_06e2_6bfe_ed90344d0b28
  2ed29e53_0d07_f94c_69fa_4365c369a1dd["build_event()"]
  e35222ea_3daa_de5e_3d5f_66469f2fb218 -->|calls| 2ed29e53_0d07_f94c_69fa_4365c369a1dd
  034eb538_8c9d_e943_ab91_3ef5cfad2ef9["is_passive_event()"]
  e35222ea_3daa_de5e_3d5f_66469f2fb218 -->|calls| 034eb538_8c9d_e943_ab91_3ef5cfad2ef9
  style e35222ea_3daa_de5e_3d5f_66469f2fb218 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js lines 13–63

export function visit_event_attribute(node, context) {
	let capture = false;

	let event_name = node.name.slice(2);
	if (is_capture_event(event_name)) {
		event_name = event_name.slice(0, -7);
		capture = true;
	}

	// we still need to support the weird `onclick="{() => {...}}" form
	const tag = Array.isArray(node.value)
		? /** @type {AST.ExpressionTag} */ (node.value[0])
		: /** @type {AST.ExpressionTag} */ (node.value);

	let handler = build_event_handler(tag.expression, tag.metadata.expression, context);

	if (node.metadata.delegated) {
		if (!context.state.events.has(event_name)) {
			context.state.events.add(event_name);
		}

		context.state.init.push(
			b.stmt(
				b.assignment(
					'=',
					b.member(context.state.node, b.id('__' + event_name, node.name_loc)),
					handler
				)
			)
		);
	} else {
		const statement = b.stmt(
			build_event(
				event_name,
				context.state.node,
				handler,
				capture,
				is_passive_event(event_name) ? true : undefined
			)
		);

		const type = /** @type {AST.SvelteNode} */ (context.path.at(-1)).type;

		if (type === 'SvelteDocument' || type === 'SvelteWindow' || type === 'SvelteBody') {
			// These nodes are above the component tree, and its events should run parent first
			context.state.init.push(statement);
		} else {
			context.state.after_update.push(statement);
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does visit_event_attribute() do?
visit_event_attribute() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js.
Where is visit_event_attribute() defined?
visit_event_attribute() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js at line 13.
What does visit_event_attribute() call?
visit_event_attribute() calls 4 function(s): build_event, build_event_handler, is_capture_event, is_passive_event.
What calls visit_event_attribute()?
visit_event_attribute() is called by 2 function(s): Attribute, RegularElement.

Analyze Your Own Codebase

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

Try Supermodel Free