Home / File/ options.js — svelte Source File

options.js — svelte Source File

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

File javascript Compiler Transformer 3 imports 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  09b07d2e_2631_ce6a_e899_0be23871c668["options.js"]
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  09b07d2e_2631_ce6a_e899_0be23871c668 --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  09b07d2e_2631_ce6a_e899_0be23871c668 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  09b07d2e_2631_ce6a_e899_0be23871c668 --> a146f6ac_0088_8736_b6ce_318f9f115170
  67d7170b_725b_33cc_868d_fad6ed435252["index.js"]
  67d7170b_725b_33cc_868d_fad6ed435252 --> 09b07d2e_2631_ce6a_e899_0be23871c668
  style 09b07d2e_2631_ce6a_e899_0be23871c668 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { ObjectExpression } from 'estree' */
/** @import { AST } from '#compiler' */
import { NAMESPACE_MATHML, NAMESPACE_SVG } from '../../../../constants.js';
import * as e from '../../../errors.js';

/**
 * @param {AST.SvelteOptionsRaw} node
 * @returns {AST.Root['options']}
 */
export default function read_options(node) {
	/** @type {AST.SvelteOptions} */
	const component_options = {
		start: node.start,
		end: node.end,
		// @ts-ignore
		attributes: node.attributes
	};

	if (!node) {
		return component_options;
	}

	for (const attribute of node.attributes) {
		if (attribute.type !== 'Attribute') {
			e.svelte_options_invalid_attribute(attribute);
		}

		const { name } = attribute;

		switch (name) {
			case 'runes': {
				component_options.runes = get_boolean_value(attribute);
				break;
			}
			case 'tag': {
				e.svelte_options_deprecated_tag(attribute);
				break; // eslint doesn't know this is unnecessary
			}
			case 'customElement': {
				/** @type {AST.SvelteOptions['customElement']} */
				const ce = {};
				const { value: v } = attribute;
				const value = v === true || Array.isArray(v) ? v : [v];

				if (value === true) {
					e.svelte_options_invalid_customelement(attribute);
				} else if (value[0].type === 'Text') {
					const tag = get_static_value(attribute);
					validate_tag(attribute, tag);
					ce.tag = tag;
					component_options.customElement = ce;
					break;
				} else if (value[0].expression.type !== 'ObjectExpression') {
					// Before Svelte 4 it was necessary to explicitly set customElement to null or else you'd get a warning.
					// This is no longer necessary, but for backwards compat just skip in this case now.
					if (value[0].expression.type === 'Literal' && value[0].expression.value === null) {
						break;
					}
					e.svelte_options_invalid_customelement(attribute);
				}
// ... (204 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does options.js do?
options.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 options.js?
options.js defines 4 function(s): get_boolean_value, get_static_value, read_options, validate_tag.
What does options.js depend on?
options.js imports 3 module(s): constants.js, e, errors.js.
What files import options.js?
options.js is imported by 1 file(s): index.js.
Where is options.js in the architecture?
options.js is located at packages/svelte/src/compiler/phases/1-parse/read/options.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/1-parse/read).

Analyze Your Own Codebase

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

Try Supermodel Free