<p dir="auto"><code class="notranslate">deno bundle</code> (also <code class="notranslate">Deno.emit</code> with bundle) seems to have broken.</p>
<p dir="auto">For example when I export a class named Map, it conflicts with the builtin javascript Map type. By conflict I mean, that on each place where I like to use the map data structure, my own Map class will be instantiated (bundle should have renamed it to Map1 or something similar).</p>
<h2 dir="auto">Steps to reproduce</h2>
<p dir="auto">I made a minimal example consisting of two files, with which the problem can be easily reproduced:<br>
<strong>myMap.ts</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export class Map {
    hello() {
        console.log(&quot;Hi&quot;)
    }
}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">Map</span> <span class="pl-kos">{</span>
    <span class="pl-en">hello</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">"Hi"</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>test.ts</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import { Map as MyMap } from &quot;./myMap.ts&quot;

const map = new MyMap()
map.hello()
const tests = new Map&lt;string, string&gt;()
tests.set(&quot;test1&quot;, &quot;my test&quot;)"><pre class="notranslate"><code class="notranslate">import { Map as MyMap } from "./myMap.ts"

const map = new MyMap()
map.hello()
const tests = new Map&lt;string, string&gt;()
tests.set("test1", "my test")
</code></pre></div>
<p dir="auto">When running test via <code class="notranslate">deno run test.ts</code>, I get the correct results:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Hi"><pre class="notranslate"><code class="notranslate">Hi
</code></pre></div>
<p dir="auto">But when running, after bundling, the error shows up:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;deno bundle test.ts test.js
Check file:///C:/work/test/test.ts
Bundle file:///C:/work/test/test.ts
Emit &quot;test.js&quot; (153B)

&gt;deno run test.js 
Hi
error: Uncaught TypeError: tests.set is not a function
tests.set(&quot;test1&quot;, &quot;my test&quot;);
      ^
    at file:///C:/work/test/test.js:9:7"><pre class="notranslate"><code class="notranslate">&gt;deno bundle test.ts test.js
Check file:///C:/work/test/test.ts
Bundle file:///C:/work/test/test.ts
Emit "test.js" (153B)

&gt;deno run test.js 
Hi
error: Uncaught TypeError: tests.set is not a function
tests.set("test1", "my test");
      ^
    at file:///C:/work/test/test.js:9:7
</code></pre></div>
<p dir="auto"><strong>test.js</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Map {
    hello() {
        console.log(&quot;Hi&quot;);
    }
}
const map = new Map();
map.hello();
const tests = new Map();
tests.set(&quot;test1&quot;, &quot;my test&quot;);"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Map</span> <span class="pl-kos">{</span>
    <span class="pl-en">hello</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">"Hi"</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">map</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Map</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">map</span><span class="pl-kos">.</span><span class="pl-en">hello</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">tests</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Map</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">tests</span><span class="pl-kos">.</span><span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s">"test1"</span><span class="pl-kos">,</span> <span class="pl-s">"my test"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Which is obviously incorrect.</p>
<h2 dir="auto">Additional details</h2>
<p dir="auto">Deno version: deno 1.14.0</p>
<p dir="auto">Edit: It appears this is for all requests:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const request = new Request('https://api.github.com/repos/denoland/deno');
console.log(request.cache); // throws TypeError"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">request</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Request</span><span class="pl-kos">(</span><span class="pl-s">'https://api.github.com/repos/denoland/deno'</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">request</span><span class="pl-kos">.</span><span class="pl-c1">cache</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// throws TypeError</span></pre></div>
<hr>
<p dir="auto">In Deno v<code class="notranslate">1.9.1</code>: for each <a href="https://doc.deno.land/builtin/unstable#Deno.RequestEvent" rel="nofollow"><code class="notranslate">Deno.RequestEvent</code></a> yielded by <a href="https://doc.deno.land/builtin/unstable#Deno.serveHttp" rel="nofollow"><code class="notranslate">Deno.serveHttp</code></a>, accessing the value of <code class="notranslate">requestEvent.request.cache</code> throws a TypeError.</p>
<p dir="auto">Here is the source:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/denoland/deno/blob/a1ac17f9fa8d22e13a619598941aad4fba2fd6a3/op_crates/fetch/23_request.js#L341-L344">deno/op_crates/fetch/23_request.js</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 341 to 344
      in
      <a data-pjax="true" class="commit-tease-sha" href="/denoland/deno/commit/a1ac17f9fa8d22e13a619598941aad4fba2fd6a3">a1ac17f</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L341" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="341"></td>
          <td id="LC341" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">get</span> <span class="pl-en">cache</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L342" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="342"></td>
          <td id="LC342" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-s1">webidl</span><span class="pl-kos">.</span><span class="pl-en">assertBranded</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-v">Request</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L343" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="343"></td>
          <td id="LC343" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">TypeError</span><span class="pl-kos">(</span><span class="pl-s">"This property is not implemented."</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L344" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="344"></td>
          <td id="LC344" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">This did not occur in <code class="notranslate">1.9.0</code> (the value was <code class="notranslate">undefined</code>). See the reproduction case below:</p>
<h3 dir="auto">Reproduce:</h3>
<p dir="auto"><code class="notranslate">example.ts</code>:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="async function handleConnection(conn: Deno.Conn) {
  for await (const { request, respondWith } of Deno.serveHttp(conn)) {
    try {
      const { cache } = request;
      respondWith(new Response(`Cache mode is: ${cache}`));
    } catch (ex) {
      await respondWith(new Response(ex.toString(), { status: 500 }));
      throw ex;
    }
  }
}

async function main() {
  const hostname = &quot;localhost&quot;;
  const port = 8000;
  const url = new URL(`http://${hostname}:${port}/`);

  await Deno.permissions.request({ name: &quot;net&quot;, host: url.host });

  const listener = Deno.listen({ hostname, port });
  console.log(`Listening at ${url.href}\nUse ctrl+c to stop`);

  for await (const conn of listener) handleConnection(conn);
}

if (import.meta.main) main();"><pre class="notranslate"><span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">handleConnection</span><span class="pl-kos">(</span><span class="pl-s1">conn</span>: <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-smi">Conn</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">for</span> <span class="pl-k">await</span> <span class="pl-kos">(</span><span class="pl-k">const</span> <span class="pl-kos">{</span> request<span class="pl-kos">,</span> respondWith <span class="pl-kos">}</span> <span class="pl-k">of</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">serveHttp</span><span class="pl-kos">(</span><span class="pl-s1">conn</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">try</span> <span class="pl-kos">{</span>
      <span class="pl-k">const</span> <span class="pl-kos">{</span> cache <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">request</span><span class="pl-kos">;</span>
      <span class="pl-en">respondWith</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">Response</span><span class="pl-kos">(</span><span class="pl-s">`Cache mode is: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">cache</span><span class="pl-kos">}</span></span>`</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">catch</span> <span class="pl-kos">(</span><span class="pl-s1">ex</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">await</span> <span class="pl-en">respondWith</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">Response</span><span class="pl-kos">(</span><span class="pl-s1">ex</span><span class="pl-kos">.</span><span class="pl-en">toString</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">status</span>: <span class="pl-c1">500</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">throw</span> <span class="pl-s1">ex</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">async</span> <span class="pl-k">function</span> <span class="pl-en">main</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">hostname</span> <span class="pl-c1">=</span> <span class="pl-s">"localhost"</span><span class="pl-kos">;</span>
  <span class="pl-k">const</span> <span class="pl-s1">port</span> <span class="pl-c1">=</span> <span class="pl-c1">8000</span><span class="pl-kos">;</span>
  <span class="pl-k">const</span> <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">URL</span><span class="pl-kos">(</span><span class="pl-s">`http://<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">hostname</span><span class="pl-kos">}</span></span>:<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">port</span><span class="pl-kos">}</span></span>/`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-k">await</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-c1">permissions</span><span class="pl-kos">.</span><span class="pl-en">request</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c1">name</span>: <span class="pl-s">"net"</span><span class="pl-kos">,</span> <span class="pl-c1">host</span>: <span class="pl-s1">url</span><span class="pl-kos">.</span><span class="pl-c1">host</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">listener</span> <span class="pl-c1">=</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">listen</span><span class="pl-kos">(</span><span class="pl-kos">{</span> hostname<span class="pl-kos">,</span> port <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">`Listening at <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">url</span><span class="pl-kos">.</span><span class="pl-c1">href</span><span class="pl-kos">}</span></span>\nUse ctrl+c to stop`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-k">for</span> <span class="pl-k">await</span> <span class="pl-kos">(</span><span class="pl-k">const</span> <span class="pl-s1">conn</span> <span class="pl-k">of</span> <span class="pl-s1">listener</span><span class="pl-kos">)</span> <span class="pl-en">handleConnection</span><span class="pl-kos">(</span><span class="pl-s1">conn</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-k">import</span><span class="pl-kos">.</span><span class="pl-c1">meta</span><span class="pl-kos">.</span><span class="pl-c1">main</span><span class="pl-kos">)</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<ol dir="auto">
<li>Start server:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="% deno --unstable run example.ts
⚠️  ️Deno requests network access to &quot;localhost:8000&quot;. Grant? [g/d (g = grant, d = deny)] g
Listening at http://localhost:8000/
Use ctrl+c to stop"><pre class="notranslate"><code class="notranslate">% deno --unstable run example.ts
⚠️  ️Deno requests network access to "localhost:8000". Grant? [g/d (g = grant, d = deny)] g
Listening at http://localhost:8000/
Use ctrl+c to stop
</code></pre></div>
<ol start="2" dir="auto">
<li>Navigate to <a href="http://localhost:8000/" rel="nofollow">http://localhost:8000/</a> in a browser. Switch back to terminal.</li>
<li>An exception was thrown. <code class="notranslate">stderr</code>:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Uncaught (in promise) TypeError: This property is not implemented.
      const { cache } = request;
              ^
    at Request.get cache (deno:op_crates/fetch/23_request.js:343:13)
    at handleConnection (file:///Users/jesse/example/example.ts:4:15)"><pre class="notranslate"><code class="notranslate">error: Uncaught (in promise) TypeError: This property is not implemented.
      const { cache } = request;
              ^
    at Request.get cache (deno:op_crates/fetch/23_request.js:343:13)
    at handleConnection (file:///Users/jesse/example/example.ts:4:15)
</code></pre></div>
<h3 dir="auto">Version</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="% deno --version
deno 1.9.1 (release, x86_64-apple-darwin)
v8 9.1.269.5
typescript 4.2.2"><pre class="notranslate"><code class="notranslate">% deno --version
deno 1.9.1 (release, x86_64-apple-darwin)
v8 9.1.269.5
typescript 4.2.2
</code></pre></div>