.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / nodeContextLookup.js
1 // Too weird for Flow
2 "use strict";
3
4 /**
5  * Create a collection of Maps that serve to contextualize a given node.
6  * This is useful to ensure that you only compare nodes that share a certain
7  * context.
8  *
9  * All nodes are initially contextualized by their input source.
10  * From there, you can contextualize them however you want.
11  *
12  * For a usage example, see `selector-no-descending-specificity`.
13  */
14 module.exports = function() {
15   const contextMap = new Map();
16
17   return {
18     getContext(node) {
19       const nodeSource = node.source.input.from;
20       const baseContext = creativeGetMap(contextMap, nodeSource);
21       const subContexts = Array.from(arguments).slice(1);
22
23       return subContexts.reduce((result, context) => {
24         return creativeGetMap(result, context);
25       }, baseContext);
26     }
27   };
28 };
29
30 function creativeGetMap(someMap, someThing) {
31   if (!someMap.has(someThing)) {
32     someMap.set(someThing, new Map());
33   }
34   return someMap.get(someThing);
35 }