<p dir="auto">Does babel make code that will conditionally run native generators instead of always using the performance cost of regenerator (when using <code class="notranslate">transform-regenerator</code>)?</p>
<p dir="auto">f.e., something similar to (examples copied pasted from regenerator site):</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if (supportsGenerators()) {
    function *range(max, step) {
      var count = 0;
      step = step || 1;

      for (var i = 0; i &lt; max; i += step) {
        count++;
        yield i;
      }

      return count;
    }

    var gen = range(20, 3), info;

    while (!(info = gen.next()).done) {
      console.log(info.value);
    }

    console.log(&quot;steps taken: &quot; + info.value);
}
else {
    var marked0$0 = [range].map(regeneratorRuntime.mark);
    function range(max, step) {
      var count, i;

      return regeneratorRuntime.wrap(function range$(context$1$0) {
        while (1) switch (context$1$0.prev = context$1$0.next) {
        case 0:
          count = 0;
          step = step || 1;

          i = 0;
        case 3:
          if (!(i &lt; max)) {
            context$1$0.next = 10;
            break;
          }

          count++;
          context$1$0.next = 7;
          return i;
        case 7:
          i += step;
          context$1$0.next = 3;
          break;
        case 10:
          return context$1$0.abrupt(&quot;return&quot;, count);
        case 11:
        case &quot;end&quot;:
          return context$1$0.stop();
        }
      }, marked0$0[0], this);
    }

    var gen = range(20, 3), info;

    while (!(info = gen.next()).done) {
      console.log(info.value);
    }

    console.log(&quot;steps taken: &quot; + info.value);
}"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-en">supportsGenerators</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">function</span> <span class="pl-c1">*</span><span class="pl-s1">range</span><span class="pl-kos">(</span><span class="pl-s1">max</span><span class="pl-kos">,</span> <span class="pl-s1">step</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">var</span> <span class="pl-s1">count</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
      <span class="pl-s1">step</span> <span class="pl-c1">=</span> <span class="pl-s1">step</span> <span class="pl-c1">||</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>

      <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">max</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">+=</span> <span class="pl-s1">step</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">count</span><span class="pl-c1">++</span><span class="pl-kos">;</span>
        <span class="pl-k">yield</span> <span class="pl-s1">i</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span>

      <span class="pl-k">return</span> <span class="pl-s1">count</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-k">var</span> <span class="pl-s1">gen</span> <span class="pl-c1">=</span> <span class="pl-en">range</span><span class="pl-kos">(</span><span class="pl-c1">20</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">info</span><span class="pl-kos">;</span>

    <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">info</span> <span class="pl-c1">=</span> <span class="pl-s1">gen</span><span class="pl-kos">.</span><span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">done</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">info</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"steps taken: "</span> <span class="pl-c1">+</span> <span class="pl-s1">info</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-k">else</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">marked0$0</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-s1">range</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">regeneratorRuntime</span><span class="pl-kos">.</span><span class="pl-c1">mark</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">function</span> <span class="pl-en">range</span><span class="pl-kos">(</span><span class="pl-s1">max</span><span class="pl-kos">,</span> <span class="pl-s1">step</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">var</span> <span class="pl-s1">count</span><span class="pl-kos">,</span> <span class="pl-s1">i</span><span class="pl-kos">;</span>

      <span class="pl-k">return</span> <span class="pl-s1">regeneratorRuntime</span><span class="pl-kos">.</span><span class="pl-en">wrap</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">range$</span><span class="pl-kos">(</span><span class="pl-s1">context$1$0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">prev</span> <span class="pl-c1">=</span> <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">next</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">case</span> <span class="pl-c1">0</span>:
          <span class="pl-s1">count</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
          <span class="pl-s1">step</span> <span class="pl-c1">=</span> <span class="pl-s1">step</span> <span class="pl-c1">||</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>

          <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
        <span class="pl-k">case</span> <span class="pl-c1">3</span>:
          <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">max</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">next</span> <span class="pl-c1">=</span> <span class="pl-c1">10</span><span class="pl-kos">;</span>
            <span class="pl-k">break</span><span class="pl-kos">;</span>
          <span class="pl-kos">}</span>

          <span class="pl-s1">count</span><span class="pl-c1">++</span><span class="pl-kos">;</span>
          <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">next</span> <span class="pl-c1">=</span> <span class="pl-c1">7</span><span class="pl-kos">;</span>
          <span class="pl-k">return</span> <span class="pl-s1">i</span><span class="pl-kos">;</span>
        <span class="pl-k">case</span> <span class="pl-c1">7</span>:
          <span class="pl-s1">i</span> <span class="pl-c1">+=</span> <span class="pl-s1">step</span><span class="pl-kos">;</span>
          <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">next</span> <span class="pl-c1">=</span> <span class="pl-c1">3</span><span class="pl-kos">;</span>
          <span class="pl-k">break</span><span class="pl-kos">;</span>
        <span class="pl-k">case</span> <span class="pl-c1">10</span>:
          <span class="pl-k">return</span> <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-en">abrupt</span><span class="pl-kos">(</span><span class="pl-s">"return"</span><span class="pl-kos">,</span> <span class="pl-s1">count</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">case</span> <span class="pl-c1">11</span>:
        <span class="pl-k">case</span> <span class="pl-s">"end"</span>:
          <span class="pl-k">return</span> <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-en">stop</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">marked0$0</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-k">var</span> <span class="pl-s1">gen</span> <span class="pl-c1">=</span> <span class="pl-en">range</span><span class="pl-kos">(</span><span class="pl-c1">20</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">info</span><span class="pl-kos">;</span>

    <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">info</span> <span class="pl-c1">=</span> <span class="pl-s1">gen</span><span class="pl-kos">.</span><span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">done</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">info</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"steps taken: "</span> <span class="pl-c1">+</span> <span class="pl-s1">info</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Cellule/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Cellule">@Cellule</a></p>
</blockquote>
<h3 dir="auto">Bug information</h3>
<ul dir="auto">
<li><strong>Babel version:</strong> 6.8.0</li>
<li><strong>Node version:</strong> 5.5.0</li>
<li><strong>npm version:</strong> 3.7.2</li>
</ul>
<h3 dir="auto">Options</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    &quot;plugins&quot;: [&quot;transform-es2015-modules-umd&quot;]
  }"><pre class="notranslate"><code class="notranslate">{
    "plugins": ["transform-es2015-modules-umd"]
  }
</code></pre></div>
<h3 dir="auto">Input code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="require(&quot;module&quot;).test;"><pre class="notranslate"><span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"module"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">test</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">Compiling <code class="notranslate">require("module").test;</code> with plugin <code class="notranslate">transform-es2015-modules-umd</code><br>
throws the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: test.js: Property object of MemberExpression expected node to be of a type [&quot;Expression&quot;] but instead got null
at Object.validate (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-types\lib\definitions\index.js:115:13)
at Object.validate (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-types\lib\index.js:552:9)
at NodePath._replaceWith (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\replacement.js:214:7)
at NodePath._remove (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\removal.js:60:10)
at NodePath.remove (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\removal.js:31:8)
at PluginPass.CallExpression (E:\Projects\chakra-runner\node_modules\babel-plugin-transform-es2015-modules-amd\lib\index.js:42:12)
at NodePath._call (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\context.js:78:18)
at NodePath.call (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\context.js:49:17)
at NodePath.visit (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\context.js:108:12)
at TraversalContext.visitQueue (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\context.js:174:16)"><pre class="notranslate"><code class="notranslate">TypeError: test.js: Property object of MemberExpression expected node to be of a type ["Expression"] but instead got null
at Object.validate (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-types\lib\definitions\index.js:115:13)
at Object.validate (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-types\lib\index.js:552:9)
at NodePath._replaceWith (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\replacement.js:214:7)
at NodePath._remove (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\removal.js:60:10)
at NodePath.remove (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\removal.js:31:8)
at PluginPass.CallExpression (E:\Projects\chakra-runner\node_modules\babel-plugin-transform-es2015-modules-amd\lib\index.js:42:12)
at NodePath._call (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\context.js:78:18)
at NodePath.call (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\context.js:49:17)
at NodePath.visit (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\path\context.js:108:12)
at TraversalContext.visitQueue (E:\Projects\chakra-runner\node_modules\babel-cli\node_modules\babel-traverse\lib\context.js:174:16)
</code></pre></div>