All files / src/compiler/phases/2-analyze/css utils.js

100% Statements 33/33
100% Branches 10/10
100% Functions 2/2
100% Lines 33/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 342x 2x 2x 2x 2x 2x 728x 728x 402x 728x 292x 292x 326x 34x 34x 728x 2x 2x 2x 2x 2x 2x 262x 262x 262x 118x 262x 144x 144x 262x 262x 228x 228x  
const UNKNOWN = {};
 
/**
 * @param {import('estree').Node} node
 * @param {Set<any>} set
 */
function gather_possible_values(node, set) {
	if (node.type === 'Literal') {
		set.add(String(node.value));
	} else if (node.type === 'ConditionalExpression') {
		gather_possible_values(node.consequent, set);
		gather_possible_values(node.alternate, set);
	} else {
		set.add(UNKNOWN);
	}
}
 
/**
 * @param {import('#compiler').Text | import('#compiler').ExpressionTag} chunk
 * @returns {Set<string> | null}
 */
export function get_possible_values(chunk) {
	const values = new Set();
 
	if (chunk.type === 'Text') {
		values.add(chunk.data);
	} else {
		gather_possible_values(chunk.expression, values);
	}
 
	if (values.has(UNKNOWN)) return null;
	return values;
}