<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
The following code throws an error that <code class="notranslate">bar</code> is not defined (no error in babel@6).</p>
<p dir="auto"><strong>Input Code</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="async function foo() {
  await (async function bar() {
    await bar();
  })();
}

foo();"><pre class="notranslate"><span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">await</span> <span class="pl-kos">(</span><span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">bar</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">await</span> <span class="pl-en">bar</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-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior</strong><br>
The code inside an async self-executing named function is able to refer to the function by name.</p>
<p dir="auto"><strong>Babel Configuration (.babelrc)</strong></p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;presets&quot;: [
    [&quot;@babel/env&quot;, {
      &quot;modules&quot;: &quot;cjs&quot;,
      &quot;useBuiltIns&quot;: &quot;entry&quot;
    }],
    &quot;@babel/typescript&quot;,
    &quot;@babel/react&quot;
  ]
}"><pre class="notranslate">{
  <span class="pl-ent">"presets"</span>: [
    [<span class="pl-s"><span class="pl-pds">"</span>@babel/env<span class="pl-pds">"</span></span>, {
      <span class="pl-ent">"modules"</span>: <span class="pl-s"><span class="pl-pds">"</span>cjs<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"useBuiltIns"</span>: <span class="pl-s"><span class="pl-pds">"</span>entry<span class="pl-pds">"</span></span>
    }],
    <span class="pl-s"><span class="pl-pds">"</span>@babel/typescript<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>@babel/react<span class="pl-pds">"</span></span>
  ]
}</pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): @babel/core@7.1.2, @babel/preset-env@7.1.0, @babel/preset-typescript@7.1.0, @babel/preset-react@7.0.0</li>
<li>Node/npm version: node v10.10.0, npm@6.4.1</li>
<li>OS: OSX 10.13.6</li>
<li>Monorepo: no</li>
<li>How you are using Babel: webpack (loader) / parcel</li>
</ul>
<p dir="auto"><strong>Possible Solution</strong><br>
This is probably caused by asyncToGenerator / regenerator. <code class="notranslate">bar</code> is eventually located not inside <code class="notranslate">bar</code> itself and the function <code class="notranslate">bar</code> is not transpiled into a function declaration (this was in babel@6 and therefore there was no error present), but rather is still a function expression.</p>
<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
When trying to upgrade to Babel 7. Calling async function from within self-invoking function now causes <code class="notranslate">ReferenceError: poll is not defined</code>.</p>
<p dir="auto"><strong>Input Code</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="(async function poll() {
  console.log(await Promise.resolve('Hello'))
  setTimeout(poll, 1000);
})();"><pre class="notranslate"><span class="pl-kos">(</span><span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">poll</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-k">await</span> <span class="pl-v">Promise</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s">'Hello'</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
  <span class="pl-en">setTimeout</span><span class="pl-kos">(</span><span class="pl-s1">poll</span><span class="pl-kos">,</span> <span class="pl-c1">1000</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-kos">;</span></pre></div>
<p dir="auto"><strong>Transformed Code</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="(function () {
  var _poll = _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee() {
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.t0 = console;
            _context.next = 3;
            return Promise.resolve('Hello');

          case 3:
            _context.t1 = _context.sent;

            _context.t0.log.call(_context.t0, _context.t1);

            setTimeout(poll, 1000);

          case 6:
          case &quot;end&quot;:
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function poll() {
    return _poll.apply(this, arguments);
  };
})()();"><pre class="notranslate"><span class="pl-kos">(</span><span class="pl-k">function</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">_poll</span> <span class="pl-c1">=</span> <span class="pl-en">_asyncToGenerator</span><span class="pl-kos">(</span>
  <span class="pl-c">/*#__PURE__*/</span>
  <span class="pl-s1">regeneratorRuntime</span><span class="pl-kos">.</span><span class="pl-en">mark</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">_callee</span><span class="pl-kos">(</span><span class="pl-kos">)</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">_callee$</span><span class="pl-kos">(</span><span class="pl-s1">_context</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-kos">{</span>
        <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">_context</span><span class="pl-kos">.</span><span class="pl-c1">prev</span> <span class="pl-c1">=</span> <span class="pl-s1">_context</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">_context</span><span class="pl-kos">.</span><span class="pl-c1">t0</span> <span class="pl-c1">=</span> <span class="pl-smi">console</span><span class="pl-kos">;</span>
            <span class="pl-s1">_context</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">return</span> <span class="pl-v">Promise</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s">'Hello'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

          <span class="pl-k">case</span> <span class="pl-c1">3</span>:
            <span class="pl-s1">_context</span><span class="pl-kos">.</span><span class="pl-c1">t1</span> <span class="pl-c1">=</span> <span class="pl-s1">_context</span><span class="pl-kos">.</span><span class="pl-c1">sent</span><span class="pl-kos">;</span>

            <span class="pl-s1">_context</span><span class="pl-kos">.</span><span class="pl-c1">t0</span><span class="pl-kos">.</span><span class="pl-c1">log</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">_context</span><span class="pl-kos">.</span><span class="pl-c1">t0</span><span class="pl-kos">,</span> <span class="pl-s1">_context</span><span class="pl-kos">.</span><span class="pl-c1">t1</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

            <span class="pl-en">setTimeout</span><span class="pl-kos">(</span><span class="pl-s1">poll</span><span class="pl-kos">,</span> <span class="pl-c1">1000</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

          <span class="pl-k">case</span> <span class="pl-c1">6</span>:
          <span class="pl-k">case</span> <span class="pl-s">"end"</span>:
            <span class="pl-k">return</span> <span class="pl-s1">_context</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-kos">,</span> <span class="pl-s1">_callee</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-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-k">function</span> <span class="pl-en">poll</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-s1">_poll</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-smi">arguments</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-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Error</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Applications.js:64 Uncaught (in promise) ReferenceError: poll is not defined
    at _callee$ (Applications.js:64)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:296)
    at Generator.prototype.(anonymous function) [as next] (webpack:///./node_modules/regenerator-runtime/runtime.js?:114:21)
    at asyncGeneratorStep (Applications.js:19)
    at _next (Applications.js:21)"><pre class="notranslate"><span class="pl-v">Applications</span><span class="pl-kos">.</span><span class="pl-en">js</span>:<span class="pl-c1">64</span> <span class="pl-v">Uncaught</span> <span class="pl-kos">(</span><span class="pl-s1">in</span> <span class="pl-s1">promise</span><span class="pl-kos">)</span><span class="pl-kos"></span> ReferenceError: <span class="pl-s1">poll</span> <span class="pl-s1">is</span> <span class="pl-s1">not</span> <span class="pl-s1">defined</span>
    <span class="pl-en">at</span> <span class="pl-s1">_callee$</span> <span class="pl-kos">(</span><span class="pl-v">Applications</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">64</span><span class="pl-kos">)</span>
    <span class="pl-en">at</span> <span class="pl-s1">tryCatch</span> <span class="pl-kos">(</span><span class="pl-s1">runtime</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">62</span><span class="pl-kos">)</span>
    <span class="pl-s1">at</span> <span class="pl-v">Generator</span><span class="pl-kos">.</span><span class="pl-c1">invoke</span> <span class="pl-kos">[</span><span class="pl-s1">as</span> <span class="pl-s1">_invoke</span><span class="pl-kos">]</span> <span class="pl-kos">(</span><span class="pl-s1">runtime</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">296</span><span class="pl-kos">)</span>
    <span class="pl-s1">at</span> <span class="pl-v">Generator</span><span class="pl-kos">.</span><span class="pl-en">prototype</span><span class="pl-kos">.</span><span class="pl-kos">(</span><span class="pl-s1">anonymous</span> <span class="pl-s1">function</span><span class="pl-kos">)</span> <span class="pl-kos">[</span><span class="pl-s1">as</span> <span class="pl-s1">next</span><span class="pl-kos">]</span> <span class="pl-kos">(</span><span class="pl-s1">webpack</span>:<span class="pl-c">///./node_modules/regenerator-runtime/runtime.js?:114:21)</span>
    <span class="pl-s1">at</span> <span class="pl-en">asyncGeneratorStep</span> <span class="pl-kos">(</span><span class="pl-v">Applications</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">19</span><span class="pl-kos">)</span>
    <span class="pl-s1">at</span> <span class="pl-en">_next</span> <span class="pl-kos">(</span><span class="pl-v">Applications</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">21</span><span class="pl-kos">)</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong><br>
Recursively calls async function.</p>
<p dir="auto"><strong>Babel Configuration (babel.config.js, webpack.config.js)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = function (api) {
    api.cache(true)
    const presets = [ '@babel/preset-env', '@babel/preset-react' ];
    const plugins = [ '@babel/plugin-proposal-class-properties' ];
  
    return {
      presets,
      plugins
    };
  }"><pre class="notranslate"><span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-en">exports</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">api</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s1">api</span><span class="pl-kos">.</span><span class="pl-en">cache</span><span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span>
    <span class="pl-k">const</span> <span class="pl-s1">presets</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span> <span class="pl-s">'@babel/preset-env'</span><span class="pl-kos">,</span> <span class="pl-s">'@babel/preset-react'</span> <span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">plugins</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span> <span class="pl-s">'@babel/plugin-proposal-class-properties'</span> <span class="pl-kos">]</span><span class="pl-kos">;</span>
  
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
      presets<span class="pl-kos">,</span>
      plugins
    <span class="pl-kos">}</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span></pre></div>
<p dir="auto">Using @babel/polyfill in webpack.config.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="entry: {
  react: ['@babel/polyfill', './index.js']
},"><pre class="notranslate"><span class="pl-s1">entry</span>: <span class="pl-kos">{</span>
  <span class="pl-c1">react</span>: <span class="pl-kos">[</span><span class="pl-s">'@babel/polyfill'</span><span class="pl-kos">,</span> <span class="pl-s">'./index.js'</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): v7.0.0</li>
<li>Node/npm version: v8.9.0</li>
<li>OS: OSX 10.12.6</li>
<li>Monorepo: no</li>
<li>How you are using Babel: loader</li>
</ul>
<p dir="auto"><strong>Additional context/Screenshots</strong><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/734863/46206095-d7aff880-c31a-11e8-813b-18812f223064.png"><img width="484" alt="screen shot 2018-09-28 at 12 33 51" src="https://user-images.githubusercontent.com/734863/46206095-d7aff880-c31a-11e8-813b-18812f223064.png" style="max-width: 100%;"></a></p>