Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(svelte-vite): Use compiled AST output as source of truth for getting component name #30369

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
atttempt to fix type error
  • Loading branch information
xeho91 committed Jan 26, 2025
commit 04ab7b99859b40bd000395bbc5c03f650b336512
5 changes: 3 additions & 2 deletions code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { basename, relative } from 'node:path';

import { logger } from 'storybook/internal/node-logger';

import type AST from 'estree';
import MagicString from 'magic-string';
import { replace, typescript } from 'svelte-preprocess';
import { preprocess } from 'svelte/compiler';
Expand Down Expand Up @@ -41,9 +42,9 @@ svelteDocParserOptions.getAstDefaultOptions = () => ({
*/
function getComponentName(ast: ReturnType<import('rollup').PluginContext['parse']>): string {
// NOTE: Assertion, because rollup returns a type `AcornNode` for some reason, which doesn't overlap with `Program` from estree
const exportDefaultDeclaration = (ast as unknown as import('estree').Program).body.find(
const exportDefaultDeclaration = (ast as unknown as AST.Program).body.find(
(n) => n.type === 'ExportDefaultDeclaration'
);
) as AST.ExportDefaultDeclaration | undefined;

if (!exportDefaultDeclaration) {
throw new Error('Unreachable - no default export found');
Expand Down
Loading