title: SyntaxError: Unexpected Identifier (Generators in ES6)
body: <p>I came up with this simple experiment after reading the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators" rel="noreferrer">documentation on generators from MDN</a>:</p>
  <pre><code>var nodes = {
      type: 'root',
      value: [
          { type: 'char', value: 'a' },
          { type: 'char', value: 'b' },
          { type: 'char', value: 'c' },
      ],
  };
  
  function* recursiveGenerator(node) {
      if (node.type === 'root') {
          node.value.forEach(function (subnode) {
              for (var suffix of recursiveGenerator(subnode)) {
                  yield suffix;
              }
          });
      }
  
      else {
          yield node.value;
      }
  }
  
  for (generated of recursiveGenerator(nodes)) {
      console.log(generated);
  }
  </code></pre>
  <p>Running it on node.js v0.11.9 with the <code>--harmony</code> flag set produces the following error:</p>
  <pre><code>alix@900X4C:~$ node --version
  v0.11.9
  alix@900X4C:~$ node --harmony test.js 
  
  /home/alix/test.js:14
                  yield suffix;
                        ^^^^^^
  SyntaxError: Unexpected identifier
  </code></pre>
  <p>I also tried using <code>for ... in ...</code> and the <code>let</code> keyword instead of <code>var</code>, but without any success.</p>
  <p>I don't understand <a href="http://wiki.ecmascript.org/doku.php?id=harmony:generators#delegating_yield" rel="noreferrer">what <code>yield*</code> does exactly</a>, but if I use it within the <code>for</code> loop I get instead:</p>
  <pre><code>alix@900X4C:~$ node --harmony test.js 
  
  /home/alix/test.js:14
                  yield* suffix;
                  ^
  ReferenceError: yield is not defined
  </code></pre>
  <p>If I replace the yield in the for with <code>console.log()</code> it outputs <code>a</code>, <code>b</code> and <code>c</code>. What am I doing wrong?</p>
  <hr />
  <h2>Edit</h2>
  <p>Here's a minimalistic generator, showing that node.js knows what to do with generators:</p>
  <pre><code>function* alpha() {
      yield 'a';
      yield 'b';
      yield 'c';
  }
  
  for (var suffix of alpha()) {
      console.log(suffix);
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>alix@900X4C:~$ node --harmony y.js 
  a
  b
  c
  </code></pre>
  <hr />
  <h2>Solution (thanks @Andrew)</h2>
  <pre><code>function* recursiveGenerator(node) {
      if (node.type === 'root') {
          for (var i = 0; i &lt; node.value.length; ++i) {
              var subnode = node.value[i];
  
              for (var suffix of recursiveGenerator(subnode)) {
                  yield suffix;
              }
          }
      }
  
      else {
          yield node.value;
      }
  }
  
  for (generated of recursiveGenerator(nodes)) {
      console.log(generated);
  }
  </code></pre>