Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions code/core/src/csf-tools/ConfigFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,23 @@ describe('ConfigFile', () => {
)
).toEqual(['test', 'vitest', '!a11ytest']);
});
it('parses correctly with .type<T>() chaining on export default', () => {
const source = dedent`
import { definePreview } from '@storybook/react-vite';

export default definePreview({
parameters: {
foo: 'bar',
},
}).type<{
parameters: {
customParam?: string;
};
}>();
`;
const config = loadConfig(source).parse();
expect(config.getFieldValue(['parameters', 'foo'])).toEqual('bar');
});
Comment on lines +296 to +312

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Assert warning suppression explicitly in this regression test.

This test only validates parsed data; it can still pass even if the parser logs the false warning again. Please also assert that no warning is emitted during parse for this .type<T>() pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/csf-tools/ConfigFile.test.ts` around lines 296 - 312, The test
must assert that no warning is emitted during parse for the .type<T>() chaining
case: wrap the call to loadConfig(source).parse() with a spy on the warning
emitter (e.g., jest.spyOn(console, 'warn') or the test logger used by
loadConfig), call parse via loadConfig(source).parse(), then expect the spy not
to have been called, and finally restore the spy; reference the existing
loadConfig(...) and parse() calls so you add the spy before parse and the
expect(spy).not.toHaveBeenCalled() after.

});
});

Expand Down
16 changes: 13 additions & 3 deletions code/core/src/csf-tools/ConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,19 @@ export class ConfigFile {
self.hasDefaultExport = true;
let decl = self._resolveDeclaration(node.declaration as t.Node, parent);

// csf factory
if (t.isCallExpression(decl) && t.isObjectExpression(decl.arguments[0])) {
decl = decl.arguments[0];
// csf factory - unwrap call expressions like definePreview({...}) or definePreview({...}).type<T>()
while (t.isCallExpression(decl)) {
if (t.isObjectExpression(decl.arguments[0])) {
decl = decl.arguments[0];
break;
} else if (
t.isMemberExpression(decl.callee) &&
t.isCallExpression(decl.callee.object)
) {
decl = decl.callee.object;
} else {
break;
}
}

if (t.isObjectExpression(decl)) {
Expand Down
Loading