Home / Function/ read_attribute_value() — svelte Function Reference

read_attribute_value() — svelte Function Reference

Architecture documentation for the read_attribute_value() function in element.js from the svelte codebase.

Function javascript Compiler Transformer calls 4 called by 1

Entity Profile

Dependency Diagram

graph TD
  9fcb1dc7_f1ea_4501_df05_9617e7c7d114["read_attribute_value()"]
  206889ff_1f9f_b6c1_d530_059d001e1cf4["element.js"]
  9fcb1dc7_f1ea_4501_df05_9617e7c7d114 -->|defined in| 206889ff_1f9f_b6c1_d530_059d001e1cf4
  774b1b65_7dad_02c2_b4ca_c77fc0d799ec["read_attribute()"]
  774b1b65_7dad_02c2_b4ca_c77fc0d799ec -->|calls| 9fcb1dc7_f1ea_4501_df05_9617e7c7d114
  643a8559_c423_3568_92f9_91e141374c9c["read_attribute_value()"]
  9fcb1dc7_f1ea_4501_df05_9617e7c7d114 -->|calls| 643a8559_c423_3568_92f9_91e141374c9c
  babf57bd_0606_e8ec_fde4_75ed47bb1407["read_sequence()"]
  9fcb1dc7_f1ea_4501_df05_9617e7c7d114 -->|calls| babf57bd_0606_e8ec_fde4_75ed47bb1407
  7cef41bd_b7cf_112a_875e_5ca7e892c65e["expected_token()"]
  9fcb1dc7_f1ea_4501_df05_9617e7c7d114 -->|calls| 7cef41bd_b7cf_112a_875e_5ca7e892c65e
  4f8e16ea_8c4f_54ac_7148_a1cdef2e20d3["expected_attribute_value()"]
  9fcb1dc7_f1ea_4501_df05_9617e7c7d114 -->|calls| 4f8e16ea_8c4f_54ac_7148_a1cdef2e20d3
  style 9fcb1dc7_f1ea_4501_df05_9617e7c7d114 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/1-parse/state/element.js lines 718–769

function read_attribute_value(parser) {
	const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
	if (quote_mark && parser.eat(quote_mark)) {
		return [
			{
				start: parser.index - 1,
				end: parser.index - 1,
				type: 'Text',
				raw: '',
				data: ''
			}
		];
	}

	/** @type {Array<AST.ExpressionTag | AST.Text>} */
	let value;
	try {
		value = read_sequence(
			parser,
			() => {
				// handle common case of quote marks existing outside of regex for performance reasons
				if (quote_mark) return parser.match(quote_mark);
				return !!parser.match_regex(regex_invalid_unquoted_attribute_value);
			},
			'in attribute value'
		);
	} catch (/** @type {any} */ error) {
		if (error.code === 'js_parse_error') {
			// if the attribute value didn't close + self-closing tag
			// eg: `<Component test={{a:1} />`
			// acorn may throw a `Unterminated regular expression` because of `/>`
			const pos = error.position?.[0];
			if (pos !== undefined && parser.template.slice(pos - 1, pos + 1) === '/>') {
				parser.index = pos;
				e.expected_token(pos, quote_mark || '}');
			}
		}
		throw error;
	}

	if (value.length === 0 && !quote_mark) {
		e.expected_attribute_value(parser.index);
	}

	if (quote_mark) parser.index += 1;

	if (quote_mark || value.length > 1 || value[0].type === 'Text') {
		return value;
	} else {
		return value[0];
	}
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does read_attribute_value() do?
read_attribute_value() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/1-parse/state/element.js.
Where is read_attribute_value() defined?
read_attribute_value() is defined in packages/svelte/src/compiler/phases/1-parse/state/element.js at line 718.
What does read_attribute_value() call?
read_attribute_value() calls 4 function(s): expected_attribute_value, expected_token, read_attribute_value, read_sequence.
What calls read_attribute_value()?
read_attribute_value() is called by 1 function(s): read_attribute.

Analyze Your Own Codebase

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

Try Supermodel Free