UNPKG

scancss

Version:

A robust CSS stylesheet statistics collector and analyzer

93 lines (67 loc) 2.81 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleAtRule = handleAtRule; var _cssAtRules = require('../../../constants/cssAtRules'); var _rePrefixedString = require('../../../constants/rePrefixedString'); var _countUsage = require('../../../calculators/countUsage'); var _isAtRuleDeclaration = require('../../../predicates/isAtRuleDeclaration'); var _handleVendorPrefix = require('../../handleVendorPrefix'); var _handleImport = require('../handleImport'); var _handleKeyframes = require('../handleKeyframes'); var _handleMediaQueryParams = require('../handleMediaQueryParams'); var _handleSupports = require('../handleSupports'); var _handleAtRuleFunctions = require('../handleAtRuleFunctions'); var _handleAtRuleDescriptor = require('../handleAtRuleDescriptor'); /* eslint-disable-next-line complexity */ function handleAtRule(atRule, report, options) { report.atRules.total++; if (Array.isArray(atRule.nodes) && atRule.nodes.length === 0) { report.atRules.empty++; } const atRuleName = atRule.name.toLowerCase(); (0, _countUsage.countUsage)(atRuleName, report.atRules.usage); /** Count vendor prefixes in at-rules names */ if (_rePrefixedString.rePrefixedString.test(atRuleName)) { report.atRules.prefixed++; (0, _handleVendorPrefix.handleVendorPrefix)(atRuleName, report); } /** Count unknown at-rules */ const unprefixedAtRuleName = atRuleName.replace(_rePrefixedString.rePrefixedString, ''); if (_cssAtRules.cssAtRules.includes(unprefixedAtRuleName) === false) { report.atRules.unknown.total++; (0, _countUsage.countUsage)(atRuleName, report.atRules.unknown.usage); } if (atRuleName === 'import') { (0, _handleImport.handleImport)(atRule, report, options); } if (atRuleName === 'supports') { (0, _handleSupports.handleSupports)(atRule, report, options); } if (atRuleName === 'media') { (0, _handleMediaQueryParams.handleMediaQueryParams)(atRule.params, report, options); } if (unprefixedAtRuleName === 'keyframes') { (0, _handleKeyframes.handleKeyframes)(atRule, report); } if (options.functions) { if (unprefixedAtRuleName === 'document' || unprefixedAtRuleName === 'import' || unprefixedAtRuleName === 'namespace') { (0, _handleAtRuleFunctions.handleAtRuleFunctions)(atRule.params, report); } if (unprefixedAtRuleName === 'font-face') { atRule.walkDecls(decl => { (0, _handleAtRuleFunctions.handleAtRuleFunctions)(decl.value, report); }); } } if (options.declarations) { atRule.walkDecls(decl => { if ((0, _isAtRuleDeclaration.isAtRuleDeclaration)(unprefixedAtRuleName, decl) === false) { (0, _handleAtRuleDescriptor.handleAtRuleDescriptor)(decl, report); return; } (0, _countUsage.countUsage)(atRuleName, report.declarations.inAtRules); }); } }