diff --git a/.vscode/launch.json b/.vscode/launch.json index 29f7e43fa..bda43a429 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -139,7 +139,7 @@ "program": "${workspaceFolder}/node_modules/.bin/jest", "cwd": "${workspaceFolder}/core/instrument", "args": [ - "mdx-template", + "esm-template", ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", diff --git a/core/instrument/src/babel/esm-stories.ts b/core/instrument/src/babel/esm-stories.ts index 306d804f0..6466a43cc 100644 --- a/core/instrument/src/babel/esm-stories.ts +++ b/core/instrument/src/babel/esm-stories.ts @@ -70,7 +70,7 @@ export const extractCSFStories = ( if (template) { doc.template = extractFunction( path as NodePath, - { init: template.value }, + { type: 'VariableDeclarator', init: template.value }, template.key.name, ) as Document['template']; } diff --git a/core/instrument/test/__snapshots__/esm-template.test.ts.snap b/core/instrument/test/__snapshots__/esm-template.test.ts.snap index 90025ff8d..a498462e9 100644 --- a/core/instrument/test/__snapshots__/esm-template.test.ts.snap +++ b/core/instrument/test/__snapshots__/esm-template.test.ts.snap @@ -52,7 +52,51 @@ export const Button: FC = props => ( "dateModified": 2020-11-16T21:16:17.737Z, "package": "f4ca1c7bc1501c3fcaf51e85d24145e2", "smartControls": false, - "template": undefined, + "template": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 0, + }, + "start": Object { + "column": 0, + "line": 0, + }, + }, + "name": "props", + "usage": Array [ + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 0, + }, + "start": Object { + "column": 21, + "line": 0, + }, + }, + "shorthand": undefined, + }, + ], + "value": "props", + }, + ], + "id": "template", + "loc": Object { + "end": Object { + "column": 42, + "line": 10, + }, + "start": Object { + "column": 12, + "line": 10, + }, + }, + "name": "template", + }, "title": "Introduction/Template doc", }, "packages": Object { @@ -143,7 +187,54 @@ export const Button: FC = props => ( "version": "1.40.5", }, }, - "stories": Object {}, + "stories": Object { + "John": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 0, + }, + "start": Object { + "column": 0, + "line": 0, + }, + }, + "name": "props", + "usage": Array [ + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 0, + }, + "start": Object { + "column": 21, + "line": 0, + }, + }, + "shorthand": undefined, + }, + ], + "value": "props", + }, + ], + "id": "John", + "loc": Object { + "end": Object { + "column": 42, + "line": 10, + }, + "start": Object { + "column": 12, + "line": 10, + }, + }, + "name": "John", + "source": "props =>