Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

(chore) - Reduce size of visitor function (#8)

authored by

Phil Pluckthun and committed by
GitHub
1a5ff4fa bb9f6a9e

+11 -12
+11 -12
alias/language/visitor.mjs
··· 6 6 const path = []; 7 7 const ancestors = []; 8 8 9 - function callback(node, key, parent, isLeaving) { 10 - const visitFn = getVisitFn(visitor, node.kind, isLeaving); 11 - if (visitFn) { 12 - const result = visitFn.call(visitor, node, key, parent, path, ancestors); 13 - if (result === BREAK) throw BREAK; 14 - return result; 15 - } 16 - } 17 - 18 9 function traverse(node, key, parent) { 19 10 let hasEdited = false; 20 11 21 - const resultEnter = callback(node, key, parent, false); 12 + const enter = getVisitFn(visitor, node.kind, false); 13 + const resultEnter = 14 + enter && enter.call(visitor, node, key, parent, path, ancestors); 22 15 if (resultEnter === false) { 23 16 return node; 24 17 } else if (resultEnter === null) { 25 18 return null; 19 + } else if (resultEnter === BREAK) { 20 + throw BREAK; 26 21 } else if (resultEnter && typeof resultEnter.kind === 'string') { 27 22 hasEdited = resultEnter !== node; 28 23 node = resultEnter; ··· 68 63 } 69 64 70 65 if (parent) ancestors.pop(); 71 - const resultLeave = callback(node, key, parent, true); 72 - if (resultLeave !== undefined) { 66 + const leave = getVisitFn(visitor, node.kind, true); 67 + const resultLeave = 68 + leave && leave.call(visitor, node, key, parent, path, ancestors); 69 + if (resultLeave === BREAK) { 70 + throw BREAK; 71 + } else if (resultLeave !== undefined) { 73 72 return resultLeave; 74 73 } else if (resultEnter !== undefined) { 75 74 return hasEdited ? copy : resultEnter;