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

100% Statements 44/44
100% Branches 11/11
100% Functions 5/5
100% Lines 41/41

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 34 35 36 37 38 39 40 41 422x 2x 2x 2x 2x 2x 2x 2x 2x 362x 362x 2x 2x 2x 2x 94x 74x 74x 2x 2x 134x 2x 2x 2x 2x 1231x 207x 207x 207x 207x 1231x 1231x 2x 2x 1217x 6x 1217x 1211x 1211x 1217x 2x  
import { walk } from 'zimmerframe';
import { warn } from '../../../warnings.js';
import { is_keyframes_node } from '../../css.js';
 
/**
 * @param {import('#compiler').Css.StyleSheet} stylesheet
 * @param {import('../../types.js').RawWarning[]} warnings
 */
export function warn_unused(stylesheet, warnings) {
	walk(stylesheet, { warnings, stylesheet }, visitors);
}
 
/** @type {import('zimmerframe').Visitors<import('#compiler').Css.Node, { warnings: import('../../types.js').RawWarning[], stylesheet: import('#compiler').Css.StyleSheet }>} */
const visitors = {
	Atrule(node, context) {
		if (!is_keyframes_node(node)) {
			context.next();
		}
	},
	PseudoClassSelector(node, context) {
		if (node.name === 'is' || node.name === 'where') {
			context.next();
		}
	},
	ComplexSelector(node, context) {
		if (!node.metadata.used) {
			const content = context.state.stylesheet.content;
			const text = content.styles.substring(node.start - content.start, node.end - content.start);
			warn(context.state.warnings, node, context.path, 'css-unused-selector', text);
		}
 
		context.next();
	},
	Rule(node, context) {
		if (node.metadata.is_global_block) {
			context.visit(node.prelude);
		} else {
			context.next();
		}
	}
};