From 85280eabf4f8d3f52d1bb8c958a8adf5eace2702 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 12 Jun 2022 08:49:11 +0800 Subject: [PATCH] Merge pull request #18464 from joshwooding/fix-csf3-storyName-storyStoreV7 Story index: Warn on `storyName` in CSF3 exports --- lib/csf-tools/src/CsfFile.test.ts | 19 +++++++++++++++++++ lib/csf-tools/src/CsfFile.ts | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/lib/csf-tools/src/CsfFile.test.ts b/lib/csf-tools/src/CsfFile.test.ts index 6bfa3245610..80d2bc2ca05 100644 --- a/lib/csf-tools/src/CsfFile.test.ts +++ b/lib/csf-tools/src/CsfFile.test.ts @@ -613,5 +613,24 @@ describe('CsfFile', () => { __id: foo-bar--a `); }); + + it('Object export with storyName', () => { + const consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation(); + + parse( + dedent` + export default { title: 'foo/bar' }; + export const A = { + storyName: 'Apple' + } + `, + true + ); + + expect(consoleWarnMock).toHaveBeenCalledWith( + 'Unexpected usage of "storyName" in "A". Please use "name" instead.' + ); + consoleWarnMock.mockRestore(); + }); }); }); diff --git a/lib/csf-tools/src/CsfFile.ts b/lib/csf-tools/src/CsfFile.ts index 3d38d6a2f93..88a8fbd5eec 100644 --- a/lib/csf-tools/src/CsfFile.ts +++ b/lib/csf-tools/src/CsfFile.ts @@ -268,6 +268,10 @@ export class CsfFile { __isArgsStory = isArgsStory(p.value as t.Expression, parent, self); } else if (p.key.name === 'name' && t.isStringLiteral(p.value)) { name = p.value.value; + } else if (p.key.name === 'storyName' && t.isStringLiteral(p.value)) { + logger.warn( + `Unexpected usage of "storyName" in "${exportName}". Please use "name" instead.` + ); } self._storyAnnotations[exportName][p.key.name] = p.value; }