12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- "use strict"
- module.exports = function mergeVisitorsInPlace(visitor1, visitor2) {
- for (const key of Object.keys(visitor2)) {
- const handler1 = visitor1[key]
- const handler2 = visitor2[key]
- if (typeof handler1 === "function") {
- if (handler1._handlers) {
- handler1._handlers.push(handler2)
- } else {
- const handlers = [handler1, handler2]
- visitor1[key] = Object.assign(dispatch.bind(null, handlers), {
- _handlers: handlers,
- })
- }
- } else {
- visitor1[key] = handler2
- }
- }
- return visitor1
- }
- function dispatch(handlers, node) {
- for (const h of handlers) {
- h(node)
- }
- }
|