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

90.62% Statements 29/32
80% Branches 4/5
100% Functions 1/1
90% Lines 27/30

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 312x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 321x 317x 317x 317x 317x 317x 317x       317x 317x 4x 4x 317x 317x 321x 321x 321x  
/** @import { LabeledStatement } from 'estree' */
/** @import { SvelteNode } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
 
/**
 * @param {LabeledStatement} node
 * @param {Context} context
 */
export function LabeledStatement(node, context) {
	if (node.label.name === '$') {
		const parent = /** @type {SvelteNode} */ (context.path.at(-1));
 
		const is_reactive_statement =
			context.state.ast_type === 'instance' && parent.type === 'Program';
 
		if (context.state.analysis.runes) {
			if (is_reactive_statement) {
				e.legacy_reactive_statement_invalid(node);
			}
		} else {
			if (!is_reactive_statement) {
				w.reactive_declaration_invalid_placement(node);
			}
		}
	}
 
	context.next();
}