All files / src/compiler/phases/3-transform/client/visitors ExpressionStatement.js

100% Statements 25/25
100% Branches 7/7
100% Functions 1/1
100% Lines 23/23

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 242x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1592x 663x 663x 663x 78x 78x 78x 78x 78x 663x 1514x 1514x 1514x  
/** @import { Expression, ExpressionStatement } from 'estree' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { get_rune } from '../../../scope.js';
 
/**
 * @param {ExpressionStatement} node
 * @param {ComponentContext} context
 */
export function ExpressionStatement(node, context) {
	if (node.expression.type === 'CallExpression') {
		const rune = get_rune(node.expression, context.state.scope);
 
		if (rune === '$effect' || rune === '$effect.pre') {
			const callee = rune === '$effect' ? '$.user_effect' : '$.user_pre_effect';
			const func = /** @type {Expression} */ (context.visit(node.expression.arguments[0]));
 
			return b.stmt(b.call(callee, /** @type {Expression} */ (func)));
		}
	}
 
	context.next();
}