Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit a2ceee6

Browse files
authored
look for csf3 export if storiesOf import is not detected (#39)
1 parent df8edbd commit a2ceee6

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

__tests__/fixtures/feature-storybook-ref/b.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2021 Canva Inc. All Rights Reserved.
22

3-
import { storiesOf } from "@storybook/react";
43
import * as React from "react";
54

65
export default {

__tests__/fixtures/feature-storybook-ref/c.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2021 Canva Inc. All Rights Reserved.
22

3-
import { storiesOf, type Meta } from "@storybook/react";
3+
import { type Meta } from "@storybook/react";
44
import * as React from "react";
55

66
export default {

__tests__/fixtures/feature-storybook-ref/d_e.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2021 Canva Inc. All Rights Reserved.
22

3-
import { storiesOf, type Meta } from "@storybook/react";
3+
import { type Meta } from "@storybook/react";
44
import * as React from "react";
55

66
export default {

src/processors/feature.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class FeatureFileProcessor extends TypeScriptFileProcessor {
8888

8989
const walkTree = (node: ts.Node): void => {
9090
if (
91+
// storiesOf syntax is used
92+
importFound &&
9193
ts.isCallExpression(node) &&
9294
FeatureFileProcessor.isStoriesOf(node.expression)
9395
) {
@@ -102,7 +104,8 @@ export class FeatureFileProcessor extends TypeScriptFileProcessor {
102104
return;
103105
}
104106

105-
if (ts.isExportAssignment(node)) {
107+
// no storiesOf syntax found, csf3 is assumed
108+
if (!importFound && ts.isExportAssignment(node)) {
106109
let { expression } = node;
107110
if (
108111
ts.isAsExpression(expression) ||
@@ -136,8 +139,7 @@ export class FeatureFileProcessor extends TypeScriptFileProcessor {
136139
// Look for stories import first
137140
if (!importFound && FeatureFileProcessor.isStoriesImport(node)) {
138141
importFound = true;
139-
} else if (importFound && !ts.isImportDeclaration(node)) {
140-
// Look for `storiesOf` calls only if there was import
142+
} else if (!ts.isImportDeclaration(node)) {
141143
walkTree(node);
142144
}
143145
};

0 commit comments

Comments
 (0)