12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 'use strict';
- module.exports = function nodeContextLookup() {
- const contextMap = new Map();
- return {
-
- getContext(node, ...subContexts) {
- if (!node.source) throw new Error('The node source must be present');
- const nodeSource = node.source.input.from;
- const baseContext = creativeGetMap(contextMap, nodeSource);
- return subContexts.reduce((result, context) => creativeGetMap(result, context), baseContext);
- },
- };
- };
- function creativeGetMap(someMap, someThing) {
- if (!someMap.has(someThing)) {
- someMap.set(someThing, new Map());
- }
- return someMap.get(someThing);
- }
|