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

96.22% Statements 51/53
93.33% Branches 14/15
100% Functions 1/1
95.91% Lines 47/49

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 502x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1572x 1572x 1572x     1572x 1572x 4x 4x 1568x 1572x 4x 4x 4x 1564x 1572x 3x 3x 3x 3x 3x 3x 1561x 1572x 3x 3x 3x 3x 3x 3x 1558x 1572x 13x 13x 1545x 1545x 1545x  
/** @import { CallExpression, Expression } from 'estree' */
/** @import { Context } from '../types.js' */
import { is_ignored } from '../../../../state.js';
import * as b from '../../../../utils/builders.js';
import { get_rune } from '../../../scope.js';
import { transform_inspect_rune } from '../../utils.js';
 
/**
 * @param {CallExpression} node
 * @param {Context} context
 */
export function CallExpression(node, context) {
	const rune = get_rune(node, context.state.scope);
 
	if (rune === '$host') {
		return b.id('undefined');
	}
 
	if (rune === '$effect.tracking') {
		return b.literal(false);
	}
 
	if (rune === '$effect.root') {
		// ignore $effect.root() calls, just return a noop which mimics the cleanup function
		return b.arrow([], b.block([]));
	}
 
	if (rune === '$state.snapshot') {
		return b.call(
			'$.snapshot',
			/** @type {Expression} */ (context.visit(node.arguments[0])),
			is_ignored(node, 'state_snapshot_uncloneable') && b.true
		);
	}
 
	if (rune === '$state.is') {
		return b.call(
			'Object.is',
			/** @type {Expression} */ (context.visit(node.arguments[0])),
			/** @type {Expression} */ (context.visit(node.arguments[1]))
		);
	}
 
	if (rune === '$inspect' || rune === '$inspect().with') {
		return transform_inspect_rune(node, context);
	}
 
	context.next();
}