Skip to content

Commit

Permalink
Merge pull request #13386 from storybookjs/13247-fix-svelte-argstable
Browse files Browse the repository at this point in the history
Addon-docs: Handle svelte docgen failures gracefully
  • Loading branch information
shilman authored Dec 6, 2020
2 parents 07ec616 + 39255ac commit 058b79c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
25 changes: 15 additions & 10 deletions addons/docs/src/frameworks/svelte/extractArgTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArgTypes } from '@storybook/api';
import { logger } from '@storybook/client-logger';

import { ArgTypesExtractor } from '../../lib/docgen';

Expand Down Expand Up @@ -33,19 +34,23 @@ type Docgen = {
};

export const extractArgTypes: ArgTypesExtractor = (component) => {
// eslint-disable-next-line new-cap
const comp: ComponentWithDocgen = new component({ props: {} });
// eslint-disable-next-line no-underscore-dangle
const docs = comp.__docgen;

const results = createArgTypes(docs);

return results;
try {
// eslint-disable-next-line new-cap
const comp: ComponentWithDocgen = new component({ props: {} });
// eslint-disable-next-line no-underscore-dangle
const docgen = comp.__docgen;
if (docgen) {
return createArgTypes(docgen);
}
} catch (err) {
logger.log(`Error extracting argTypes: ${err}`);
}
return {};
};

export const createArgTypes = (docs: Docgen) => {
export const createArgTypes = (docgen: Docgen) => {
const results: ArgTypes = {};
docs.data.forEach((item) => {
docgen.data.forEach((item) => {
results[item.name] = {
control: { type: parseType(item.type.type) },
name: item.name,
Expand Down
14 changes: 14 additions & 0 deletions examples/svelte-kitchen-sink/src/stories/error.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ErrorView from './views/ErrorView.svelte';

export default {
title: 'Error',
component: ErrorView,
parameters: {
chromatic: { disable: true },
storyshots: { disable: true },
},
};

export const Error = () => ({
Component: ErrorView,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script>
export let myFunction;
myFunction();
</script>

0 comments on commit 058b79c

Please sign in to comment.