fix(parse): unwrap TSSatisfiesExpression in named-identifier default-export init#633
Open
darioabc wants to merge 1 commit into
Open
fix(parse): unwrap TSSatisfiesExpression in named-identifier default-export init#633darioabc wants to merge 1 commit into
darioabc wants to merge 1 commit into
Conversation
…export init
Ladle's getDefaultExport walker unwraps TSSatisfiesExpression /
TSAsExpression when the *direct declaration* is wrapped, e.g.
`export default { … } satisfies Meta<…>;`. It did not unwrap
the same expression when it appears as the **init** of a named
identifier that is then re-exported by name:
const meta = { title: 'X', component: Y } satisfies Meta<typeof Y>;
export default meta;
The named-identifier branch resolves objNode to the init expression
but does not strip the `satisfies` wrapper, so objNode.properties
is undefined and title/meta silently never reach the result. Story
files using this pattern were dropped from the index.
Mirror the existing direct-declaration unwrap. ~6 LOC. Add unit tests
for the `satisfies` and `as` named-identifier patterns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Modern Storybook codebases use the
satisfiesoperator to attach theMeta<typeof X>type to a story'smetaobject while still allowing TypeScript to widenmeta.componentto its actual type:Ladle's
getDefaultExportwalker handlesTSSatisfiesExpression/TSAsExpressionwhen the direct declaration is wrapped, e.g.export default { … } satisfies Meta<…>;. But it does not unwrap the same expression when it appears as the init of a named identifier that is then re-exported by name (the snippet above).Effect:
objNodeends up pointing at theTSSatisfiesExpressionnode rather than the underlyingObjectExpression. The subsequentobjNode.properties.forEachwalks an empty array (the satisfies node has no.properties), so thetitleandmetafields silently never reach the result. Story files using this pattern are dropped from the index — Ladle reports0stories indexed when the codebase has hundreds, with no error or warning.Verified in a 312-story production codebase. Without the patch: 0/312 indexed. With: 312/312.
Change
packages/ladle/lib/cli/vite-plugin/parse/get-default-export.js: after resolving a named identifier to its init expression, also unwrapTSAsExpression/TSSatisfiesExpression. Mirrors the existing handling for the direct-declaration case at the same site.Three lines of logic, ~12 LOC including the explanatory comment.
Test plan
packages/ladle/tests/parse/get-default-export.test.ts:Get default export through named identifier withsatisfies``Get default export through named identifier withas``"Can't parse the default title and meta of file.js. Meta must be serializable and title a string literal.". Both pass with the fix applied.pnpm --filter @ladle/react test— 9 suites / 58 tests, up from 56).pnpm typecheckandpnpm lintclean.Reviewer notes
The fix mirrors the existing direct-declaration unwrap (the
if ([…].includes(astPath.node.declaration.type))block four lines above). Pattern symmetry: every place where Ladle resolves the "default-exported object", strip thesatisfies/aswrapper.No public API change; pure parser robustness improvement.
Optional follow-up: extract the unwrap into a helper (e.g.
unwrapTsTypeAssertions(node)) to centralise the "resolve to ObjectExpression" rules and prevent the next site from drifting again. Not done in this PR to keep the diff minimal.Out of scope
composeEnhancers(separate PR).