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

94.44% Statements 34/36
88.88% Branches 8/9
100% Functions 1/1
94.11% Lines 32/34

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 352x 2x 2x 2x 2x 2x 2x 2x 2x 2x 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';
 
/**
 * @param {RenderTag} node
 * @param {Context} context
 */
export function RenderTag(node, context) {
	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();
}