-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Exported mutable variable in namespace with setter function does not mutate value #5259
Comments
Afaik this is expected by we try to model similar approach to babel where we compile each module as isolated. https://babeljs.io/docs/en/babel-plugin-transform-typescript
Babel raises compile time exception though, while we do not fail but does not allow those behavior. I may wrong, so will leave issue opened until getting second eye on this. |
Yeah that makes sense, babel doesn't even try to compile it so 🤷 - swc does compile it so I was surprised when a call simply didn't work at all, would rather it fail instead of code just running differently though. |
It's consistent with behavior of tsc with isolatedModules: true |
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. |
**Description:** ## Bugfixes - Exported `let`/`var` declarations in TypeScript namespaces should be mutable. - Fix missing declaration of complex exported patterns in TypeScript namespaces. - Preserve concrete TS namespaces. ## New Features - Introducing [Verbatim Module Syntax](https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax). - Enum value will now be inlined whenever possible within a single module, optimizing runtime performance. - Constant enums will be automatically eliminated when feasible, This can reduce bundle size. - Added support for cross-referencing enum values. ## Deprecated `TsEnumConfig` is deprecated - The `treat_const_enum_as_enum` transform option is deprecated. - The `ts_enum_is_readonly` assumption option is deprecated. **BREAKING CHANGE:** TypeScript Config is changed. **Related issue:** - Closes #5197 - Closes #5259 - Closes #7177 - Closes #7453 - Closes #7676 - Closes #7681 - Closes #7791 - Closes #7961
Describe the bug
If an export from a namespace is mutable, and a function in the namespace mutates the value, the exported value is not mutated.
Input code
Config
Playground link
https://play.swc.rs/?version=1.2.218&code=H4sIAAAAAAAAA8tLzE0tLkhMTlVwVKjmUgCC1IqC%2FKIShZzUEoVEBVsFU2suZOG00rzkksz8PIXi1BJHjbLEnNJUK4W80tyk1CJNqAEgANIJlrQGC9Vy1QIA8jab8GkAAAA%3D&config=H4sIAAAAAAAAA0WNSwrDMAxE76J1tt3kDj2ESZXg4B8aBWqM7165OGQnzedNoxMbrY2KE7CMCzWp%2B9JKWgtjE1%2BUFlKYtLsA7vY4OVgtwniZF3IGT3eh6JPf6yBtORZh4LFcOsKd7AaK%2BXMNof3HDGiVmNMJ6g9olj3eM61ycf8BnwbyVboAAAA%3D
Expected behavior
tsc
output correctly mutates the value:Actual behavior
Mutates the variable internal to the namespace but not the exported value from the namespace.
Version
1.2.218
Additional context
No response
The text was updated successfully, but these errors were encountered: