Home / Function/ gather_possible_values() — svelte Function Reference

gather_possible_values() — svelte Function Reference

Architecture documentation for the gather_possible_values() function in utils.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  2683d5fa_0833_82ff_0112_15223a15bc7d["gather_possible_values()"]
  ad593fd6_3727_04c3_f22e_c845647cea4d["utils.js"]
  2683d5fa_0833_82ff_0112_15223a15bc7d -->|defined in| ad593fd6_3727_04c3_f22e_c845647cea4d
  28a76788_b161_f034_e658_6787237c5c8a["get_possible_values()"]
  28a76788_b161_f034_e658_6787237c5c8a -->|calls| 2683d5fa_0833_82ff_0112_15223a15bc7d
  style 2683d5fa_0833_82ff_0112_15223a15bc7d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/2-analyze/css/utils.js lines 11–78

function gather_possible_values(node, is_class, set, is_nested = false) {
	if (set.has(UNKNOWN)) {
		// no point traversing any further
		return;
	}

	if (node.type === 'Literal') {
		set.add(String(node.value));
	} else if (node.type === 'ConditionalExpression') {
		gather_possible_values(node.consequent, is_class, set, is_nested);
		gather_possible_values(node.alternate, is_class, set, is_nested);
	} else if (node.type === 'LogicalExpression') {
		if (node.operator === '&&') {
			// && is a special case, because the only way the left
			// hand value can be included is if it's falsy. this is
			// a bit of extra work but it's worth it because
			// `class={[condition && 'blah']}` is common,
			// and we don't want to deopt on `condition`
			const left = new Set();
			gather_possible_values(node.left, is_class, left, is_nested);

			if (left.has(UNKNOWN)) {
				// add all non-nullish falsy values, unless this is a `class` attribute that
				// will be processed by cslx, in which case falsy values are removed, unless
				// they're not inside an array/object (TODO 6.0 remove that last part)
				if (!is_class || !is_nested) {
					set.add('');
					set.add(false);
					set.add(NaN);
					set.add(0); // -0 and 0n are also falsy, but stringify to '0'
				}
			} else {
				for (const value of left) {
					if (!value && value != undefined && (!is_class || !is_nested)) {
						set.add(value);
					}
				}
			}

			gather_possible_values(node.right, is_class, set, is_nested);
		} else {
			gather_possible_values(node.left, is_class, set, is_nested);
			gather_possible_values(node.right, is_class, set, is_nested);
		}
	} else if (is_class && node.type === 'ArrayExpression') {
		for (const entry of node.elements) {
			if (entry) {
				gather_possible_values(entry, is_class, set, true);
			}
		}
	} else if (is_class && node.type === 'ObjectExpression') {
		for (const property of node.properties) {
			if (
				property.type === 'Property' &&
				!property.computed &&
				(property.key.type === 'Identifier' || property.key.type === 'Literal')
			) {
				set.add(
					property.key.type === 'Identifier' ? property.key.name : String(property.key.value)
				);
			} else {
				set.add(UNKNOWN);
			}
		}
	} else {
		set.add(UNKNOWN);
	}
}

Domain

Subdomains

Frequently Asked Questions

What does gather_possible_values() do?
gather_possible_values() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/css/utils.js.
Where is gather_possible_values() defined?
gather_possible_values() is defined in packages/svelte/src/compiler/phases/2-analyze/css/utils.js at line 11.
What calls gather_possible_values()?
gather_possible_values() is called by 1 function(s): get_possible_values.

Analyze Your Own Codebase

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

Try Supermodel Free