Skip to content

Commit

Permalink
merge next & fix errors from svelte-check
Browse files Browse the repository at this point in the history
  • Loading branch information
xeho91 committed Sep 5, 2024
2 parents a8e4f3e + 1732cd7 commit ee77a76
Show file tree
Hide file tree
Showing 54 changed files with 3,428 additions and 1,913 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"storybook": "^8.2.2",
"svelte": "5.0.0-next.243",
"svelte": "5.0.0-next.244",
"svelte-check": "^3.8.4",
"tslib": "^2.6.3",
"type-fest": "^4.20.1",
Expand All @@ -113,7 +113,7 @@
"peerDependencies": {
"@storybook/svelte": "^8.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.0 || ^4.0.0",
"svelte": "^5.0.0-next.243 || ^5.0.0",
"svelte": "^5.0.0-next.244 || ^5.0.0",
"vite": "^5.0.0"
},
"packageManager": "[email protected]+sha256.dbdf5961c32909fb030595a9daa1dae720162e658609a8f92f2fa99835510ca5",
Expand Down
4,405 changes: 2,911 additions & 1,494 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Program } from 'estree';
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createExportDefaultMeta } from './create-export-default';

import type { ESTreeAST } from '#parser/ast';

describe(createExportDefaultMeta.name, () => {
it('creates a new export default correctly', ({ expect }) => {
const stringified = print(
Expand All @@ -12,7 +13,7 @@ describe(createExportDefaultMeta.name, () => {
type: 'Identifier',
name: 'meta',
},
}) as unknown as Program
}) as unknown as ESTreeAST.Program
).code;

expect(stringified).toMatchInlineSnapshot(`"export default meta;"`);
Expand All @@ -25,7 +26,7 @@ describe(createExportDefaultMeta.name, () => {
type: 'Identifier',
name: '__renamed_meta',
},
}) as unknown as Program
}) as unknown as ESTreeAST.Program
).code;

expect(stringified).toMatchInlineSnapshot(`"export default __renamed_meta;"`);
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/post-transform/appendix/create-export-default.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { ExportDefaultDeclaration } from 'estree';

import type { getMetaIdentifier } from '#parser/analyse/define-meta/meta-identifier';
import type { ESTreeAST } from '#parser/ast';

interface Params {
metaIdentifier: ReturnType<typeof getMetaIdentifier>;
filename?: string;
}

export function createExportDefaultMeta(params: Params): ExportDefaultDeclaration {
export function createExportDefaultMeta(params: Params): ESTreeAST.ExportDefaultDeclaration {
const { metaIdentifier } = params;

return {
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/post-transform/appendix/create-export-order.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { ExportNamedDeclaration } from 'estree';

import type { getStoriesIdentifiers } from '#parser/analyse/story/attributes/identifiers';
import type { ESTreeAST } from '#parser/ast';

interface Params {
storyIdentifiers: ReturnType<typeof getStoriesIdentifiers>;
filename?: string;
}

export function createExportOrderVariable(params: Params): ExportNamedDeclaration {
export function createExportOrderVariable(params: Params): ESTreeAST.ExportNamedDeclaration {
const { storyIdentifiers } = params;

const exported = {
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/post-transform/appendix/create-import.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pkg from '@storybook/addon-svelte-csf/package.json' with { type: 'json' };
import type { ImportDeclaration } from 'estree';

import type { ESTreeAST } from '#parser/ast';

/**
* The export is defined in the `package.json` export map
*/
export function createRuntimeStoriesImport(): ImportDeclaration {
export function createRuntimeStoriesImport(): ESTreeAST.ImportDeclaration {
const imported = {
type: 'Identifier',
// WARN: Tempting to use `createRuntimeStories.name` here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Program } from 'estree';
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createNamedExportStory } from './create-named-export-story';
import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call';

import type { ESTreeAST } from '#parser/ast';

describe(createNamedExportStory.name, () => {
it('correctly creates a variable with named exports order', ({ expect }) => {
const stringified = print(
Expand All @@ -28,7 +29,7 @@ describe(createNamedExportStory.name, () => {
params: [],
},
}),
}) as unknown as Program
}) as unknown as ESTreeAST.Program
).code;

expect(stringified).toMatchInlineSnapshot(`"export const Default = __stories["Default"];"`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { ExportNamedDeclaration, Identifier } from 'estree';

import type { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call';

import type { ESTreeAST } from '#parser/ast';

interface Params {
exportName: string;
filename?: string;
node: ReturnType<typeof createVariableFromRuntimeStoriesCall>;
}

export function createNamedExportStory(params: Params): ExportNamedDeclaration {
export function createNamedExportStory(params: Params): ESTreeAST.ExportNamedDeclaration {
const { exportName, node } = params;

const exported = {
Expand Down Expand Up @@ -49,5 +49,5 @@ export function createNamedExportStory(params: Params): ExportNamedDeclaration {
}

function getNameFromVariable(node: Params['node']): string {
return (node.declarations[0].id as Identifier).name;
return (node.declarations[0].id as ESTreeAST.Identifier).name;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { FunctionDeclaration, VariableDeclaration } from 'estree';

import type { getMetaIdentifier } from '#parser/analyse/define-meta/meta-identifier';
import type { ESTreeAST } from '#parser/ast';

interface Params {
storiesFunctionDeclaration: FunctionDeclaration;
storiesFunctionDeclaration: ESTreeAST.FunctionDeclaration;
metaIdentifier: ReturnType<typeof getMetaIdentifier>;
filename?: string;
}

export function createVariableFromRuntimeStoriesCall(params: Params): VariableDeclaration {
export function createVariableFromRuntimeStoriesCall(
params: Params
): ESTreeAST.VariableDeclaration {
const { storiesFunctionDeclaration, metaIdentifier } = params;

return {
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/post-transform/define-meta/insert-description.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { logger } from '@storybook/node-logger';
import type { Comment } from 'estree';

import {
findASTPropertyIndex,
Expand All @@ -10,8 +9,7 @@ import {
getDocsPropertyValue,
getParametersPropertyValue,
} from '#compiler/post-transform/shared/description';

import { createASTProperty, createASTObjectExpression } from '#parser/ast';
import { createASTObjectExpression, createASTProperty, type ESTreeAST } from '#parser/ast';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import { getDefineMetaFirstArgumentObjectExpression } from '#parser/extract/svelte/define-meta';
Expand Down Expand Up @@ -130,7 +128,7 @@ export function insertDefineMetaJSDocCommentAsDescription(params: Params): void
* Adopted from: https://github.com/storybookjs/storybook/blob/next/code/lib/csf-tools/src/enrichCsf.ts/#L148-L164
* Adjusted for this addon, because here we use AST format from `estree`, not `babel`.
*/
function extractDescription(leadingComments: Comment[]) {
function extractDescription(leadingComments: ESTreeAST.Comment[]) {
const comments = leadingComments
.map((comment) => {
if (
Expand Down
20 changes: 11 additions & 9 deletions src/compiler/post-transform/shared/description.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { logger } from '@storybook/node-logger';
import dedent from 'dedent';
import type { ObjectExpression, Property } from 'estree';
import type { Component } from 'svelte/compiler';

import type { ESTreeAST, SvelteAST } from '#parser/ast';

import { createASTObjectExpression } from '#parser/ast';

interface FindPropertyOptions {
name: string;
node: ObjectExpression;
node: ESTreeAST.ObjectExpression;
filename?: string;
component?: Component;
component?: SvelteAST.Component;
}

/**
Expand All @@ -35,12 +35,12 @@ export const findPropertyParametersIndex = (options: Omit<FindPropertyOptions, '
export const getParametersProperty = (options: Omit<FindPropertyOptions, 'name'>) => {
const { node } = options;

return node.properties[findPropertyParametersIndex(options)] as Property;
return node.properties[findPropertyParametersIndex(options)] as ESTreeAST.Property;
};

export const getParametersPropertyValue = (
options: Omit<FindPropertyOptions, 'name'>
): ObjectExpression => {
): ESTreeAST.ObjectExpression => {
const { filename, component } = options;
let property = getParametersProperty(options);

Expand Down Expand Up @@ -68,7 +68,7 @@ export const getParametersPropertyValue = (
property.value.type === 'FunctionExpression' &&
property.value.body.body[0].type === 'ReturnStatement'
) {
const properties: ObjectExpression['properties'] = [];
const properties: ESTreeAST.ObjectExpression['properties'] = [];
if (property.value.body.body[0].argument) {
properties.push({
type: 'SpreadElement',
Expand Down Expand Up @@ -113,7 +113,9 @@ export const findPropertyDocsIndex = (options: Omit<FindPropertyOptions, 'name'>
};

export const getDocsProperty = (options: Omit<FindPropertyOptions, 'name'>) => {
return getParametersPropertyValue(options).properties[findPropertyDocsIndex(options)] as Property;
return getParametersPropertyValue(options).properties[
findPropertyDocsIndex(options)
] as ESTreeAST.Property;
};

export const getDocsPropertyValue = (options: Omit<FindPropertyOptions, 'name'>) => {
Expand Down Expand Up @@ -149,7 +151,7 @@ export const findPropertyDescriptionIndex = (options: Omit<FindPropertyOptions,
export const getDescriptionProperty = (options: Omit<FindPropertyOptions, 'name'>) => {
return getDocsPropertyValue(options).properties[
findPropertyDescriptionIndex(options)
] as Property;
] as ESTreeAST.Property;
};

export const getDescriptionPropertyValue = (options: Omit<FindPropertyOptions, 'name'>) => {
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/post-transform/story/insert-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
} from '#compiler/post-transform/shared/description';
import { createASTObjectExpression, createASTProperty } from '#parser/ast';

import type { ESTreeAST } from '#parser/ast';
import type { extractStoriesNodesFromExportDefaultFn } from '#parser/extract/compiled/stories';
import { getStoryPropsObjectExpression } from '#parser/extract/compiled/story';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { Literal, Property } from 'estree';

interface Params {
nodes: {
Expand Down Expand Up @@ -97,8 +97,8 @@ export function insertStoryHTMLCommentAsDescription(params: Params) {
) {
const propertyName = storyPropsObjectExpression.properties.find(
(p) => p.type === 'Property' && p.key.type === 'Literal' && p.key.value === 'name'
) as Property;
const name = (propertyName.value as Literal).value;
) as ESTreeAST.Property;
const name = (propertyName.value as ESTreeAST.Literal).value;
logger.warn(
dedent`
Svelte CSF:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Comment, Component } from 'svelte/compiler';
import { print } from 'svelte-ast-print';
import { describe, it } from 'vitest';

import { transformComponentMetaToDefineMeta } from './component-meta-to-define-meta';

import type { SvelteAST } from '#parser/ast';
import { parseAndExtractSvelteNode } from '#tests/extractor';

describe(transformComponentMetaToDefineMeta.name, () => {
Expand All @@ -15,7 +15,7 @@ describe(transformComponentMetaToDefineMeta.name, () => {
<Meta title="Atoms/Button" component={Button} />
`;
const node = await parseAndExtractSvelteNode<Component>(code, 'Component');
const node = await parseAndExtractSvelteNode<SvelteAST.Component>(code, 'Component');

expect(
print(
Expand All @@ -38,8 +38,8 @@ describe(transformComponentMetaToDefineMeta.name, () => {
<Meta title="Atoms/Button" component={Button} />
`;
const [comment, component] = await Promise.all([
parseAndExtractSvelteNode<Comment>(code, 'Comment'),
parseAndExtractSvelteNode<Component>(code, 'Component'),
parseAndExtractSvelteNode<SvelteAST.Comment>(code, 'Comment'),
parseAndExtractSvelteNode<SvelteAST.Component>(code, 'Component'),
]);

expect(
Expand Down Expand Up @@ -71,7 +71,7 @@ describe(transformComponentMetaToDefineMeta.name, () => {
}
}} />
`;
const component = await parseAndExtractSvelteNode<Component>(code, 'Component');
const component = await parseAndExtractSvelteNode<SvelteAST.Component>(code, 'Component');

expect(print(transformComponentMetaToDefineMeta({ component }))).toMatchInlineSnapshot(`
"const { Story } = defineMeta({
Expand Down Expand Up @@ -99,7 +99,7 @@ describe(transformComponentMetaToDefineMeta.name, () => {
<Meta component={WithParameters} parameters={{ ...parameters, baz: 'yes'}} />
`;
const component = await parseAndExtractSvelteNode<Component>(code, 'Component');
const component = await parseAndExtractSvelteNode<SvelteAST.Component>(code, 'Component');

expect(print(transformComponentMetaToDefineMeta({ component }))).toMatchInlineSnapshot(`
"const { Story } = defineMeta({
Expand Down
Loading

0 comments on commit ee77a76

Please sign in to comment.