Skip to content

Commit

Permalink
Update 01-var.js
Browse files Browse the repository at this point in the history
#1 Fallback stats
  • Loading branch information
LeaVerou committed Oct 2, 2020
1 parent e8a60b3 commit d5367ca
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions js/01-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ let ret = {
properties: {},
functions: {},
supports: {},
"pseudo-classes": {}
"pseudo-classes": {},
fallback: {
none: 0,
literal: 0,
var: 0
}
};

walkRules(ast, rule => {
Expand All @@ -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);
}
}
Expand Down

0 comments on commit d5367ca

Please sign in to comment.