* Register a Babel-style visitor map; calls accumulate per node type. * A bucket is a function (= `{ enter }`) or `{ enter?, exit? }`. * @param {VisitorMap<TNode>} map visitor map keyed by node type * @returns {SourceProcessor<TNode, TProcessOptions>} `this`, for chaining
(map)
| 68 | * @returns {SourceProcessor<TNode, TProcessOptions>} `this`, for chaining |
| 69 | */ |
| 70 | use(map) { |
| 71 | // `map`'s keys are node-type enum members; `Object.keys` stringifies them, |
| 72 | // so index the compiled array by the number to match the numeric `node.type`. |
| 73 | for (const type of Object.keys(map)) { |
| 74 | const key = Number(type); |
| 75 | const v = map[key]; |
| 76 | let bucket = this._visitors[key]; |
| 77 | if (!bucket) { |
| 78 | bucket = { enter: [], exit: [] }; |
| 79 | this._visitors[key] = bucket; |
| 80 | } |
| 81 | if (typeof v === "function") { |
| 82 | bucket.enter.push(v); |
| 83 | } else { |
| 84 | if (v.enter) bucket.enter.push(v.enter); |
| 85 | if (v.exit) bucket.exit.push(v.exit); |
| 86 | } |
| 87 | } |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Run the grammar over `input`, firing visitors in source order. No |
no test coverage detected