From d5367ca1debf35542e1da639cc8034f23d4226e6 Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Fri, 2 Oct 2020 18:47:17 +0300 Subject: [PATCH] Update 01-var.js #1 Fallback stats --- js/01-var.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/js/01-var.js b/js/01-var.js index 16727a2..dba38b2 100644 --- a/js/01-var.js +++ b/js/01-var.js @@ -4,7 +4,12 @@ let ret = { properties: {}, functions: {}, supports: {}, - "pseudo-classes": {} + "pseudo-classes": {}, + fallback: { + none: 0, + literal: 0, + var: 0 + } }; walkRules(ast, rule => { @@ -16,13 +21,26 @@ walkRules(ast, rule => { let parsedSelectors = {}; walkDeclarations(ast, ({property, value}, rule) => { - if (matches(value, /var\(\s*--/)) { + if (matches(value, /\bvar\(\s*--/)) { if (!property.startsWith("--")) { incrementByKey(ret.properties, property); } for (let call of extractFunctionCalls(value)) { - if (call.name !== "var" && call.args.includes("var(--")) { + if (call.name === "var") { + let fallback = call.args.split(",").slice(1).join(","); + + if (matches(fallback, /\bvar\(\s*--/)) { + ret.fallback.var++; + } + else if (fallback) { + ret.fallback.literal++; + } + else { + ret.fallback.none++; + } + } + else if (call.args.includes("var(--")) { incrementByKey(ret.functions, call.name); } }