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

Imported modules in compiled code pollute the local scope. #12220

Closed
midnightnoon opened this issue Sep 25, 2021 · 1 comment · Fixed by #13025
Closed

Imported modules in compiled code pollute the local scope. #12220

midnightnoon opened this issue Sep 25, 2021 · 1 comment · Fixed by #13025
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@midnightnoon
Copy link

deno 1.14.0

Code that is imported pollutes the local scope but only when compiled. For example, the following code works when called with deno run but does not work when the executable produced by deno compile is ran.

test.ts

import j2 from './test2.ts'

//@ts-ignore
console.log(j2 === JSON)

if(globalThis.JSON === JSON) console.log('Locally scoped JSON has not been changed.')
else console.log('Locally scoped JSON has been changed!')

console.log(JSON.stringify({}))

test2.ts

export default class JSON{}
> deno run test.ts
false
Locally scoped JSON has not been changed.
{}

> deno compile test.ts
> ./test.exe
true
Locally scoped JSON has been changed!
error: TypeError: JSON.stringify is not a function
    at file://$deno$/bundle.js:12:18
@Nitive
Copy link

Nitive commented Sep 29, 2021

This is also the case with deno bundle

$ deno bundle -q test.ts
class JSON {
}
console.log(JSON === JSON);
if (globalThis.JSON === JSON) console.log('Locally scoped JSON has not been changed.');
else console.log('Locally scoped JSON has been changed!');
console.log(JSON.stringify({
}));
deno 1.13.2 works as expected ```sh $ deno bundle -q test.ts class JSON1 { } console.log(JSON1 === JSON); if (globalThis.JSON === JSON) console.log('Locally scoped JSON has not been changed.'); else console.log('Locally scoped JSON has been changed!'); console.log(JSON.stringify({ })); ```
deno 1.14.2 (currently latest) has this bug ```sh $ deno bundle -q test.ts class JSON { } console.log(JSON === JSON); if (globalThis.JSON === JSON) console.log('Locally scoped JSON has not been changed.'); else console.log('Locally scoped JSON has been changed!'); console.log(JSON.stringify({ })); ```

@bartlomieju bartlomieju added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants