Home / Function/ read_selector() — svelte Function Reference

read_selector() — svelte Function Reference

Architecture documentation for the read_selector() function in style.js from the svelte codebase.

Function javascript Compiler Transformer calls 7 called by 1

Entity Profile

Dependency Diagram

graph TD
  fcabd261_14f2_2647_3794_39b7100eda95["read_selector()"]
  251e2338_f8b8_69b4_b2e5_29ee7decbfa6["style.js"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|defined in| 251e2338_f8b8_69b4_b2e5_29ee7decbfa6
  a2faeba8_5477_23ae_005c_e02d8e7f69c1["read_selector_list()"]
  a2faeba8_5477_23ae_005c_e02d8e7f69c1 -->|calls| fcabd261_14f2_2647_3794_39b7100eda95
  7a0ffc5c_c833_ca6c_fe33_60f0f57e9307["read_identifier()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| 7a0ffc5c_c833_ca6c_fe33_60f0f57e9307
  a2faeba8_5477_23ae_005c_e02d8e7f69c1["read_selector_list()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| a2faeba8_5477_23ae_005c_e02d8e7f69c1
  643a8559_c423_3568_92f9_91e141374c9c["read_attribute_value()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| 643a8559_c423_3568_92f9_91e141374c9c
  ae0c2614_bb2e_88b4_b84e_1fd1d9fd582b["allow_comment_or_whitespace()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| ae0c2614_bb2e_88b4_b84e_1fd1d9fd582b
  748b9c17_0154_345a_02e1_d388a473a561["read_combinator()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| 748b9c17_0154_345a_02e1_d388a473a561
  dff4fce6_a04d_698c_eef1_f67b276d0b98["css_selector_invalid()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| dff4fce6_a04d_698c_eef1_f67b276d0b98
  feea79ed_c6f7_4068_9c81_9734e5dcbfb7["unexpected_eof()"]
  fcabd261_14f2_2647_3794_39b7100eda95 -->|calls| feea79ed_c6f7_4068_9c81_9734e5dcbfb7
  style fcabd261_14f2_2647_3794_39b7100eda95 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/1-parse/read/style.js lines 164–369

function read_selector(parser, inside_pseudo_class = false) {
	const list_start = parser.index;

	/** @type {AST.CSS.RelativeSelector[]} */
	const children = [];

	/**
	 * @param {AST.CSS.Combinator | null} combinator
	 * @param {number} start
	 * @returns {AST.CSS.RelativeSelector}
	 */
	function create_selector(combinator, start) {
		return {
			type: 'RelativeSelector',
			combinator,
			selectors: [],
			start,
			end: -1,
			metadata: {
				is_global: false,
				is_global_like: false,
				scoped: false
			}
		};
	}

	/** @type {AST.CSS.RelativeSelector} */
	let relative_selector = create_selector(null, parser.index);

	while (parser.index < parser.template.length) {
		let start = parser.index;

		if (parser.eat('&')) {
			relative_selector.selectors.push({
				type: 'NestingSelector',
				name: '&',
				start,
				end: parser.index
			});
		} else if (parser.eat('*')) {
			let name = '*';

			if (parser.eat('|')) {
				// * is the namespace (which we ignore)
				name = read_identifier(parser);
			}

			relative_selector.selectors.push({
				type: 'TypeSelector',
				name,
				start,
				end: parser.index
			});
		} else if (parser.eat('#')) {
			relative_selector.selectors.push({
				type: 'IdSelector',
				name: read_identifier(parser),
				start,
				end: parser.index
			});
		} else if (parser.eat('.')) {
			relative_selector.selectors.push({
				type: 'ClassSelector',
				name: read_identifier(parser),
				start,
				end: parser.index
			});
		} else if (parser.eat('::')) {
			relative_selector.selectors.push({
				type: 'PseudoElementSelector',
				name: read_identifier(parser),
				start,
				end: parser.index
			});
			// We read the inner selectors of a pseudo element to ensure it parses correctly,
			// but we don't do anything with the result.
			if (parser.eat('(')) {
				read_selector_list(parser, true);
				parser.eat(')', true);
			}
		} else if (parser.eat(':')) {

Domain

Subdomains

Frequently Asked Questions

What does read_selector() do?
read_selector() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/1-parse/read/style.js.
Where is read_selector() defined?
read_selector() is defined in packages/svelte/src/compiler/phases/1-parse/read/style.js at line 164.
What does read_selector() call?
read_selector() calls 7 function(s): allow_comment_or_whitespace, css_selector_invalid, read_attribute_value, read_combinator, read_identifier, read_selector_list, unexpected_eof.
What calls read_selector()?
read_selector() is called by 1 function(s): read_selector_list.

Analyze Your Own Codebase

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

Try Supermodel Free