Socket
Socket
Sign inDemoInstall

@storybook/addon-svelte-csf

Package Overview
Dependencies
Maintainers
31
Versions
279
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/addon-svelte-csf - npm Package Compare versions

Comparing version 4.0.10 to 4.0.11

7

dist/parser/collect-stories.d.ts

@@ -0,1 +1,2 @@

import type { StoryDef } from './extract-stories.ts';
interface Meta {

@@ -5,5 +6,5 @@ name: string;

}
declare const _default: (StoriesComponent: any, { stories, allocatedIds }: {
stories?: {} | undefined;
allocatedIds?: never[] | undefined;
declare const _default: (StoriesComponent: any, { stories, allocatedIds, }: {
stories: Record<string, StoryDef>;
allocatedIds: string[];
}, exportedMeta?: undefined) => {

@@ -10,0 +11,0 @@ meta?: undefined;

@@ -10,3 +10,3 @@ /* eslint-env browser */

: () => document.createElement('div');
export default (StoriesComponent, { stories = {}, allocatedIds = [] }, exportedMeta = undefined) => {
export default (StoriesComponent, { stories = {}, allocatedIds = [], }, exportedMeta = undefined) => {
const repositories = {

@@ -100,2 +100,12 @@ meta: null,

}
const relStory = stories[storyId];
if (relStory?.description) {
storyFn.parameters = combineParameters(storyFn.parameters || {}, {
docs: {
description: {
story: relStory.description,
},
},
});
}
// eslint-disable-next-line no-param-reassign

@@ -102,0 +112,0 @@ all[storyId] = storyFn;

@@ -1,5 +0,6 @@

interface StoryDef {
export interface StoryDef {
name: string;
template: boolean;
source: string;
description?: string;
hasArgs: boolean;

@@ -6,0 +7,0 @@ }

@@ -140,2 +140,3 @@ import * as svelte from 'svelte/compiler';

}
let latestComment;
svelte.walk(ast.html, {

@@ -167,3 +168,3 @@ enter(node) {

}
stories[isTemplate ? `tpl:${id}` : id] = {
const story = {
name,

@@ -174,2 +175,9 @@ template: isTemplate,

};
if (!isTemplate && latestComment) {
// throws dedent expression is not callable.
// @ts-ignore
story.description = dedent `${latestComment}`;
}
stories[isTemplate ? `tpl:${id}` : id] = story;
latestComment = undefined;
}

@@ -180,4 +188,15 @@ }

fillMetaFromAttributes(meta, node.attributes);
latestComment = undefined;
}
else if (node.type === 'Comment') {
this.skip();
latestComment = node.data?.trim();
return;
}
},
leave(node) {
if (node.type !== "Comment" && node.type !== "Text") {
latestComment = undefined;
}
}
});

@@ -184,0 +203,0 @@ return {

@@ -238,3 +238,2 @@ import { describe, expect, test } from 'vitest';

"source": "<div>story 1</div>",
"storyId": "test--story-1",
"template": false,

@@ -277,3 +276,2 @@ },

"source": "<div>story 1</div>",
"storyId": "test--story-1",
"template": false,

@@ -315,3 +313,2 @@ },

"source": "<div>story 1</div>",
"storyId": "test--story-1",
"template": false,

@@ -376,2 +373,135 @@ },

});
test('With description', () => {
expect(extractStories(`
<script>
import { Story } from '@storybook/svelte';
import Button from './Button.svelte';
</script>
<!-- Story Description -->
<Story name="Desc">
<div>a story</div>
</Story>
`)).toMatchInlineSnapshot(`
{
"allocatedIds": [
"default",
"Story",
"Button",
],
"meta": {},
"stories": {
"Desc": {
"description": "Story Description",
"hasArgs": false,
"name": "Desc",
"source": "<div>a story</div>",
"template": false,
},
},
}
`);
});
test('With multiline description', () => {
expect(extractStories(`
<script>
import { Story } from '@storybook/svelte';
import Button from './Button.svelte';
</script>
<!--
Story Description
another line.
-->
<Story name="Desc">
<div>a story</div>
</Story>
`)).toMatchInlineSnapshot(`
{
"allocatedIds": [
"default",
"Story",
"Button",
],
"meta": {},
"stories": {
"Desc": {
"description": "Story Description
another line.",
"hasArgs": false,
"name": "Desc",
"source": "<div>a story</div>",
"template": false,
},
},
}
`);
});
test('With unrelated nested description', () => {
expect(extractStories(`
<script>
import { Story } from '@storybook/svelte';
import Button from './Button.svelte';
</script>
<div>
<!-- unrelated desc -->
</div>
<Story name="Desc">
<div>a story</div>
</Story>
`)).toMatchInlineSnapshot(`
{
"allocatedIds": [
"default",
"Story",
"Button",
],
"meta": {},
"stories": {
"Desc": {
"hasArgs": false,
"name": "Desc",
"source": "<div>a story</div>",
"template": false,
},
},
}
`);
});
test('With unrelated description', () => {
expect(extractStories(`
<script>
import { Story } from '@storybook/svelte';
import Button from './Button.svelte';
</script>
<!-- unrelated desc -->
<div></div>
<Story name="Desc">
<div>a story</div>
</Story>
`)).toMatchInlineSnapshot(`
{
"allocatedIds": [
"default",
"Story",
"Button",
],
"meta": {},
"stories": {
"Desc": {
"hasArgs": false,
"name": "Desc",
"source": "<div>a story</div>",
"template": false,
},
},
}
`);
});
});
{
"name": "@storybook/addon-svelte-csf",
"version": "4.0.10",
"version": "4.0.11",
"description": "Allows to write stories in Svelte syntax",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc