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

Added typescript support for code snippets #15

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/frameworks/solid-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "storybook-solidjs-vite",
"type": "module",
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.5",
"description": "Storybook for SolidJS and Vite: Develop SolidJS in isolation with Hot Reloading.",
"keywords": [
"storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/solid/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "storybook-solidjs",
"type": "module",
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.5",
"description": "Storybook SolidJS renderer",
"keywords": [
"storybook"
Expand Down
13 changes: 13 additions & 0 deletions packages/renderers/solid/src/docs/sourceDecorator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ test('component with method prop', () => {
`);
});

test('component with typescript', () => {
const newSrc = generateSolidSource(
'Component',
'{ args: { double: (x: number) => { return x * 2; } } }',
);

expect(newSrc).toMatchInlineSnapshot(`
"<Component double={(x: number) => {
return x * 2;
}} />"
`);
});

test('component missing story config', () => {
const newSrc = () => generateSolidSource('Component', '5 + 4');

Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/solid/src/docs/sourceDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ interface SolidProps {
* The source code will be in the form of a `Story` object.
*/
function parseProps(src: string): SolidProps {
const ast = parser.parseExpression(src, { plugins: ['jsx'] });
const ast = parser.parseExpression(src, { plugins: ['jsx', 'typescript'] });
if (ast.type != 'ObjectExpression') throw 'Expected `ObjectExpression` type';
// Find args property.
const args_prop = ast.properties.find((v: any) => {
Expand Down