code: public static function visitWithTypeInfo(TypeInfo $typeInfo, $visitor)
      {
          return [
              'enter' => static function (Node $node) use ($typeInfo, $visitor) {
                  $typeInfo->enter($node);
                  $fn = self::getVisitFn($visitor, $node->kind, false);
  
                  if ($fn) {
                      $result = call_user_func_array($fn, func_get_args());
                      if ($result !== null) {
                          $typeInfo->leave($node);
                          if ($result instanceof Node) {
                              $typeInfo->enter($result);
                          }
                      }
  
                      return $result;
                  }
  
                  return null;
              },
              'leave' => static function (Node $node) use ($typeInfo, $visitor) {
                  $fn     = self::getVisitFn($visitor, $node->kind, true);
                  $result = $fn ? call_user_func_array($fn, func_get_args()) : null;
                  $typeInfo->leave($node);
  
                  return $result;
              },
          ];
      }
docs: Creates a new visitor instance which maintains a provided TypeInfo instance
  along with visiting visitor.