<h3 dir="auto">Input Code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { x, ...y } = foo();"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> x<span class="pl-kos">,</span> ...<span class="pl-s1">y</span> <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;dependencies&quot;: {
    &quot;babel-plugin-transform-object-rest-spread&quot;: &quot;^6.19.0&quot;,
    &quot;babel-cli&quot;: &quot;^6.18.0&quot;
  },
  &quot;scripts&quot;: {
    &quot;build&quot;: &quot;babel --plugins transform-object-rest-spread src.js &gt; out.js&quot;
  }
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"dependencies"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"babel-plugin-transform-object-rest-spread"</span>: <span class="pl-s">"^6.19.0"</span><span class="pl-kos">,</span>
    <span class="pl-s">"babel-cli"</span>: <span class="pl-s">"^6.18.0"</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-s">"scripts"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"build"</span>: <span class="pl-s">"babel --plugins transform-object-rest-spread src.js &gt; out.js"</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const _ref = foo();
const { x } = _ref;
const y = _objectWithoutProperties(_ref, [&quot;x&quot;]);"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">_ref</span> <span class="pl-c1">=</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">const</span> <span class="pl-kos">{</span> x <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">_ref</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-en">_objectWithoutProperties</span><span class="pl-kos">(</span><span class="pl-s1">_ref</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s">"x"</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { x } = foo();
const y = _objectWithoutProperties(foo(), [&quot;x&quot;]);"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> x <span class="pl-kos">}</span> <span class="pl-c1">=</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">const</span> <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-en">_objectWithoutProperties</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> <span class="pl-kos">[</span><span class="pl-s">"x"</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Context</h3>


<h3 dir="auto">Your Environment</h3>

<table role="table">
<thead>
<tr>
<th>software</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>babel-core@6.18.2, babel-cli@6.18.0, babel-plugin-transform-object-rest-spread@6.19.0</td>
</tr>
<tr>
<td>node</td>
<td>4.1.2, 6.5.0, 7.1.0</td>
</tr>
<tr>
<td>npm</td>
<td>2.14.4, 3.10.3, 3.10.9</td>
</tr>
<tr>
<td>Operating System</td>
<td>Windows, Linux</td>
</tr>
</tbody>
</table>
<p dir="auto">It also does something <em>crazy</em> for this code <g-emoji class="g-emoji" alias="stuck_out_tongue_winking_eye" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f61c.png">😜</g-emoji> ... <code class="notranslate">c</code> gets hoisted out of the arrow function and then the above bug duplicates the entire thing:</p>
<p dir="auto">in:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { a } = foo(({ b, ...c }) =&gt; {
  console.log(b, c);
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> a <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">{</span> b<span class="pl-kos">,</span> ...<span class="pl-s1">c</span> <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</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">b</span><span class="pl-kos">,</span> <span class="pl-s1">c</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">out:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { a } = foo(({ b }) =&gt; {
  console.log(b, c);
});
const c = _objectWithoutProperties(foo(({ b }) =&gt; {
  console.log(b, c);
}), [&quot;b&quot;]);"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> a <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">{</span> b <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</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">b</span><span class="pl-kos">,</span> <span class="pl-s1">c</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">const</span> <span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-en">_objectWithoutProperties</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> b <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</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">b</span><span class="pl-kos">,</span> <span class="pl-s1">c</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-s">"b"</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Currently:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[1, 2].push(...arguments);"><pre class="notranslate"><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span>...<span class="pl-smi">arguments</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Outputs:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[1, 2].push.apply([1, 2], _slice.call(arguments));"><pre class="notranslate"><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">push</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">_slice</span><span class="pl-kos">.</span><span class="pl-en">call</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></pre></div>
<p dir="auto">But it should be (something like):</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var _ref;
(_ref = [1, 2]).push.apply(_ref, _slice.call(arguments));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">_ref</span><span class="pl-kos">;</span>
<span class="pl-kos">(</span><span class="pl-s1">_ref</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">push</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">_ref</span><span class="pl-kos">,</span> <span class="pl-s1">_slice</span><span class="pl-kos">.</span><span class="pl-en">call</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></pre></div>