Skip to content

Commit

Permalink
cleanup & notes
Browse files Browse the repository at this point in the history
  • Loading branch information
xeho91 committed Aug 27, 2024
1 parent 40d16b7 commit 2ebe840
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/compiler/post-transform/shared/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export const getParametersPropertyValue = (
Property:
${JSON.stringify(property, null, 2)}
`);

// TODO: this is unsafe. If this happens, we'll just have an error later on. we want to skip instead.
// NOTE: We're emitting a warning when it happens
return undefined as never;
}

Expand Down Expand Up @@ -132,6 +131,7 @@ export const getDocsPropertyValue = (options: Omit<FindPropertyOptions, 'name'>)
Property:
${JSON.stringify(property, null, 2)}
`);
// NOTE: We're emitting a warning when it happens
return undefined as never;
}

Expand Down Expand Up @@ -167,6 +167,7 @@ export const getDescriptionPropertyValue = (options: Omit<FindPropertyOptions, '
Property:
${JSON.stringify(property, null, 2)}
`);
// NOTE: We're emitting a warning when it happens
return undefined as never;
}

Expand Down
18 changes: 11 additions & 7 deletions src/compiler/pre-transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import pkg from '@storybook/addon-svelte-csf/package.json' with { type: 'json' };
import type { Identifier, ImportDeclaration, Program, VariableDeclaration } from 'estree';
import type {
Identifier,
ImportDeclaration,
ObjectExpression,
Program,
VariableDeclaration,
} from 'estree';
import type { Comment, Fragment, Root, Script, SvelteNode } from 'svelte/compiler';

import { transformComponentMetaToDefineMeta } from '#compiler/pre-transform/codemods/component-meta-to-define-meta';
Expand Down Expand Up @@ -112,12 +118,10 @@ export async function codemodLegacyNodes(params: Params): Promise<Root> {
state.defineMetaFromExportConstMeta = transformed;
}

const { init } = declaration.declarations[0];

if (init?.type !== 'ObjectExpression') {
// TODO: Document it?
throw new Error('Invalid syntax in legacy story...');
}
// NOTE:
// Type assertion because we already ran transform codemod function by this point (`transformed`).
// So the possible issue is on our side, not user.
const { init } = declaration.declarations[0] as ObjectExpression;

const { properties } = init;

Expand Down

0 comments on commit 2ebe840

Please sign in to comment.