-
-
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
[TypeScript] const enum should be hoisted #3648
Comments
another case: console.log(Foo.Bar.A)
namespace Foo {
export const enum Bar {
A = 1
}
console.log("A")
}
console.log(Foo.Bar.B)
namespace Foo {
export const enum Bar {
B = 2
}
console.log("B")
} expected output console.log(1 /* A */);
var Foo;
(function (Foo) {
console.log("A");
})(Foo || (Foo = {}));
console.log(2 /* B */);
(function (Foo) {
console.log("B");
})(Foo || (Foo = {})); |
I think it's partially fixed by #3647. When the const enum is defined and used in the same file, the const enum will be inlined directly, and the hoist issue will disappear. |
Do you think we should close this issue? |
console.log(Foo.A);
console.log(Bar.Foo.A)
const enum Foo {
A = 1
}
namespace Bar {
export const enum Foo {
A = 1
}
console.log("A")
} console.log(1);
console.log(Bar.Foo.A);
var Foo;
(function(Foo) {
Foo[Foo["A"] = 1] = "A";
})(Foo || (Foo = {}));
var Bar1;
(function(Bar) {
let Foo;
(function(Foo) {
Foo[Foo["A"] = 1] = "A";
})(Foo = Bar.Foo || (Bar.Foo = {}));
console.log("A");
})(Bar1 || (Bar1 = {})); |
This comment has been minimized.
This comment has been minimized.
Currently, there is no progress. Furthermore, the new TypeScript 5.0 has made enums even more complex, as opaque computed enum members can now be used. Reference: microsoft/TypeScript#50528 We cannot completely eliminate const enums like TS, but we can make every effort to replace their references. |
This issue should be closed. |
This comment has been minimized.
This comment has been minimized.
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. |
Describe the bug
TS Playground
Input code
Config
Playground link
https://play.swc.rs/?version=1.2.143&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP13DLz9dz1LTm4koGCpYopOaV5ioAxRSquRSAwFHBVsGQqxYA10T3ajEAAAA%3D&config=H4sIAAAAAAAAAy2LQQ6AIAwE%2F9KzB8PBA3%2FwEQ1Wg0ElbUk0hL9bjLfdmd0KuwTwFTKyEPckz6l4gwd9MkngmBUGUDG0YhJqVpA3UpuQuNE5MHRcS0nU%2F%2F32qanzKPNvlAu1F9feoEVwAAAA
Expected behavior
see TypeScript output
Actual behavior
No response
Version
1.2.143
Additional context
No response
The text was updated successfully, but these errors were encountered: