All files / src/compiler/phases/2-analyze/visitors RenderTag.js

95.45% Statements 42/44
88.88% Branches 8/9
100% Functions 1/1
95% Lines 38/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 412x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 164x 164x 164x 164x 164x 164x 164x 164x 164x 164x 164x 61x     61x 164x 164x 164x 164x 15x 164x 1x 1x 163x 163x 163x 163x 163x  
/** @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';
 
/**
 * @param {AST.RenderTag} node
 * @param {Context} context
 */
export function RenderTag(node, context) {
	validate_opening_tag(node, context.state, '@');
 
	const callee = unwrap_optional(node.expression).callee;
 
	node.metadata.dynamic =
		callee.type !== 'Identifier' || context.state.scope.get(callee.name)?.kind !== 'normal';
 
	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.next({ ...context.state, render_tag: node });
}