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

100% Statements 30/30
100% Branches 7/7
100% Functions 1/1
100% Lines 28/28

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 292x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2741x 2741x 2741x 298x 298x 298x 276x 276x 276x 276x 276x 276x 298x 298x 2729x 2729x 2729x  
/** @import { AssignmentExpression } from 'estree' */
/** @import { SvelteNode } from '#compiler' */
/** @import { Context } from '../types' */
import { extract_identifiers, object } from '../../../utils/ast.js';
import { validate_assignment } from './shared/utils.js';
 
/**
 * @param {AssignmentExpression} node
 * @param {Context} context
 */
export function AssignmentExpression(node, context) {
	validate_assignment(node, node.left, context.state);
 
	if (context.state.reactive_statement) {
		const id = node.left.type === 'MemberExpression' ? object(node.left) : node.left;
		if (id !== null) {
			for (const id of extract_identifiers(node.left)) {
				const binding = context.state.scope.get(id.name);
 
				if (binding) {
					context.state.reactive_statement.assignments.add(binding);
				}
			}
		}
	}
 
	context.next();
}