Skip to content

Commit

Permalink
Allow indexer parser walking on instance & add stories with legacy in…
Browse files Browse the repository at this point in the history
…stance test
  • Loading branch information
xeho91 committed Jul 22, 2024
1 parent afdbfc3 commit 6cdaf9d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/indexer/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,19 @@ export async function parseForIndexer(
},

Root(node, context) {
const { module, fragment } = node;
const {
fragment,
// TODO: Remove it in the next major version
instance,
module,
} = node;
const { state, visit } = context;

// TODO: Remove it in the next major version
if (legacyTemplate && instance) {
visit(instance, state);
}

if (module) {
visit(module, state);
} else if (!legacyTemplate) {
Expand All @@ -83,12 +93,12 @@ export async function parseForIndexer(
visit(fragment, state);
},

// NOTE: We walk on instance (if flag was enabled - `Root` handles it) or module
Script(node, context) {
const { content, context: scriptContext } = node;
const { content } = node;
const { state, visit } = context;
if (scriptContext === 'module') {
visit(content, state);
}

visit(content, state);
},

Program(node, context) {
Expand Down
41 changes: 41 additions & 0 deletions tests/stories/LegacyWithInstance.stories.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script lang="ts">
import { Story, Template } from '@storybook/addon-svelte-csf';
import type { Meta } from '@storybook/svelte';
import LegacyTemplate from './LegacyTemplate.svelte';
/**
* Description set explicitly in the comment above export const meta.
*
* Multiline supported. And also Markdown syntax:
*
* * **Bold**,
* * _Italic_,
* * `Code`.
*/
export const meta = {
title: 'LegacyTemplate',
component: LegacyTemplate,
tags: ['autodocs'],
} satisfies Meta<LegacyTemplate>;
let count = $state(0);
function handleClick() {
count += 1;
}
</script>

<Template let:args let:context>
<p>Using default template</p>
<LegacyTemplate {...args} onclick={handleClick} />
</Template>

<Template id="rounded" let:args>
<p>Using rounded template</p>
<LegacyTemplate {...args} onclick={handleClick} rounded />
</Template>

<Story name="Default" />

<Story name="Rounded" template="rounded" />

0 comments on commit 6cdaf9d

Please sign in to comment.