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

look for csf3 export if storiesOf import is not detected #39

Merged
merged 2 commits into from
Aug 16, 2023
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
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
Loading