From 88c00b98f55209078554cfd31067178c6ae1e0aa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 22 Oct 2024 13:39:37 -0400 Subject: [PATCH 1/2] fix #525 --- packages/editor/src/lib/Workspace.svelte.ts | 17 +++++--- .../src/lib/Output/CompilerOptions.svelte | 40 +++++++++---------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/packages/editor/src/lib/Workspace.svelte.ts b/packages/editor/src/lib/Workspace.svelte.ts index ffa3c915a4..3479a9e578 100644 --- a/packages/editor/src/lib/Workspace.svelte.ts +++ b/packages/editor/src/lib/Workspace.svelte.ts @@ -1,4 +1,4 @@ -import type { CompileError, CompileResult } from 'svelte/compiler'; +import type { CompileError, CompileOptions, CompileResult } from 'svelte/compiler'; import { EditorState } from '@codemirror/state'; import { compile_file } from './compile-worker'; import { BROWSER } from 'esm-env'; @@ -79,7 +79,7 @@ export class Workspace { creating = $state.raw<{ parent: string; type: 'file' | 'directory' } | null>(null); modified = $state>({}); - compiler_options = $state.raw<{ generate: 'client' | 'server'; dev: boolean }>({ + #compiler_options = $state.raw<{ generate: 'client' | 'server'; dev: boolean }>({ generate: 'client', dev: false }); @@ -128,6 +128,10 @@ export class Workspace { return this.#files; } + get compiler_options() { + return this.#compiler_options; + } + get current() { return this.#current; } @@ -150,10 +154,6 @@ export class Workspace { }); } - invalidate() { - this.#reset_diagnostics(); - } - mark_saved() { this.modified = {}; } @@ -304,6 +304,11 @@ export class Workspace { this.#view = null; } + update_compiler_options(options: CompileOptions) { + this.#compiler_options = { ...this.#compiler_options, ...options }; + this.#reset_diagnostics(); + } + update_file(file: File) { if (file.name === this.#current.name) { this.#current = file; diff --git a/packages/repl/src/lib/Output/CompilerOptions.svelte b/packages/repl/src/lib/Output/CompilerOptions.svelte index 63ad9565e4..c6faea12c3 100644 --- a/packages/repl/src/lib/Output/CompilerOptions.svelte +++ b/packages/repl/src/lib/Output/CompilerOptions.svelte @@ -3,10 +3,6 @@ import { Checkbox } from '@sveltejs/site-kit/components'; let { workspace }: { workspace: Workspace } = $props(); - - function onchange() { - workspace.invalidate(); - }
@@ -14,29 +10,29 @@
generate: - - - - - + {#each ['client', 'server'] as generate} + { + workspace.update_compiler_options({ generate }); + }} + /> + + {/each}
}); From f7de64962069c1755990999e5386bba92d373906 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 22 Oct 2024 13:54:33 -0400 Subject: [PATCH 2/2] lint --- packages/editor/src/lib/Workspace.svelte.ts | 9 +++++++-- packages/repl/src/lib/Output/CompilerOptions.svelte | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/lib/Workspace.svelte.ts b/packages/editor/src/lib/Workspace.svelte.ts index 3479a9e578..ea6840819b 100644 --- a/packages/editor/src/lib/Workspace.svelte.ts +++ b/packages/editor/src/lib/Workspace.svelte.ts @@ -74,12 +74,17 @@ const default_extensions = [ // extensions.push(vim()); // } +interface ExposedCompilerOptions { + generate: 'client' | 'server'; + dev: boolean; +} + export class Workspace { // TODO this stuff should all be readonly creating = $state.raw<{ parent: string; type: 'file' | 'directory' } | null>(null); modified = $state>({}); - #compiler_options = $state.raw<{ generate: 'client' | 'server'; dev: boolean }>({ + #compiler_options = $state.raw({ generate: 'client', dev: false }); @@ -304,7 +309,7 @@ export class Workspace { this.#view = null; } - update_compiler_options(options: CompileOptions) { + update_compiler_options(options: Partial) { this.#compiler_options = { ...this.#compiler_options, ...options }; this.#reset_diagnostics(); } diff --git a/packages/repl/src/lib/Output/CompilerOptions.svelte b/packages/repl/src/lib/Output/CompilerOptions.svelte index c6faea12c3..b16bdcd3e5 100644 --- a/packages/repl/src/lib/Output/CompilerOptions.svelte +++ b/packages/repl/src/lib/Output/CompilerOptions.svelte @@ -10,7 +10,7 @@
generate: - {#each ['client', 'server'] as generate} + {#each ['client', 'server'] as const as generate}