All files / src/compiler/phases/2-analyze/visitors VariableDeclarator.js

93.75% Statements 30/32
92.85% Branches 13/14
100% Functions 1/1
93.33% Lines 28/30

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 312x 2x 2x 2x 2x 2x 2x 2x 2x 2x 7895x 7895x 7895x 6133x 354x 354x 354x 5718x 282x 6133x 353x 353x 1x 6133x     6133x 1762x 1762x 1762x  
/** @import { VariableDeclarator } from 'estree' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { ensure_no_module_import_conflict } from './shared/utils.js';
 
/**
 * @param {VariableDeclarator} node
 * @param {Context} context
 */
export function VariableDeclarator(node, context) {
	ensure_no_module_import_conflict(node, context.state);
 
	if (!context.state.analysis.runes) {
		if (node.init?.type !== 'CallExpression') return;
 
		const callee = node.init.callee;
		if (
			callee.type !== 'Identifier' ||
			(callee.name !== '$state' && callee.name !== '$derived' && callee.name !== '$props')
		) {
			return;
		}
 
		if (context.state.scope.get(callee.name)?.kind !== 'store_sub') {
			e.rune_invalid_usage(node.init, callee.name);
		}
	}
 
	context.next();
}