You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
We don't have const enum in TS support due to isolatedModules setting (more on this here: sveltejs/svelte-preprocess#281).
But I want it so bad.
Describe the solution you'd like
A cool workaround would be to allow terser to inline const objects.
Here's the code:
If you run it in the Terser REPL, it will turn it into this:
constn=1;exportfunctionblablah(){returnn}
, which is more or less what const enum does (in reality it inlines the stuff, so there's no variables at all, but that doesn't matter imo).
But here's the problem. If you copy the compiled code from this simple Svelte component, and run it through Terser, the States variable won't disappear! Here, it's highlighted in the image.
And the reason, I believe, is that the content of context='module' in the compiled version of the code goes way down to the function instance. But if you move the declaration up so it's right below the imports, it will be inlined! (highlighted as well)
As far as I understand it shouldn't break anything in the components/runtime, but will help us get a little bit more optimized code. Free optimization, a very low hanging fruit and a functional replacement for const enum!
Describe alternatives you've considered
None.
How important is this feature to you?
Very nice to have :)
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is your feature request related to a problem? Please describe.
We don't have const enum in TS support due to
isolatedModules
setting (more on this here: sveltejs/svelte-preprocess#281).But I want it so bad.
Describe the solution you'd like
A cool workaround would be to allow terser to inline const objects.
Here's the code:
If you run it in the Terser REPL, it will turn it into this:
, which is more or less what const enum does (in reality it inlines the stuff, so there's no variables at all, but that doesn't matter imo).
But here's the problem. If you copy the compiled code from this simple Svelte component, and run it through Terser, the


States
variable won't disappear! Here, it's highlighted in the image.And the reason, I believe, is that the content of
context='module'
in the compiled version of the code goes way down to thefunction instance
. But if you move the declaration up so it's right below the imports, it will be inlined! (highlighted as well)As far as I understand it shouldn't break anything in the components/runtime, but will help us get a little bit more optimized code. Free optimization, a very low hanging fruit and a functional replacement for
const enum
!Describe alternatives you've considered
None.
How important is this feature to you?
Very nice to have :)
The text was updated successfully, but these errors were encountered: