packages/walt-parser-tools/src/map-node.js
function mapNode(visitor) {
  const nodeMapper = node => {
    if (node == null) {
      return node;
    }

    const mappingFunction = (() => {
      if ('*' in visitor && typeof visitor['*'] === 'function') {
        return visitor['*'];
      }

      if (node.Type in visitor && typeof visitor[node.Type] === 'function') {
        return visitor[node.Type];
      }
      return identity;
    })();

    if (mappingFunction.length === 2) {
      return mappingFunction(node, nodeMapper);
    }

    const mappedNode = mappingFunction(node);
    const params = mappedNode.params.map(nodeMapper);

    return extend(mappedNode, { params });
  };

  return nodeMapper;
}
function mapNode(visitor) {
  const nodeMapper = node => {
    if (node == null) {
      return node;
    }

    const mappingFunction = (() => {
      if ('*' in visitor && typeof visitor['*'] === 'function') {
        return visitor['*'];
      }

      if (node.Type in visitor && typeof visitor[node.Type] === 'function') {
        return visitor[node.Type];
      }
      return identity;
    })();

    if (mappingFunction.length === 2) {
      return mappingFunction(node, nodeMapper);
    }

    const mappedNode = mappingFunction(node);
    const params = mappedNode.params.map(nodeMapper);

    return extend(mappedNode, { params });
  };

  return nodeMapper;
}
function mapNode ( visitor ) { const nodeMapper = node => { if ( node == null ) { return node ; } const mappingFunction = ( ( ) => { if ( '*' in visitor && typeof visitor [ '*' ] === 'function' ) { return visitor [ '*' ] ; } if ( node . Type in visitor && typeof visitor [ node . Type ] === 'function' ) { return visitor [ node . Type ] ; } return identity ; } ) ( ) ; if ( mappingFunction . length === 2 ) { return mappingFunction ( node , nodeMapper ) ; } const mappedNode = mappingFunction ( node ) ; const params = mappedNode . params . map ( nodeMapper ) ; return extend ( mappedNode , { params } ) ; } ; return nodeMapper ; }
This should maybe be it's own module.
This should maybe be it s own module .