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

98.48% Statements 65/66
94.73% Branches 18/19
100% Functions 1/1
98.38% Lines 61/62

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 50 51 52 53 54 55 56 57 58 59 60 61 62 632x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1827x 1827x   1827x 1827x 5x 1827x 1827x 5x 5x 5x 5x 5x 1827x 1827x 7x 7x 7x 7x 1827x 1827x 1827x 18x 1827x 1792x 1792x 1827x 1827x 1827x 1827x 1827x 1827x 2x 2x 2x 1827x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1790x 1790x 1790x  
/** @import { CallExpression, Expression } from 'estree' */
/** @import { Context } from '../types' */
import { dev, 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) {
	switch (get_rune(node, context.state.scope)) {
		case '$host':
			return b.id('$$props.$$host');
 
		case '$effect.tracking':
			return b.call('$.effect_tracking');
 
		case '$state.snapshot':
			return b.call(
				'$.snapshot',
				/** @type {Expression} */ (context.visit(node.arguments[0])),
				is_ignored(node, 'state_snapshot_uncloneable') && b.true
			);
 
		case '$effect.root':
			return b.call(
				'$.effect_root',
				.../** @type {Expression[]} */ (node.arguments.map((arg) => context.visit(arg)))
			);
 
		case '$inspect':
		case '$inspect().with':
			return transform_inspect_rune(node, context);
	}
 
	if (
		dev &&
		node.callee.type === 'MemberExpression' &&
		node.callee.object.type === 'Identifier' &&
		node.callee.object.name === 'console' &&
		context.state.scope.get('console') === null &&
		node.callee.property.type === 'Identifier' &&
		['debug', 'dir', 'error', 'group', 'groupCollapsed', 'info', 'log', 'trace', 'warn'].includes(
			node.callee.property.name
		)
	) {
		return b.call(
			node.callee,
			b.spread(
				b.call(
					'$.log_if_contains_state',
					b.literal(node.callee.property.name),
					.../** @type {Expression[]} */ (node.arguments.map((arg) => context.visit(arg)))
				)
			)
		);
	}
 
	context.next();
}