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

74.41% Statements 32/43
80% Branches 8/10
100% Functions 1/1
73.17% Lines 30/41

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 422x 2x 2x 2x 2x 2x 2x 2x 2x 2x 49x 43x 43x 43x 43x 43x 43x   43x 43x 43x 43x 43x 43x 43x 43x 43x                     43x 6x 6x 6x  
/** @import { Expression, PropertyDefinition } from 'estree' */
/** @import { Context } from '../types.js' */
import * as b from '../../../../utils/builders.js';
import { get_rune } from '../../../scope.js';
 
/**
 * @param {PropertyDefinition} node
 * @param {Context} context
 */
export function PropertyDefinition(node, context) {
	if (context.state.analysis.runes && node.value != null && node.value.type === 'CallExpression') {
		const rune = get_rune(node.value, context.state.scope);
 
		if (
			rune === '$state' ||
			rune === '$state.link' ||
			rune === '$state.raw' ||
			rune === '$derived'
		) {
			return {
				...node,
				value:
					node.value.arguments.length === 0
						? null
						: /** @type {Expression} */ (context.visit(node.value.arguments[0]))
			};
		}

		if (rune === '$derived.by') {
			return {
				...node,
				value:
					node.value.arguments.length === 0
						? null
						: b.call(/** @type {Expression} */ (context.visit(node.value.arguments[0])))
			};
		}
	}
 
	context.next();
}