Skip to content

Commit

Permalink
build(#10336): impl SatisfiesExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
acid-chicken committed Mar 20, 2023
1 parent 2eecb8e commit bdbbb92
Show file tree
Hide file tree
Showing 431 changed files with 1,414 additions and 1,383 deletions.
221 changes: 125 additions & 96 deletions packages/frontend/.storybook/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ import { existsSync, readFileSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import { basename, dirname } from 'node:path/posix';
import { promisify } from 'node:util';
import { generate } from 'astring';
import { GENERATOR, type State, generate } from 'astring';
import type * as estree from 'estree';
import * as glob from 'glob';
import { format } from 'prettier';

interface SatisfiesExpression extends estree.BaseExpression {
type: 'SatisfiesExpression';
expression: estree.Expression;
reference: estree.Identifier;
}

const generator = {
...GENERATOR,
SatisfiesExpression(node: SatisfiesExpression, state: State) {
this[node.expression.type](node.expression, state);
state.write(' satisfies ');
this[node.reference.type](node.reference, state);
},
}

function h<T extends estree.Node>(component: T['type'], props: Omit<T, 'type'>): T {
const type = component.replace(/(?:^|-)([a-z])/g, (_, c) => c.toUpperCase());
return Object.assign(props, { type }) as T;
Expand Down Expand Up @@ -56,10 +71,14 @@ function toStories(component: string): string {
local={<identifier name="Meta" />}
imported={<identifier name="Meta" />}
/>,
<import-specifier
local={<identifier name="Story" />}
imported={<identifier name="Story" />}
/>,
...hasImplStories
? []
: [
<import-specifier
local={<identifier name="StoryObj" />}
imported={<identifier name="StoryObj" />}
/>,
],
]}
/>,
...hasMsw
Expand Down Expand Up @@ -93,19 +112,24 @@ function toStories(component: string): string {
<variable-declarator
id={<identifier name="meta" />}
init={
<object-expression
properties={[
<property
key={<identifier name="title" />}
value={literal}
kind="init"
/>,
<property
key={<identifier name="component" />}
value={identifier}
kind="init"
/>,
]}
<satisfies-expression
expression={
<object-expression
properties={[
<property
key={<identifier name="title" />}
value={literal}
kind="init"
/>,
<property
key={<identifier name="component" />}
value={identifier}
kind="init"
/>,
]}
/>
}
reference={<identifier name={`Meta<typeof ${identifier.name}>`} />}
/>
}
/>,
Expand All @@ -123,89 +147,94 @@ function toStories(component: string): string {
<variable-declarator
id={<identifier name="Default" />}
init={
<object-expression
properties={[
<property
key={<identifier name="render" />}
value={
<function-expression
id={<identifier name="render" />}
params={[
<identifier name="args" />,
<object-pattern
properties={[
<property
key={<identifier name="argTypes" />}
value={<identifier name="argTypes" />}
kind="init"
shorthand
<satisfies-expression
expression={
<object-expression
properties={[
<property
key={<identifier name="render" />}
value={
<function-expression
id={<identifier name="render" />}
params={[
<identifier name="args" />,
<object-pattern
properties={[
<property
key={<identifier name="argTypes" />}
value={<identifier name="argTypes" />}
kind="init"
shorthand
/>,
]}
/>,
]}
/>,
]}
body={
<block-statement
body={[
<return-statement
argument={
<object-expression
properties={[
<property
key={<identifier name="components" />}
value={
<object-expression
properties={[
<property
key={identifier}
value={identifier}
kind="init"
shorthand
/>,
]}
/>
}
kind="init"
/>,
<property
key={<identifier name="props" />}
value={
<call-expression
callee={
<member-expression
object={<identifier name="Object" />}
property={<identifier name="keys" />}
body={
<block-statement
body={[
<return-statement
argument={
<object-expression
properties={[
<property
key={<identifier name="components" />}
value={
<object-expression
properties={[
<property
key={identifier}
value={identifier}
kind="init"
shorthand
/>,
]}
/>
}
arguments={[
<identifier name="argTypes" />,
]}
/>
}
kind="init"
/>,
<property
key={<identifier name="template" />}
value={<literal value={`<${identifier.name} v-bind="$props" />`} />}
kind="init"
/>,
]}
/>
}
/>,
]}
kind="init"
/>,
<property
key={<identifier name="props" />}
value={
<call-expression
callee={
<member-expression
object={<identifier name="Object" />}
property={<identifier name="keys" />}
/>
}
arguments={[
<identifier name="argTypes" />,
]}
/>
}
kind="init"
/>,
<property
key={<identifier name="template" />}
value={<literal value={`<${identifier.name} v-bind="$props" />`} />}
kind="init"
/>,
]}
/>
}
/>,
]}
/>
}
/>
}
/>
}
method
kind="init"
/>,
<property
key={<identifier name="parameters" />}
value={parameters}
kind="init"
/>,
]}
method
kind="init"
/>,
<property
key={<identifier name="parameters" />}
value={parameters}
kind="init"
/>,
]}
/>
}
reference={<identifier name={`StoryObj<typeof ${identifier.name}>`} />}
/>
}
/>,
Expand All @@ -221,7 +250,7 @@ function toStories(component: string): string {
/>
) as unknown as estree.Program;
return format(
generate(program) + (hasImplStories ? readFileSync(`${implStories}.ts`, 'utf-8') : ''),
generate(program, { generator }) + (hasImplStories ? readFileSync(`${implStories}.ts`, 'utf-8') : ''),
{
parser: 'babel-ts',
singleQuote: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkAbuseReport.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta, StoryObj } from '@storybook/vue3';
import MkAbuseReport from './MkAbuseReport.vue';
const meta = {
title: 'components/MkAbuseReport',
component: MkAbuseReport,
};
} satisfies Meta<typeof MkAbuseReport>;
export const Default = {
render(args, { argTypes }) {
return {
Expand All @@ -17,5 +17,5 @@ export const Default = {
parameters: {
layout: 'centered',
},
};
} satisfies StoryObj<typeof MkAbuseReport>;
export default meta;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta, StoryObj } from '@storybook/vue3';
import MkAbuseReportWindow from './MkAbuseReportWindow.vue';
const meta = {
title: 'components/MkAbuseReportWindow',
component: MkAbuseReportWindow,
};
} satisfies Meta<typeof MkAbuseReportWindow>;
export const Default = {
render(args, { argTypes }) {
return {
Expand All @@ -17,5 +17,5 @@ export const Default = {
parameters: {
layout: 'centered',
},
};
} satisfies StoryObj<typeof MkAbuseReportWindow>;
export default meta;
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkAchievements.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta, StoryObj } from '@storybook/vue3';
import MkAchievements from './MkAchievements.vue';
const meta = {
title: 'components/MkAchievements',
component: MkAchievements,
};
} satisfies Meta<typeof MkAchievements>;
export const Default = {
render(args, { argTypes }) {
return {
Expand All @@ -17,5 +17,5 @@ export const Default = {
parameters: {
layout: 'centered',
},
};
} satisfies StoryObj<typeof MkAchievements>;
export default meta;
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkAnalogClock.stories.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta } from '@storybook/vue3';
const meta = {
title: 'components/MkAnalogClock',
component: MkAnalogClock,
};
} satisfies Meta<typeof MkAnalogClock>;
export default meta;
import MkAnalogClock from './MkAnalogClock.vue';
export const Default = {
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkAsUi.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta, StoryObj } from '@storybook/vue3';
import MkAsUi from './MkAsUi.vue';
const meta = {
title: 'components/MkAsUi',
component: MkAsUi,
};
} satisfies Meta<typeof MkAsUi>;
export const Default = {
render(args, { argTypes }) {
return {
Expand All @@ -17,5 +17,5 @@ export const Default = {
parameters: {
layout: 'centered',
},
};
} satisfies StoryObj<typeof MkAsUi>;
export default meta;
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkAutocomplete.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta, StoryObj } from '@storybook/vue3';
import MkAutocomplete from './MkAutocomplete.vue';
const meta = {
title: 'components/MkAutocomplete',
component: MkAutocomplete,
};
} satisfies Meta<typeof MkAutocomplete>;
export const Default = {
render(args, { argTypes }) {
return {
Expand All @@ -17,5 +17,5 @@ export const Default = {
parameters: {
layout: 'centered',
},
};
} satisfies StoryObj<typeof MkAutocomplete>;
export default meta;
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkAvatars.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, Story } from '@storybook/vue3';
import { Meta, StoryObj } from '@storybook/vue3';
import MkAvatars from './MkAvatars.vue';
const meta = {
title: 'components/MkAvatars',
component: MkAvatars,
};
} satisfies Meta<typeof MkAvatars>;
export const Default = {
render(args, { argTypes }) {
return {
Expand All @@ -17,5 +17,5 @@ export const Default = {
parameters: {
layout: 'centered',
},
};
} satisfies StoryObj<typeof MkAvatars>;
export default meta;
Loading

0 comments on commit bdbbb92

Please sign in to comment.