Skip to content

Commit

Permalink
[#20] Remove optional chaining operator
Browse files Browse the repository at this point in the history
(unsupported by BigQuery)
  • Loading branch information
LeaVerou committed Oct 5, 2020
1 parent 465ecf1 commit ee937c2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
8 changes: 5 additions & 3 deletions js/20-gradients.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ walkDeclarations(ast, ({property, value}) => {

// Separate color and position(s)
stops = stops.map(s => {
let color = s.match(/#[a-f0-9]+|(?:rgba?|hsla?|color)\((\(.*?\)|.)+?\)/)?.[0];
let match = s.match(/#[a-f0-9]+|(?:rgba?|hsla?|color)\((\(.*?\)|.)+?\)/);
let color = match && match[0];

if (!color) {
color = s.match(keywordRegex)?.[0];
let match = s.match(keywordRegex);
color = match && match[0];
}

let pos = s.replace(color, "").trim().split(/\s+/);
Expand All @@ -79,7 +81,7 @@ walkDeclarations(ast, ({property, value}) => {
}
// Two positions of which the first is 0 or the same as the last one
else if (s.pos.length === 2) {
if (parseFLoat(s.pos[0]) === 0 || prev.pos.length === 2 && s.pos[0] === prev.pos?.[1] || prev.pos.length === 1 && s.pos[0] === s.pos[0]) {
if (parseFLoat(s.pos[0]) === 0 || prev.pos.length === 2 && s.pos[0] === (prev.pos && prev.pos[1]) || prev.pos.length === 1 && s.pos[0] === s.pos[0]) {
ret.hard_stops++;
}
}
Expand Down
4 changes: 1 addition & 3 deletions runtime/var-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ walkElements(computed, node => {
}
})



return {summary, computed};

};
Expand Down Expand Up @@ -340,7 +338,7 @@ function serializeElement(element) {

return str;
}

return element;
}

Expand Down
66 changes: 66 additions & 0 deletions vars/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export default function compute() {

function walkElements(node, callback, parent) {
if (Array.isArray(node)) {
for (let n of node) {
walkElements(n, callback, node);
}
}
else {
callback(node, parent);

if (node.children) {
walkElements(node.children, callback, node);
}
}
}

let ret = {

};

function countDependencyLength(declarations, property) {
let o = declarations[property];

if (o === undefined) {
return 0;
}

if (!o.references || o.references.length === 0) {
return 0;
}

let lengths = o.references.map(p => countDependencyLength(declarations, p));

return 1 + Math.max(...lengths);
}

walkElements(vars.computed, (node, parent) => {
if (node.declarations) {
// Make inheritance explicit
if (parent && parent.declarations) {
for (let property in parent.declarations) {
if (!(property in node.declarations)) {
node.declarations[property] = Object.assign({inherited: true}, parent.declarations[property]);
}
}
}

for (let property in node.declarations) {

let o = node.declarations[property];
if (o.computed && o.computed.trim() === "initial" && o.value.trim() !== "initial") {
// Cycle or missing ref
incrementByKey(ret, "initial");
}
else if (o.references) {
let depth = countDependencyLength(node.declarations, property);
incrementByKey(ret, depth);
}
}
}
});

return ret;

}

0 comments on commit ee937c2

Please sign in to comment.