From b7048fd213385f9d3e58a63aebf972868ee440b9 Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Thu, 29 Oct 2020 14:47:25 +0200 Subject: [PATCH] Get registered variables (that are currently set) Rel #1 --- vars/registered.js | 35 +++++++++++++++++++++++++++++++++++ vars/root.js | 1 - 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 vars/registered.js diff --git a/vars/registered.js b/vars/registered.js new file mode 100644 index 0000000..a677dca --- /dev/null +++ b/vars/registered.js @@ -0,0 +1,35 @@ +export default function compute() { + +function walkElements(node, callback) { + if (Array.isArray(node)) { + for (let n of node) { + walkElements(n, callback); + } + } + else { + callback(node); + + if (node.children) { + walkElements(node.children, callback); + } + } +} + +let ret = new Set(); + +walkElements(vars.computed, node => { + if (node.declarations) { + for (let property in node.declarations) { + let value; + let o = node.declarations[property]; + + if (property.startsWith("--") && o.type) { + ret.add(property); + } + } + } +}); + +return [...ret]; + +} diff --git a/vars/root.js b/vars/root.js index 8b3676d..e053bf0 100644 --- a/vars/root.js +++ b/vars/root.js @@ -24,7 +24,6 @@ let ret = { walkElements(vars.computed, node => { if (node.declarations) { for (let property in node.declarations) { - let value; let o = node.declarations[property]; if (property.startsWith("--")) {