diff --git a/sites/svelte-5-preview/src/lib/Output/Output.svelte b/sites/svelte-5-preview/src/lib/Output/Output.svelte
index d1018d6a6f..eebb8a23ad 100644
--- a/sites/svelte-5-preview/src/lib/Output/Output.svelte
+++ b/sites/svelte-5-preview/src/lib/Output/Output.svelte
@@ -58,8 +58,7 @@
let view = 'result';
let markdown = '';
- /** @type {import('svelte/types/compiler/interfaces').Ast} */
- let ast;
+ $: ast = compiled?.result?.ast;
@@ -110,7 +109,7 @@
-{#if showAst}
+{#if showAst && ast}
{#if $module_editor}
diff --git a/sites/svelte-5-preview/src/lib/Repl.svelte b/sites/svelte-5-preview/src/lib/Repl.svelte
index ff144d5d32..87c465e271 100644
--- a/sites/svelte-5-preview/src/lib/Repl.svelte
+++ b/sites/svelte-5-preview/src/lib/Repl.svelte
@@ -254,7 +254,7 @@
if (!compiler || !$selected) return;
if ($selected.type === 'svelte' || $selected.type === 'js') {
- compiled = await compiler.compile($selected, $compile_options, false);
+ compiled = await compiler.compile($selected, $compile_options, true);
runes = compiled.result.metadata?.runes ?? false;
} else {
runes = false;
diff --git a/sites/svelte-5-preview/src/lib/workers/compiler/index.js b/sites/svelte-5-preview/src/lib/workers/compiler/index.js
index 56ff247161..d3d7e475d1 100644
--- a/sites/svelte-5-preview/src/lib/workers/compiler/index.js
+++ b/sites/svelte-5-preview/src/lib/workers/compiler/index.js
@@ -3,6 +3,7 @@ self.window = self; //TODO: still need?: egregious hack to get magic-string to w
/**
* @type {{
+ * parse: typeof import('svelte/compiler').parse;
* compile: typeof import('svelte/compiler').compile;
* compileModule: typeof import('svelte/compiler').compileModule;
* VERSION: string;
@@ -65,6 +66,8 @@ function compile({ id, source, options, return_ast }) {
const { js, css, warnings, metadata } = compiled;
+ const ast = return_ast ? svelte.parse(source, { modern: true }) : undefined;
+
return {
id,
result: {
@@ -72,7 +75,8 @@ function compile({ id, source, options, return_ast }) {
css: css?.code || `/* Add a tag to see compiled CSS */`,
error: null,
warnings,
- metadata
+ metadata,
+ ast
}
};
} else if (options.filename.endsWith('.svelte.js')) {
diff --git a/sites/svelte-5-preview/src/routes/+page.svelte b/sites/svelte-5-preview/src/routes/+page.svelte
index 5db6ae65eb..3ce2f7062d 100644
--- a/sites/svelte-5-preview/src/routes/+page.svelte
+++ b/sites/svelte-5-preview/src/routes/+page.svelte
@@ -92,4 +92,5 @@
on:change={change_from_editor}
on:remove={change_from_editor}
previewTheme={$theme.current}
+ showAst={true}
/>