Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno bundle doesn't resolve conflicting names (ex. Map) #12121

Closed
bxantus opened this issue Sep 17, 2021 · 3 comments
Closed

deno bundle doesn't resolve conflicting names (ex. Map) #12121

bxantus opened this issue Sep 17, 2021 · 3 comments
Labels
duplicate a duplicate of another issue

Comments

@bxantus
Copy link

bxantus commented Sep 17, 2021

deno bundle (also Deno.emit with bundle) seems to have broken.

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).

Steps to reproduce

I made a minimal example consisting of two files, with which the problem can be easily reproduced:
myMap.ts

export class Map {
    hello() {
        console.log("Hi")
    }
}

test.ts

import { Map as MyMap } from "./myMap.ts"

const map = new MyMap()
map.hello()
const tests = new Map<string, string>()
tests.set("test1", "my test")

When running test via deno run test.ts, I get the correct results:

Hi

But when running, after bundling, the error shows up:

>deno bundle test.ts test.js
Check file:///C:/work/test/test.ts
Bundle file:///C:/work/test/test.ts
Emit "test.js" (153B)

>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

test.js

class Map {
    hello() {
        console.log("Hi");
    }
}
const map = new Map();
map.hello();
const tests = new Map();
tests.set("test1", "my test");

Which is obviously incorrect.

Additional details

Deno version: deno 1.14.0

@bxantus
Copy link
Author

bxantus commented Sep 17, 2021

Update: deno 1.13 isn't affected by this bug (my project and the small test behaves correctly with it too)
test.js with deno 1.13.0

class Map1 {
    hello() {
        console.log("Hi");
    }
}
const map = new Map1();
map.hello();
const tests = new Map();
tests.set("test1", "my test");

@MarkTiedemann
Copy link
Contributor

Seems like this is the same issue: #12086

@kitsonk kitsonk added the duplicate a duplicate of another issue label Sep 18, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Sep 18, 2021

Yes, duplicate of #10286. Previously symbols that shadowed the global scope symbols were being unnecessarily renamed, now they aren't being renamed at all.

@kitsonk kitsonk closed this as completed Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants