Home / File/ UpdateExpression.js — svelte Source File

UpdateExpression.js — svelte Source File

Architecture documentation for UpdateExpression.js, a javascript file in the svelte codebase. 5 imports, 1 dependents.

File javascript Compiler Transformer 5 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  5ec95d09_9bd6_c503_274b_b0589008b7ac["UpdateExpression.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  5ec95d09_9bd6_c503_274b_b0589008b7ac --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  804afe56_25d1_9f41_dafe_adc75e952134["object"]
  5ec95d09_9bd6_c503_274b_b0589008b7ac --> 804afe56_25d1_9f41_dafe_adc75e952134
  d04d7971_88df_542d_dd4f_26170ce6f581["utils.js"]
  5ec95d09_9bd6_c503_274b_b0589008b7ac --> d04d7971_88df_542d_dd4f_26170ce6f581
  dcd117e6_7004_e4da_f4a2_f82f6e43060c["validate_mutation"]
  5ec95d09_9bd6_c503_274b_b0589008b7ac --> dcd117e6_7004_e4da_f4a2_f82f6e43060c
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  5ec95d09_9bd6_c503_274b_b0589008b7ac --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"]
  7665e008_f37d_b860_a594_f2539a66af4e --> 5ec95d09_9bd6_c503_274b_b0589008b7ac
  style 5ec95d09_9bd6_c503_274b_b0589008b7ac fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AssignmentExpression, Expression, UpdateExpression } from 'estree' */
/** @import { Context } from '../types' */
import { object } from '../../../../utils/ast.js';
import * as b from '#compiler/builders';
import { validate_mutation } from './shared/utils.js';

/**
 * @param {UpdateExpression} node
 * @param {Context} context
 */
export function UpdateExpression(node, context) {
	const argument = node.argument;

	if (
		argument.type === 'MemberExpression' &&
		argument.object.type === 'ThisExpression' &&
		argument.property.type === 'PrivateIdentifier' &&
		context.state.state_fields.has('#' + argument.property.name)
	) {
		let fn = '$.update';
		if (node.prefix) fn += '_pre';

		/** @type {Expression[]} */
		const args = [argument];
		if (node.operator === '--') {
			args.push(b.literal(-1));
		}

		return b.call(fn, ...args);
	}

	if (argument.type !== 'Identifier' && argument.type !== 'MemberExpression') {
		throw new Error('An impossible state was reached');
	}

	const left = object(argument);
	const transformers = left && context.state.transform[left.name];

	if (left === argument && transformers?.update) {
		// we don't need to worry about ownership_invalid_mutation here, because
		// we're not mutating but reassigning
		return transformers.update(node);
	}

	let update = /** @type {Expression} */ (context.next());

	if (left && transformers?.mutate) {
		update = transformers.mutate(
			left,
			/** @type {AssignmentExpression | UpdateExpression} */ (update)
		);
	}

	return validate_mutation(node, context, update);
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does UpdateExpression.js do?
UpdateExpression.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in UpdateExpression.js?
UpdateExpression.js defines 1 function(s): UpdateExpression.
What does UpdateExpression.js depend on?
UpdateExpression.js imports 5 module(s): ast.js, builders, object, utils.js, validate_mutation.
What files import UpdateExpression.js?
UpdateExpression.js is imported by 1 file(s): transform-client.js.
Where is UpdateExpression.js in the architecture?
UpdateExpression.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/UpdateExpression.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client/visitors).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free