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

100% Statements 27/27
100% Branches 7/7
100% Functions 1/1
100% Lines 26/26

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 272x 2x 2x 2x 2x 2x 2x 2x 2x 146x 146x 146x 146x 111x 146x 9x 9x 9x 9x 9x 9x 9x 9x 137x 137x 137x  
/** @import { UpdateExpression } from 'estree' */
/** @import { Context } from '../types.js' */
import * as b from '../../../../utils/builders.js';
 
/**
 * @param {UpdateExpression} node
 * @param {Context} context
 */
export function UpdateExpression(node, context) {
	const argument = node.argument;
 
	if (
		argument.type === 'Identifier' &&
		context.state.scope.get(argument.name)?.kind === 'store_sub'
	) {
		return b.call(
			node.prefix ? '$.update_store_pre' : '$.update_store',
			b.assignment('??=', b.id('$$store_subs'), b.object([])),
			b.literal(argument.name),
			b.id(argument.name.slice(1)),
			node.operator === '--' && b.literal(-1)
		);
	}
 
	return context.next();
}