Home / File/ PropertyDefinition.js — svelte Source File

PropertyDefinition.js — svelte Source File

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

File javascript Compiler Transformer 3 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  14a27279_5dd2_0a06_e564_302fb6ffcbc1["PropertyDefinition.js"]
  ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"]
  14a27279_5dd2_0a06_e564_302fb6ffcbc1 --> ee93d8a6_6fde_b1c1_e15b_3a4da5326305
  bed91719_d047_2256_e199_ee875d5f49b9["get_rune"]
  14a27279_5dd2_0a06_e564_302fb6ffcbc1 --> bed91719_d047_2256_e199_ee875d5f49b9
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  14a27279_5dd2_0a06_e564_302fb6ffcbc1 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  86cf8685_38fa_3a1c_9b81_21c452968289["transform-server.js"]
  86cf8685_38fa_3a1c_9b81_21c452968289 --> 14a27279_5dd2_0a06_e564_302fb6ffcbc1
  style 14a27279_5dd2_0a06_e564_302fb6ffcbc1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression, PropertyDefinition } from 'estree' */
/** @import { Context } from '../types.js' */
import * as b from '#compiler/builders';
import { get_rune } from '../../../scope.js';

/**
 * @param {PropertyDefinition} node
 * @param {Context} context
 */
export function PropertyDefinition(node, context) {
	if (context.state.analysis.runes && node.value != null && node.value.type === 'CallExpression') {
		const rune = get_rune(node.value, context.state.scope);

		if (rune === '$state' || rune === '$state.raw') {
			return {
				...node,
				value:
					node.value.arguments.length === 0
						? null
						: /** @type {Expression} */ (context.visit(node.value.arguments[0]))
			};
		}

		if (rune === '$derived.by' || rune === '$derived') {
			const fn = /** @type {Expression} */ (context.visit(node.value.arguments[0]));
			return {
				...node,
				value:
					node.value.arguments.length === 0
						? null
						: b.call('$.derived', rune === '$derived' ? b.thunk(fn) : fn)
			};
		}
	}

	context.next();
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does PropertyDefinition.js do?
PropertyDefinition.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 PropertyDefinition.js?
PropertyDefinition.js defines 1 function(s): PropertyDefinition.
What does PropertyDefinition.js depend on?
PropertyDefinition.js imports 3 module(s): builders, get_rune, scope.js.
What files import PropertyDefinition.js?
PropertyDefinition.js is imported by 1 file(s): transform-server.js.
Where is PropertyDefinition.js in the architecture?
PropertyDefinition.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/PropertyDefinition.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/server/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free