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

100% Statements 28/28
100% Branches 8/8
100% Functions 1/1
100% Lines 27/27

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 282x 2x 2x 2x 2x 2x 2x 2x 2x 104x 104x 104x 104x 262x 262x 262x 36x 262x 26x 26x 4x 4x 26x 262x 104x 104x 104x  
/** @import { ClassBody } from 'estree' */
/** @import { Context } from '../types' */
import { get_rune } from '../../scope.js';
 
/**
 * @param {ClassBody} node
 * @param {Context} context
 */
export function ClassBody(node, context) {
	/** @type {string[]} */
	const private_derived_state = [];
 
	for (const definition of node.body) {
		if (
			definition.type === 'PropertyDefinition' &&
			definition.key.type === 'PrivateIdentifier' &&
			definition.value?.type === 'CallExpression'
		) {
			const rune = get_rune(definition.value, context.state.scope);
			if (rune === '$derived' || rune === '$derived.by') {
				private_derived_state.push(definition.key.name);
			}
		}
	}
 
	context.next({ ...context.state, private_derived_state });
}