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

100% Statements 27/27
80% Branches 4/5
100% Functions 1/1
100% Lines 25/25

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 262x 2x 2x 2x 2x 2x 2x 2x 2x 2x 415x 415x 415x 12x 12x 12x 12x 12x 12x 12x 12x 12x 409x 409x 409x  
/** @import { UpdateExpression } from 'estree' */
/** @import { Context } from '../types' */
import { object } from '../../../utils/ast.js';
import { validate_assignment } from './shared/utils.js';
 
/**
 * @param {UpdateExpression} node
 * @param {Context} context
 */
export function UpdateExpression(node, context) {
	validate_assignment(node, node.argument, context.state);
 
	if (context.state.reactive_statement) {
		const id = node.argument.type === 'MemberExpression' ? object(node.argument) : node.argument;
		if (id?.type === 'Identifier') {
			const binding = context.state.scope.get(id.name);
 
			if (binding) {
				context.state.reactive_statement.assignments.add(binding);
			}
		}
	}
 
	context.next();
}