From cf05881093d4e3e3cb6d9af6aa69b07e9949c1f4 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 16 Aug 2023 10:07:54 +1000 Subject: [PATCH] look for csf3 export if storiesOf import is not detected --- __tests__/fixtures/feature-storybook-ref/b.stories.tsx | 1 - __tests__/fixtures/feature-storybook-ref/c.stories.tsx | 2 +- __tests__/fixtures/feature-storybook-ref/d_e.stories.tsx | 2 +- src/processors/feature.ts | 8 +++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/__tests__/fixtures/feature-storybook-ref/b.stories.tsx b/__tests__/fixtures/feature-storybook-ref/b.stories.tsx index 08a6c26..1f08278 100644 --- a/__tests__/fixtures/feature-storybook-ref/b.stories.tsx +++ b/__tests__/fixtures/feature-storybook-ref/b.stories.tsx @@ -1,6 +1,5 @@ // Copyright 2021 Canva Inc. All Rights Reserved. -import { storiesOf } from "@storybook/react"; import * as React from "react"; export default { diff --git a/__tests__/fixtures/feature-storybook-ref/c.stories.tsx b/__tests__/fixtures/feature-storybook-ref/c.stories.tsx index be39278..7d54604 100644 --- a/__tests__/fixtures/feature-storybook-ref/c.stories.tsx +++ b/__tests__/fixtures/feature-storybook-ref/c.stories.tsx @@ -1,6 +1,6 @@ // Copyright 2021 Canva Inc. All Rights Reserved. -import { storiesOf, type Meta } from "@storybook/react"; +import { type Meta } from "@storybook/react"; import * as React from "react"; export default { diff --git a/__tests__/fixtures/feature-storybook-ref/d_e.stories.tsx b/__tests__/fixtures/feature-storybook-ref/d_e.stories.tsx index 624a4f0..854fe7e 100644 --- a/__tests__/fixtures/feature-storybook-ref/d_e.stories.tsx +++ b/__tests__/fixtures/feature-storybook-ref/d_e.stories.tsx @@ -1,6 +1,6 @@ // Copyright 2021 Canva Inc. All Rights Reserved. -import { storiesOf, type Meta } from "@storybook/react"; +import { type Meta } from "@storybook/react"; import * as React from "react"; export default { diff --git a/src/processors/feature.ts b/src/processors/feature.ts index ce54fba..ebdfefb 100644 --- a/src/processors/feature.ts +++ b/src/processors/feature.ts @@ -88,6 +88,8 @@ export class FeatureFileProcessor extends TypeScriptFileProcessor { const walkTree = (node: ts.Node): void => { if ( + // storiesOf syntax is used + importFound && ts.isCallExpression(node) && FeatureFileProcessor.isStoriesOf(node.expression) ) { @@ -102,7 +104,8 @@ export class FeatureFileProcessor extends TypeScriptFileProcessor { return; } - if (ts.isExportAssignment(node)) { + // no storiesOf syntax found, csf3 is assumed + if (!importFound && ts.isExportAssignment(node)) { let { expression } = node; if ( ts.isAsExpression(expression) || @@ -136,8 +139,7 @@ export class FeatureFileProcessor extends TypeScriptFileProcessor { // Look for stories import first if (!importFound && FeatureFileProcessor.isStoriesImport(node)) { importFound = true; - } else if (importFound && !ts.isImportDeclaration(node)) { - // Look for `storiesOf` calls only if there was import + } else if (!ts.isImportDeclaration(node)) { walkTree(node); } };