-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Description
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
terserrollup plugin (to have readable output). Also, even though the default state ofpreserveConstEnumsisfalse, you can set it just to be sure. - replace
App.sveltecontents with this:
<script lang='ts'>
const enum State {
opened,
closed,
}
let state = State.opened;
// We add this so it is not moved into module context
state++
</script>- run
npm buildor 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";
function instance($$self) {
var State;
(function (State) {
State[State["opened"] = 0] = "opened";
State[State["closed"] = 1] = "closed";
})(State || (State = {}));
let state = State.opened;
// We add this so it is not moved into module context
state++;
return [];
}
class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, null, safe_not_equal, {});
}
}
export default Component;Expected behavior
Should be built into something like this:
/* generated by Svelte v3.29.7 */
import { SvelteComponent, init, safe_not_equal } from "svelte/internal";
function instance($$self) {
let state = 0;
// We add this so it is not moved into module context
state++;
return [];
}
class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, null, safe_not_equal, {});
}
}
export default Component;Additional context
Copied from here.
@dummdidumm suggested that the reason is the isolatedModules setting. I tried to set it into false, no luck. Also it seems to me that if you do not export the const enum isolatedModules doesn't seem to affect it at all (based mostly on this article).
I tried to compile the following TS file with and without the isolatedModules setting:
const enum State {
closed,
opened,
}
let state = State.closed;
export const fn = () => {}The result seems to be the same (and correct):
"use strict";
exports.__esModule = true;
exports.fn = void 0;
var state = 0 /* closed */;
exports.fn = function () { };curiousdannii
Metadata
Metadata
Assignees
Labels
No labels