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
Describe the bug
If you use a const enum in the <script> tag it will still generate a runtime object.
To Reproduce
use official template and run the official script for TS support
disable terser rollup plugin (to have readable output). Also, even though the default state of preserveConstEnums is false, you can set it just to be sure.
replace App.svelte contents with this:
<scriptlang='ts'>constenumState{
opened,
closed,}letstate=State.opened;// We add this so it is not moved into module contextstate++</script>
run npm build or just look into IDE tab with the pre-built version of the component. It will look like this:
/* generated by Svelte v3.29.7 */import{SvelteComponent,init,safe_not_equal}from"svelte/internal";functioninstance($$self){varState;(function(State){State[State["opened"]=0]="opened";State[State["closed"]=1]="closed";})(State||(State={}));letstate=State.opened;// We add this so it is not moved into module contextstate++;return[];}classComponentextendsSvelteComponent{constructor(options){super();init(this,options,instance,null,safe_not_equal,{});}}exportdefaultComponent;
Expected behavior
Should be built into something like this:
/* generated by Svelte v3.29.7 */import{SvelteComponent,init,safe_not_equal}from"svelte/internal";functioninstance($$self){letstate=0;// We add this so it is not moved into module contextstate++;return[];}classComponentextendsSvelteComponent{constructor(options){super();init(this,options,instance,null,safe_not_equal,{});}}exportdefaultComponent;
The text was updated successfully, but these errors were encountered:
Since this is a build error, the right place to file this would be svelte-preprocess since that does the TS->JS preprocessing.
The reason why this happens (I guess) is because the tsconfig contains isolatedModules: true so that each file can be transpiled independently. const enum needs to know the whole project though, so using it is not possible. To not error out, TypeScript's transpilation seems to fall back to generating a regular enum.
Describe the bug
If you use a
const enum
in the<script>
tag it will still generate a runtime object.To Reproduce
terser
rollup plugin (to have readable output). Also, even though the default state ofpreserveConstEnums
isfalse
, you can set it just to be sure.App.svelte
contents with this:npm build
or just look into IDE tab with the pre-built version of the component. It will look like this:Expected behavior
Should be built into something like this:
The text was updated successfully, but these errors were encountered: