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

TS namespace containing just declare class incorrectly removed #7676

Closed
nicolo-ribaudo opened this issue Jul 19, 2023 · 2 comments · Fixed by #7202
Closed

TS namespace containing just declare class incorrectly removed #7676

nicolo-ribaudo opened this issue Jul 19, 2023 · 2 comments · Fixed by #7202
Labels
Milestone

Comments

@nicolo-ribaudo
Copy link

Describe the bug

TS doesn't remove namespaces that contain declare class, while SWC does

Input code

namespace NS {
  declare class D {}
}

console.log(typeof NS)

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2019",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.70&code=H4sIAAAAAAAAA8tLzE0tLkhMTlXwC1ao5lJQSElNzkksSlUAksXFCi4K1bVctVxcyfl5xfk5qXo5%2BekaJZUFqflpQPWaXADOIbDEPgAAAA%3D%3D&config=H4sIAAAAAAAAA1VPSQ7CMAy85xWRzxyAAxL8gUdEwa2Csil2JaKqfydpk0Jv9iye8SykhDdpeMi5jGWJKhGmfS8IZc%2FqUxDgHJF0MpHh1FmmSg3KEq7QsjHAKo3I1YV0PV%2FuzQE2BMLuaJgz3gz5P1MHFxMSHYVVqvxo8ZgoWiq48JpWsv1S%2B24NbvAT9bD9MBh6dienCcXyBaIK9Y0XAQAA

Expected behavior

var NS;
(function (NS) {
})(NS || (NS = {}));
console.log(typeof NS);

Actual behavior

console.log(typeof NS);

and at runtime it throws that NS is not declared

Version

1.3.70

Additional context

No response

@magic-akari
Copy link
Member

duplicate #5197
will be fixed in #7202

@swc-bot
Copy link
Collaborator

swc-bot commented Aug 19, 2023

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 Aug 19, 2023
@kdy1 kdy1 added this to the Planned milestone Sep 25, 2023
kdy1 pushed a commit that referenced this issue Sep 25, 2023
**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
@kdy1 kdy1 modified the milestones: Planned, v1.3.89 Sep 25, 2023
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.

4 participants