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

95% Statements 38/40
88.88% Branches 8/9
100% Functions 1/1
94.59% Lines 35/37

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 382x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 154x 154x 154x 154x 154x 154x 154x 154x 154x 154x 154x 61x     61x 154x 154x 154x 154x 13x 154x 1x 1x 153x 153x 153x  
/** @import { RenderTag } 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';
 
/**
 * @param {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);
	}
 
	context.next({ ...context.state, render_tag: node });
}