title: Recursive Generators in JavaScript
body: <p>I am trying to write a recursive generator for an in order traversal.</p>
  
  <pre><code>class Tree {
    *inOrderTraversal() {
      function* helper(node) {
        if (node.left !== null) {
          // this line is executed, but helper is not being called
          helper(node.left); 
        }
        yield node.value;
        if (node.right !== null) {
          helper(node.right);
        }
      }
  
      for (let i of helper(this.root)) {
        yield i;
      }
    }
    // other methods omitted
  }
  </code></pre>
  
  <p>And I am calling the generator like so:</p>
  
  <pre><code>const tree = new Tree();
  tree.add(2);
  tree.add(1);
  tree.add(3);
  
  for (let i of tree.inOrderTraversal()) {
      console.log(i); // only prints 2
  }
  </code></pre>
  
  <p>Why is the generator only yielding <code>2</code>? Why is it at least not yielding <code>1</code> before <code>2</code>? </p>
  
  <p>How can I fix this?</p>
  
  <p>If it helps, I am transpiling the code using babel.</p>
  
  <p><code>babel --optional runtime test.js | node</code></p>