storybook 9.1.4 → 9.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/index.cjs +43 -43
- package/dist/bin/index.js +43 -43
- package/dist/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +43 -43
- package/dist/common/index.js +43 -43
- package/dist/core-server/index.cjs +1 -1
- package/dist/core-server/index.js +1 -1
- package/dist/csf-tools/index.cjs +133 -128
- package/dist/csf-tools/index.js +225 -220
- package/dist/manager/globals-runtime.js +1 -1
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.d.ts +8 -534
- package/dist/manager-api/index.js +1 -1
- package/dist/telemetry/index.cjs +1 -1
- package/dist/telemetry/index.js +1 -1
- package/package.json +1 -1
package/dist/csf-tools/index.js
CHANGED
|
@@ -36,31 +36,31 @@ var k = Le((T) => {
|
|
|
36
36
|
e[r - 1] = arguments[r];
|
|
37
37
|
var t = Array.from(typeof s == "string" ? [s] : s);
|
|
38
38
|
t[t.length - 1] = t[t.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
39
|
-
var i = t.reduce(function(
|
|
39
|
+
var i = t.reduce(function(c, p) {
|
|
40
40
|
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
41
|
-
return d ?
|
|
42
|
-
var
|
|
43
|
-
return (b = (
|
|
44
|
-
})) :
|
|
41
|
+
return d ? c.concat(d.map(function(u) {
|
|
42
|
+
var g, b;
|
|
43
|
+
return (b = (g = u.match(/[\t ]/g)) === null || g === void 0 ? void 0 : g.length) !== null && b !== void 0 ? b : 0;
|
|
44
|
+
})) : c;
|
|
45
45
|
}, []);
|
|
46
46
|
if (i.length) {
|
|
47
47
|
var a = new RegExp(`
|
|
48
48
|
[ ]{` + Math.min.apply(Math, i) + "}", "g");
|
|
49
|
-
t = t.map(function(
|
|
50
|
-
return
|
|
49
|
+
t = t.map(function(c) {
|
|
50
|
+
return c.replace(a, `
|
|
51
51
|
`);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
t[0] = t[0].replace(/^\r?\n/, "");
|
|
55
55
|
var o = t[0];
|
|
56
|
-
return e.forEach(function(
|
|
57
|
-
var d = o.match(/(?:^|\n)( *)$/), u = d ? d[1] : "",
|
|
58
|
-
typeof
|
|
59
|
-
`) && (
|
|
56
|
+
return e.forEach(function(c, p) {
|
|
57
|
+
var d = o.match(/(?:^|\n)( *)$/), u = d ? d[1] : "", g = c;
|
|
58
|
+
typeof c == "string" && c.includes(`
|
|
59
|
+
`) && (g = String(c).split(`
|
|
60
60
|
`).map(function(b, y) {
|
|
61
61
|
return y === 0 ? b : "" + u + b;
|
|
62
62
|
}).join(`
|
|
63
|
-
`)), o +=
|
|
63
|
+
`)), o += g + t[p + 1];
|
|
64
64
|
}), o;
|
|
65
65
|
}
|
|
66
66
|
f(se, "dedent");
|
|
@@ -69,14 +69,14 @@ var k = Le((T) => {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
// src/csf-tools/CsfFile.ts
|
|
72
|
-
var
|
|
72
|
+
var P = U(k(), 1);
|
|
73
73
|
import { readFile as Ue, writeFile as qe } from "node:fs/promises";
|
|
74
74
|
import {
|
|
75
75
|
BabelFileClass as Be,
|
|
76
76
|
babelParse as fe,
|
|
77
77
|
generate as We,
|
|
78
78
|
recast as de,
|
|
79
|
-
types as
|
|
79
|
+
types as l,
|
|
80
80
|
traverse as Ge
|
|
81
81
|
} from "storybook/internal/babel";
|
|
82
82
|
import { isExportStory as ne, storyNameFromExport as oe, toId as ze } from "storybook/internal/csf";
|
|
@@ -84,7 +84,7 @@ import { logger as ae } from "storybook/internal/node-logger";
|
|
|
84
84
|
|
|
85
85
|
// src/csf-tools/findVarInitialization.ts
|
|
86
86
|
import { types as V } from "storybook/internal/babel";
|
|
87
|
-
var
|
|
87
|
+
var O = /* @__PURE__ */ f((s, e) => {
|
|
88
88
|
let r = null, t = null;
|
|
89
89
|
return e.body.find((i) => (V.isVariableDeclaration(i) ? t = i.declarations : V.isExportNamedDeclaration(i) && V.isVariableDeclaration(i.declaration) &&
|
|
90
90
|
(t = i.declaration.declarations), t && t.find((a) => V.isVariableDeclarator(a) && V.isIdentifier(a.id) && a.id.name === s ? (r = a.init, !0) :
|
|
@@ -94,24 +94,24 @@ var P = /* @__PURE__ */ f((s, e) => {
|
|
|
94
94
|
// src/csf-tools/CsfFile.ts
|
|
95
95
|
var Xe = /\/preview(.(js|jsx|mjs|ts|tsx))?$/, Ke = /* @__PURE__ */ f((s) => Xe.test(s), "isValidPreviewPath");
|
|
96
96
|
function Je(s) {
|
|
97
|
-
if (
|
|
97
|
+
if (l.isArrayExpression(s))
|
|
98
98
|
return s.elements.map((e) => {
|
|
99
|
-
if (
|
|
99
|
+
if (l.isStringLiteral(e))
|
|
100
100
|
return e.value;
|
|
101
101
|
throw new Error(`Expected string literal: ${e}`);
|
|
102
102
|
});
|
|
103
|
-
if (
|
|
103
|
+
if (l.isStringLiteral(s))
|
|
104
104
|
return new RegExp(s.value);
|
|
105
|
-
if (
|
|
105
|
+
if (l.isRegExpLiteral(s))
|
|
106
106
|
return new RegExp(s.pattern, s.flags);
|
|
107
107
|
throw new Error(`Unknown include/exclude: ${s}`);
|
|
108
108
|
}
|
|
109
109
|
f(Je, "parseIncludeExclude");
|
|
110
110
|
function le(s) {
|
|
111
|
-
if (!
|
|
111
|
+
if (!l.isArrayExpression(s))
|
|
112
112
|
throw new Error("CSF: Expected tags array");
|
|
113
113
|
return s.elements.map((e) => {
|
|
114
|
-
if (
|
|
114
|
+
if (l.isStringLiteral(e))
|
|
115
115
|
return e.value;
|
|
116
116
|
throw new Error("CSF: Expected tag to be string literal");
|
|
117
117
|
});
|
|
@@ -126,19 +126,19 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
126
126
|
return `${e || ""} ${r}`.trim();
|
|
127
127
|
}, "formatLocation"), Qe = /* @__PURE__ */ f((s) => Ze.test(s), "isModuleMock"), ce = /* @__PURE__ */ f((s, e, r) => {
|
|
128
128
|
let t = s;
|
|
129
|
-
if (
|
|
129
|
+
if (l.isCallExpression(s)) {
|
|
130
130
|
let { callee: i, arguments: a } = s;
|
|
131
|
-
if (
|
|
132
|
-
(a.length === 0 || a.length === 1 &&
|
|
133
|
-
let o = i.object.name,
|
|
134
|
-
|
|
131
|
+
if (l.isProgram(e) && l.isMemberExpression(i) && l.isIdentifier(i.object) && l.isIdentifier(i.property) && i.property.name === "bind" &&
|
|
132
|
+
(a.length === 0 || a.length === 1 && l.isObjectExpression(a[0]) && a[0].properties.length === 0)) {
|
|
133
|
+
let o = i.object.name, c = O(o, e);
|
|
134
|
+
c && (r._templates[o] = c, t = c);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
return
|
|
137
|
+
return l.isArrowFunctionExpression(t) || l.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
|
|
138
138
|
}, "isArgsStory"), He = /* @__PURE__ */ f((s) => {
|
|
139
|
-
if (
|
|
139
|
+
if (l.isArrayExpression(s))
|
|
140
140
|
return s.elements.map((e) => {
|
|
141
|
-
if (
|
|
141
|
+
if (l.isStringLiteral(e))
|
|
142
142
|
return e.value;
|
|
143
143
|
throw new Error(`Expected string literal named export: ${e}`);
|
|
144
144
|
});
|
|
@@ -150,13 +150,13 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
150
150
|
},
|
|
151
151
|
{}
|
|
152
152
|
), "sortExports"), Ye = /* @__PURE__ */ f((s) => {
|
|
153
|
-
if (
|
|
153
|
+
if (l.isArrowFunctionExpression(s) || l.isFunctionDeclaration(s)) {
|
|
154
154
|
let e = s.params;
|
|
155
155
|
if (e.length >= 1) {
|
|
156
156
|
let [r] = e;
|
|
157
|
-
if (
|
|
157
|
+
if (l.isObjectPattern(r))
|
|
158
158
|
return !!r.properties.find((t) => {
|
|
159
|
-
if (
|
|
159
|
+
if (l.isObjectProperty(t) && l.isIdentifier(t.key))
|
|
160
160
|
return t.key.name === "mount";
|
|
161
161
|
});
|
|
162
162
|
}
|
|
@@ -168,10 +168,10 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
168
168
|
}
|
|
169
169
|
constructor(e, r, t) {
|
|
170
170
|
let i = e.trim();
|
|
171
|
-
super(
|
|
171
|
+
super(P.dedent`
|
|
172
172
|
CSF: ${i} ${v(r, t)}
|
|
173
173
|
|
|
174
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
174
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
175
175
|
`), this.name = this.constructor.name;
|
|
176
176
|
}
|
|
177
177
|
}, K = class extends Error {
|
|
@@ -180,10 +180,10 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
180
180
|
}
|
|
181
181
|
constructor(e, r, t) {
|
|
182
182
|
let i = `${e} ${v(r, t)}`.trim();
|
|
183
|
-
super(
|
|
183
|
+
super(P.dedent`
|
|
184
184
|
CSF: ${e} ${v(r, t)}
|
|
185
185
|
|
|
186
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
186
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
187
187
|
`), this.name = this.constructor.name;
|
|
188
188
|
}
|
|
189
189
|
}, B = class extends Error {
|
|
@@ -192,10 +192,10 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
192
192
|
}
|
|
193
193
|
constructor(e, r, t) {
|
|
194
194
|
let i = `${e} ${v(r, t)}`.trim();
|
|
195
|
-
super(
|
|
195
|
+
super(P.dedent`
|
|
196
196
|
CSF: ${e} ${v(r, t)}
|
|
197
197
|
|
|
198
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
198
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
199
199
|
`), this.name = this.constructor.name;
|
|
200
200
|
}
|
|
201
201
|
}, W = class extends Error {
|
|
@@ -204,10 +204,10 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
204
204
|
}
|
|
205
205
|
constructor(e, r, t) {
|
|
206
206
|
let i = "".trim();
|
|
207
|
-
super(
|
|
207
|
+
super(P.dedent`
|
|
208
208
|
CSF: ${e} ${v(r, t)}
|
|
209
209
|
|
|
210
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
210
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
211
211
|
`), this.name = this.constructor.name;
|
|
212
212
|
}
|
|
213
213
|
}, J = class {
|
|
@@ -225,12 +225,12 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
225
225
|
f(this, "CsfFile");
|
|
226
226
|
}
|
|
227
227
|
_parseTitle(e) {
|
|
228
|
-
let r =
|
|
229
|
-
if (
|
|
228
|
+
let r = l.isIdentifier(e) ? O(e.name, this._ast.program) : e;
|
|
229
|
+
if (l.isStringLiteral(r))
|
|
230
230
|
return r.value;
|
|
231
|
-
if (
|
|
231
|
+
if (l.isTSSatisfiesExpression(r) && l.isStringLiteral(r.expression))
|
|
232
232
|
return r.expression.value;
|
|
233
|
-
throw new Error(
|
|
233
|
+
throw new Error(P.dedent`
|
|
234
234
|
CSF: unexpected dynamic title ${v(r, this._options.fileName)}
|
|
235
235
|
|
|
236
236
|
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
@@ -242,29 +242,29 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
242
242
|
this._metaNode = e;
|
|
243
243
|
let t = {};
|
|
244
244
|
e.properties.forEach((i) => {
|
|
245
|
-
if (
|
|
245
|
+
if (l.isIdentifier(i.key)) {
|
|
246
246
|
if (this._metaAnnotations[i.key.name] = i.value, i.key.name === "title")
|
|
247
247
|
t.title = this._parseTitle(i.value);
|
|
248
248
|
else if (["includeStories", "excludeStories"].includes(i.key.name))
|
|
249
249
|
t[i.key.name] = Je(i.value);
|
|
250
250
|
else if (i.key.name === "component") {
|
|
251
251
|
let a = i.value;
|
|
252
|
-
if (
|
|
253
|
-
let
|
|
254
|
-
(d) =>
|
|
252
|
+
if (l.isIdentifier(a)) {
|
|
253
|
+
let c = a.name, p = r.body.find(
|
|
254
|
+
(d) => l.isImportDeclaration(d) && d.specifiers.find((u) => u.local.name === c)
|
|
255
255
|
);
|
|
256
256
|
if (p) {
|
|
257
257
|
let { source: d } = p;
|
|
258
|
-
|
|
258
|
+
l.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
let { code: o } = de.print(i.value, {});
|
|
262
262
|
t.component = o;
|
|
263
263
|
} else if (i.key.name === "tags") {
|
|
264
264
|
let a = i.value;
|
|
265
|
-
|
|
265
|
+
l.isIdentifier(a) && (a = O(a.name, this._ast.program)), t.tags = le(a);
|
|
266
266
|
} else if (i.key.name === "id")
|
|
267
|
-
if (
|
|
267
|
+
if (l.isStringLiteral(i.value))
|
|
268
268
|
t.id = i.value.value;
|
|
269
269
|
else
|
|
270
270
|
throw new Error(`Unexpected component id: ${i.value}`);
|
|
@@ -273,10 +273,10 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
273
273
|
}
|
|
274
274
|
getStoryExport(e) {
|
|
275
275
|
let r = this._storyExports[e];
|
|
276
|
-
if (r =
|
|
276
|
+
if (r = l.isVariableDeclarator(r) ? r.init : r, l.isCallExpression(r)) {
|
|
277
277
|
let { callee: t, arguments: i } = r;
|
|
278
|
-
if (
|
|
279
|
-
i.length === 1 &&
|
|
278
|
+
if (l.isMemberExpression(t) && l.isIdentifier(t.object) && l.isIdentifier(t.property) && t.property.name === "bind" && (i.length === 0 ||
|
|
279
|
+
i.length === 1 && l.isObjectExpression(i[0]) && i[0].properties.length === 0)) {
|
|
280
280
|
let { name: a } = t.object;
|
|
281
281
|
r = this._templates[a];
|
|
282
282
|
}
|
|
@@ -288,33 +288,35 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
288
288
|
if (Ge(this._ast, {
|
|
289
289
|
ExportDefaultDeclaration: {
|
|
290
290
|
enter(t) {
|
|
291
|
-
let { node: i, parent: a } = t, o =
|
|
292
|
-
if (e._options.transformInlineMeta && !o &&
|
|
291
|
+
let { node: i, parent: a } = t, o = l.isIdentifier(i.declaration) && l.isProgram(a);
|
|
292
|
+
if (e._options.transformInlineMeta && !o && l.isExpression(i.declaration)) {
|
|
293
293
|
let d = t.scope.generateUidIdentifier("meta");
|
|
294
294
|
e._metaVariableName = d.name;
|
|
295
295
|
let u = [
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
l.variableDeclaration("const", [l.variableDeclarator(d, i.declaration)]),
|
|
297
|
+
l.exportDefaultDeclaration(d)
|
|
298
298
|
];
|
|
299
|
-
u.forEach((
|
|
299
|
+
u.forEach((g) => g.loc = t.node.loc), t.replaceWithMultiple(u);
|
|
300
300
|
return;
|
|
301
301
|
}
|
|
302
|
-
let
|
|
302
|
+
let c, p;
|
|
303
303
|
if (o) {
|
|
304
304
|
let d = i.declaration.name;
|
|
305
305
|
e._metaVariableName = d;
|
|
306
|
-
let u = /* @__PURE__ */ f((
|
|
306
|
+
let u = /* @__PURE__ */ f((g) => l.isIdentifier(g.id) && g.id.name === d, "isVariableDeclarator");
|
|
307
307
|
e._metaStatement = e._ast.program.body.find(
|
|
308
|
-
(
|
|
308
|
+
(g) => l.isVariableDeclaration(g) && g.declarations.find(u)
|
|
309
309
|
), p = (e?._metaStatement?.declarations || []).find(
|
|
310
310
|
u
|
|
311
311
|
)?.init;
|
|
312
312
|
} else
|
|
313
313
|
e._metaStatement = i, p = i.declaration;
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
314
|
+
if (l.isObjectExpression(p) ? c = p : /* export default { ... } as Meta<...> */ /* export default { ... } satisfies Meta<...> */ (l.
|
|
315
|
+
isTSAsExpression(p) || l.isTSSatisfiesExpression(p)) && l.isObjectExpression(p.expression) ? c = p.expression : (
|
|
316
|
+
// export default { ... } satisfies Meta as Meta<...>
|
|
317
|
+
l.isTSAsExpression(p) && l.isTSSatisfiesExpression(p.expression) && l.isObjectExpression(p.expression.expression) && (c = p.expression.
|
|
318
|
+
expression)
|
|
319
|
+
), c && l.isProgram(a) && e._parseMeta(c, a), e._metaStatement && !e._metaNode)
|
|
318
320
|
throw new q(
|
|
319
321
|
"default export must be an object",
|
|
320
322
|
e._metaStatement,
|
|
@@ -326,62 +328,63 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
326
328
|
ExportNamedDeclaration: {
|
|
327
329
|
enter(t) {
|
|
328
330
|
let { node: i, parent: a } = t, o;
|
|
329
|
-
|
|
330
|
-
i.declaration) && (o = [i.declaration]), o ? o.forEach((
|
|
331
|
-
if (
|
|
332
|
-
let p = !1, { name: d } =
|
|
333
|
-
if (d === "__namedExportsOrder" &&
|
|
334
|
-
e._namedExportsOrder = He(
|
|
331
|
+
l.isVariableDeclaration(i.declaration) ? o = i.declaration.declarations.filter((c) => l.isVariableDeclarator(c)) : l.isFunctionDeclaration(
|
|
332
|
+
i.declaration) && (o = [i.declaration]), o ? o.forEach((c) => {
|
|
333
|
+
if (l.isIdentifier(c.id)) {
|
|
334
|
+
let p = !1, { name: d } = c.id;
|
|
335
|
+
if (d === "__namedExportsOrder" && l.isVariableDeclarator(c)) {
|
|
336
|
+
e._namedExportsOrder = He(c.init);
|
|
335
337
|
return;
|
|
336
338
|
}
|
|
337
|
-
e._storyExports[d] =
|
|
339
|
+
e._storyExports[d] = c, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
338
340
|
let u = oe(d);
|
|
339
341
|
e._storyAnnotations[d] ? ae.warn(
|
|
340
342
|
`Unexpected annotations for "${d}" before story declaration`
|
|
341
343
|
) : e._storyAnnotations[d] = {};
|
|
342
|
-
let
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
let g;
|
|
345
|
+
if (l.isVariableDeclarator(c) ? l.isTSAsExpression(c.init) && l.isTSSatisfiesExpression(c.init.expression) ? g = c.init.expression.
|
|
346
|
+
expression : l.isTSAsExpression(c.init) || l.isTSSatisfiesExpression(c.init) ? g = c.init.expression : g = c.init : g = c, l.isCallExpression(
|
|
347
|
+
g) && l.isMemberExpression(g.callee) && l.isIdentifier(g.callee.property) && (g.callee.property.name === "story" || g.callee.property.
|
|
348
|
+
name === "extend") && (p = !0, g = g.arguments[0]), e._metaIsFactory && !p)
|
|
346
349
|
throw new B(
|
|
347
350
|
"expected factory story",
|
|
348
|
-
|
|
351
|
+
g,
|
|
349
352
|
e._options.fileName
|
|
350
353
|
);
|
|
351
354
|
if (!e._metaIsFactory && p)
|
|
352
355
|
throw e._metaNode ? new B(
|
|
353
356
|
"expected non-factory story",
|
|
354
|
-
|
|
357
|
+
g,
|
|
355
358
|
e._options.fileName
|
|
356
359
|
) : new W(
|
|
357
360
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
358
|
-
|
|
361
|
+
g,
|
|
359
362
|
e._options.fileName
|
|
360
363
|
);
|
|
361
364
|
let b = {};
|
|
362
|
-
|
|
363
|
-
if (
|
|
365
|
+
l.isObjectExpression(g) ? (b.__isArgsStory = !0, g.properties.forEach((y) => {
|
|
366
|
+
if (l.isIdentifier(y.key)) {
|
|
364
367
|
if (y.key.name === "render")
|
|
365
368
|
b.__isArgsStory = ce(
|
|
366
369
|
y.value,
|
|
367
370
|
a,
|
|
368
371
|
e
|
|
369
372
|
);
|
|
370
|
-
else if (y.key.name === "name" &&
|
|
373
|
+
else if (y.key.name === "name" && l.isStringLiteral(y.value))
|
|
371
374
|
u = y.value.value;
|
|
372
|
-
else if (y.key.name === "storyName" &&
|
|
375
|
+
else if (y.key.name === "storyName" && l.isStringLiteral(y.value))
|
|
373
376
|
ae.warn(
|
|
374
377
|
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
375
378
|
);
|
|
376
|
-
else if (y.key.name === "parameters" &&
|
|
379
|
+
else if (y.key.name === "parameters" && l.isObjectExpression(y.value)) {
|
|
377
380
|
let _ = y.value.properties.find(
|
|
378
|
-
(L) =>
|
|
381
|
+
(L) => l.isObjectProperty(L) && l.isIdentifier(L.key) && L.key.name === "__id"
|
|
379
382
|
);
|
|
380
383
|
_ && (b.__id = _.value.value);
|
|
381
384
|
}
|
|
382
385
|
e._storyAnnotations[d][y.key.name] = y.value;
|
|
383
386
|
}
|
|
384
|
-
})) : b.__isArgsStory = ce(
|
|
387
|
+
})) : b.__isArgsStory = ce(g, a, e), e._stories[d] = {
|
|
385
388
|
id: "FIXME",
|
|
386
389
|
name: u,
|
|
387
390
|
parameters: b,
|
|
@@ -390,20 +393,22 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
390
393
|
}
|
|
391
394
|
};
|
|
392
395
|
}
|
|
393
|
-
}) : i.specifiers.length > 0 && i.specifiers.forEach((
|
|
394
|
-
if (
|
|
395
|
-
let { name: p } =
|
|
396
|
+
}) : i.specifiers.length > 0 && i.specifiers.forEach((c) => {
|
|
397
|
+
if (l.isExportSpecifier(c) && l.isIdentifier(c.exported)) {
|
|
398
|
+
let { name: p } = c.exported, { name: d } = c.local, u = l.isProgram(a) ? O(d, a) : c.local;
|
|
396
399
|
if (p === "default") {
|
|
397
|
-
let
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
let g;
|
|
401
|
+
l.isObjectExpression(u) ? g = u : /* export default { ... } as Meta<...> */ /* export default { ... } satisfies Meta<...> */ (l.
|
|
402
|
+
isTSAsExpression(u) || l.isTSSatisfiesExpression(u)) && l.isObjectExpression(u.expression) ? g = u.expression : (
|
|
403
|
+
// export default { ... } satisfies Meta as Meta<...>
|
|
404
|
+
l.isTSAsExpression(u) && l.isTSSatisfiesExpression(u.expression) && l.isObjectExpression(u.expression.expression) && (g = u.
|
|
405
|
+
expression.expression)
|
|
406
|
+
), g && l.isProgram(a) && e._parseMeta(g, a);
|
|
402
407
|
} else {
|
|
403
|
-
let
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}), e._storyAnnotations[p] =
|
|
408
|
+
let g = {}, b = u;
|
|
409
|
+
l.isObjectExpression(b) && b.properties.forEach((y) => {
|
|
410
|
+
l.isIdentifier(y.key) && (g[y.key.name] = y.value);
|
|
411
|
+
}), e._storyAnnotations[p] = g, e._storyStatements[p] = u, e._storyPaths[p] = t, e._stories[p] = {
|
|
407
412
|
id: "FIXME",
|
|
408
413
|
name: p,
|
|
409
414
|
localName: d,
|
|
@@ -418,12 +423,12 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
418
423
|
ExpressionStatement: {
|
|
419
424
|
enter({ node: t, parent: i }) {
|
|
420
425
|
let { expression: a } = t;
|
|
421
|
-
if (
|
|
426
|
+
if (l.isProgram(i) && l.isAssignmentExpression(a) && l.isMemberExpression(a.left) && l.isIdentifier(a.left.object) && l.isIdentifier(
|
|
422
427
|
a.left.property)) {
|
|
423
|
-
let o = a.left.object.name,
|
|
424
|
-
if (e._storyAnnotations[o] && (
|
|
425
|
-
|
|
426
|
-
}) : e._storyAnnotations[o][
|
|
428
|
+
let o = a.left.object.name, c = a.left.property.name, p = a.right;
|
|
429
|
+
if (e._storyAnnotations[o] && (c === "story" && l.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
430
|
+
l.isIdentifier(d.key) && (e._storyAnnotations[o][d.key.name] = d.value);
|
|
431
|
+
}) : e._storyAnnotations[o][c] = p), c === "storyName" && l.isStringLiteral(p)) {
|
|
427
432
|
let d = p.value, u = e._stories[o];
|
|
428
433
|
if (!u)
|
|
429
434
|
return;
|
|
@@ -435,23 +440,23 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
435
440
|
CallExpression: {
|
|
436
441
|
enter(t) {
|
|
437
442
|
let { node: i } = t, { callee: a } = i;
|
|
438
|
-
if (
|
|
439
|
-
throw new Error(
|
|
443
|
+
if (l.isIdentifier(a) && a.name === "storiesOf")
|
|
444
|
+
throw new Error(P.dedent`
|
|
440
445
|
Unexpected \`storiesOf\` usage: ${v(i, e._options.fileName)}.
|
|
441
446
|
|
|
442
|
-
SB8 does not support \`storiesOf\`.
|
|
447
|
+
SB8 does not support \`storiesOf\`.
|
|
443
448
|
`);
|
|
444
|
-
if (
|
|
449
|
+
if (l.isMemberExpression(a) && l.isIdentifier(a.property) && a.property.name === "meta" && l.isIdentifier(a.object) && i.arguments.
|
|
445
450
|
length > 0) {
|
|
446
|
-
let
|
|
447
|
-
if (
|
|
448
|
-
if (Ke(
|
|
451
|
+
let c = t.scope.getBinding(a.object.name)?.path?.parentPath?.node;
|
|
452
|
+
if (l.isImportDeclaration(c))
|
|
453
|
+
if (Ke(c.source.value)) {
|
|
449
454
|
let p = i.arguments[0];
|
|
450
455
|
e._metaVariableName = a.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
451
456
|
} else
|
|
452
457
|
throw new W(
|
|
453
458
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
454
|
-
|
|
459
|
+
c,
|
|
455
460
|
e._options.fileName
|
|
456
461
|
);
|
|
457
462
|
}
|
|
@@ -460,7 +465,7 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
460
465
|
ImportDeclaration: {
|
|
461
466
|
enter({ node: t }) {
|
|
462
467
|
let { source: i } = t;
|
|
463
|
-
if (
|
|
468
|
+
if (l.isStringLiteral(i))
|
|
464
469
|
e.imports.push(i.value);
|
|
465
470
|
else
|
|
466
471
|
throw new Error("CSF: unexpected import source");
|
|
@@ -474,21 +479,21 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
474
479
|
(t, [i, a]) => {
|
|
475
480
|
if (!ne(i, e._meta))
|
|
476
481
|
return t;
|
|
477
|
-
let o = a.parameters?.__id ?? ze(e._meta?.id || e._meta?.title, oe(i)),
|
|
482
|
+
let o = a.parameters?.__id ?? ze(e._meta?.id || e._meta?.title, oe(i)), c = { ...a.parameters, __id: o }, { includeStories: p } = e.
|
|
478
483
|
_meta || {};
|
|
479
|
-
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (
|
|
480
|
-
let d = e._storyAnnotations[i], { tags: u, play:
|
|
484
|
+
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (c.docsOnly = !0), t[i] = { ...a, id: o, parameters: c };
|
|
485
|
+
let d = e._storyAnnotations[i], { tags: u, play: g } = d;
|
|
481
486
|
if (u) {
|
|
482
|
-
let _ =
|
|
487
|
+
let _ = l.isIdentifier(u) ? O(u.name, this._ast.program) : u;
|
|
483
488
|
t[i].tags = le(_);
|
|
484
489
|
}
|
|
485
|
-
|
|
490
|
+
g && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
486
491
|
let b = t[i].__stats;
|
|
487
492
|
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((_) => {
|
|
488
493
|
b[_] = !!d[_] || !!e._metaAnnotations[_];
|
|
489
494
|
});
|
|
490
495
|
let y = e.getStoryExport(i);
|
|
491
|
-
return b.storyFn = !!(
|
|
496
|
+
return b.storyFn = !!(l.isArrowFunctionExpression(y) || l.isFunctionDeclaration(y)), b.mount = Ye(d.play ?? e._metaAnnotations.play),
|
|
492
497
|
b.moduleMock = !!e.imports.find((_) => Qe(_)), t;
|
|
493
498
|
},
|
|
494
499
|
{}
|
|
@@ -517,7 +522,7 @@ var v = /* @__PURE__ */ f((s, e) => {
|
|
|
517
522
|
let { fileName: e } = this._options;
|
|
518
523
|
if (!e)
|
|
519
524
|
throw new Error(
|
|
520
|
-
|
|
525
|
+
P.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
521
526
|
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
522
527
|
);
|
|
523
528
|
return Object.entries(this._stories).map(([r, t]) => {
|
|
@@ -582,7 +587,7 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
582
587
|
if (i)
|
|
583
588
|
return be(t, i.value);
|
|
584
589
|
}
|
|
585
|
-
}, "_getPath"),
|
|
590
|
+
}, "_getPath"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
586
591
|
if (s.length === 0) {
|
|
587
592
|
if (n.isObjectExpression(e))
|
|
588
593
|
return e.properties;
|
|
@@ -591,7 +596,7 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
591
596
|
if (n.isObjectExpression(e)) {
|
|
592
597
|
let [r, ...t] = s, i = e.properties.find((a) => N(a) === r);
|
|
593
598
|
if (i)
|
|
594
|
-
return t.length === 0 ? e.properties :
|
|
599
|
+
return t.length === 0 ? e.properties : Ee(t, i.value);
|
|
595
600
|
}
|
|
596
601
|
}, "_getPathProperties"), z = /* @__PURE__ */ f((s, e) => {
|
|
597
602
|
let r = null, t = null;
|
|
@@ -666,8 +671,8 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
666
671
|
}
|
|
667
672
|
} else r.specifiers ? r.specifiers.forEach((i) => {
|
|
668
673
|
if (n.isExportSpecifier(i) && n.isIdentifier(i.local) && n.isIdentifier(i.exported)) {
|
|
669
|
-
let { name: a } = i.local, { name: o } = i.exported,
|
|
670
|
-
|
|
674
|
+
let { name: a } = i.local, { name: o } = i.exported, c = z(a, t);
|
|
675
|
+
c && (e._exports[o] = c.init, e._exportDecls[o] = c);
|
|
671
676
|
}
|
|
672
677
|
}) : H.warn(
|
|
673
678
|
Y({
|
|
@@ -685,10 +690,10 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
685
690
|
if (n.isMemberExpression(i) && n.isIdentifier(i.object) && i.object.name === "module" && n.isIdentifier(i.property) && i.property.
|
|
686
691
|
name === "exports") {
|
|
687
692
|
let o = a;
|
|
688
|
-
n.isIdentifier(a) && (o = I(a.name, t)), o = G(o), n.isObjectExpression(o) ? (e._exportsObject = o, o.properties.forEach((
|
|
689
|
-
let p = N(
|
|
693
|
+
n.isIdentifier(a) && (o = I(a.name, t)), o = G(o), n.isObjectExpression(o) ? (e._exportsObject = o, o.properties.forEach((c) => {
|
|
694
|
+
let p = N(c);
|
|
690
695
|
if (p) {
|
|
691
|
-
let d =
|
|
696
|
+
let d = c.value;
|
|
692
697
|
n.isIdentifier(d) && (d = I(
|
|
693
698
|
d.name,
|
|
694
699
|
t
|
|
@@ -721,7 +726,7 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
721
726
|
getFieldProperties(e) {
|
|
722
727
|
let [r, ...t] = e, i = this._exports[r];
|
|
723
728
|
if (i)
|
|
724
|
-
return
|
|
729
|
+
return Ee(t, i);
|
|
725
730
|
}
|
|
726
731
|
getFieldValue(e) {
|
|
727
732
|
let r = this.getFieldNode(e);
|
|
@@ -760,8 +765,8 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
760
765
|
return;
|
|
761
766
|
}
|
|
762
767
|
if (a && i.length === 0 && this._exportDecls[e[0]]) {
|
|
763
|
-
let
|
|
764
|
-
n.isVariableDeclarator(
|
|
768
|
+
let c = this._exportDecls[e[0]];
|
|
769
|
+
n.isVariableDeclarator(c) && (c.init = $([], r));
|
|
765
770
|
} else {
|
|
766
771
|
if (this.hasDefaultExport)
|
|
767
772
|
throw new Error(
|
|
@@ -770,10 +775,10 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
770
775
|
)}" field as the default export is not an object in this file.`
|
|
771
776
|
);
|
|
772
777
|
{
|
|
773
|
-
let
|
|
774
|
-
n.variableDeclaration("const", [n.variableDeclarator(n.identifier(t),
|
|
778
|
+
let c = $(i, r), p = n.exportNamedDeclaration(
|
|
779
|
+
n.variableDeclaration("const", [n.variableDeclarator(n.identifier(t), c)])
|
|
775
780
|
);
|
|
776
|
-
this._exports[t] =
|
|
781
|
+
this._exports[t] = c, this._ast.program.body.push(p);
|
|
777
782
|
}
|
|
778
783
|
}
|
|
779
784
|
}
|
|
@@ -842,7 +847,7 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
842
847
|
removeField(e) {
|
|
843
848
|
let r = /* @__PURE__ */ f((i, a) => {
|
|
844
849
|
let o = i.findIndex(
|
|
845
|
-
(
|
|
850
|
+
(c) => n.isIdentifier(c.key) && c.key.name === a || n.isStringLiteral(c.key) && c.key.value === a
|
|
846
851
|
);
|
|
847
852
|
o >= 0 && i.splice(o, 1);
|
|
848
853
|
}, "removeProperty");
|
|
@@ -856,8 +861,8 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
856
861
|
if (n.isExportDefaultDeclaration(a)) {
|
|
857
862
|
let o = a.declaration;
|
|
858
863
|
if (n.isIdentifier(o) && (o = I(o.name, this._ast.program)), o = G(o), n.isObjectExpression(o)) {
|
|
859
|
-
let
|
|
860
|
-
r(
|
|
864
|
+
let c = o.properties;
|
|
865
|
+
r(c, e[0]), i = !0;
|
|
861
866
|
}
|
|
862
867
|
}
|
|
863
868
|
if (n.isExpressionStatement(a) && n.isAssignmentExpression(a.expression) && n.isMemberExpression(a.expression.left) && n.isIdentifier(
|
|
@@ -962,15 +967,15 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
962
967
|
*/
|
|
963
968
|
setRequireImport(e, r) {
|
|
964
969
|
let t = this._ast.program.body.find((o) => {
|
|
965
|
-
let
|
|
970
|
+
let c = n.isVariableDeclaration(o) && o.declarations.length === 1 && n.isVariableDeclarator(o.declarations[0]) && n.isCallExpression(o.
|
|
966
971
|
declarations[0].init) && n.isIdentifier(o.declarations[0].init.callee) && o.declarations[0].init.callee.name === "require" && n.isStringLiteral(
|
|
967
972
|
o.declarations[0].init.arguments[0]) && (o.declarations[0].init.arguments[0].value === r || o.declarations[0].init.arguments[0].value ===
|
|
968
973
|
r.split("node:")[1]);
|
|
969
|
-
return
|
|
974
|
+
return c && (r = o.declarations[0].init.arguments[0].value), c;
|
|
970
975
|
}), i = /* @__PURE__ */ f((o) => n.isObjectPattern(t?.declarations[0].id) && t?.declarations[0].id.properties.find(
|
|
971
|
-
(
|
|
972
|
-
), "hasRequireSpecifier"), a = /* @__PURE__ */ f((o,
|
|
973
|
-
isIdentifier(o.declarations[0].id) && o.declarations[0].id.name ===
|
|
976
|
+
(c) => n.isObjectProperty(c) && n.isIdentifier(c.key) && c.key.name === o
|
|
977
|
+
), "hasRequireSpecifier"), a = /* @__PURE__ */ f((o, c) => o.declarations.length === 1 && n.isVariableDeclarator(o.declarations[0]) && n.
|
|
978
|
+
isIdentifier(o.declarations[0].id) && o.declarations[0].id.name === c, "hasDefaultRequireSpecifier");
|
|
974
979
|
if (typeof e == "string") {
|
|
975
980
|
let o = /* @__PURE__ */ f(() => {
|
|
976
981
|
this._ast.program.body.unshift(
|
|
@@ -1079,22 +1084,22 @@ ctoryPreview");
|
|
|
1079
1084
|
|
|
1080
1085
|
// src/csf-tools/getStorySortParameter.ts
|
|
1081
1086
|
var je = U(k(), 1);
|
|
1082
|
-
import { babelParse as lt, generate as
|
|
1087
|
+
import { babelParse as lt, generate as he, types as E, traverse as ct } from "storybook/internal/babel";
|
|
1083
1088
|
import { logger as pt } from "storybook/internal/node-logger";
|
|
1084
1089
|
var ee = /* @__PURE__ */ f((s, e) => {
|
|
1085
1090
|
let r;
|
|
1086
1091
|
return s.properties.forEach((t) => {
|
|
1087
|
-
|
|
1092
|
+
E.isIdentifier(t.key) && t.key.name === e && (r = t.value);
|
|
1088
1093
|
}), r;
|
|
1089
1094
|
}, "getValue"), te = /* @__PURE__ */ f((s) => {
|
|
1090
1095
|
let e = R(s);
|
|
1091
|
-
if (
|
|
1096
|
+
if (E.isArrayExpression(e))
|
|
1092
1097
|
return e.elements.map((r) => te(r));
|
|
1093
|
-
if (
|
|
1094
|
-
return e.properties.reduce((r, t) => (
|
|
1095
|
-
if (
|
|
1098
|
+
if (E.isObjectExpression(e))
|
|
1099
|
+
return e.properties.reduce((r, t) => (E.isIdentifier(t.key) && (r[t.key.name] = te(t.value)), r), {});
|
|
1100
|
+
if (E.isLiteral(e))
|
|
1096
1101
|
return e.value;
|
|
1097
|
-
if (
|
|
1102
|
+
if (E.isIdentifier(e))
|
|
1098
1103
|
return w(e.name, !0);
|
|
1099
1104
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1100
1105
|
}, "parseValue"), w = /* @__PURE__ */ f((s, e) => {
|
|
@@ -1112,22 +1117,22 @@ var ee = /* @__PURE__ */ f((s, e) => {
|
|
|
1112
1117
|
if (e)
|
|
1113
1118
|
throw new Error(r);
|
|
1114
1119
|
pt.log(r);
|
|
1115
|
-
}, "unsupported"), R = /* @__PURE__ */ f((s) =>
|
|
1120
|
+
}, "unsupported"), R = /* @__PURE__ */ f((s) => E.isTSAsExpression(s) || E.isTSSatisfiesExpression(s) ? s.expression : s, "stripTSModifiers"),
|
|
1116
1121
|
Se = /* @__PURE__ */ f((s) => {
|
|
1117
1122
|
let e = R(s);
|
|
1118
|
-
if (
|
|
1123
|
+
if (E.isObjectExpression(e)) {
|
|
1119
1124
|
let r = ee(e, "options");
|
|
1120
1125
|
if (r) {
|
|
1121
|
-
if (
|
|
1126
|
+
if (E.isObjectExpression(r))
|
|
1122
1127
|
return ee(r, "storySort");
|
|
1123
1128
|
w("options", !0);
|
|
1124
1129
|
}
|
|
1125
1130
|
}
|
|
1126
1131
|
}, "parseParameters"), _e = /* @__PURE__ */ f((s, e) => {
|
|
1127
1132
|
let r = R(s);
|
|
1128
|
-
if (
|
|
1133
|
+
if (E.isObjectExpression(r)) {
|
|
1129
1134
|
let t = ee(r, "parameters");
|
|
1130
|
-
if (
|
|
1135
|
+
if (E.isIdentifier(t) && (t = O(t.name, e)), t)
|
|
1131
1136
|
return Se(t);
|
|
1132
1137
|
} else
|
|
1133
1138
|
w("default", !0);
|
|
@@ -1138,8 +1143,8 @@ Se = /* @__PURE__ */ f((s) => {
|
|
|
1138
1143
|
if (ct(r, {
|
|
1139
1144
|
ExportNamedDeclaration: {
|
|
1140
1145
|
enter({ node: t }) {
|
|
1141
|
-
|
|
1142
|
-
if (
|
|
1146
|
+
E.isVariableDeclaration(t.declaration) ? t.declaration.declarations.forEach((i) => {
|
|
1147
|
+
if (E.isVariableDeclarator(i) && E.isIdentifier(i.id)) {
|
|
1143
1148
|
let { name: a } = i.id;
|
|
1144
1149
|
if (a === "parameters" && i.init) {
|
|
1145
1150
|
let o = R(i.init);
|
|
@@ -1147,111 +1152,111 @@ Se = /* @__PURE__ */ f((s) => {
|
|
|
1147
1152
|
}
|
|
1148
1153
|
}
|
|
1149
1154
|
}) : t.specifiers.forEach((i) => {
|
|
1150
|
-
|
|
1155
|
+
E.isIdentifier(i.exported) && i.exported.name === "parameters" && w("parameters", !1);
|
|
1151
1156
|
});
|
|
1152
1157
|
}
|
|
1153
1158
|
},
|
|
1154
1159
|
ExportDefaultDeclaration: {
|
|
1155
1160
|
enter({ node: t }) {
|
|
1156
1161
|
let i = t.declaration;
|
|
1157
|
-
|
|
1158
|
-
i.arguments[0], r.program) :
|
|
1162
|
+
E.isIdentifier(i) && (i = O(i.name, r.program)), i = R(i), E.isCallExpression(i) && E.isObjectExpression(i.arguments?.[0]) ? e = _e(
|
|
1163
|
+
i.arguments[0], r.program) : E.isObjectExpression(i) ? e = _e(i, r.program) : w("default", !1);
|
|
1159
1164
|
}
|
|
1160
1165
|
}
|
|
1161
1166
|
}), !!e) {
|
|
1162
|
-
if (
|
|
1163
|
-
let { code: t } =
|
|
1167
|
+
if (E.isArrowFunctionExpression(e)) {
|
|
1168
|
+
let { code: t } = he(e, {});
|
|
1164
1169
|
return (0, eval)(t);
|
|
1165
1170
|
}
|
|
1166
|
-
if (
|
|
1167
|
-
let { code: t } =
|
|
1171
|
+
if (E.isFunctionExpression(e)) {
|
|
1172
|
+
let { code: t } = he(e, {}), i = e.id?.name, a = `(a, b) => {
|
|
1168
1173
|
${t};
|
|
1169
1174
|
return ${i}(a, b)
|
|
1170
1175
|
}`;
|
|
1171
1176
|
return (0, eval)(a);
|
|
1172
1177
|
}
|
|
1173
|
-
return
|
|
1178
|
+
return E.isLiteral(e) || E.isArrayExpression(e) || E.isObjectExpression(e) ? te(e) : w("storySort", !0);
|
|
1174
1179
|
}
|
|
1175
1180
|
}, "getStorySortParameter");
|
|
1176
1181
|
|
|
1177
1182
|
// src/csf-tools/enrichCsf.ts
|
|
1178
|
-
import { generate as ft, types as
|
|
1183
|
+
import { generate as ft, types as x } from "storybook/internal/babel";
|
|
1179
1184
|
var dt = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1180
|
-
let i = e.getStoryExport(r), a =
|
|
1181
|
-
name === "meta", o = !t?.disableSource && ut(i),
|
|
1182
|
-
|
|
1183
|
-
p.push(
|
|
1184
|
-
let
|
|
1185
|
+
let i = e.getStoryExport(r), a = x.isCallExpression(i) && x.isMemberExpression(i.callee) && x.isIdentifier(i.callee.object) && i.callee.object.
|
|
1186
|
+
name === "meta", o = !t?.disableSource && ut(i), c = !t?.disableDescription && Pe(e._storyStatements[r]), p = [], d = a ? x.memberExpression(
|
|
1187
|
+
x.identifier(r), x.identifier("input")) : x.identifier(r), u = x.memberExpression(d, x.identifier("parameters"));
|
|
1188
|
+
p.push(x.spreadElement(u));
|
|
1189
|
+
let g = x.optionalMemberExpression(
|
|
1185
1190
|
u,
|
|
1186
|
-
|
|
1191
|
+
x.identifier("docs"),
|
|
1187
1192
|
!1,
|
|
1188
1193
|
!0
|
|
1189
1194
|
), b = [];
|
|
1190
1195
|
if (o) {
|
|
1191
|
-
let y =
|
|
1192
|
-
|
|
1193
|
-
|
|
1196
|
+
let y = x.optionalMemberExpression(
|
|
1197
|
+
g,
|
|
1198
|
+
x.identifier("source"),
|
|
1194
1199
|
!1,
|
|
1195
1200
|
!0
|
|
1196
1201
|
);
|
|
1197
1202
|
b.push(
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
+
x.objectProperty(
|
|
1204
|
+
x.identifier("source"),
|
|
1205
|
+
x.objectExpression([
|
|
1206
|
+
x.objectProperty(x.identifier("originalSource"), x.stringLiteral(o)),
|
|
1207
|
+
x.spreadElement(y)
|
|
1203
1208
|
])
|
|
1204
1209
|
)
|
|
1205
1210
|
);
|
|
1206
1211
|
}
|
|
1207
|
-
if (
|
|
1208
|
-
let y =
|
|
1209
|
-
|
|
1210
|
-
|
|
1212
|
+
if (c) {
|
|
1213
|
+
let y = x.optionalMemberExpression(
|
|
1214
|
+
g,
|
|
1215
|
+
x.identifier("description"),
|
|
1211
1216
|
!1,
|
|
1212
1217
|
!0
|
|
1213
1218
|
);
|
|
1214
1219
|
b.push(
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
+
x.objectProperty(
|
|
1221
|
+
x.identifier("description"),
|
|
1222
|
+
x.objectExpression([
|
|
1223
|
+
x.objectProperty(x.identifier("story"), x.stringLiteral(c)),
|
|
1224
|
+
x.spreadElement(y)
|
|
1220
1225
|
])
|
|
1221
1226
|
)
|
|
1222
1227
|
);
|
|
1223
1228
|
}
|
|
1224
1229
|
if (b.length > 0) {
|
|
1225
1230
|
p.push(
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1231
|
+
x.objectProperty(
|
|
1232
|
+
x.identifier("docs"),
|
|
1233
|
+
x.objectExpression([x.spreadElement(g), ...b])
|
|
1229
1234
|
)
|
|
1230
1235
|
);
|
|
1231
|
-
let y =
|
|
1232
|
-
|
|
1236
|
+
let y = x.expressionStatement(
|
|
1237
|
+
x.assignmentExpression("=", u, x.objectExpression(p))
|
|
1233
1238
|
);
|
|
1234
1239
|
s._ast.program.body.push(y);
|
|
1235
1240
|
}
|
|
1236
|
-
}, "enrichCsfStory"),
|
|
1241
|
+
}, "enrichCsfStory"), Oe = /* @__PURE__ */ f((s, e, r) => {
|
|
1237
1242
|
if (!e.length) {
|
|
1238
1243
|
s.properties.find(
|
|
1239
|
-
(p) =>
|
|
1244
|
+
(p) => x.isObjectProperty(p) && x.isIdentifier(p.key) && p.key.name === "component"
|
|
1240
1245
|
) || s.properties.unshift(r);
|
|
1241
1246
|
return;
|
|
1242
1247
|
}
|
|
1243
1248
|
let [t, ...i] = e, a = s.properties.find(
|
|
1244
|
-
(
|
|
1249
|
+
(c) => x.isObjectProperty(c) && x.isIdentifier(c.key) && c.key.name === t && x.isObjectExpression(c.value)
|
|
1245
1250
|
), o;
|
|
1246
|
-
a ? o = a.value : (o =
|
|
1251
|
+
a ? o = a.value : (o = x.objectExpression([]), s.properties.push(x.objectProperty(x.identifier(t), o))), Oe(o, i, r);
|
|
1247
1252
|
}, "addComponentDescription"), mt = /* @__PURE__ */ f((s, e, r) => {
|
|
1248
|
-
let t = !r?.disableDescription &&
|
|
1253
|
+
let t = !r?.disableDescription && Pe(e._metaStatement);
|
|
1249
1254
|
if (t) {
|
|
1250
1255
|
let i = s._metaNode;
|
|
1251
|
-
i &&
|
|
1256
|
+
i && x.isObjectExpression(i) && Oe(
|
|
1252
1257
|
i,
|
|
1253
1258
|
["parameters", "docs", "description"],
|
|
1254
|
-
|
|
1259
|
+
x.objectProperty(x.identifier("component"), x.stringLiteral(t))
|
|
1255
1260
|
);
|
|
1256
1261
|
}
|
|
1257
1262
|
}, "enrichCsfMeta"), Qt = /* @__PURE__ */ f((s, e, r) => {
|
|
@@ -1259,9 +1264,9 @@ var dt = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1259
1264
|
dt(s, e, t, r);
|
|
1260
1265
|
});
|
|
1261
1266
|
}, "enrichCsf"), ut = /* @__PURE__ */ f((s) => {
|
|
1262
|
-
let e =
|
|
1267
|
+
let e = x.isVariableDeclarator(s) ? s.init : s, { code: r } = ft(e, {});
|
|
1263
1268
|
return r;
|
|
1264
|
-
}, "extractSource"),
|
|
1269
|
+
}, "extractSource"), Pe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((r) => r.type === "CommentLine" || !r.value.startsWith(
|
|
1265
1270
|
"*") ? null : r.value.split(`
|
|
1266
1271
|
`).map((t) => t.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
|
|
1267
1272
|
`).trim()).filter(Boolean).join(`
|
|
@@ -1289,12 +1294,12 @@ async function bt({
|
|
|
1289
1294
|
let o = Q(s, {
|
|
1290
1295
|
fileName: e,
|
|
1291
1296
|
transformInlineMeta: !0,
|
|
1292
|
-
makeTitle: /* @__PURE__ */ f((
|
|
1297
|
+
makeTitle: /* @__PURE__ */ f((h) => {
|
|
1293
1298
|
let S = gt({
|
|
1294
1299
|
storyFilePath: e,
|
|
1295
1300
|
configDir: r,
|
|
1296
1301
|
stories: t,
|
|
1297
|
-
userTitle:
|
|
1302
|
+
userTitle: h
|
|
1298
1303
|
}) || "unknown";
|
|
1299
1304
|
return S === "unknown" && ve.warn(
|
|
1300
1305
|
re.dedent`
|
|
@@ -1303,10 +1308,10 @@ async function bt({
|
|
|
1303
1308
|
`
|
|
1304
1309
|
), S;
|
|
1305
1310
|
}, "makeTitle")
|
|
1306
|
-
}).parse(),
|
|
1307
|
-
(
|
|
1308
|
-
),
|
|
1309
|
-
if (u ? m.isObjectProperty(u) && (u.value =
|
|
1311
|
+
}).parse(), c = o._ast, p = o._metaVariableName, d = o._metaNode, u = d.properties.find(
|
|
1312
|
+
(h) => m.isObjectProperty(h) && m.isIdentifier(h.key) && h.key.name === "title"
|
|
1313
|
+
), g = m.stringLiteral(o._meta?.title || "unknown");
|
|
1314
|
+
if (u ? m.isObjectProperty(u) && (u.value = g) : d.properties.push(m.objectProperty(m.identifier("title"), g)), !d || !o._meta)
|
|
1310
1315
|
throw new Error(
|
|
1311
1316
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
1312
1317
|
|
|
@@ -1314,24 +1319,24 @@ Please make sure you have a default export with the meta object. If you are usin
|
|
|
1314
1319
|
le an issue with details about your use case.`
|
|
1315
1320
|
);
|
|
1316
1321
|
let b = {};
|
|
1317
|
-
Object.keys(o._stories).map((
|
|
1322
|
+
Object.keys(o._stories).map((h) => {
|
|
1318
1323
|
let S = xt(
|
|
1319
1324
|
"test",
|
|
1320
1325
|
"dev",
|
|
1321
1326
|
...a,
|
|
1322
1327
|
...o.meta?.tags || [],
|
|
1323
|
-
...o._stories[
|
|
1328
|
+
...o._stories[h].tags || []
|
|
1324
1329
|
);
|
|
1325
|
-
yt(S, i) && (b[
|
|
1330
|
+
yt(S, i) && (b[h] = o._storyStatements[h]);
|
|
1326
1331
|
});
|
|
1327
1332
|
let y = o._file.path.scope.generateUidIdentifier("test"), _ = o._file.path.scope.generateUidIdentifier("describe");
|
|
1328
1333
|
if (Object.keys(b).length === 0) {
|
|
1329
|
-
let
|
|
1334
|
+
let h = m.expressionStatement(
|
|
1330
1335
|
m.callExpression(m.memberExpression(_, m.identifier("skip")), [
|
|
1331
1336
|
m.stringLiteral("No valid tests found")
|
|
1332
1337
|
])
|
|
1333
1338
|
);
|
|
1334
|
-
|
|
1339
|
+
c.program.body.push(h);
|
|
1335
1340
|
let S = [
|
|
1336
1341
|
m.importDeclaration(
|
|
1337
1342
|
[
|
|
@@ -1341,11 +1346,11 @@ le an issue with details about your use case.`
|
|
|
1341
1346
|
m.stringLiteral("vitest")
|
|
1342
1347
|
)
|
|
1343
1348
|
];
|
|
1344
|
-
|
|
1349
|
+
c.program.body.unshift(...S);
|
|
1345
1350
|
} else {
|
|
1346
1351
|
let ie = function() {
|
|
1347
1352
|
let j = o._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), D = m.memberExpression(
|
|
1348
|
-
m.callExpression(m.memberExpression(
|
|
1353
|
+
m.callExpression(m.memberExpression(h, m.identifier("getState")), []),
|
|
1349
1354
|
m.identifier("testPath")
|
|
1350
1355
|
), F = m.memberExpression(
|
|
1351
1356
|
m.memberExpression(m.identifier("globalThis"), m.identifier("__vitest_worker__")),
|
|
@@ -1374,9 +1379,9 @@ le an issue with details about your use case.`
|
|
|
1374
1379
|
};
|
|
1375
1380
|
var L = ie;
|
|
1376
1381
|
f(ie, "getTestGuardDeclaration");
|
|
1377
|
-
let
|
|
1382
|
+
let h = o._file.path.scope.generateUidIdentifier("expect"), S = o._file.path.scope.generateUidIdentifier("testStory"), De = m.identifier(
|
|
1378
1383
|
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Ie, isRunningFromThisFileId: Ne } = ie();
|
|
1379
|
-
|
|
1384
|
+
c.program.body.push(Ie);
|
|
1380
1385
|
let we = /* @__PURE__ */ f(({
|
|
1381
1386
|
localName: j,
|
|
1382
1387
|
exportName: D,
|
|
@@ -1408,12 +1413,12 @@ le an issue with details about your use case.`
|
|
|
1408
1413
|
let F = o._stories[j].localName ?? j, C = o._stories[j].name ?? j;
|
|
1409
1414
|
return we({ testTitle: C, localName: F, exportName: j, node: D });
|
|
1410
1415
|
}).filter((j) => !!j), Ce = m.ifStatement(Ne, m.blockStatement(Fe));
|
|
1411
|
-
|
|
1416
|
+
c.program.body.push(Ce);
|
|
1412
1417
|
let Te = [
|
|
1413
1418
|
m.importDeclaration(
|
|
1414
1419
|
[
|
|
1415
1420
|
m.importSpecifier(y, m.identifier("test")),
|
|
1416
|
-
m.importSpecifier(
|
|
1421
|
+
m.importSpecifier(h, m.identifier("expect"))
|
|
1417
1422
|
],
|
|
1418
1423
|
m.stringLiteral("vitest")
|
|
1419
1424
|
),
|
|
@@ -1425,7 +1430,7 @@ le an issue with details about your use case.`
|
|
|
1425
1430
|
m.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1426
1431
|
)
|
|
1427
1432
|
];
|
|
1428
|
-
|
|
1433
|
+
c.program.body.unshift(...Te);
|
|
1429
1434
|
}
|
|
1430
1435
|
return me(o, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1431
1436
|
}
|
|
@@ -1442,7 +1447,7 @@ export {
|
|
|
1442
1447
|
Qt as enrichCsf,
|
|
1443
1448
|
mt as enrichCsfMeta,
|
|
1444
1449
|
dt as enrichCsfStory,
|
|
1445
|
-
|
|
1450
|
+
Pe as extractDescription,
|
|
1446
1451
|
ut as extractSource,
|
|
1447
1452
|
ot as formatConfig,
|
|
1448
1453
|
me as formatCsf,
|