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

100% Statements 26/26
100% Branches 6/6
100% Functions 1/1
100% Lines 25/25

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 262x 2x 2x 2x 2x 2x 2x 2x 2x 1084x 320x 320x 320x 320x 300x 300x 320x 1084x 1084x 1084x 1005x 1005x 1084x 1084x 1084x  
/** @import { OnDirective } from '#compiler' */
/** @import { Context } from '../types' */
import * as w from '../../../warnings.js';
 
/**
 * @param {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;
	}
 
	context.next({ ...context.state, expression: node.metadata.expression });
}