storybook 9.0.16 → 9.0.17
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/components/index.cjs +4584 -4418
- package/dist/components/index.d.ts +8 -11
- package/dist/components/index.js +2741 -2571
- package/dist/csf-tools/index.cjs +319 -321
- package/dist/csf-tools/index.js +239 -241
- package/dist/manager/globals-module-info.cjs +0 -1
- package/dist/manager/globals-module-info.js +0 -1
- package/dist/manager/globals-runtime.js +15176 -15007
- package/dist/manager/runtime.js +102 -102
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.js +1 -1
- package/dist/telemetry/index.cjs +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +1 -1
- package/package.json +1 -1
package/dist/csf-tools/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var Ge = Object.create;
|
|
3
|
-
var
|
|
3
|
+
var V = Object.defineProperty;
|
|
4
4
|
var ze = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var Xe = Object.getOwnPropertyNames;
|
|
6
6
|
var Ke = Object.getPrototypeOf, Je = Object.prototype.hasOwnProperty;
|
|
7
|
-
var f = (s, e) =>
|
|
7
|
+
var f = (s, e) => V(s, "name", { value: e, configurable: !0 });
|
|
8
8
|
var Qe = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports), He = (s, e) => {
|
|
9
9
|
for (var r in e)
|
|
10
|
-
|
|
10
|
+
V(s, r, { get: e[r], enumerable: !0 });
|
|
11
11
|
}, fe = (s, e, r, t) => {
|
|
12
12
|
if (e && typeof e == "object" || typeof e == "function")
|
|
13
13
|
for (let i of Xe(e))
|
|
14
|
-
!Je.call(s, i) && i !== r &&
|
|
14
|
+
!Je.call(s, i) && i !== r && V(s, i, { get: () => e[i], enumerable: !(t = ze(e, i)) || t.enumerable });
|
|
15
15
|
return s;
|
|
16
16
|
};
|
|
17
17
|
var z = (s, e, r) => (r = s != null ? Ge(Ke(s)) : {}, fe(
|
|
@@ -19,61 +19,61 @@ var z = (s, e, r) => (r = s != null ? Ge(Ke(s)) : {}, fe(
|
|
|
19
19
|
// file that has been converted to a CommonJS file using a Babel-
|
|
20
20
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
21
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
-
e || !s || !s.__esModule ?
|
|
22
|
+
e || !s || !s.__esModule ? V(r, "default", { value: s, enumerable: !0 }) : r,
|
|
23
23
|
s
|
|
24
|
-
)), Ye = (s) => fe(
|
|
24
|
+
)), Ye = (s) => fe(V({}, "__esModule", { value: !0 }), s);
|
|
25
25
|
|
|
26
26
|
// ../node_modules/ts-dedent/dist/index.js
|
|
27
|
-
var
|
|
27
|
+
var $ = Qe((A) => {
|
|
28
28
|
"use strict";
|
|
29
|
-
Object.defineProperty(
|
|
30
|
-
|
|
29
|
+
Object.defineProperty(A, "__esModule", { value: !0 });
|
|
30
|
+
A.dedent = void 0;
|
|
31
31
|
function de(s) {
|
|
32
32
|
for (var e = [], r = 1; r < arguments.length; r++)
|
|
33
33
|
e[r - 1] = arguments[r];
|
|
34
34
|
var t = Array.from(typeof s == "string" ? [s] : s);
|
|
35
35
|
t[t.length - 1] = t[t.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
36
|
-
var i = t.reduce(function(
|
|
36
|
+
var i = t.reduce(function(c, p) {
|
|
37
37
|
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
38
|
-
return d ?
|
|
38
|
+
return d ? c.concat(d.map(function(g) {
|
|
39
39
|
var x, h;
|
|
40
40
|
return (h = (x = g.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && h !== void 0 ? h : 0;
|
|
41
|
-
})) :
|
|
41
|
+
})) : c;
|
|
42
42
|
}, []);
|
|
43
43
|
if (i.length) {
|
|
44
|
-
var
|
|
44
|
+
var a = new RegExp(`
|
|
45
45
|
[ ]{` + Math.min.apply(Math, i) + "}", "g");
|
|
46
|
-
t = t.map(function(
|
|
47
|
-
return
|
|
46
|
+
t = t.map(function(c) {
|
|
47
|
+
return c.replace(a, `
|
|
48
48
|
`);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
t[0] = t[0].replace(/^\r?\n/, "");
|
|
52
|
-
var
|
|
53
|
-
return e.forEach(function(
|
|
54
|
-
var d =
|
|
55
|
-
typeof
|
|
56
|
-
`) && (x = String(
|
|
52
|
+
var o = t[0];
|
|
53
|
+
return e.forEach(function(c, p) {
|
|
54
|
+
var d = o.match(/(?:^|\n)( *)$/), g = d ? d[1] : "", x = c;
|
|
55
|
+
typeof c == "string" && c.includes(`
|
|
56
|
+
`) && (x = String(c).split(`
|
|
57
57
|
`).map(function(h, b) {
|
|
58
58
|
return b === 0 ? h : "" + g + h;
|
|
59
59
|
}).join(`
|
|
60
|
-
`)),
|
|
61
|
-
}),
|
|
60
|
+
`)), o += x + t[p + 1];
|
|
61
|
+
}), o;
|
|
62
62
|
}
|
|
63
63
|
f(de, "dedent");
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
A.dedent = de;
|
|
65
|
+
A.default = de;
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// src/csf-tools/index.ts
|
|
69
69
|
var dt = {};
|
|
70
70
|
He(dt, {
|
|
71
|
-
BadMetaError: () =>
|
|
71
|
+
BadMetaError: () => M,
|
|
72
72
|
ConfigFile: () => ee,
|
|
73
73
|
CsfFile: () => K,
|
|
74
|
-
MixedFactoryError: () =>
|
|
74
|
+
MixedFactoryError: () => L,
|
|
75
75
|
MultipleMetaError: () => X,
|
|
76
|
-
NoMetaError: () =>
|
|
76
|
+
NoMetaError: () => R,
|
|
77
77
|
babelParse: () => $e.babelParse,
|
|
78
78
|
babelParseFile: () => be,
|
|
79
79
|
enrichCsf: () => pt,
|
|
@@ -100,39 +100,39 @@ He(dt, {
|
|
|
100
100
|
module.exports = Ye(dt);
|
|
101
101
|
|
|
102
102
|
// src/csf-tools/CsfFile.ts
|
|
103
|
-
var J = require("node:fs/promises"),
|
|
104
|
-
O = z(
|
|
103
|
+
var J = require("node:fs/promises"), l = require("storybook/internal/babel"), v = require("storybook/internal/csf"), re = require("storybook/internal/node-logger"),
|
|
104
|
+
O = z($(), 1);
|
|
105
105
|
|
|
106
106
|
// src/csf-tools/findVarInitialization.ts
|
|
107
|
-
var
|
|
107
|
+
var N = require("storybook/internal/babel");
|
|
108
108
|
var P = /* @__PURE__ */ f((s, e) => {
|
|
109
109
|
let r = null, t = null;
|
|
110
|
-
return e.body.find((i) => (
|
|
111
|
-
i.declaration) && (t = i.declaration.declarations), t && t.find((
|
|
112
|
-
id.name === s ? (r =
|
|
110
|
+
return e.body.find((i) => (N.types.isVariableDeclaration(i) ? t = i.declarations : N.types.isExportNamedDeclaration(i) && N.types.isVariableDeclaration(
|
|
111
|
+
i.declaration) && (t = i.declaration.declarations), t && t.find((a) => N.types.isVariableDeclarator(a) && N.types.isIdentifier(a.id) && a.
|
|
112
|
+
id.name === s ? (r = a.init, !0) : !1))), r;
|
|
113
113
|
}, "findVarInitialization");
|
|
114
114
|
|
|
115
115
|
// src/csf-tools/CsfFile.ts
|
|
116
116
|
var Ze = /\/preview(.(js|jsx|mjs|ts|tsx))?$/, xe = /* @__PURE__ */ f((s) => Ze.test(s), "isValidPreviewPath");
|
|
117
117
|
function et(s) {
|
|
118
|
-
if (
|
|
118
|
+
if (l.types.isArrayExpression(s))
|
|
119
119
|
return s.elements.map((e) => {
|
|
120
|
-
if (
|
|
120
|
+
if (l.types.isStringLiteral(e))
|
|
121
121
|
return e.value;
|
|
122
122
|
throw new Error(`Expected string literal: ${e}`);
|
|
123
123
|
});
|
|
124
|
-
if (
|
|
124
|
+
if (l.types.isStringLiteral(s))
|
|
125
125
|
return new RegExp(s.value);
|
|
126
|
-
if (
|
|
126
|
+
if (l.types.isRegExpLiteral(s))
|
|
127
127
|
return new RegExp(s.pattern, s.flags);
|
|
128
128
|
throw new Error(`Unknown include/exclude: ${s}`);
|
|
129
129
|
}
|
|
130
130
|
f(et, "parseIncludeExclude");
|
|
131
131
|
function me(s) {
|
|
132
|
-
if (!
|
|
132
|
+
if (!l.types.isArrayExpression(s))
|
|
133
133
|
throw new Error("CSF: Expected tags array");
|
|
134
134
|
return s.elements.map((e) => {
|
|
135
|
-
if (
|
|
135
|
+
if (l.types.isStringLiteral(e))
|
|
136
136
|
return e.value;
|
|
137
137
|
throw new Error("CSF: Expected tag to be string literal");
|
|
138
138
|
});
|
|
@@ -147,19 +147,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
147
147
|
return `${e || ""} ${r}`.trim();
|
|
148
148
|
}, "formatLocation"), ye = /* @__PURE__ */ f((s) => it.test(s), "isModuleMock"), ue = /* @__PURE__ */ f((s, e, r) => {
|
|
149
149
|
let t = s;
|
|
150
|
-
if (
|
|
151
|
-
let { callee: i, arguments:
|
|
152
|
-
if (
|
|
153
|
-
name === "bind" && (
|
|
154
|
-
let
|
|
155
|
-
|
|
150
|
+
if (l.types.isCallExpression(s)) {
|
|
151
|
+
let { callee: i, arguments: a } = s;
|
|
152
|
+
if (l.types.isProgram(e) && l.types.isMemberExpression(i) && l.types.isIdentifier(i.object) && l.types.isIdentifier(i.property) && i.property.
|
|
153
|
+
name === "bind" && (a.length === 0 || a.length === 1 && l.types.isObjectExpression(a[0]) && a[0].properties.length === 0)) {
|
|
154
|
+
let o = i.object.name, c = P(o, e);
|
|
155
|
+
c && (r._templates[o] = c, t = c);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
return
|
|
158
|
+
return l.types.isArrowFunctionExpression(t) || l.types.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
|
|
159
159
|
}, "isArgsStory"), tt = /* @__PURE__ */ f((s) => {
|
|
160
|
-
if (
|
|
160
|
+
if (l.types.isArrayExpression(s))
|
|
161
161
|
return s.elements.map((e) => {
|
|
162
|
-
if (
|
|
162
|
+
if (l.types.isStringLiteral(e))
|
|
163
163
|
return e.value;
|
|
164
164
|
throw new Error(`Expected string literal named export: ${e}`);
|
|
165
165
|
});
|
|
@@ -171,19 +171,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
171
171
|
},
|
|
172
172
|
{}
|
|
173
173
|
), "sortExports"), rt = /* @__PURE__ */ f((s) => {
|
|
174
|
-
if (
|
|
174
|
+
if (l.types.isArrowFunctionExpression(s) || l.types.isFunctionDeclaration(s)) {
|
|
175
175
|
let e = s.params;
|
|
176
176
|
if (e.length >= 1) {
|
|
177
177
|
let [r] = e;
|
|
178
|
-
if (
|
|
178
|
+
if (l.types.isObjectPattern(r))
|
|
179
179
|
return !!r.properties.find((t) => {
|
|
180
|
-
if (
|
|
180
|
+
if (l.types.isObjectProperty(t) && l.types.isIdentifier(t.key))
|
|
181
181
|
return t.key.name === "mount";
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
return !1;
|
|
186
|
-
}, "hasMount"), it = /^[.\/#].*\.mock($|\.[^.]*$)/i,
|
|
186
|
+
}, "hasMount"), it = /^[.\/#].*\.mock($|\.[^.]*$)/i, R = class extends Error {
|
|
187
187
|
static {
|
|
188
188
|
f(this, "NoMetaError");
|
|
189
189
|
}
|
|
@@ -207,7 +207,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
207
207
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
208
208
|
`), this.name = this.constructor.name;
|
|
209
209
|
}
|
|
210
|
-
},
|
|
210
|
+
}, L = class extends Error {
|
|
211
211
|
static {
|
|
212
212
|
f(this, "MixedFactoryError");
|
|
213
213
|
}
|
|
@@ -219,7 +219,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
219
219
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
220
220
|
`), this.name = this.constructor.name;
|
|
221
221
|
}
|
|
222
|
-
},
|
|
222
|
+
}, M = class extends Error {
|
|
223
223
|
static {
|
|
224
224
|
f(this, "BadMetaError");
|
|
225
225
|
}
|
|
@@ -246,10 +246,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
246
246
|
f(this, "CsfFile");
|
|
247
247
|
}
|
|
248
248
|
_parseTitle(e) {
|
|
249
|
-
let r =
|
|
250
|
-
if (
|
|
249
|
+
let r = l.types.isIdentifier(e) ? P(e.name, this._ast.program) : e;
|
|
250
|
+
if (l.types.isStringLiteral(r))
|
|
251
251
|
return r.value;
|
|
252
|
-
if (
|
|
252
|
+
if (l.types.isTSSatisfiesExpression(r) && l.types.isStringLiteral(r.expression))
|
|
253
253
|
return r.expression.value;
|
|
254
254
|
throw new Error(O.dedent`
|
|
255
255
|
CSF: unexpected dynamic title ${D(r, this._options.fileName)}
|
|
@@ -263,29 +263,29 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
263
263
|
this._metaNode = e;
|
|
264
264
|
let t = {};
|
|
265
265
|
e.properties.forEach((i) => {
|
|
266
|
-
if (
|
|
266
|
+
if (l.types.isIdentifier(i.key)) {
|
|
267
267
|
if (this._metaAnnotations[i.key.name] = i.value, i.key.name === "title")
|
|
268
268
|
t.title = this._parseTitle(i.value);
|
|
269
269
|
else if (["includeStories", "excludeStories"].includes(i.key.name))
|
|
270
270
|
t[i.key.name] = et(i.value);
|
|
271
271
|
else if (i.key.name === "component") {
|
|
272
|
-
let
|
|
273
|
-
if (
|
|
274
|
-
let
|
|
275
|
-
(d) =>
|
|
272
|
+
let a = i.value;
|
|
273
|
+
if (l.types.isIdentifier(a)) {
|
|
274
|
+
let c = a.name, p = r.body.find(
|
|
275
|
+
(d) => l.types.isImportDeclaration(d) && d.specifiers.find((g) => g.local.name === c)
|
|
276
276
|
);
|
|
277
277
|
if (p) {
|
|
278
278
|
let { source: d } = p;
|
|
279
|
-
|
|
279
|
+
l.types.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
let { code:
|
|
283
|
-
t.component =
|
|
282
|
+
let { code: o } = l.recast.print(i.value, {});
|
|
283
|
+
t.component = o;
|
|
284
284
|
} else if (i.key.name === "tags") {
|
|
285
|
-
let
|
|
286
|
-
|
|
285
|
+
let a = i.value;
|
|
286
|
+
l.types.isIdentifier(a) && (a = P(a.name, this._ast.program)), t.tags = me(a);
|
|
287
287
|
} else if (i.key.name === "id")
|
|
288
|
-
if (
|
|
288
|
+
if (l.types.isStringLiteral(i.value))
|
|
289
289
|
t.id = i.value.value;
|
|
290
290
|
else
|
|
291
291
|
throw new Error(`Unexpected component id: ${i.value}`);
|
|
@@ -294,49 +294,49 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
294
294
|
}
|
|
295
295
|
getStoryExport(e) {
|
|
296
296
|
let r = this._storyExports[e];
|
|
297
|
-
if (r =
|
|
297
|
+
if (r = l.types.isVariableDeclarator(r) ? r.init : r, l.types.isCallExpression(r)) {
|
|
298
298
|
let { callee: t, arguments: i } = r;
|
|
299
|
-
if (
|
|
300
|
-
(i.length === 0 || i.length === 1 &&
|
|
301
|
-
let { name:
|
|
302
|
-
r = this._templates[
|
|
299
|
+
if (l.types.isMemberExpression(t) && l.types.isIdentifier(t.object) && l.types.isIdentifier(t.property) && t.property.name === "bind" &&
|
|
300
|
+
(i.length === 0 || i.length === 1 && l.types.isObjectExpression(i[0]) && i[0].properties.length === 0)) {
|
|
301
|
+
let { name: a } = t.object;
|
|
302
|
+
r = this._templates[a];
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
return r;
|
|
306
306
|
}
|
|
307
307
|
parse() {
|
|
308
308
|
let e = this;
|
|
309
|
-
if ((0,
|
|
309
|
+
if ((0, l.traverse)(this._ast, {
|
|
310
310
|
ExportDefaultDeclaration: {
|
|
311
311
|
enter(t) {
|
|
312
|
-
let { node: i, parent:
|
|
313
|
-
if (e._options.transformInlineMeta && !
|
|
312
|
+
let { node: i, parent: a } = t, o = l.types.isIdentifier(i.declaration) && l.types.isProgram(a);
|
|
313
|
+
if (e._options.transformInlineMeta && !o && l.types.isExpression(i.declaration)) {
|
|
314
314
|
let d = t.scope.generateUidIdentifier("meta");
|
|
315
315
|
e._metaVariableName = d.name;
|
|
316
316
|
let g = [
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
l.types.variableDeclaration("const", [l.types.variableDeclarator(d, i.declaration)]),
|
|
318
|
+
l.types.exportDefaultDeclaration(d)
|
|
319
319
|
];
|
|
320
320
|
g.forEach((x) => x.loc = t.node.loc), t.replaceWithMultiple(g);
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
|
-
let
|
|
324
|
-
if (
|
|
323
|
+
let c, p;
|
|
324
|
+
if (o) {
|
|
325
325
|
let d = i.declaration.name;
|
|
326
326
|
e._metaVariableName = d;
|
|
327
|
-
let g = /* @__PURE__ */ f((x) =>
|
|
327
|
+
let g = /* @__PURE__ */ f((x) => l.types.isIdentifier(x.id) && x.id.name === d, "isVariableDeclarator");
|
|
328
328
|
e._metaStatement = e._ast.program.body.find(
|
|
329
|
-
(x) =>
|
|
329
|
+
(x) => l.types.isVariableDeclaration(x) && x.declarations.find(g)
|
|
330
330
|
), p = (e?._metaStatement?.declarations || []).find(
|
|
331
331
|
g
|
|
332
332
|
)?.init;
|
|
333
333
|
} else
|
|
334
334
|
e._metaStatement = i, p = i.declaration;
|
|
335
|
-
if (
|
|
335
|
+
if (l.types.isObjectExpression(p) ? c = p : (
|
|
336
336
|
// export default { ... } as Meta<...>
|
|
337
|
-
(
|
|
338
|
-
),
|
|
339
|
-
throw new
|
|
337
|
+
(l.types.isTSAsExpression(p) || l.types.isTSSatisfiesExpression(p)) && l.types.isObjectExpression(p.expression) && (c = p.expression)
|
|
338
|
+
), c && l.types.isProgram(a) && e._parseMeta(c, a), e._metaStatement && !e._metaNode)
|
|
339
|
+
throw new R(
|
|
340
340
|
"default export must be an object",
|
|
341
341
|
e._metaStatement,
|
|
342
342
|
e._options.fileName
|
|
@@ -346,63 +346,63 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
346
346
|
},
|
|
347
347
|
ExportNamedDeclaration: {
|
|
348
348
|
enter(t) {
|
|
349
|
-
let { node: i, parent:
|
|
350
|
-
|
|
351
|
-
isFunctionDeclaration(i.declaration) && (
|
|
352
|
-
if (
|
|
353
|
-
let p = !1, { name: d } =
|
|
354
|
-
if (d === "__namedExportsOrder" &&
|
|
355
|
-
e._namedExportsOrder = tt(
|
|
349
|
+
let { node: i, parent: a } = t, o;
|
|
350
|
+
l.types.isVariableDeclaration(i.declaration) ? o = i.declaration.declarations.filter((c) => l.types.isVariableDeclarator(c)) : l.types.
|
|
351
|
+
isFunctionDeclaration(i.declaration) && (o = [i.declaration]), o ? o.forEach((c) => {
|
|
352
|
+
if (l.types.isIdentifier(c.id)) {
|
|
353
|
+
let p = !1, { name: d } = c.id;
|
|
354
|
+
if (d === "__namedExportsOrder" && l.types.isVariableDeclarator(c)) {
|
|
355
|
+
e._namedExportsOrder = tt(c.init);
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
|
-
e._storyExports[d] =
|
|
358
|
+
e._storyExports[d] = c, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
359
359
|
let g = (0, v.storyNameFromExport)(d);
|
|
360
360
|
e._storyAnnotations[d] ? re.logger.warn(
|
|
361
361
|
`Unexpected annotations for "${d}" before story declaration`
|
|
362
362
|
) : e._storyAnnotations[d] = {};
|
|
363
363
|
let x;
|
|
364
|
-
if (
|
|
365
|
-
expression :
|
|
364
|
+
if (l.types.isVariableDeclarator(c) ? x = l.types.isTSAsExpression(c.init) || l.types.isTSSatisfiesExpression(c.init) ? c.init.
|
|
365
|
+
expression : c.init : x = c, l.types.isCallExpression(x) && l.types.isMemberExpression(x.callee) && l.types.isIdentifier(x.callee.
|
|
366
366
|
property) && x.callee.property.name === "story" && (p = !0, x = x.arguments[0]), e._metaIsFactory && !p)
|
|
367
|
-
throw new
|
|
367
|
+
throw new L(
|
|
368
368
|
"expected factory story",
|
|
369
369
|
x,
|
|
370
370
|
e._options.fileName
|
|
371
371
|
);
|
|
372
372
|
if (!e._metaIsFactory && p)
|
|
373
|
-
throw e._metaNode ? new
|
|
373
|
+
throw e._metaNode ? new L(
|
|
374
374
|
"expected non-factory story",
|
|
375
375
|
x,
|
|
376
376
|
e._options.fileName
|
|
377
|
-
) : new
|
|
377
|
+
) : new M(
|
|
378
378
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
379
379
|
x,
|
|
380
380
|
e._options.fileName
|
|
381
381
|
);
|
|
382
382
|
let h = {};
|
|
383
|
-
|
|
384
|
-
if (
|
|
383
|
+
l.types.isObjectExpression(x) ? (h.__isArgsStory = !0, x.properties.forEach((b) => {
|
|
384
|
+
if (l.types.isIdentifier(b.key)) {
|
|
385
385
|
if (b.key.name === "render")
|
|
386
386
|
h.__isArgsStory = ue(
|
|
387
387
|
b.value,
|
|
388
|
-
|
|
388
|
+
a,
|
|
389
389
|
e
|
|
390
390
|
);
|
|
391
|
-
else if (b.key.name === "name" &&
|
|
391
|
+
else if (b.key.name === "name" && l.types.isStringLiteral(b.value))
|
|
392
392
|
g = b.value.value;
|
|
393
|
-
else if (b.key.name === "storyName" &&
|
|
393
|
+
else if (b.key.name === "storyName" && l.types.isStringLiteral(b.value))
|
|
394
394
|
re.logger.warn(
|
|
395
395
|
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
396
396
|
);
|
|
397
|
-
else if (b.key.name === "parameters" &&
|
|
398
|
-
let
|
|
399
|
-
(
|
|
397
|
+
else if (b.key.name === "parameters" && l.types.isObjectExpression(b.value)) {
|
|
398
|
+
let _ = b.value.properties.find(
|
|
399
|
+
(W) => l.types.isObjectProperty(W) && l.types.isIdentifier(W.key) && W.key.name === "__id"
|
|
400
400
|
);
|
|
401
|
-
|
|
401
|
+
_ && (h.__id = _.value.value);
|
|
402
402
|
}
|
|
403
403
|
e._storyAnnotations[d][b.key.name] = b.value;
|
|
404
404
|
}
|
|
405
|
-
})) : h.__isArgsStory = ue(x,
|
|
405
|
+
})) : h.__isArgsStory = ue(x, a, e), e._stories[d] = {
|
|
406
406
|
id: "FIXME",
|
|
407
407
|
name: g,
|
|
408
408
|
parameters: h,
|
|
@@ -411,19 +411,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
411
411
|
}
|
|
412
412
|
};
|
|
413
413
|
}
|
|
414
|
-
}) : i.specifiers.length > 0 && i.specifiers.forEach((
|
|
415
|
-
if (
|
|
416
|
-
let { name: p } =
|
|
414
|
+
}) : i.specifiers.length > 0 && i.specifiers.forEach((c) => {
|
|
415
|
+
if (l.types.isExportSpecifier(c) && l.types.isIdentifier(c.exported)) {
|
|
416
|
+
let { name: p } = c.exported, { name: d } = c.local, g = l.types.isProgram(a) ? P(d, a) : c.local;
|
|
417
417
|
if (p === "default") {
|
|
418
418
|
let x;
|
|
419
|
-
|
|
419
|
+
l.types.isObjectExpression(g) ? x = g : (
|
|
420
420
|
// export default { ... } as Meta<...>
|
|
421
|
-
|
|
422
|
-
), x &&
|
|
421
|
+
l.types.isTSAsExpression(g) && l.types.isObjectExpression(g.expression) && (x = g.expression)
|
|
422
|
+
), x && l.types.isProgram(a) && e._parseMeta(x, a);
|
|
423
423
|
} else {
|
|
424
424
|
let x = {}, h = g;
|
|
425
|
-
|
|
426
|
-
|
|
425
|
+
l.types.isObjectExpression(h) && h.properties.forEach((b) => {
|
|
426
|
+
l.types.isIdentifier(b.key) && (x[b.key.name] = b.value);
|
|
427
427
|
}), e._storyAnnotations[p] = x, e._storyStatements[p] = g, e._storyPaths[p] = t, e._stories[p] = {
|
|
428
428
|
id: "FIXME",
|
|
429
429
|
name: p,
|
|
@@ -438,14 +438,14 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
438
438
|
},
|
|
439
439
|
ExpressionStatement: {
|
|
440
440
|
enter({ node: t, parent: i }) {
|
|
441
|
-
let { expression:
|
|
442
|
-
if (
|
|
443
|
-
object) &&
|
|
444
|
-
let
|
|
445
|
-
if (e._storyAnnotations[
|
|
446
|
-
|
|
447
|
-
}) : e._storyAnnotations[
|
|
448
|
-
let d = p.value, g = e._stories[
|
|
441
|
+
let { expression: a } = t;
|
|
442
|
+
if (l.types.isProgram(i) && l.types.isAssignmentExpression(a) && l.types.isMemberExpression(a.left) && l.types.isIdentifier(a.left.
|
|
443
|
+
object) && l.types.isIdentifier(a.left.property)) {
|
|
444
|
+
let o = a.left.object.name, c = a.left.property.name, p = a.right;
|
|
445
|
+
if (e._storyAnnotations[o] && (c === "story" && l.types.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
446
|
+
l.types.isIdentifier(d.key) && (e._storyAnnotations[o][d.key.name] = d.value);
|
|
447
|
+
}) : e._storyAnnotations[o][c] = p), c === "storyName" && l.types.isStringLiteral(p)) {
|
|
448
|
+
let d = p.value, g = e._stories[o];
|
|
449
449
|
if (!g)
|
|
450
450
|
return;
|
|
451
451
|
g.name = d;
|
|
@@ -455,24 +455,24 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
455
455
|
},
|
|
456
456
|
CallExpression: {
|
|
457
457
|
enter(t) {
|
|
458
|
-
let { node: i } = t, { callee:
|
|
459
|
-
if (
|
|
458
|
+
let { node: i } = t, { callee: a } = i;
|
|
459
|
+
if (l.types.isIdentifier(a) && a.name === "storiesOf")
|
|
460
460
|
throw new Error(O.dedent`
|
|
461
461
|
Unexpected \`storiesOf\` usage: ${D(i, e._options.fileName)}.
|
|
462
462
|
|
|
463
463
|
SB8 does not support \`storiesOf\`.
|
|
464
464
|
`);
|
|
465
|
-
if (
|
|
465
|
+
if (l.types.isMemberExpression(a) && l.types.isIdentifier(a.property) && a.property.name === "meta" && l.types.isIdentifier(a.object) &&
|
|
466
466
|
i.arguments.length > 0) {
|
|
467
|
-
let
|
|
468
|
-
if (
|
|
469
|
-
if (xe(
|
|
467
|
+
let c = t.scope.getBinding(a.object.name)?.path?.parentPath?.node;
|
|
468
|
+
if (l.types.isImportDeclaration(c))
|
|
469
|
+
if (xe(c.source.value)) {
|
|
470
470
|
let p = i.arguments[0];
|
|
471
|
-
e._metaVariableName =
|
|
471
|
+
e._metaVariableName = a.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
472
472
|
} else
|
|
473
|
-
throw new
|
|
473
|
+
throw new M(
|
|
474
474
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
475
|
-
|
|
475
|
+
c,
|
|
476
476
|
e._options.fileName
|
|
477
477
|
);
|
|
478
478
|
}
|
|
@@ -481,36 +481,36 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
481
481
|
ImportDeclaration: {
|
|
482
482
|
enter({ node: t }) {
|
|
483
483
|
let { source: i } = t;
|
|
484
|
-
if (
|
|
484
|
+
if (l.types.isStringLiteral(i))
|
|
485
485
|
e.imports.push(i.value);
|
|
486
486
|
else
|
|
487
487
|
throw new Error("CSF: unexpected import source");
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
}), !e._meta)
|
|
491
|
-
throw new
|
|
491
|
+
throw new R("missing default export", e._ast, e._options.fileName);
|
|
492
492
|
let r = Object.entries(e._stories);
|
|
493
493
|
if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
|
|
494
494
|
e._stories = r.reduce(
|
|
495
|
-
(t, [i,
|
|
495
|
+
(t, [i, a]) => {
|
|
496
496
|
if (!(0, v.isExportStory)(i, e._meta))
|
|
497
497
|
return t;
|
|
498
|
-
let
|
|
498
|
+
let o = a.parameters?.__id ?? (0, v.toId)(e._meta?.id || e._meta?.title, (0, v.storyNameFromExport)(i)), c = { ...a.parameters, __id: o },
|
|
499
499
|
{ includeStories: p } = e._meta || {};
|
|
500
|
-
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (
|
|
500
|
+
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (c.docsOnly = !0), t[i] = { ...a, id: o, parameters: c };
|
|
501
501
|
let d = e._storyAnnotations[i], { tags: g, play: x } = d;
|
|
502
502
|
if (g) {
|
|
503
|
-
let
|
|
504
|
-
t[i].tags = me(
|
|
503
|
+
let _ = l.types.isIdentifier(g) ? P(g.name, this._ast.program) : g;
|
|
504
|
+
t[i].tags = me(_);
|
|
505
505
|
}
|
|
506
506
|
x && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
507
507
|
let h = t[i].__stats;
|
|
508
|
-
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((
|
|
509
|
-
h[
|
|
508
|
+
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((_) => {
|
|
509
|
+
h[_] = !!d[_] || !!e._metaAnnotations[_];
|
|
510
510
|
});
|
|
511
511
|
let b = e.getStoryExport(i);
|
|
512
|
-
return h.storyFn = !!(
|
|
513
|
-
play), h.moduleMock = !!e.imports.find((
|
|
512
|
+
return h.storyFn = !!(l.types.isArrowFunctionExpression(b) || l.types.isFunctionDeclaration(b)), h.mount = rt(d.play ?? e._metaAnnotations.
|
|
513
|
+
play), h.moduleMock = !!e.imports.find((_) => ye(_)), t;
|
|
514
514
|
},
|
|
515
515
|
{}
|
|
516
516
|
), Object.keys(e._storyExports).forEach((t) => {
|
|
@@ -522,7 +522,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
522
522
|
if (t.length !== i.length)
|
|
523
523
|
throw new Error(
|
|
524
524
|
`Missing exports after sort: ${t.filter(
|
|
525
|
-
(
|
|
525
|
+
(a) => !i.includes(a)
|
|
526
526
|
)}`
|
|
527
527
|
);
|
|
528
528
|
}
|
|
@@ -561,13 +561,13 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
561
561
|
code: s,
|
|
562
562
|
filename: e = "",
|
|
563
563
|
ast: r
|
|
564
|
-
}) => new
|
|
565
|
-
let r = (0,
|
|
564
|
+
}) => new l.BabelFileClass({ filename: e }, { code: s, ast: r ?? (0, l.babelParse)(s) }), "babelParseFile"), Q = /* @__PURE__ */ f((s, e) => {
|
|
565
|
+
let r = (0, l.babelParse)(s), t = be({ code: s, filename: e.fileName, ast: r });
|
|
566
566
|
return new K(r, e, t);
|
|
567
567
|
}, "loadCsf"), ie = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, r) => {
|
|
568
|
-
let t = (0,
|
|
568
|
+
let t = (0, l.generate)(s._ast, e, r);
|
|
569
569
|
return e.sourceMaps ? t : t.code;
|
|
570
|
-
}, "formatCsf"), he = /* @__PURE__ */ f((s, e = {}) =>
|
|
570
|
+
}, "formatCsf"), he = /* @__PURE__ */ f((s, e = {}) => l.recast.print(s._ast, e), "printCsf"), st = /* @__PURE__ */ f(async (s, e) => {
|
|
571
571
|
let r = (await (0, J.readFile)(s, "utf-8")).toString();
|
|
572
572
|
return Q(r, { ...e, fileName: s });
|
|
573
573
|
}, "readCsf"), nt = /* @__PURE__ */ f(async (s, e) => {
|
|
@@ -577,20 +577,20 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
577
577
|
}, "writeCsf");
|
|
578
578
|
|
|
579
579
|
// src/csf-tools/ConfigFile.ts
|
|
580
|
-
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"), Ee = z(
|
|
580
|
+
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"), Ee = z($(), 1);
|
|
581
581
|
var se = /* @__PURE__ */ f(({
|
|
582
582
|
expectedType: s,
|
|
583
583
|
foundType: e,
|
|
584
584
|
node: r
|
|
585
585
|
}) => Ee.dedent`
|
|
586
586
|
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${r?.type}'.
|
|
587
|
-
`, "getCsfParsingErrorMessage"),
|
|
587
|
+
`, "getCsfParsingErrorMessage"), F = /* @__PURE__ */ f((s) => n.types.isIdentifier(s.key) ? s.key.name : n.types.isStringLiteral(s.key) ?
|
|
588
588
|
s.key.value : null, "propKey"), Y = /* @__PURE__ */ f((s) => n.types.isTSAsExpression(s) || n.types.isTSSatisfiesExpression(s) ? Y(s.expression) :
|
|
589
589
|
s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
590
590
|
if (s.length === 0)
|
|
591
591
|
return e;
|
|
592
592
|
if (n.types.isObjectExpression(e)) {
|
|
593
|
-
let [r, ...t] = s, i = e.properties.find((
|
|
593
|
+
let [r, ...t] = s, i = e.properties.find((a) => F(a) === r);
|
|
594
594
|
if (i)
|
|
595
595
|
return _e(t, i.value);
|
|
596
596
|
}
|
|
@@ -601,26 +601,26 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
601
601
|
throw new Error("Expected object expression");
|
|
602
602
|
}
|
|
603
603
|
if (n.types.isObjectExpression(e)) {
|
|
604
|
-
let [r, ...t] = s, i = e.properties.find((
|
|
604
|
+
let [r, ...t] = s, i = e.properties.find((a) => F(a) === r);
|
|
605
605
|
if (i)
|
|
606
606
|
return t.length === 0 ? e.properties : je(t, i.value);
|
|
607
607
|
}
|
|
608
608
|
}, "_getPathProperties"), Z = /* @__PURE__ */ f((s, e) => {
|
|
609
609
|
let r = null, t = null;
|
|
610
610
|
return e.body.find((i) => (n.types.isVariableDeclaration(i) ? t = i.declarations : n.types.isExportNamedDeclaration(i) && n.types.isVariableDeclaration(
|
|
611
|
-
i.declaration) && (t = i.declaration.declarations), t && t.find((
|
|
612
|
-
id.name === s ? (r =
|
|
613
|
-
}, "_findVarDeclarator"),
|
|
611
|
+
i.declaration) && (t = i.declaration.declarations), t && t.find((a) => n.types.isVariableDeclarator(a) && n.types.isIdentifier(a.id) && a.
|
|
612
|
+
id.name === s ? (r = a, !0) : !1))), r;
|
|
613
|
+
}, "_findVarDeclarator"), w = /* @__PURE__ */ f((s, e) => Z(s, e)?.init, "_findVarInitialization"), q = /* @__PURE__ */ f((s, e) => {
|
|
614
614
|
if (s.length === 0)
|
|
615
615
|
return e;
|
|
616
|
-
let [r, ...t] = s, i =
|
|
616
|
+
let [r, ...t] = s, i = q(t, e);
|
|
617
617
|
return n.types.objectExpression([n.types.objectProperty(n.types.identifier(r), i)]);
|
|
618
|
-
}, "_makeObjectExpression"),
|
|
619
|
-
let [t, ...i] = s,
|
|
620
|
-
(
|
|
618
|
+
}, "_makeObjectExpression"), U = /* @__PURE__ */ f((s, e, r) => {
|
|
619
|
+
let [t, ...i] = s, a = r.properties.find(
|
|
620
|
+
(o) => F(o) === t
|
|
621
621
|
);
|
|
622
|
-
|
|
623
|
-
n.types.objectProperty(n.types.identifier(t),
|
|
622
|
+
a ? n.types.isObjectExpression(a.value) && i.length > 0 ? U(i, e, a.value) : a.value = q(i, e) : r.properties.push(
|
|
623
|
+
n.types.objectProperty(n.types.identifier(t), q(i, e))
|
|
624
624
|
);
|
|
625
625
|
}, "_updateExportNode"), ee = class {
|
|
626
626
|
constructor(e, r, t) {
|
|
@@ -637,10 +637,10 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
637
637
|
}
|
|
638
638
|
_parseExportsObject(e) {
|
|
639
639
|
this._exportsObject = e, e.properties.forEach((r) => {
|
|
640
|
-
let t =
|
|
640
|
+
let t = F(r);
|
|
641
641
|
if (t) {
|
|
642
642
|
let i = r.value;
|
|
643
|
-
n.types.isIdentifier(i) && (i =
|
|
643
|
+
n.types.isIdentifier(i) && (i = w(i.name, this._ast.program)), this._exports[t] = i;
|
|
644
644
|
}
|
|
645
645
|
});
|
|
646
646
|
}
|
|
@@ -650,7 +650,7 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
650
650
|
ExportDefaultDeclaration: {
|
|
651
651
|
enter({ node: r, parent: t }) {
|
|
652
652
|
e.hasDefaultExport = !0;
|
|
653
|
-
let i = n.types.isIdentifier(r.declaration) && n.types.isProgram(t) ?
|
|
653
|
+
let i = n.types.isIdentifier(r.declaration) && n.types.isProgram(t) ? w(r.declaration.name, t) : r.declaration;
|
|
654
654
|
i = Y(i), n.types.isCallExpression(i) && n.types.isObjectExpression(i.arguments[0]) && (i = i.arguments[0]), n.types.isObjectExpression(
|
|
655
655
|
i) ? e._parseExportsObject(i) : H.logger.warn(
|
|
656
656
|
se({
|
|
@@ -666,20 +666,20 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
666
666
|
if (n.types.isVariableDeclaration(r.declaration))
|
|
667
667
|
r.declaration.declarations.forEach((i) => {
|
|
668
668
|
if (n.types.isVariableDeclarator(i) && n.types.isIdentifier(i.id)) {
|
|
669
|
-
let { name:
|
|
670
|
-
n.types.isIdentifier(
|
|
669
|
+
let { name: a } = i.id, o = i.init;
|
|
670
|
+
n.types.isIdentifier(o) && (o = w(o.name, t)), e._exports[a] = o, e._exportDecls[a] = i;
|
|
671
671
|
}
|
|
672
672
|
});
|
|
673
673
|
else if (n.types.isFunctionDeclaration(r.declaration)) {
|
|
674
674
|
let i = r.declaration;
|
|
675
675
|
if (n.types.isIdentifier(i.id)) {
|
|
676
|
-
let { name:
|
|
677
|
-
e._exportDecls[
|
|
676
|
+
let { name: a } = i.id;
|
|
677
|
+
e._exportDecls[a] = i;
|
|
678
678
|
}
|
|
679
679
|
} else r.specifiers ? r.specifiers.forEach((i) => {
|
|
680
680
|
if (n.types.isExportSpecifier(i) && n.types.isIdentifier(i.local) && n.types.isIdentifier(i.exported)) {
|
|
681
|
-
let { name:
|
|
682
|
-
|
|
681
|
+
let { name: a } = i.local, { name: o } = i.exported, c = Z(a, t);
|
|
682
|
+
c && (e._exports[o] = c.init, e._exportDecls[o] = c);
|
|
683
683
|
}
|
|
684
684
|
}) : H.logger.warn(
|
|
685
685
|
se({
|
|
@@ -693,16 +693,16 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
693
693
|
ExpressionStatement: {
|
|
694
694
|
enter({ node: r, parent: t }) {
|
|
695
695
|
if (n.types.isAssignmentExpression(r.expression) && r.expression.operator === "=") {
|
|
696
|
-
let { left: i, right:
|
|
696
|
+
let { left: i, right: a } = r.expression;
|
|
697
697
|
if (n.types.isMemberExpression(i) && n.types.isIdentifier(i.object) && i.object.name === "module" && n.types.isIdentifier(i.property) &&
|
|
698
698
|
i.property.name === "exports") {
|
|
699
|
-
let
|
|
700
|
-
n.types.isIdentifier(
|
|
701
|
-
(
|
|
702
|
-
let p =
|
|
699
|
+
let o = a;
|
|
700
|
+
n.types.isIdentifier(a) && (o = w(a.name, t)), o = Y(o), n.types.isObjectExpression(o) ? (e._exportsObject = o, o.properties.forEach(
|
|
701
|
+
(c) => {
|
|
702
|
+
let p = F(c);
|
|
703
703
|
if (p) {
|
|
704
|
-
let d =
|
|
705
|
-
n.types.isIdentifier(d) && (d =
|
|
704
|
+
let d = c.value;
|
|
705
|
+
n.types.isIdentifier(d) && (d = w(
|
|
706
706
|
d.name,
|
|
707
707
|
t
|
|
708
708
|
)), e._exports[p] = d;
|
|
@@ -710,8 +710,8 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
710
710
|
})) : H.logger.warn(
|
|
711
711
|
se({
|
|
712
712
|
expectedType: "ObjectExpression",
|
|
713
|
-
foundType:
|
|
714
|
-
node:
|
|
713
|
+
foundType: o?.type,
|
|
714
|
+
node: o
|
|
715
715
|
})
|
|
716
716
|
);
|
|
717
717
|
}
|
|
@@ -750,31 +750,31 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
752
|
setFieldNode(e, r) {
|
|
753
|
-
let [t, ...i] = e,
|
|
753
|
+
let [t, ...i] = e, a = this._exports[t];
|
|
754
754
|
if (this._exportsObject) {
|
|
755
|
-
let p = this._exportsObject.properties.find((d) =>
|
|
755
|
+
let p = this._exportsObject.properties.find((d) => F(d) === t);
|
|
756
756
|
if (p && n.types.isIdentifier(p.value)) {
|
|
757
757
|
let d = Z(p.value.name, this._ast.program);
|
|
758
758
|
if (d && n.types.isObjectExpression(d.init)) {
|
|
759
|
-
|
|
759
|
+
U(i, r, d.init);
|
|
760
760
|
return;
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
|
-
|
|
763
|
+
U(e, r, this._exportsObject), this._exports[e[0]] = r;
|
|
764
764
|
return;
|
|
765
765
|
}
|
|
766
|
-
if (
|
|
767
|
-
|
|
766
|
+
if (a && n.types.isObjectExpression(a) && i.length > 0) {
|
|
767
|
+
U(i, r, a);
|
|
768
768
|
return;
|
|
769
769
|
}
|
|
770
|
-
let
|
|
771
|
-
if (
|
|
772
|
-
|
|
770
|
+
let o = Z(t, this._ast.program);
|
|
771
|
+
if (o && n.types.isObjectExpression(o.init)) {
|
|
772
|
+
U(i, r, o.init);
|
|
773
773
|
return;
|
|
774
774
|
}
|
|
775
|
-
if (
|
|
776
|
-
let
|
|
777
|
-
n.types.isVariableDeclarator(
|
|
775
|
+
if (a && i.length === 0 && this._exportDecls[e[0]]) {
|
|
776
|
+
let c = this._exportDecls[e[0]];
|
|
777
|
+
n.types.isVariableDeclarator(c) && (c.init = q([], r));
|
|
778
778
|
} else {
|
|
779
779
|
if (this.hasDefaultExport)
|
|
780
780
|
throw new Error(
|
|
@@ -783,10 +783,10 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
783
783
|
)}" field as the default export is not an object in this file.`
|
|
784
784
|
);
|
|
785
785
|
{
|
|
786
|
-
let
|
|
787
|
-
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(t),
|
|
786
|
+
let c = q(i, r), p = n.types.exportNamedDeclaration(
|
|
787
|
+
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(t), c)])
|
|
788
788
|
);
|
|
789
|
-
this._exports[t] =
|
|
789
|
+
this._exports[t] = c, this._ast.program.body.push(p);
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
792
|
}
|
|
@@ -854,31 +854,31 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
854
854
|
return t;
|
|
855
855
|
}
|
|
856
856
|
removeField(e) {
|
|
857
|
-
let r = /* @__PURE__ */ f((i,
|
|
858
|
-
let
|
|
859
|
-
(
|
|
857
|
+
let r = /* @__PURE__ */ f((i, a) => {
|
|
858
|
+
let o = i.findIndex(
|
|
859
|
+
(c) => n.types.isIdentifier(c.key) && c.key.name === a || n.types.isStringLiteral(c.key) && c.key.value === a
|
|
860
860
|
);
|
|
861
|
-
|
|
861
|
+
o >= 0 && i.splice(o, 1);
|
|
862
862
|
}, "removeProperty");
|
|
863
863
|
if (e.length === 1) {
|
|
864
864
|
let i = !1;
|
|
865
|
-
if (this._ast.program.body.forEach((
|
|
866
|
-
if (n.types.isExportNamedDeclaration(
|
|
867
|
-
let
|
|
868
|
-
n.types.isIdentifier(
|
|
865
|
+
if (this._ast.program.body.forEach((a) => {
|
|
866
|
+
if (n.types.isExportNamedDeclaration(a) && n.types.isVariableDeclaration(a.declaration)) {
|
|
867
|
+
let o = a.declaration.declarations[0];
|
|
868
|
+
n.types.isIdentifier(o.id) && o.id.name === e[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(a), 1), i = !0);
|
|
869
869
|
}
|
|
870
|
-
if (n.types.isExportDefaultDeclaration(
|
|
871
|
-
let
|
|
872
|
-
if (n.types.isIdentifier(
|
|
873
|
-
let
|
|
874
|
-
r(
|
|
870
|
+
if (n.types.isExportDefaultDeclaration(a)) {
|
|
871
|
+
let o = a.declaration;
|
|
872
|
+
if (n.types.isIdentifier(o) && (o = w(o.name, this._ast.program)), o = Y(o), n.types.isObjectExpression(o)) {
|
|
873
|
+
let c = o.properties;
|
|
874
|
+
r(c, e[0]), i = !0;
|
|
875
875
|
}
|
|
876
876
|
}
|
|
877
|
-
if (n.types.isExpressionStatement(
|
|
878
|
-
n.types.isIdentifier(
|
|
879
|
-
property) &&
|
|
880
|
-
let
|
|
881
|
-
r(
|
|
877
|
+
if (n.types.isExpressionStatement(a) && n.types.isAssignmentExpression(a.expression) && n.types.isMemberExpression(a.expression.left) &&
|
|
878
|
+
n.types.isIdentifier(a.expression.left.object) && a.expression.left.object.name === "module" && n.types.isIdentifier(a.expression.left.
|
|
879
|
+
property) && a.expression.left.property.name === "exports" && n.types.isObjectExpression(a.expression.right)) {
|
|
880
|
+
let o = a.expression.right.properties;
|
|
881
|
+
r(o, e[0]), i = !0;
|
|
882
882
|
}
|
|
883
883
|
}), i)
|
|
884
884
|
return;
|
|
@@ -910,8 +910,8 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
910
910
|
let t = this.getFieldNode(e);
|
|
911
911
|
if (t)
|
|
912
912
|
if (n.types.isArrayExpression(t)) {
|
|
913
|
-
let i = t.elements.findIndex((
|
|
914
|
-
|
|
913
|
+
let i = t.elements.findIndex((a) => n.types.isStringLiteral(a) ? a.value === r : n.types.isObjectExpression(a) ? this._getPresetValue(
|
|
914
|
+
a, "name") === r : this._getPnpWrappedValue(a) === r);
|
|
915
915
|
if (i >= 0)
|
|
916
916
|
t.elements.splice(i, 1);
|
|
917
917
|
else
|
|
@@ -932,12 +932,12 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
932
932
|
valueToNode(e) {
|
|
933
933
|
let r = this._inferQuotes(), t;
|
|
934
934
|
if (r === "single") {
|
|
935
|
-
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: r } }),
|
|
936
|
-
(0, n.traverse)(
|
|
935
|
+
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: r } }), a = (0, n.babelParse)(`const __x = ${i}`);
|
|
936
|
+
(0, n.traverse)(a, {
|
|
937
937
|
VariableDeclaration: {
|
|
938
|
-
enter({ node:
|
|
939
|
-
|
|
940
|
-
declarations[0].id.name === "__x" && (t =
|
|
938
|
+
enter({ node: o }) {
|
|
939
|
+
o.declarations.length === 1 && n.types.isVariableDeclarator(o.declarations[0]) && n.types.isIdentifier(o.declarations[0].id) && o.
|
|
940
|
+
declarations[0].id.name === "__x" && (t = o.declarations[0].init);
|
|
941
941
|
}
|
|
942
942
|
}
|
|
943
943
|
});
|
|
@@ -975,18 +975,18 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
975
975
|
* @param fromImport - The module to import from
|
|
976
976
|
*/
|
|
977
977
|
setRequireImport(e, r) {
|
|
978
|
-
let t = this._ast.program.body.find((
|
|
979
|
-
let
|
|
980
|
-
isCallExpression(
|
|
981
|
-
"require" && n.types.isStringLiteral(
|
|
978
|
+
let t = this._ast.program.body.find((o) => {
|
|
979
|
+
let c = n.types.isVariableDeclaration(o) && o.declarations.length === 1 && n.types.isVariableDeclarator(o.declarations[0]) && n.types.
|
|
980
|
+
isCallExpression(o.declarations[0].init) && n.types.isIdentifier(o.declarations[0].init.callee) && o.declarations[0].init.callee.name ===
|
|
981
|
+
"require" && n.types.isStringLiteral(o.declarations[0].init.arguments[0]) && (o.declarations[0].init.arguments[0].value === r || o.declarations[0].
|
|
982
982
|
init.arguments[0].value === r.split("node:")[1]);
|
|
983
|
-
return
|
|
984
|
-
}), i = /* @__PURE__ */ f((
|
|
985
|
-
(
|
|
986
|
-
), "hasRequireSpecifier"),
|
|
987
|
-
n.types.isIdentifier(
|
|
983
|
+
return c && (r = o.declarations[0].init.arguments[0].value), c;
|
|
984
|
+
}), i = /* @__PURE__ */ f((o) => n.types.isObjectPattern(t?.declarations[0].id) && t?.declarations[0].id.properties.find(
|
|
985
|
+
(c) => n.types.isObjectProperty(c) && n.types.isIdentifier(c.key) && c.key.name === o
|
|
986
|
+
), "hasRequireSpecifier"), a = /* @__PURE__ */ f((o, c) => o.declarations.length === 1 && n.types.isVariableDeclarator(o.declarations[0]) &&
|
|
987
|
+
n.types.isIdentifier(o.declarations[0].id) && o.declarations[0].id.name === c, "hasDefaultRequireSpecifier");
|
|
988
988
|
if (typeof e == "string") {
|
|
989
|
-
let
|
|
989
|
+
let o = /* @__PURE__ */ f(() => {
|
|
990
990
|
this._ast.program.body.unshift(
|
|
991
991
|
n.types.variableDeclaration("const", [
|
|
992
992
|
n.types.variableDeclarator(
|
|
@@ -996,17 +996,17 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
996
996
|
])
|
|
997
997
|
);
|
|
998
998
|
}, "addDefaultRequireSpecifier");
|
|
999
|
-
t &&
|
|
1000
|
-
} else t ? e.forEach((
|
|
1001
|
-
i(
|
|
1002
|
-
n.types.objectProperty(n.types.identifier(
|
|
999
|
+
t && a(t, e) || o();
|
|
1000
|
+
} else t ? e.forEach((o) => {
|
|
1001
|
+
i(o) || t.declarations[0].id.properties.push(
|
|
1002
|
+
n.types.objectProperty(n.types.identifier(o), n.types.identifier(o), void 0, !0)
|
|
1003
1003
|
);
|
|
1004
1004
|
}) : this._ast.program.body.unshift(
|
|
1005
1005
|
n.types.variableDeclaration("const", [
|
|
1006
1006
|
n.types.variableDeclarator(
|
|
1007
1007
|
n.types.objectPattern(
|
|
1008
1008
|
e.map(
|
|
1009
|
-
(
|
|
1009
|
+
(o) => n.types.objectProperty(n.types.identifier(o), n.types.identifier(o), void 0, !0)
|
|
1010
1010
|
)
|
|
1011
1011
|
),
|
|
1012
1012
|
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(r)])
|
|
@@ -1043,10 +1043,10 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1043
1043
|
let t = this._ast.program.body.find((p) => {
|
|
1044
1044
|
let d = n.types.isImportDeclaration(p) && (p.source.value === r || p.source.value === r.split("node:")[1]);
|
|
1045
1045
|
return d && (r = p.source.value), d;
|
|
1046
|
-
}), i = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"),
|
|
1046
|
+
}), i = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"), a = /* @__PURE__ */ f(
|
|
1047
1047
|
(p, d) => p.specifiers.find(
|
|
1048
1048
|
(g) => n.types.isImportSpecifier(g) && n.types.isIdentifier(g.imported) && g.imported.name === d
|
|
1049
|
-
), "hasImportSpecifier"),
|
|
1049
|
+
), "hasImportSpecifier"), o = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1050
1050
|
(g) => n.types.isImportNamespaceSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name === d
|
|
1051
1051
|
), "hasNamespaceImportSpecifier");
|
|
1052
1052
|
e === null ? t || this._ast.program.body.unshift(n.types.importDeclaration([], n.types.stringLiteral(r))) : typeof e == "string" ? t ? (/* @__PURE__ */ f(
|
|
@@ -1060,13 +1060,13 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1060
1060
|
n.types.stringLiteral(r)
|
|
1061
1061
|
)
|
|
1062
1062
|
) : Array.isArray(e) ? t ? e.forEach((p) => {
|
|
1063
|
-
|
|
1063
|
+
a(t, p) || t.specifiers.push(i(p));
|
|
1064
1064
|
}) : this._ast.program.body.unshift(
|
|
1065
1065
|
n.types.importDeclaration(
|
|
1066
1066
|
e.map(i),
|
|
1067
1067
|
n.types.stringLiteral(r)
|
|
1068
1068
|
)
|
|
1069
|
-
) : e.namespace && (t ?
|
|
1069
|
+
) : e.namespace && (t ? o(t, e.namespace) || t.specifiers.push(
|
|
1070
1070
|
n.types.importNamespaceSpecifier(n.types.identifier(e.namespace))
|
|
1071
1071
|
) : this._ast.program.body.unshift(
|
|
1072
1072
|
n.types.importDeclaration(
|
|
@@ -1092,14 +1092,14 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1092
1092
|
view")), "isCsfFactoryPreview");
|
|
1093
1093
|
|
|
1094
1094
|
// src/csf-tools/getStorySortParameter.ts
|
|
1095
|
-
var y = require("storybook/internal/babel"), De = require("storybook/internal/node-logger"), Ie = z(
|
|
1095
|
+
var y = require("storybook/internal/babel"), De = require("storybook/internal/node-logger"), Ie = z($(), 1);
|
|
1096
1096
|
var ne = /* @__PURE__ */ f((s, e) => {
|
|
1097
1097
|
let r;
|
|
1098
1098
|
return s.properties.forEach((t) => {
|
|
1099
1099
|
y.types.isIdentifier(t.key) && t.key.name === e && (r = t.value);
|
|
1100
1100
|
}), r;
|
|
1101
1101
|
}, "getValue"), oe = /* @__PURE__ */ f((s) => {
|
|
1102
|
-
let e =
|
|
1102
|
+
let e = B(s);
|
|
1103
1103
|
if (y.types.isArrayExpression(e))
|
|
1104
1104
|
return e.elements.map((r) => oe(r));
|
|
1105
1105
|
if (y.types.isObjectExpression(e))
|
|
@@ -1107,9 +1107,9 @@ var ne = /* @__PURE__ */ f((s, e) => {
|
|
|
1107
1107
|
if (y.types.isLiteral(e))
|
|
1108
1108
|
return e.value;
|
|
1109
1109
|
if (y.types.isIdentifier(e))
|
|
1110
|
-
return
|
|
1110
|
+
return C(e.name, !0);
|
|
1111
1111
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1112
|
-
}, "parseValue"),
|
|
1112
|
+
}, "parseValue"), C = /* @__PURE__ */ f((s, e) => {
|
|
1113
1113
|
let r = Ie.dedent`
|
|
1114
1114
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1115
1115
|
|
|
@@ -1124,25 +1124,25 @@ var ne = /* @__PURE__ */ f((s, e) => {
|
|
|
1124
1124
|
if (e)
|
|
1125
1125
|
throw new Error(r);
|
|
1126
1126
|
De.logger.log(r);
|
|
1127
|
-
}, "unsupported"),
|
|
1127
|
+
}, "unsupported"), B = /* @__PURE__ */ f((s) => y.types.isTSAsExpression(s) || y.types.isTSSatisfiesExpression(s) ? s.expression : s, "strip\
|
|
1128
1128
|
TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
1129
|
-
let e =
|
|
1129
|
+
let e = B(s);
|
|
1130
1130
|
if (y.types.isObjectExpression(e)) {
|
|
1131
1131
|
let r = ne(e, "options");
|
|
1132
1132
|
if (r) {
|
|
1133
1133
|
if (y.types.isObjectExpression(r))
|
|
1134
1134
|
return ne(r, "storySort");
|
|
1135
|
-
|
|
1135
|
+
C("options", !0);
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
1138
1138
|
}, "parseParameters"), ve = /* @__PURE__ */ f((s, e) => {
|
|
1139
|
-
let r =
|
|
1139
|
+
let r = B(s);
|
|
1140
1140
|
if (y.types.isObjectExpression(r)) {
|
|
1141
1141
|
let t = ne(r, "parameters");
|
|
1142
1142
|
if (y.types.isIdentifier(t) && (t = P(t.name, e)), t)
|
|
1143
1143
|
return Ne(t);
|
|
1144
1144
|
} else
|
|
1145
|
-
|
|
1145
|
+
C("default", !0);
|
|
1146
1146
|
}, "parseDefault"), ct = /* @__PURE__ */ f((s) => {
|
|
1147
1147
|
if (!s.includes("storySort"))
|
|
1148
1148
|
return;
|
|
@@ -1152,22 +1152,22 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1152
1152
|
enter({ node: t }) {
|
|
1153
1153
|
y.types.isVariableDeclaration(t.declaration) ? t.declaration.declarations.forEach((i) => {
|
|
1154
1154
|
if (y.types.isVariableDeclarator(i) && y.types.isIdentifier(i.id)) {
|
|
1155
|
-
let { name:
|
|
1156
|
-
if (
|
|
1157
|
-
let
|
|
1158
|
-
e = Ne(
|
|
1155
|
+
let { name: a } = i.id;
|
|
1156
|
+
if (a === "parameters" && i.init) {
|
|
1157
|
+
let o = B(i.init);
|
|
1158
|
+
e = Ne(o);
|
|
1159
1159
|
}
|
|
1160
1160
|
}
|
|
1161
1161
|
}) : t.specifiers.forEach((i) => {
|
|
1162
|
-
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" &&
|
|
1162
|
+
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" && C("parameters", !1);
|
|
1163
1163
|
});
|
|
1164
1164
|
}
|
|
1165
1165
|
},
|
|
1166
1166
|
ExportDefaultDeclaration: {
|
|
1167
1167
|
enter({ node: t }) {
|
|
1168
1168
|
let i = t.declaration;
|
|
1169
|
-
y.types.isIdentifier(i) && (i = P(i.name, r.program)), i =
|
|
1170
|
-
e = ve(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = ve(i, r.program) :
|
|
1169
|
+
y.types.isIdentifier(i) && (i = P(i.name, r.program)), i = B(i), y.types.isCallExpression(i) && y.types.isObjectExpression(i.arguments?.[0]) ?
|
|
1170
|
+
e = ve(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = ve(i, r.program) : C("default", !1);
|
|
1171
1171
|
}
|
|
1172
1172
|
}
|
|
1173
1173
|
}), !!e) {
|
|
@@ -1176,21 +1176,21 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1176
1176
|
return (0, eval)(t);
|
|
1177
1177
|
}
|
|
1178
1178
|
if (y.types.isFunctionExpression(e)) {
|
|
1179
|
-
let { code: t } = (0, y.generate)(e, {}), i = e.id?.name,
|
|
1179
|
+
let { code: t } = (0, y.generate)(e, {}), i = e.id?.name, a = `(a, b) => {
|
|
1180
1180
|
${t};
|
|
1181
1181
|
return ${i}(a, b)
|
|
1182
1182
|
}`;
|
|
1183
|
-
return (0, eval)(
|
|
1183
|
+
return (0, eval)(a);
|
|
1184
1184
|
}
|
|
1185
|
-
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ? oe(e) :
|
|
1185
|
+
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ? oe(e) : C("storySort", !0);
|
|
1186
1186
|
}
|
|
1187
1187
|
}, "getStorySortParameter");
|
|
1188
1188
|
|
|
1189
1189
|
// src/csf-tools/enrichCsf.ts
|
|
1190
1190
|
var u = require("storybook/internal/babel");
|
|
1191
1191
|
var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1192
|
-
let i = e.getStoryExport(r),
|
|
1193
|
-
i.callee.object.name === "meta",
|
|
1192
|
+
let i = e.getStoryExport(r), a = u.types.isCallExpression(i) && u.types.isMemberExpression(i.callee) && u.types.isIdentifier(i.callee.object) &&
|
|
1193
|
+
i.callee.object.name === "meta", o = !t?.disableSource && Te(i), c = !t?.disableDescription && ae(e._storyStatements[r]), p = [], d = a ? u.types.
|
|
1194
1194
|
memberExpression(u.types.identifier(r), u.types.identifier("input")) : u.types.identifier(r), g = u.types.memberExpression(d, u.types.identifier(
|
|
1195
1195
|
"parameters"));
|
|
1196
1196
|
p.push(u.types.spreadElement(g));
|
|
@@ -1200,7 +1200,7 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1200
1200
|
!1,
|
|
1201
1201
|
!0
|
|
1202
1202
|
), h = [];
|
|
1203
|
-
if (
|
|
1203
|
+
if (o) {
|
|
1204
1204
|
let b = u.types.optionalMemberExpression(
|
|
1205
1205
|
x,
|
|
1206
1206
|
u.types.identifier("source"),
|
|
@@ -1211,13 +1211,13 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1211
1211
|
u.types.objectProperty(
|
|
1212
1212
|
u.types.identifier("source"),
|
|
1213
1213
|
u.types.objectExpression([
|
|
1214
|
-
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(
|
|
1214
|
+
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(o)),
|
|
1215
1215
|
u.types.spreadElement(b)
|
|
1216
1216
|
])
|
|
1217
1217
|
)
|
|
1218
1218
|
);
|
|
1219
1219
|
}
|
|
1220
|
-
if (
|
|
1220
|
+
if (c) {
|
|
1221
1221
|
let b = u.types.optionalMemberExpression(
|
|
1222
1222
|
x,
|
|
1223
1223
|
u.types.identifier("description"),
|
|
@@ -1228,7 +1228,7 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1228
1228
|
u.types.objectProperty(
|
|
1229
1229
|
u.types.identifier("description"),
|
|
1230
1230
|
u.types.objectExpression([
|
|
1231
|
-
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(
|
|
1231
|
+
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(c)),
|
|
1232
1232
|
u.types.spreadElement(b)
|
|
1233
1233
|
])
|
|
1234
1234
|
)
|
|
@@ -1253,10 +1253,10 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1253
1253
|
) || s.properties.unshift(r);
|
|
1254
1254
|
return;
|
|
1255
1255
|
}
|
|
1256
|
-
let [t, ...i] = e,
|
|
1257
|
-
(
|
|
1258
|
-
),
|
|
1259
|
-
|
|
1256
|
+
let [t, ...i] = e, a = s.properties.find(
|
|
1257
|
+
(c) => u.types.isObjectProperty(c) && u.types.isIdentifier(c.key) && c.key.name === t && u.types.isObjectExpression(c.value)
|
|
1258
|
+
), o;
|
|
1259
|
+
a ? o = a.value : (o = u.types.objectExpression([]), s.properties.push(u.types.objectProperty(u.types.identifier(t), o))), Fe(o, i, r);
|
|
1260
1260
|
}, "addComponentDescription"), Ce = /* @__PURE__ */ f((s, e, r) => {
|
|
1261
1261
|
let t = !r?.disableDescription && ae(e._metaStatement);
|
|
1262
1262
|
if (t) {
|
|
@@ -1285,7 +1285,7 @@ var $e = require("storybook/internal/babel");
|
|
|
1285
1285
|
|
|
1286
1286
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1287
1287
|
var m = require("storybook/internal/babel"), ke = require("storybook/internal/common"), Ve = require("storybook/internal/csf"), le = require("storybook/internal/node-logger"),
|
|
1288
|
-
ce = z(
|
|
1288
|
+
ce = z($(), 1);
|
|
1289
1289
|
var ft = /* @__PURE__ */ f((s, e) => !(e.include.length && !e.include.some((r) => s?.includes(r)) || e.exclude.some((r) => s?.includes(r))),
|
|
1290
1290
|
"isValidTest");
|
|
1291
1291
|
async function Ae({
|
|
@@ -1294,19 +1294,17 @@ async function Ae({
|
|
|
1294
1294
|
configDir: r,
|
|
1295
1295
|
stories: t,
|
|
1296
1296
|
tagsFilter: i,
|
|
1297
|
-
previewLevelTags:
|
|
1297
|
+
previewLevelTags: a = []
|
|
1298
1298
|
}) {
|
|
1299
|
-
|
|
1300
|
-
return s;
|
|
1301
|
-
let l = Q(s, {
|
|
1299
|
+
let o = Q(s, {
|
|
1302
1300
|
fileName: e,
|
|
1303
1301
|
transformInlineMeta: !0,
|
|
1304
|
-
makeTitle: /* @__PURE__ */ f((
|
|
1302
|
+
makeTitle: /* @__PURE__ */ f((E) => {
|
|
1305
1303
|
let S = (0, ke.getStoryTitle)({
|
|
1306
1304
|
storyFilePath: e,
|
|
1307
1305
|
configDir: r,
|
|
1308
1306
|
stories: t,
|
|
1309
|
-
userTitle:
|
|
1307
|
+
userTitle: E
|
|
1310
1308
|
}) || "unknown";
|
|
1311
1309
|
return S === "unknown" && le.logger.warn(
|
|
1312
1310
|
ce.dedent`
|
|
@@ -1315,10 +1313,10 @@ async function Ae({
|
|
|
1315
1313
|
`
|
|
1316
1314
|
), S;
|
|
1317
1315
|
}, "makeTitle")
|
|
1318
|
-
}).parse(),
|
|
1319
|
-
(
|
|
1320
|
-
),
|
|
1321
|
-
if (
|
|
1316
|
+
}).parse(), c = o._ast, p = o._metaVariableName, d = o._metaNode, g = d.properties.find(
|
|
1317
|
+
(E) => m.types.isObjectProperty(E) && m.types.isIdentifier(E.key) && E.key.name === "title"
|
|
1318
|
+
), x = m.types.stringLiteral(o._meta?.title || "unknown");
|
|
1319
|
+
if (g ? m.types.isObjectProperty(g) && (g.value = x) : d.properties.push(m.types.objectProperty(m.types.identifier("title"), x)), !d || !o.
|
|
1322
1320
|
_meta)
|
|
1323
1321
|
throw new Error(
|
|
1324
1322
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1326,49 +1324,49 @@ async function Ae({
|
|
|
1326
1324
|
Please make sure you have a default export with the meta object. If you are using a different export format that is not supported, please fi\
|
|
1327
1325
|
le an issue with details about your use case.`
|
|
1328
1326
|
);
|
|
1329
|
-
let
|
|
1330
|
-
Object.keys(
|
|
1327
|
+
let h = {};
|
|
1328
|
+
Object.keys(o._stories).map((E) => {
|
|
1331
1329
|
let S = (0, Ve.combineTags)(
|
|
1332
1330
|
"test",
|
|
1333
1331
|
"dev",
|
|
1334
|
-
...
|
|
1335
|
-
...
|
|
1336
|
-
...
|
|
1332
|
+
...a,
|
|
1333
|
+
...o.meta?.tags || [],
|
|
1334
|
+
...o._stories[E].tags || []
|
|
1337
1335
|
);
|
|
1338
|
-
ft(S, i) && (
|
|
1336
|
+
ft(S, i) && (h[E] = o._storyStatements[E]);
|
|
1339
1337
|
});
|
|
1340
|
-
let
|
|
1341
|
-
if (Object.keys(
|
|
1342
|
-
let
|
|
1343
|
-
m.types.callExpression(m.types.memberExpression(
|
|
1338
|
+
let b = o._file.path.scope.generateUidIdentifier("test"), _ = o._file.path.scope.generateUidIdentifier("describe");
|
|
1339
|
+
if (Object.keys(h).length === 0) {
|
|
1340
|
+
let E = m.types.expressionStatement(
|
|
1341
|
+
m.types.callExpression(m.types.memberExpression(_, m.types.identifier("skip")), [
|
|
1344
1342
|
m.types.stringLiteral("No valid tests found")
|
|
1345
1343
|
])
|
|
1346
1344
|
);
|
|
1347
|
-
|
|
1345
|
+
c.program.body.push(E);
|
|
1348
1346
|
let S = [
|
|
1349
1347
|
m.types.importDeclaration(
|
|
1350
1348
|
[
|
|
1351
|
-
m.types.importSpecifier(
|
|
1352
|
-
m.types.importSpecifier(
|
|
1349
|
+
m.types.importSpecifier(b, m.types.identifier("test")),
|
|
1350
|
+
m.types.importSpecifier(_, m.types.identifier("describe"))
|
|
1353
1351
|
],
|
|
1354
1352
|
m.types.stringLiteral("vitest")
|
|
1355
1353
|
)
|
|
1356
1354
|
];
|
|
1357
|
-
|
|
1355
|
+
c.program.body.unshift(...S);
|
|
1358
1356
|
} else {
|
|
1359
1357
|
let pe = function() {
|
|
1360
|
-
let j =
|
|
1361
|
-
m.types.callExpression(m.types.memberExpression(
|
|
1358
|
+
let j = o._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), I = m.types.memberExpression(
|
|
1359
|
+
m.types.callExpression(m.types.memberExpression(E, m.types.identifier("getState")), []),
|
|
1362
1360
|
m.types.identifier("testPath")
|
|
1363
|
-
),
|
|
1361
|
+
), T = m.types.memberExpression(
|
|
1364
1362
|
m.types.memberExpression(m.types.identifier("globalThis"), m.types.identifier("__vitest_worker__")),
|
|
1365
1363
|
m.types.identifier("filepath")
|
|
1366
|
-
),
|
|
1364
|
+
), k = m.types.logicalExpression(
|
|
1367
1365
|
"??",
|
|
1368
1366
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1369
1367
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1370
|
-
|
|
1371
|
-
|
|
1368
|
+
T,
|
|
1369
|
+
I
|
|
1372
1370
|
), G = m.types.callExpression(
|
|
1373
1371
|
m.types.memberExpression(
|
|
1374
1372
|
m.types.callExpression(m.types.identifier("convertToFilePath"), [
|
|
@@ -1379,37 +1377,37 @@ le an issue with details about your use case.`
|
|
|
1379
1377
|
]),
|
|
1380
1378
|
m.types.identifier("includes")
|
|
1381
1379
|
),
|
|
1382
|
-
[
|
|
1380
|
+
[k]
|
|
1383
1381
|
);
|
|
1384
1382
|
return { isRunningFromThisFileDeclaration: m.types.variableDeclaration("const", [
|
|
1385
1383
|
m.types.variableDeclarator(j, G)
|
|
1386
1384
|
]), isRunningFromThisFileId: j };
|
|
1387
1385
|
};
|
|
1388
|
-
var
|
|
1386
|
+
var W = pe;
|
|
1389
1387
|
f(pe, "getTestGuardDeclaration");
|
|
1390
|
-
let
|
|
1388
|
+
let E = o._file.path.scope.generateUidIdentifier("expect"), S = o._file.path.scope.generateUidIdentifier("testStory"), Re = m.types.identifier(
|
|
1391
1389
|
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Le, isRunningFromThisFileId: Me } = pe();
|
|
1392
|
-
|
|
1390
|
+
c.program.body.push(Le);
|
|
1393
1391
|
let Ue = /* @__PURE__ */ f(({
|
|
1394
1392
|
localName: j,
|
|
1395
|
-
exportName:
|
|
1396
|
-
testTitle:
|
|
1397
|
-
node:
|
|
1393
|
+
exportName: I,
|
|
1394
|
+
testTitle: T,
|
|
1395
|
+
node: k
|
|
1398
1396
|
}) => {
|
|
1399
1397
|
let G = m.types.expressionStatement(
|
|
1400
|
-
m.types.callExpression(
|
|
1401
|
-
m.types.stringLiteral(
|
|
1398
|
+
m.types.callExpression(b, [
|
|
1399
|
+
m.types.stringLiteral(T),
|
|
1402
1400
|
m.types.callExpression(S, [
|
|
1403
|
-
m.types.stringLiteral(
|
|
1401
|
+
m.types.stringLiteral(I),
|
|
1404
1402
|
m.types.identifier(j),
|
|
1405
|
-
m.types.identifier(
|
|
1403
|
+
m.types.identifier(p),
|
|
1406
1404
|
Re
|
|
1407
1405
|
])
|
|
1408
1406
|
])
|
|
1409
1407
|
);
|
|
1410
|
-
return G.loc =
|
|
1411
|
-
}, "getTestStatementForStory"), qe = Object.entries(
|
|
1412
|
-
if (
|
|
1408
|
+
return G.loc = k.loc, G;
|
|
1409
|
+
}, "getTestStatementForStory"), qe = Object.entries(h).map(([j, I]) => {
|
|
1410
|
+
if (I === null) {
|
|
1413
1411
|
le.logger.warn(
|
|
1414
1412
|
ce.dedent`
|
|
1415
1413
|
[Storybook]: Could not transform "${j}" story into test at "${e}".
|
|
@@ -1418,15 +1416,15 @@ le an issue with details about your use case.`
|
|
|
1418
1416
|
);
|
|
1419
1417
|
return;
|
|
1420
1418
|
}
|
|
1421
|
-
let
|
|
1422
|
-
return Ue({ testTitle:
|
|
1419
|
+
let T = o._stories[j].localName ?? j, k = o._stories[j].name ?? j;
|
|
1420
|
+
return Ue({ testTitle: k, localName: T, exportName: j, node: I });
|
|
1423
1421
|
}).filter((j) => !!j), Be = m.types.ifStatement(Me, m.types.blockStatement(qe));
|
|
1424
|
-
|
|
1422
|
+
c.program.body.push(Be);
|
|
1425
1423
|
let We = [
|
|
1426
1424
|
m.types.importDeclaration(
|
|
1427
1425
|
[
|
|
1428
|
-
m.types.importSpecifier(
|
|
1429
|
-
m.types.importSpecifier(
|
|
1426
|
+
m.types.importSpecifier(b, m.types.identifier("test")),
|
|
1427
|
+
m.types.importSpecifier(E, m.types.identifier("expect"))
|
|
1430
1428
|
],
|
|
1431
1429
|
m.types.stringLiteral("vitest")
|
|
1432
1430
|
),
|
|
@@ -1438,8 +1436,8 @@ le an issue with details about your use case.`
|
|
|
1438
1436
|
m.types.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1439
1437
|
)
|
|
1440
1438
|
];
|
|
1441
|
-
|
|
1439
|
+
c.program.body.unshift(...We);
|
|
1442
1440
|
}
|
|
1443
|
-
return ie(
|
|
1441
|
+
return ie(o, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1444
1442
|
}
|
|
1445
1443
|
f(Ae, "vitestTransform");
|