Skip to content

Maintenance: Remove parser re-export from storybook/internal/babel#34693

Closed
valentinpalkovic wants to merge 1 commit into
nextfrom
valentin/slim-internal-babel-barrel
Closed

Maintenance: Remove parser re-export from storybook/internal/babel#34693
valentinpalkovic wants to merge 1 commit into
nextfrom
valentin/slim-internal-babel-barrel

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented May 3, 2026

Closes #

What I did

Stacked on top of #34692 (resolve → oxc-resolver), which is itself stacked on #34625 (change-detection oxc adoption).

This PR slims the storybook/internal/babel re-export barrel by removing the raw parser namespace export from @babel/parser. Two thin helpers replace it:

  • parseAst(code, options) — wraps parser.parse
  • parseAstExpression(code, options) — wraps parser.parseExpression

Both helpers live in code/core/src/babel/babelParse.ts and are re-exported from storybook/internal/babel. The single-Babel-version guarantee is preserved — callers continue to route through the bundled core entry instead of pulling their own @babel/parser copy.

Migrated callers (4)

  • code/core/src/mocking-utils/extract.ts
  • code/core/src/core-server/utils/save-story/valueToAST.ts
  • code/core/src/core-server/utils/parser/generic-parser.ts
  • code/lib/cli-storybook/src/codemod/helpers/csf-factories-utils.test.ts

Each call site previously did parser.parse(code, opts).program (or .parseExpression); they now use parseAst / parseAstExpression with identical options. No behavioural changes.

Cleanup

  • Removed babelParseExpression from babelParse.ts — zero callers in the repo, and superseded by parseAstExpression.

Why now

The parser re-export was a leaky abstraction over @babel/parser's API. Migrating off it is a prerequisite for the long-term Phase 3 plan: replacing the Babel+recast stack with oxc-transform / oxc-codegen once those tools support source-preserving transforms. With the named helpers in place, future swaps need only change the helper bodies — no widespread call-site refactor.

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

The pre-existing unit tests for mocking-utils, core-server/utils/save-story, core-server/utils/parser, babel/, and lib/cli-storybook/codemod/helpers exercise every migrated call site (77 tests pass).

Manual testing

  1. yarn nx compile core — should succeed.
  2. yarn nx run-many -t check — type-check is clean.
  3. Run an existing Storybook sandbox; story indexing, save-from-controls, and codemods all exercise the migrated parsers.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update MIGRATION.MD

parser and babelParseExpression were on the storybook/internal/babel barrel and are technically removed. `storybook/internal/*` paths are documented as internal/unsupported, so a MIGRATION.md entry is not strictly required, but a one-line note could be added if maintainers want to be explicit.

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes.
  • Make sure this PR contains one of the labels below:

Suggested label: maintenance or cleanup.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Breaking Changes

    • Removed direct parser export from Babel utilities—use convenience functions instead.
  • New Features

    • Added parseAst and parseAstExpression convenience functions with optional parser configuration support.
  • Refactor

    • Consolidated Babel parsing calls across the codebase to use unified convenience wrappers.

`storybook/internal/babel` re-exported the entire `@babel/parser`
namespace as `parser`, leaking the upstream API into the public surface
of `storybook/internal`. Replace it with two thin helpers in
`babel/babelParse.ts`:

- `parseAst(code, options)` — wraps `parser.parse`
- `parseAstExpression(code, options)` — wraps `parser.parseExpression`

Both helpers preserve the single-Babel-version guarantee: callers go
through the bundled `storybook/internal/babel` entry instead of pulling
in their own `@babel/parser` copy.

Migrated all four `parser` consumers:

- `core/src/mocking-utils/extract.ts`
- `core/src/core-server/utils/save-story/valueToAST.ts`
- `core/src/core-server/utils/parser/generic-parser.ts`
- `lib/cli-storybook/src/codemod/helpers/csf-factories-utils.test.ts`

Also remove `babelParseExpression` from `babelParse.ts` — it had zero
callers in the repo and is superseded by `parseAstExpression`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 3, 2026

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: 8db80ed3-6470-4b1b-8234-726d821f5835

📥 Commits

Reviewing files that changed from the base of the PR and between 72e6893 and 25a90ab.

📒 Files selected for processing (6)
  • code/core/src/babel/babelParse.ts
  • code/core/src/babel/index.ts
  • code/core/src/core-server/utils/parser/generic-parser.ts
  • code/core/src/core-server/utils/save-story/valueToAST.ts
  • code/core/src/mocking-utils/extract.ts
  • code/lib/cli-storybook/src/codemod/helpers/csf-factories-utils.test.ts
💤 Files with no reviewable changes (1)
  • code/core/src/babel/index.ts

📝 Walkthrough

Walkthrough

Introduced convenience wrappers parseAst and parseAstExpression in the Babel module to support optional parser options. Removed the direct parser export from the public API. Updated all internal call sites to use the new parseAst wrapper instead of accessing parser.parse() directly.

Changes

Babel API Modernization

Layer / File(s) Summary
API Definition
code/core/src/babel/babelParse.ts
Added exported parseAst(code, options?) and parseAstExpression(code, options?) wrappers that delegate to @babel/parser.parse() and parser.parseExpression() respectively, replacing the removed babelParseExpression() export.
Export Surface
code/core/src/babel/index.ts
Removed the parser import and its re-export, narrowing the module's public API surface.
Call Site Updates
code/core/src/core-server/utils/parser/generic-parser.ts, code/core/src/core-server/utils/save-story/valueToAST.ts, code/core/src/mocking-utils/extract.ts, code/lib/cli-storybook/src/codemod/helpers/csf-factories-utils.test.ts
Updated imports to use parseAst from storybook/internal/babel and replaced all parser.parse(content, ...) calls with parseAst(content, ...) while preserving parsing options and downstream return behavior (accessing .program when needed).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Review rate limit: 3/5 reviews remaining, refill in 15 minutes and 18 seconds.

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

@valentinpalkovic valentinpalkovic added maintenance User-facing maintenance tasks ci:normal labels May 3, 2026
@valentinpalkovic valentinpalkovic self-assigned this May 3, 2026
@valentinpalkovic valentinpalkovic marked this pull request as draft May 4, 2026 13:26
Base automatically changed from valentin/replace-resolve-with-oxc-resolver to next May 20, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal maintenance User-facing maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant