From f60b3140fce44d6023ea28f20f1fdbe7b78d6e89 Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Mon, 14 Sep 2020 04:07:02 +0300 Subject: [PATCH] Create 19-supports.js --- js/19-supports.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 js/19-supports.js diff --git a/js/19-supports.js b/js/19-supports.js new file mode 100644 index 0000000..a669803 --- /dev/null +++ b/js/19-supports.js @@ -0,0 +1,30 @@ +export default function compute() { + +let ret = {}; + +walkRules(ast, rule => { + incrementByKey(ret, "total"); + + let condition = rule.supports; + + // Drop whitespace around parens + condition = condition.replace(/\s*\(\s*/g, "(").replace(/\s*\)\s*/g, ")"); + + // Match property: value queries first + for (let match of condition.matchAll(/\([\w-]+\s*:/g)) { + let arg = parsel.gobbleParens(condition, match.index); + incrementByKey(ret, arg); + } + + // Then find selector queries + for (let match of condition.matchAll(/selector\(/gi)) { + let arg = parsel.gobbleParens(condition, match.index + match[0].length - 1); + incrementByKey(ret, "selector" + arg); + } +}, {type: "supports"}); + +ret = sortObject(ret); + +return ret; + +}