@@ -58,16 +58,21 @@ export function getCodeSnippet(
5858
5959 if ( storyPath === normalizedPath ) {
6060 const args = storyPath . get ( 'arguments' ) ;
61- invariant (
62- args . length === 1 ,
63- ( ) => storyPath . buildCodeFrameError ( 'Could not evaluate story expression' ) . message
64- ) ;
65- const storyArg = args [ 0 ] ;
66- invariant (
67- storyArg . isExpression ( ) ,
68- ( ) => storyPath . buildCodeFrameError ( 'Could not evaluate story expression' ) . message
69- ) ;
70- normalizedPath = storyArg ;
61+ // Allow meta.story() with zero args (CSF4)
62+ if ( args . length === 0 ) {
63+ // Leave normalizedPath as the CallExpression; we'll treat it as an empty story config later
64+ } else {
65+ invariant (
66+ args . length === 1 ,
67+ ( ) => storyPath . buildCodeFrameError ( 'Could not evaluate story expression' ) . message
68+ ) ;
69+ const storyArg = args [ 0 ] ;
70+ invariant (
71+ storyArg . isExpression ( ) ,
72+ ( ) => storyPath . buildCodeFrameError ( 'Could not evaluate story expression' ) . message
73+ ) ;
74+ normalizedPath = storyArg ;
75+ }
7176 }
7277 }
7378
@@ -90,9 +95,18 @@ export function getCodeSnippet(
9095 ) {
9196 storyFn = normalizedPath ;
9297 } else if ( ! normalizedPath . isObjectExpression ( ) ) {
93- throw normalizedPath . buildCodeFrameError (
94- 'Expected story to be csf factory, function or an object expression'
95- ) ;
98+ // Allow CSF4 meta.story() without arguments, which is equivalent to an empty object story config
99+ if (
100+ normalizedPath . isCallExpression ( ) &&
101+ Array . isArray ( normalizedPath . node . arguments ) &&
102+ normalizedPath . node . arguments . length === 0
103+ ) {
104+ // No-op: treat as an object story with no properties
105+ } else {
106+ throw normalizedPath . buildCodeFrameError (
107+ 'Expected story to be csf factory, function or an object expression'
108+ ) ;
109+ }
96110 }
97111
98112 const storyProps = normalizedPath . isObjectExpression ( )
0 commit comments