All files / src/compiler/phases/3-transform/server/visitors LabeledStatement.js

100% Statements 25/25
100% Branches 3/3
100% Functions 1/1
100% Lines 24/24

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 252x 2x 2x 2x 2x 2x 2x 2x 2x 149x 2x 2x 147x 147x 147x 147x 147x 147x 147x 147x 147x 147x 147x 147x  
/** @import { ExpressionStatement, LabeledStatement } from 'estree' */
/** @import { Context } from '../types.js' */
import * as b from '../../../../utils/builders.js';
 
/**
 * @param {LabeledStatement} node
 * @param {Context} context
 */
export function LabeledStatement(node, context) {
	if (context.state.analysis.runes || context.path.length > 1 || node.label.name !== '$') {
		return;
	}
 
	// TODO bail out if we're in module context
 
	// these statements will be topologically ordered later
	context.state.legacy_reactive_statements.set(
		node,
		// people could do "break $" inside, so we need to keep the label
		b.labeled('$', /** @type {ExpressionStatement} */ (context.visit(node.body)))
	);
 
	return b.empty;
}