<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
according to <a href="https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html" rel="nofollow">https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html</a>, It says that top-level exports is immutable. so I test it on babel and node esm module loader, but it generates different results.</p>
<p dir="auto"><strong>Input Code</strong><br>
the demo is here <a href="https://github.com/hardfist/babel-module">https://github.com/hardfist/babel-module</a><br>
<code class="notranslate">npm run esm</code> and <code class="notranslate">npm run cjs</code> generates different result.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// main.mjs
import * as lib from './lib';

lib.name = 'lib';
console.log('lib:',lib);
"><pre class="notranslate"><span class="pl-c">// main.mjs</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">lib</span> <span class="pl-k">from</span> <span class="pl-s">'./lib'</span><span class="pl-kos">;</span>

<span class="pl-s1">lib</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">=</span> <span class="pl-s">'lib'</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">'lib:'</span><span class="pl-kos">,</span><span class="pl-s1">lib</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// lib.mjs
export const foo = 'bar';"><pre class="notranslate"><span class="pl-c">// lib.mjs</span>
<span class="pl-k">export</span> <span class="pl-k">const</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-s">'bar'</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">esm results</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(node:70216) ExperimentalWarning: The ESM module loader is experimental.
TypeError: Cannot add property name, object is not extensible"><pre class="notranslate"><code class="notranslate">(node:70216) ExperimentalWarning: The ESM module loader is experimental.
TypeError: Cannot add property name, object is not extensible
</code></pre></div>
<p dir="auto">babel results</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="lib: { foo: 'bar', name: 'lib' }"><pre class="notranslate"><code class="notranslate">lib: { foo: 'bar', name: 'lib' }
</code></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong><br>
same behavior for babel and node esm module loader<br>
<strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = {
  presets: [
    [
      '@babel/env',
      {
        modules: 'commonjs',
        targets: {
          node: 'current',
        },
      },
    ],
  ],
};"><pre class="notranslate"><span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span>
      <span class="pl-s">'@babel/env'</span><span class="pl-kos">,</span>
      <span class="pl-kos">{</span>
        <span class="pl-c1">modules</span>: <span class="pl-s">'commonjs'</span><span class="pl-kos">,</span>
        <span class="pl-c1">targets</span>: <span class="pl-kos">{</span>
          <span class="pl-c1">node</span>: <span class="pl-s">'current'</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>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): 7.1.6</li>
<li>Node/npm version: 10.13.0</li>
<li>OS: 10.12.4</li>
<li>How you are using Babel: cli</li>
</ul>
<p dir="auto"><strong>Possible Solution</strong></p>

<p dir="auto"><strong>Additional context/Screenshots</strong><br>
Add any other context about the problem here. If applicable, add screenshots to help explain.</p>
<p dir="auto">export.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export var value = 0;"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">var</span> <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">import1.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {value} from &quot;./export&quot;;
value++; // SyntaxError: import.js: Line 2: &quot;value&quot; is read-only"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-s1">value</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"./export"</span><span class="pl-kos">;</span>
<span class="pl-s1">value</span><span class="pl-c1">++</span><span class="pl-kos">;</span> <span class="pl-c">// SyntaxError: import.js: Line 2: "value" is read-only</span></pre></div>
<p dir="auto">import2.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import * as export from &quot;./export&quot;;
export.value++; // No error"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">export</span> <span class="pl-k">from</span> <span class="pl-s">"./export"</span><span class="pl-kos">;</span>
<span class="pl-s1">export</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-c1">++</span><span class="pl-kos">;</span> <span class="pl-c">// No error</span></pre></div>
<p dir="auto">If I understand the specification properly, both of these should throw an error as all the properties of export should be immutable bindings</p>