CSF: Fix parsing of string literal export names#34901
Conversation
export { story as 'あ' })There was a problem hiding this comment.
Pull request overview
Fixes CSF parsing so export { X as 'string-literal' } (where Babel parses exported as a StringLiteral) is recognized as a valid story export instead of being silently skipped. This improves CSF indexing for non-identifier export aliases (including unicode).
Changes:
- Extend
ExportSpecifierhandling inCsfFileto acceptspecifier.exportedas either anIdentifierorStringLiteral. - Add/extend a unit test to cover string-literal export aliases (including a unicode example) and assert the story is indexed correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
code/core/src/csf-tools/CsfFile.ts |
Accepts StringLiteral exported names when parsing export { X as Y } specifiers so string-literal aliases aren’t dropped. |
code/core/src/csf-tools/CsfFile.test.ts |
Updates the relevant test case to include story2 as 'あ' and asserts it appears in the parsed stories list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughCSF export name parsing in ChangesString literal export name support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
Comment |
Closes N/A
What I did
Fixed a bug where stories exported via
export { X as 'string-literal' }were silently dropped during CSF parsing.In
CsfFile.ts, theexport { X as Y }handler only checked fort.isIdentifier(specifier.exported). When using a string literal as an export alias (e.g.export { story2 as 'あ' }), Babel produces aStringLiteralnode forspecifier.exportedinstead of anIdentifier, causing the story to be skipped entirely.The fix extends the check to also accept
t.isStringLiteral(specifier.exported), extracting the name via.value.NOTE: Unicode IDs are already supported in SB
storybook/code/core/src/csf/index.test.ts
Lines 14 to 15 in 5cb3626
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
No manual testing required — the bug is fully covered by the updated unit test in
CsfFile.test.ts(thetypescript satisfies as export specifiertest case now includesstory2 as 'あ'and asserts it is parsed correctly).🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit
Release Notes
Bug Fixes
Tests