read_options() — svelte Function Reference
Architecture documentation for the read_options() function in options.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 6a48e790_0ca5_6fae_197c_7c93c49d9b66["read_options()"] 09b07d2e_2631_ce6a_e899_0be23871c668["options.js"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|defined in| 09b07d2e_2631_ce6a_e899_0be23871c668 3220db43_dde7_5166_5db8_db3c6d68258d["constructor()"] 3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| 6a48e790_0ca5_6fae_197c_7c93c49d9b66 5fa124f0_50b1_3822_6a51_dc0581164b67["svelte_options_invalid_attribute()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 5fa124f0_50b1_3822_6a51_dc0581164b67 59e343be_b026_cc21_f747_3fd70165bf25["get_boolean_value()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 59e343be_b026_cc21_f747_3fd70165bf25 bcdeda6a_7e87_8849_d4b6_44191faefa0a["svelte_options_deprecated_tag()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| bcdeda6a_7e87_8849_d4b6_44191faefa0a 6740512f_738e_6aa1_59f8_033dbb554f5b["svelte_options_invalid_customelement()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 6740512f_738e_6aa1_59f8_033dbb554f5b 757b376c_e0ea_2ff2_dae4_3fc2ecf04509["get_static_value()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 757b376c_e0ea_2ff2_dae4_3fc2ecf04509 37835ed8_f4c9_aa55_0a7f_8f46a70c1ce3["validate_tag()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 37835ed8_f4c9_aa55_0a7f_8f46a70c1ce3 255e9c6d_98e4_5b4a_a7d9_346cdb50dfcf["svelte_options_invalid_customelement_props()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 255e9c6d_98e4_5b4a_a7d9_346cdb50dfcf 370927a0_ed7d_6e5f_99c4_6d7d2fb6c3f7["svelte_options_invalid_customelement_shadow()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 370927a0_ed7d_6e5f_99c4_6d7d2fb6c3f7 2294c821_a20e_d519_5b71_18d0f0a63c94["svelte_options_invalid_attribute_value()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 2294c821_a20e_d519_5b71_18d0f0a63c94 9f5cdca9_b4e6_100e_b573_4451634df02e["svelte_options_unknown_attribute()"] 6a48e790_0ca5_6fae_197c_7c93c49d9b66 -->|calls| 9f5cdca9_b4e6_100e_b573_4451634df02e style 6a48e790_0ca5_6fae_197c_7c93c49d9b66 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/1-parse/read/options.js lines 10–197
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);
}
/** @type {Array<[string, any]>} */
const properties = [];
for (const property of value[0].expression.properties) {
if (
property.type !== 'Property' ||
property.computed ||
property.key.type !== 'Identifier'
) {
e.svelte_options_invalid_customelement(attribute);
}
properties.push([property.key.name, property.value]);
}
const tag = properties.find(([name]) => name === 'tag');
if (tag) {
const tag_value = tag[1]?.value;
validate_tag(tag, tag_value);
ce.tag = tag_value;
}
const props = properties.find(([name]) => name === 'props')?.[1];
if (props) {
if (props.type !== 'ObjectExpression') {
e.svelte_options_invalid_customelement_props(attribute);
}
ce.props = {};
for (const property of /** @type {ObjectExpression} */ (props).properties) {
if (
property.type !== 'Property' ||
Domain
Subdomains
Calls
- get_boolean_value()
- get_static_value()
- svelte_options_deprecated_tag()
- svelte_options_invalid_attribute()
- svelte_options_invalid_attribute_value()
- svelte_options_invalid_customelement()
- svelte_options_invalid_customelement_props()
- svelte_options_invalid_customelement_shadow()
- svelte_options_unknown_attribute()
- validate_tag()
Called By
Source
Frequently Asked Questions
What does read_options() do?
read_options() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/1-parse/read/options.js.
Where is read_options() defined?
read_options() is defined in packages/svelte/src/compiler/phases/1-parse/read/options.js at line 10.
What does read_options() call?
read_options() calls 10 function(s): get_boolean_value, get_static_value, svelte_options_deprecated_tag, svelte_options_invalid_attribute, svelte_options_invalid_attribute_value, svelte_options_invalid_customelement, svelte_options_invalid_customelement_props, svelte_options_invalid_customelement_shadow, and 2 more.
What calls read_options()?
read_options() is called by 1 function(s): constructor.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free