examples/log-json-syntax-tree.js
function addNextNodesToASTObject(ASTObject) {
  const ASTObjectsForDepths = [ASTObject];
  function addNextNodes(ASTObject, depth) {
    const depthPlus1 = depth + 1;
    ASTObjectsForDepths[depthPlus1] = ASTObject;
    if (ASTObject.left)
      addNextNodes(ASTObject.left, depthPlus1);
    if (ASTObject.right)
      addNextNodes(ASTObject.right, depthPlus1);
    if (ASTObject.next) {
      const ASTObjectForDepth = ASTObjectsForDepths[depth];
      if (ASTObjectForDepth.nextNodes)
        ASTObjectForDepth.nextNodes.push(ASTObject.next);
      else
        ASTObjectForDepth.nextNodes = [ASTObject.next];
      addNextNodes(ASTObject.next, depth);
    }
  }
  addNextNodes(ASTObject, 0);
}
function addNextNodesToASTObject(ASTObject) {
  const ASTObjectsForDepths = [ASTObject];
  function addNextNodes(ASTObject, depth) {
    const depthPlus1 = depth + 1;
    ASTObjectsForDepths[depthPlus1] = ASTObject;
    if (ASTObject.left)
      addNextNodes(ASTObject.left, depthPlus1);
    if (ASTObject.right)
      addNextNodes(ASTObject.right, depthPlus1);
    if (ASTObject.next) {
      const ASTObjectForDepth = ASTObjectsForDepths[depth];
      if (ASTObjectForDepth.nextNodes)
        ASTObjectForDepth.nextNodes.push(ASTObject.next);
      else
        ASTObjectForDepth.nextNodes = [ASTObject.next];
      addNextNodes(ASTObject.next, depth);
    }
  }
  addNextNodes(ASTObject, 0);
}
function addNextNodesToASTObject ( ASTObject ) { const ASTObjectsForDepths = [ ASTObject ] ; function addNextNodes ( ASTObject , depth ) { const depthPlus1 = depth + 1 ; ASTObjectsForDepths [ depthPlus1 ] = ASTObject ; if ( ASTObject . left ) addNextNodes ( ASTObject . left , depthPlus1 ) ; if ( ASTObject . right ) addNextNodes ( ASTObject . right , depthPlus1 ) ; if ( ASTObject . next ) { const ASTObjectForDepth = ASTObjectsForDepths [ depth ] ; if ( ASTObjectForDepth . nextNodes ) ASTObjectForDepth . nextNodes . push ( ASTObject . next ) ; else ASTObjectForDepth . nextNodes = [ ASTObject . next ] ; addNextNodes ( ASTObject . next , depth ) ; } } addNextNodes ( ASTObject , 0 ) ; }
The next property of an AST node seems to be for the second argument of an opcode, its next property for the third argument, and so on. Add nextNodes properties to AST objects to reflect this relationship.
The next property of an AST node seems to be for the second argument of an opcode its next property for the third argument and so on . Add nextNodes properties to AST objects to reflect this relationship .