Skip to content

CSF: Fix parsing of string literal export names#34901

Merged
shilman merged 1 commit into
nextfrom
shilman/fix-csf-export-as-string-literal
May 26, 2026
Merged

CSF: Fix parsing of string literal export names#34901
shilman merged 1 commit into
nextfrom
shilman/fix-csf-export-as-string-literal

Conversation

@shilman
Copy link
Copy Markdown
Member

@shilman shilman commented May 26, 2026

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, the export { X as Y } handler only checked for t.isIdentifier(specifier.exported). When using a string literal as an export alias (e.g. export { story2 as 'あ' }), Babel produces a StringLiteral node for specifier.exported instead of an Identifier, 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

['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'],
['korean', 'kind', '바보 (babo)', 'kind--바보-babo'],

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

No manual testing required — the bug is fully covered by the updated unit test in CsfFile.test.ts (the typescript satisfies as export specifier test case now includes story2 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/core team 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

    • Fixed export specifier parsing to support string literal names in addition to identifiers
    • Improved support for Unicode characters in exported story names
  • Tests

    • Enhanced test coverage for Unicode export names and string literal export specifiers

Review Change Stack

@shilman shilman changed the title CSF: Fix parsing of string literal export names (e.g. export { story as 'あ' }) CSF: Fix parsing of string literal export names May 26, 2026
@shilman shilman added patch:yes Bugfix & documentation PR that need to be picked to main branch csf labels May 26, 2026
Copy link
Copy Markdown
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! 💯

AST reference

@shilman shilman marked this pull request as ready for review May 26, 2026 04:55
Copilot AI review requested due to automatic review settings May 26, 2026 04:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ExportSpecifier handling in CsfFile to accept specifier.exported as either an Identifier or StringLiteral.
  • 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.

@shilman shilman merged commit 11e2a8c into next May 26, 2026
147 of 155 checks passed
@shilman shilman deleted the shilman/fix-csf-export-as-string-literal branch May 26, 2026 04:59
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a250814-1636-42db-9561-2816894efa6d

📥 Commits

Reviewing files that changed from the base of the PR and between 1411339 and 5cb3626.

📒 Files selected for processing (2)
  • code/core/src/csf-tools/CsfFile.test.ts
  • code/core/src/csf-tools/CsfFile.ts

📝 Walkthrough

Walkthrough

CSF export name parsing in CsfFile.ts now handles re-export specifiers where the exported name is either an identifier or a string literal. The test case was expanded to validate this capability with a Unicode string literal export name alongside a standard identifier export.

Changes

String literal export name support

Layer / File(s) Summary
Export name parsing for literals and identifiers
code/core/src/csf-tools/CsfFile.ts
CsfFile's re-export handling now derives exportName from specifier.exported by checking whether the source is an identifier or string literal, enabling support for non-ASCII and special-character export names.
Test case for Unicode and string literal exports
code/core/src/csf-tools/CsfFile.test.ts
Test case "typescript satisfies as export specifier" expanded to export two stories: story1 as A and story2 as the Unicode export name 'あ'. Snapshots updated to reflect both story entries with their computed metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • storybookjs/storybook#32855: Modifies CsfFile.ts's handling of ExportNamedDeclaration and named exports in CSF parsing, overlapping with the story export resolution logic.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal csf patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants