UNPKG

scancss

Version:

A robust CSS stylesheet statistics collector and analyzer

39 lines (30 loc) 1.2 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleSupports = handleSupports; var _cssBrowserHacks = require('../../../constants/cssBrowserHacks'); var _rePrefixedString = require('../../../constants/rePrefixedString'); var _countUsage = require('../../../calculators/countUsage'); var _handleVendorPrefix = require('../../handleVendorPrefix'); const cssSupportsBrowserHacks = _cssBrowserHacks.cssBrowserHacks.filter(hack => hack.type === 'supports'); const rePropertyValuePair = /\(\s*(([-a-zA-Z]+):\s*(.+?))\s*\)/g; function handleSupports(atRule, report, options) { if (rePropertyValuePair.test(atRule.params)) { atRule.params.match(rePropertyValuePair).map(pair => pair.slice(1, -1).trim()).forEach(pair => { if (_rePrefixedString.rePrefixedString.test(pair)) { (0, _handleVendorPrefix.handleVendorPrefix)(pair, report); } }); } if (options.browserHacks) { cssSupportsBrowserHacks.forEach(hack => { if (hack.regex.test(atRule.params)) { atRule.params.match(hack.regex).forEach(match => { report.browserHacks.total++; (0, _countUsage.countUsage)(match, report.browserHacks.usage.supports); }); } }); } }