Home / File/ RenderTag.js — svelte Source File

RenderTag.js — svelte Source File

Architecture documentation for RenderTag.js, a javascript file in the svelte codebase. 12 imports, 1 dependents.

File javascript Compiler Transformer 12 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1["RenderTag.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  9bcad0f1_2e1e_1fe2_1a87_0967adb89be8["unwrap_optional"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 9bcad0f1_2e1e_1fe2_1a87_0967adb89be8
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> a146f6ac_0088_8736_b6ce_318f9f115170
  bf0d8f1b_17da_970d_bf44_fbcf099d5371["utils.js"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> bf0d8f1b_17da_970d_bf44_fbcf099d5371
  7148e639_69d8_a03d_3f08_bd23f41e718a["validate_opening_tag"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 7148e639_69d8_a03d_3f08_bd23f41e718a
  c4b4ac8d_9914_5ede_1aea_723bf80d2e9b["fragment.js"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> c4b4ac8d_9914_5ede_1aea_723bf80d2e9b
  313d2a82_30ea_3161_3aad_0cc2094979aa["mark_subtree_dynamic"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 313d2a82_30ea_3161_3aad_0cc2094979aa
  93f05ed0_daa8_8d1d_7b82_43c4a9020ecf["snippets.js"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 93f05ed0_daa8_8d1d_7b82_43c4a9020ecf
  e0e99a00_6e05_14b1_3821_80dbb3341928["is_resolved_snippet"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> e0e99a00_6e05_14b1_3821_80dbb3341928
  bbca3d2a_42c8_b215_d3b5_5077ccaf0797["nodes.js"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> bbca3d2a_42c8_b215_d3b5_5077ccaf0797
  6e00a8f3_2371_ecf1_5a93_296f787aca83["ExpressionMetadata"]
  7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 --> 6e00a8f3_2371_ecf1_5a93_296f787aca83
  4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"]
  4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> 7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1
  style 7dee3da2_976f_9ebe_d9d5_50ad37d6c6e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { unwrap_optional } from '../../../utils/ast.js';
import * as e from '../../../errors.js';
import { validate_opening_tag } from './shared/utils.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
import { is_resolved_snippet } from './shared/snippets.js';
import { ExpressionMetadata } from '../../nodes.js';

/**
 * @param {AST.RenderTag} node
 * @param {Context} context
 */
export function RenderTag(node, context) {
	validate_opening_tag(node, context.state, '@');

	node.metadata.path = [...context.path];

	const expression = unwrap_optional(node.expression);
	const callee = expression.callee;

	const binding = callee.type === 'Identifier' ? context.state.scope.get(callee.name) : null;

	node.metadata.dynamic = binding?.kind !== 'normal';

	/**
	 * If we can't unambiguously resolve this to a declaration, we
	 * must assume the worst and link the render tag to every snippet
	 */
	let resolved = callee.type === 'Identifier' && is_resolved_snippet(binding);

	if (binding?.initial?.type === 'SnippetBlock') {
		// if this render tag unambiguously references a local snippet, our job is easy
		node.metadata.snippets.add(binding.initial);
	}

	context.state.analysis.snippet_renderers.set(node, resolved);
	context.state.analysis.uses_render_tags = true;

	const raw_args = unwrap_optional(node.expression).arguments;
	for (const arg of raw_args) {
		if (arg.type === 'SpreadElement') {
			e.render_tag_invalid_spread_argument(arg);
		}
	}

	if (
		callee.type === 'MemberExpression' &&
		callee.property.type === 'Identifier' &&
		['bind', 'apply', 'call'].includes(callee.property.name)
	) {
		e.render_tag_invalid_call_expression(node);
	}

	mark_subtree_dynamic(context.path);

	context.visit(callee, { ...context.state, expression: node.metadata.expression });

	for (const arg of expression.arguments) {
		const metadata = new ExpressionMetadata();
		node.metadata.arguments.push(metadata);

		context.visit(arg, {
			...context.state,
			expression: metadata
		});
	}
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does RenderTag.js do?
RenderTag.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in RenderTag.js?
RenderTag.js defines 1 function(s): RenderTag.
What does RenderTag.js depend on?
RenderTag.js imports 12 module(s): ExpressionMetadata, ast.js, e, errors.js, fragment.js, is_resolved_snippet, mark_subtree_dynamic, nodes.js, and 4 more.
What files import RenderTag.js?
RenderTag.js is imported by 1 file(s): index.js.
Where is RenderTag.js in the architecture?
RenderTag.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/RenderTag.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free