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

swc renames global namespaces and enums in script file #2808

Closed
dsherret opened this issue Nov 19, 2021 · 1 comment · Fixed by #2940
Closed

swc renames global namespaces and enums in script file #2808

dsherret opened this issue Nov 19, 2021 · 1 comment · Fixed by #2940
Labels
Milestone

Comments

@dsherret
Copy link
Contributor

dsherret commented Nov 19, 2021

Describe the bug

SWC renames a TypeScript namespace in a script file to have a 1 on the end, but a name in a script file could be used by consumers in other files that aren't compiled by swc.

This only started happening recently in swc.

Input code

Also happens with enums, but here's an example with namespaces:

// test.ts
namespace Test {
  export const test = 1;
}
npx swc test.ts

Playground link

The playground has different behaviour because it's not doing a hygiene pass.

Edit: actually, it is doing this when mangle is turned off, but maybe that is ok because module is set to "common js"? The source type is set to script though.

https://play.swc.rs/?version=1.2.111&code=H4sIAAAAAAAAA8tLzE0tLkhMTlUISS0uUajm5VJQSK0oyC8qUUjOzwOKhCXmlKYq2CoYWvNy1fJy8XKBhPNzUvVy8tM1QHr0wCo0rQFv9PpSSgAAAA%3D%3D&config=H4sIAAAAAAAAA0WOQQ6DMAwE%2F%2BIzh5Yjf%2BgjomBQEIkjr5GKEH%2BvobTcrN2dkTeaEKnbqAYF63FhLRbe1JGtlRE1VaOGDB4NYQY31HMUDSYK6kwX3r0OOrI5xGgf7dOBWQT8R3IqaVgPfZRclYG7CmWcf8vdXVn65Qi28wN3OpKlTKD9Fl1wwutaf%2FEP2XIXPNAAAAA%3D

Expected behavior

var Test;
(function(Test) {
    Test.test = 1;
})(Test || (Test = {
}));

Actual behaviour

var Test1;
(function(Test) {
    Test.test = 1;
})(Test1 || (Test1 = {
}));

Version

1.2.111

Additional context

No response

@dsherret dsherret added the C-bug label Nov 19, 2021
@dsherret dsherret changed the title swc renames namespace in script file swc renames global namespace in script file Nov 19, 2021
@dsherret dsherret changed the title swc renames global namespace in script file swc renames global namespaces and enums in script file Nov 19, 2021
@kdy1 kdy1 modified the milestones: v1.2.112, v1.2.113 Nov 20, 2021
@kdy1 kdy1 modified the milestones: v1.2.117, v1.2.118 Dec 2, 2021
@kdy1 kdy1 closed this as completed in #2940 Dec 3, 2021
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants