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

Commit

Permalink
look for csf3 export if storiesOf import is not detected (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
fa93hws authored Aug 16, 2023
1 parent df8edbd commit a2ceee6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion __tests__/fixtures/feature-storybook-ref/b.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2021 Canva Inc. All Rights Reserved.

import { storiesOf } from "@storybook/react";
import * as React from "react";

export default {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/feature-storybook-ref/c.stories.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/feature-storybook-ref/d_e.stories.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/processors/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand All @@ -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) ||
Expand Down Expand Up @@ -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);
}
};
Expand Down

0 comments on commit a2ceee6

Please sign in to comment.