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

Throw descriptive error when 'of' prop is detected #37

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions src/sb-mdx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ const expressionOrNull = (attr: t.JSXAttribute['value']) =>
t.isJSXExpressionContainer(attr) ? attr.expression : null;

export function genStoryExport(ast: t.JSXElement, context: Context) {
if (getAttr(ast.openingElement, 'of')) {
throw new Error(`The 'of' prop is not supported in .stories.mdx files, only .mdx files.
See https://storybook.js.org/docs/7.0/react/writing-docs/mdx on how to write MDX files and stories separately.`);
}

const storyName = idOrNull(getAttr(ast.openingElement, 'name'));
const storyId = idOrNull(getAttr(ast.openingElement, 'id'));
const storyRef = getAttr(ast.openingElement, 'story') as t.JSXExpressionContainer;
Expand Down Expand Up @@ -264,6 +269,11 @@ export function genCanvasExports(ast: t.JSXElement, context: Context) {
}

export function genMeta(ast: t.JSXElement, options: CompilerOptions) {
if (getAttr(ast.openingElement, 'of')) {
throw new Error(`The 'of' prop is not supported in .stories.mdx files, only .mdx files.
See https://storybook.js.org/docs/7.0/react/writing-docs/mdx on how to write MDX files and stories separately.`);
}

const titleAttr = getAttr(ast.openingElement, 'title');
const idAttr = getAttr(ast.openingElement, 'id');
let title = null;
Expand Down