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 730x 730x 402x 730x 292x 292x 328x 36x 36x 730x 2x 2x 2x 2x 2x 2x 265x 265x 265x 119x 265x 146x 146x 265x 265x 229x 229x  
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;
}