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

100% Statements 30/30
100% Branches 6/6
100% Functions 1/1
100% Lines 28/28

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 292x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1174x 320x 320x 320x 320x 300x 300x 320x 1174x 1174x 1174x 1093x 1093x 1174x 1174x 1174x 1174x 1174x  
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as w from '../../../warnings.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
 
/**
 * @param {AST.OnDirective} node
 * @param {Context} context
 */
export function OnDirective(node, context) {
	if (context.state.analysis.runes) {
		const parent_type = context.path.at(-1)?.type;
 
		// Don't warn on component events; these might not be under the author's control so the warning would be unactionable
		if (parent_type === 'RegularElement' || parent_type === 'SvelteElement') {
			w.event_directive_deprecated(node, node.name);
		}
	}
 
	const parent = context.path.at(-1);
	if (parent?.type === 'SvelteElement' || parent?.type === 'RegularElement') {
		context.state.analysis.event_directive_node ??= node;
	}
 
	mark_subtree_dynamic(context.path);
 
	context.next({ ...context.state, expression: node.metadata.expression });
}