Skip to content

Commit

Permalink
chore: show ast on playground (#9440)
Browse files Browse the repository at this point in the history
The modern one
  • Loading branch information
baseballyama committed Nov 14, 2023
1 parent 66661ef commit a6fdc47
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 2 additions & 3 deletions sites/svelte-5-preview/src/lib/Output/Output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
let view = 'result';
let markdown = '';
/** @type {import('svelte/types/compiler/interfaces').Ast} */
let ast;
$: ast = compiled?.result?.ast;
</script>
<div class="view-toggle">
Expand Down Expand Up @@ -110,7 +109,7 @@
</div>
<!-- ast output -->
{#if showAst}
{#if showAst && ast}
<div class="tab-content" class:visible={selected?.type !== 'md' && view === 'ast'}>
<!-- ast view interacts with the module editor, wait for it first -->
{#if $module_editor}
Expand Down
2 changes: 1 addition & 1 deletion sites/svelte-5-preview/src/lib/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion sites/svelte-5-preview/src/lib/workers/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,14 +66,17 @@ 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: {
js: js.code,
css: css?.code || `/* Add a <sty` + `le> tag to see compiled CSS */`,
error: null,
warnings,
metadata
metadata,
ast
}
};
} else if (options.filename.endsWith('.svelte.js')) {
Expand Down
1 change: 1 addition & 0 deletions sites/svelte-5-preview/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@
on:change={change_from_editor}
on:remove={change_from_editor}
previewTheme={$theme.current}
showAst={true}
/>

1 comment on commit a6fdc47

@vercel
Copy link

@vercel vercel bot commented on a6fdc47 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview.vercel.app
svelte-5-preview-svelte.vercel.app
svelte-octane.vercel.app
svelte-5-preview-git-main-svelte.vercel.app

Please sign in to comment.