Skip to content

Commit a997057

Browse files
committed
Source-loader: Resolve differences between JS/TS AST output
1 parent c88b1b7 commit a997057

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/source-loader/src/server/abstract-syntax-tree/__snapshots__/inject-decorator.csf.test.js.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`inject-decorator positive - ts - csf includes storySource parameter in the default exported object 1`] = `
4-
"var addSourceDecorator = require(\\"@storybook/source-loader/preview\\").addSource;
5-
import React from \\"react\\";
4+
"import React from \\"react\\";
65
import { action } from \\"@storybook/addon-actions\\";
76
import { Button } from \\"@storybook/react/demo\\";
87
9-
export default {parameters: {\\"storySource\\":{\\"source\\":\\"import React from \\\\\\"react\\\\\\";\\\\nimport { action } from \\\\\\"@storybook/addon-actions\\\\\\";\\\\nimport { Button } from \\\\\\"@storybook/react/demo\\\\\\";\\\\n\\\\nexport default {\\\\n title: \\\\\\"Button\\\\\\"\\\\n};\\\\n\\\\nexport const text = () => (\\\\n <Button onClick={action(\\\\\\"clicked\\\\\\")}>Hello Button</Button>\\\\n);\\\\n\\\\nexport const emoji = () => (\\\\n <Button onClick={action(\\\\\\"clicked\\\\\\")}>\\\\n <span role=\\\\\\"img\\\\\\" aria-label=\\\\\\"so cool\\\\\\">\\\\n 😀 😎 👍 💯\\\\n </span>\\\\n </Button>\\\\n);\\\\n\\",\\"locationsMap\\":{}},},
8+
export default {parameters: {\\"storySource\\":{\\"source\\":\\"import React from \\\\\\"react\\\\\\";\\\\nimport { action } from \\\\\\"@storybook/addon-actions\\\\\\";\\\\nimport { Button } from \\\\\\"@storybook/react/demo\\\\\\";\\\\n\\\\nexport default {\\\\n title: \\\\\\"Button\\\\\\"\\\\n};\\\\n\\\\nexport const text = () => (\\\\n <Button onClick={action(\\\\\\"clicked\\\\\\")}>Hello Button</Button>\\\\n);\\\\n\\\\nexport const emoji = () => (\\\\n <Button onClick={action(\\\\\\"clicked\\\\\\")}>\\\\n <span role=\\\\\\"img\\\\\\" aria-label=\\\\\\"so cool\\\\\\">\\\\n 😀 😎 👍 💯\\\\n </span>\\\\n </Button>\\\\n);\\\\n\\",\\"locationsMap\\":{\\"button--text\\":{\\"startLoc\\":{\\"col\\":20,\\"line\\":9},\\"endLoc\\":{\\"col\\":1,\\"line\\":11},\\"startBody\\":{\\"col\\":20,\\"line\\":9},\\"endBody\\":{\\"col\\":1,\\"line\\":11}},\\"button--emoji\\":{\\"startLoc\\":{\\"col\\":21,\\"line\\":13},\\"endLoc\\":{\\"col\\":1,\\"line\\":19},\\"startBody\\":{\\"col\\":21,\\"line\\":13},\\"endBody\\":{\\"col\\":1,\\"line\\":19}}}},},
109
title: \\"Button\\"
1110
};
1211

lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export function findAddsMap(ast, storiesOfIdentifiers) {
7777
export function findExportsMap(ast) {
7878
const addsMap = {};
7979
const idsToFrameworks = {};
80+
const program = (ast && ast.program) || ast;
8081
const metaDeclaration =
81-
ast &&
82-
ast.program &&
83-
ast.program.body &&
84-
ast.program.body.find(
82+
program &&
83+
program.body &&
84+
program.body.find(
8585
d =>
8686
d.type === 'ExportDefaultDeclaration' &&
8787
d.declaration.type === 'ObjectExpression' &&

0 commit comments

Comments
 (0)