storybook 9.0.0-rc.1 → 9.0.0-rc.3
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/builder-manager/index.cjs +28 -27
- package/dist/builder-manager/index.js +47 -46
- package/dist/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +1643 -1642
- package/dist/common/index.d.ts +2 -1
- package/dist/common/index.js +46 -45
- package/dist/core-server/presets/common-manager.js +1464 -1464
- package/dist/core-server/presets/common-preset.cjs +20 -17
- package/dist/core-server/presets/common-preset.js +19 -16
- package/dist/csf-tools/index.cjs +542 -535
- package/dist/csf-tools/index.js +531 -524
- package/dist/docs-tools/index.cjs +38 -40
- package/dist/docs-tools/index.d.ts +3 -5
- package/dist/docs-tools/index.js +94 -96
- package/dist/highlight/index.cjs +14 -14
- package/dist/highlight/index.d.ts +27 -14
- package/dist/highlight/index.js +3 -3
- package/dist/highlight/preview.cjs +309 -258
- package/dist/highlight/preview.js +335 -284
- package/dist/manager/globals-runtime.js +1 -1
- package/dist/manager/runtime.js +5 -4
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.js +1 -1
- package/dist/preview/runtime.js +10530 -10468
- package/dist/test/preview.cjs +61 -49
- package/dist/test/preview.js +54 -42
- package/package.json +1 -1
package/dist/csf-tools/index.js
CHANGED
|
@@ -11,18 +11,18 @@ var Ae = Object.getOwnPropertyNames;
|
|
|
11
11
|
var $e = Object.getPrototypeOf, Re = Object.prototype.hasOwnProperty;
|
|
12
12
|
var f = (s, e) => X(s, "name", { value: e, configurable: !0 });
|
|
13
13
|
var Le = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports);
|
|
14
|
-
var Me = (s, e,
|
|
14
|
+
var Me = (s, e, r, t) => {
|
|
15
15
|
if (e && typeof e == "object" || typeof e == "function")
|
|
16
|
-
for (let
|
|
17
|
-
!Re.call(s,
|
|
16
|
+
for (let i of Ae(e))
|
|
17
|
+
!Re.call(s, i) && i !== r && X(s, i, { get: () => e[i], enumerable: !(t = Ve(e, i)) || t.enumerable });
|
|
18
18
|
return s;
|
|
19
19
|
};
|
|
20
|
-
var U = (s, e,
|
|
20
|
+
var U = (s, e, r) => (r = s != null ? ke($e(s)) : {}, Me(
|
|
21
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
23
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
24
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
e || !s || !s.__esModule ? X(
|
|
25
|
+
e || !s || !s.__esModule ? X(r, "default", { value: s, enumerable: !0 }) : r,
|
|
26
26
|
s
|
|
27
27
|
));
|
|
28
28
|
|
|
@@ -32,36 +32,36 @@ var V = Le((k) => {
|
|
|
32
32
|
Object.defineProperty(k, "__esModule", { value: !0 });
|
|
33
33
|
k.dedent = void 0;
|
|
34
34
|
function se(s) {
|
|
35
|
-
for (var e = [],
|
|
36
|
-
e[
|
|
35
|
+
for (var e = [], r = 1; r < arguments.length; r++)
|
|
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
|
|
39
|
+
var i = t.reduce(function(l, p) {
|
|
40
40
|
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
41
|
-
return d ?
|
|
41
|
+
return d ? l.concat(d.map(function(m) {
|
|
42
42
|
var x, b;
|
|
43
|
-
return (b = (x =
|
|
44
|
-
})) :
|
|
43
|
+
return (b = (x = m.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && b !== void 0 ? b : 0;
|
|
44
|
+
})) : l;
|
|
45
45
|
}, []);
|
|
46
|
-
if (
|
|
46
|
+
if (i.length) {
|
|
47
47
|
var o = new RegExp(`
|
|
48
|
-
[ ]{` + Math.min.apply(Math,
|
|
49
|
-
t = t.map(function(
|
|
50
|
-
return
|
|
48
|
+
[ ]{` + Math.min.apply(Math, i) + "}", "g");
|
|
49
|
+
t = t.map(function(l) {
|
|
50
|
+
return l.replace(o, `
|
|
51
51
|
`);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
t[0] = t[0].replace(/^\r?\n/, "");
|
|
55
|
-
var
|
|
56
|
-
return e.forEach(function(
|
|
57
|
-
var d =
|
|
58
|
-
typeof
|
|
59
|
-
`) && (x = String(
|
|
55
|
+
var a = t[0];
|
|
56
|
+
return e.forEach(function(l, p) {
|
|
57
|
+
var d = a.match(/(?:^|\n)( *)$/), m = d ? d[1] : "", x = l;
|
|
58
|
+
typeof l == "string" && l.includes(`
|
|
59
|
+
`) && (x = String(l).split(`
|
|
60
60
|
`).map(function(b, y) {
|
|
61
|
-
return y === 0 ? b : "" +
|
|
61
|
+
return y === 0 ? b : "" + m + b;
|
|
62
62
|
}).join(`
|
|
63
|
-
`)),
|
|
64
|
-
}),
|
|
63
|
+
`)), a += x + t[p + 1];
|
|
64
|
+
}), a;
|
|
65
65
|
}
|
|
66
66
|
f(se, "dedent");
|
|
67
67
|
k.dedent = se;
|
|
@@ -84,10 +84,10 @@ import { isExportStory as ne, storyNameFromExport as oe, toId as ze } from "stor
|
|
|
84
84
|
// src/csf-tools/findVarInitialization.ts
|
|
85
85
|
import { types as A } from "storybook/internal/babel";
|
|
86
86
|
var P = /* @__PURE__ */ f((s, e) => {
|
|
87
|
-
let
|
|
88
|
-
return e.body.find((
|
|
89
|
-
(t =
|
|
90
|
-
!1))),
|
|
87
|
+
let r = null, t = null;
|
|
88
|
+
return e.body.find((i) => (A.isVariableDeclaration(i) ? t = i.declarations : A.isExportNamedDeclaration(i) && A.isVariableDeclaration(i.declaration) &&
|
|
89
|
+
(t = i.declaration.declarations), t && t.find((o) => A.isVariableDeclarator(o) && A.isIdentifier(o.id) && o.id.name === s ? (r = o.init, !0) :
|
|
90
|
+
!1))), r;
|
|
91
91
|
}, "findVarInitialization");
|
|
92
92
|
|
|
93
93
|
// src/csf-tools/CsfFile.ts
|
|
@@ -116,21 +116,21 @@ function le(s) {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
f(le, "parseTags");
|
|
119
|
-
var
|
|
120
|
-
let
|
|
119
|
+
var v = /* @__PURE__ */ f((s, e) => {
|
|
120
|
+
let r = "";
|
|
121
121
|
if (s.loc) {
|
|
122
|
-
let { line: t, column:
|
|
123
|
-
|
|
122
|
+
let { line: t, column: i } = s.loc?.start || {};
|
|
123
|
+
r = `(line ${t}, col ${i})`;
|
|
124
124
|
}
|
|
125
|
-
return `${e || ""} ${
|
|
126
|
-
}, "formatLocation"), Qe = /* @__PURE__ */ f((s) => Ze.test(s), "isModuleMock"), ce = /* @__PURE__ */ f((s, e,
|
|
125
|
+
return `${e || ""} ${r}`.trim();
|
|
126
|
+
}, "formatLocation"), Qe = /* @__PURE__ */ f((s) => Ze.test(s), "isModuleMock"), ce = /* @__PURE__ */ f((s, e, r) => {
|
|
127
127
|
let t = s;
|
|
128
128
|
if (c.isCallExpression(s)) {
|
|
129
|
-
let { callee:
|
|
130
|
-
if (c.isProgram(e) && c.isMemberExpression(
|
|
129
|
+
let { callee: i, arguments: o } = s;
|
|
130
|
+
if (c.isProgram(e) && c.isMemberExpression(i) && c.isIdentifier(i.object) && c.isIdentifier(i.property) && i.property.name === "bind" &&
|
|
131
131
|
(o.length === 0 || o.length === 1 && c.isObjectExpression(o[0]) && o[0].properties.length === 0)) {
|
|
132
|
-
let
|
|
133
|
-
|
|
132
|
+
let a = i.object.name, l = P(a, e);
|
|
133
|
+
l && (r._templates[a] = l, t = l);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
return c.isArrowFunctionExpression(t) || c.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
|
|
@@ -143,18 +143,18 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
143
143
|
});
|
|
144
144
|
throw new Error(`Expected array of string literals: ${s}`);
|
|
145
145
|
}, "parseExportsOrder"), pe = /* @__PURE__ */ f((s, e) => e.reduce(
|
|
146
|
-
(
|
|
147
|
-
let
|
|
148
|
-
return
|
|
146
|
+
(r, t) => {
|
|
147
|
+
let i = s[t];
|
|
148
|
+
return i && (r[t] = i), r;
|
|
149
149
|
},
|
|
150
150
|
{}
|
|
151
151
|
), "sortExports"), Ye = /* @__PURE__ */ f((s) => {
|
|
152
152
|
if (c.isArrowFunctionExpression(s) || c.isFunctionDeclaration(s)) {
|
|
153
153
|
let e = s.params;
|
|
154
154
|
if (e.length >= 1) {
|
|
155
|
-
let [
|
|
156
|
-
if (c.isObjectPattern(
|
|
157
|
-
return !!
|
|
155
|
+
let [r] = e;
|
|
156
|
+
if (c.isObjectPattern(r))
|
|
157
|
+
return !!r.properties.find((t) => {
|
|
158
158
|
if (c.isObjectProperty(t) && c.isIdentifier(t.key))
|
|
159
159
|
return t.key.name === "mount";
|
|
160
160
|
});
|
|
@@ -165,10 +165,10 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
165
165
|
static {
|
|
166
166
|
f(this, "NoMetaError");
|
|
167
167
|
}
|
|
168
|
-
constructor(e,
|
|
169
|
-
let
|
|
168
|
+
constructor(e, r, t) {
|
|
169
|
+
let i = "".trim();
|
|
170
170
|
super(O.dedent`
|
|
171
|
-
CSF: ${e} ${
|
|
171
|
+
CSF: ${e} ${v(r, t)}
|
|
172
172
|
|
|
173
173
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
174
174
|
`), this.name = this.constructor.name;
|
|
@@ -177,10 +177,10 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
177
177
|
static {
|
|
178
178
|
f(this, "MultipleMetaError");
|
|
179
179
|
}
|
|
180
|
-
constructor(e,
|
|
181
|
-
let
|
|
180
|
+
constructor(e, r, t) {
|
|
181
|
+
let i = `${e} ${v(r, t)}`.trim();
|
|
182
182
|
super(O.dedent`
|
|
183
|
-
CSF: ${e} ${
|
|
183
|
+
CSF: ${e} ${v(r, t)}
|
|
184
184
|
|
|
185
185
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
186
186
|
`), this.name = this.constructor.name;
|
|
@@ -189,10 +189,10 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
189
189
|
static {
|
|
190
190
|
f(this, "MixedFactoryError");
|
|
191
191
|
}
|
|
192
|
-
constructor(e,
|
|
193
|
-
let
|
|
192
|
+
constructor(e, r, t) {
|
|
193
|
+
let i = `${e} ${v(r, t)}`.trim();
|
|
194
194
|
super(O.dedent`
|
|
195
|
-
CSF: ${e} ${
|
|
195
|
+
CSF: ${e} ${v(r, t)}
|
|
196
196
|
|
|
197
197
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
198
198
|
`), this.name = this.constructor.name;
|
|
@@ -201,16 +201,16 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
201
201
|
static {
|
|
202
202
|
f(this, "BadMetaError");
|
|
203
203
|
}
|
|
204
|
-
constructor(e,
|
|
205
|
-
let
|
|
204
|
+
constructor(e, r, t) {
|
|
205
|
+
let i = "".trim();
|
|
206
206
|
super(O.dedent`
|
|
207
|
-
CSF: ${e} ${
|
|
207
|
+
CSF: ${e} ${v(r, t)}
|
|
208
208
|
|
|
209
209
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
210
210
|
`), this.name = this.constructor.name;
|
|
211
211
|
}
|
|
212
212
|
}, J = class {
|
|
213
|
-
constructor(e,
|
|
213
|
+
constructor(e, r, t) {
|
|
214
214
|
this._stories = {};
|
|
215
215
|
this._metaAnnotations = {};
|
|
216
216
|
this._storyExports = {};
|
|
@@ -218,102 +218,102 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
218
218
|
this._storyStatements = {};
|
|
219
219
|
this._storyAnnotations = {};
|
|
220
220
|
this._templates = {};
|
|
221
|
-
this._ast = e, this._file = t, this._options =
|
|
221
|
+
this._ast = e, this._file = t, this._options = r, this.imports = [];
|
|
222
222
|
}
|
|
223
223
|
static {
|
|
224
224
|
f(this, "CsfFile");
|
|
225
225
|
}
|
|
226
226
|
_parseTitle(e) {
|
|
227
|
-
let
|
|
228
|
-
if (c.isStringLiteral(
|
|
229
|
-
return
|
|
230
|
-
if (c.isTSSatisfiesExpression(
|
|
231
|
-
return
|
|
227
|
+
let r = c.isIdentifier(e) ? P(e.name, this._ast.program) : e;
|
|
228
|
+
if (c.isStringLiteral(r))
|
|
229
|
+
return r.value;
|
|
230
|
+
if (c.isTSSatisfiesExpression(r) && c.isStringLiteral(r.expression))
|
|
231
|
+
return r.expression.value;
|
|
232
232
|
throw new Error(O.dedent`
|
|
233
|
-
CSF: unexpected dynamic title ${
|
|
233
|
+
CSF: unexpected dynamic title ${v(r, this._options.fileName)}
|
|
234
234
|
|
|
235
235
|
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
236
236
|
`);
|
|
237
237
|
}
|
|
238
|
-
_parseMeta(e,
|
|
238
|
+
_parseMeta(e, r) {
|
|
239
239
|
if (this._metaNode)
|
|
240
240
|
throw new K("multiple meta objects", e, this._options.fileName);
|
|
241
241
|
this._metaNode = e;
|
|
242
242
|
let t = {};
|
|
243
|
-
e.properties.forEach((
|
|
244
|
-
if (c.isIdentifier(
|
|
245
|
-
if (this._metaAnnotations[
|
|
246
|
-
t.title = this._parseTitle(
|
|
247
|
-
else if (["includeStories", "excludeStories"].includes(
|
|
248
|
-
t[
|
|
249
|
-
else if (
|
|
250
|
-
let o =
|
|
243
|
+
e.properties.forEach((i) => {
|
|
244
|
+
if (c.isIdentifier(i.key)) {
|
|
245
|
+
if (this._metaAnnotations[i.key.name] = i.value, i.key.name === "title")
|
|
246
|
+
t.title = this._parseTitle(i.value);
|
|
247
|
+
else if (["includeStories", "excludeStories"].includes(i.key.name))
|
|
248
|
+
t[i.key.name] = Je(i.value);
|
|
249
|
+
else if (i.key.name === "component") {
|
|
250
|
+
let o = i.value;
|
|
251
251
|
if (c.isIdentifier(o)) {
|
|
252
|
-
let
|
|
253
|
-
(d) => c.isImportDeclaration(d) && d.specifiers.find((
|
|
252
|
+
let l = o.name, p = r.body.find(
|
|
253
|
+
(d) => c.isImportDeclaration(d) && d.specifiers.find((m) => m.local.name === l)
|
|
254
254
|
);
|
|
255
255
|
if (p) {
|
|
256
256
|
let { source: d } = p;
|
|
257
257
|
c.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
let { code:
|
|
261
|
-
t.component =
|
|
262
|
-
} else if (
|
|
263
|
-
let o =
|
|
260
|
+
let { code: a } = de.print(i.value, {});
|
|
261
|
+
t.component = a;
|
|
262
|
+
} else if (i.key.name === "tags") {
|
|
263
|
+
let o = i.value;
|
|
264
264
|
c.isIdentifier(o) && (o = P(o.name, this._ast.program)), t.tags = le(o);
|
|
265
|
-
} else if (
|
|
266
|
-
if (c.isStringLiteral(
|
|
267
|
-
t.id =
|
|
265
|
+
} else if (i.key.name === "id")
|
|
266
|
+
if (c.isStringLiteral(i.value))
|
|
267
|
+
t.id = i.value.value;
|
|
268
268
|
else
|
|
269
|
-
throw new Error(`Unexpected component id: ${
|
|
269
|
+
throw new Error(`Unexpected component id: ${i.value}`);
|
|
270
270
|
}
|
|
271
271
|
}), this._meta = t;
|
|
272
272
|
}
|
|
273
273
|
getStoryExport(e) {
|
|
274
|
-
let
|
|
275
|
-
if (
|
|
276
|
-
let { callee: t, arguments:
|
|
277
|
-
if (c.isMemberExpression(t) && c.isIdentifier(t.object) && c.isIdentifier(t.property) && t.property.name === "bind" && (
|
|
278
|
-
|
|
274
|
+
let r = this._storyExports[e];
|
|
275
|
+
if (r = c.isVariableDeclarator(r) ? r.init : r, c.isCallExpression(r)) {
|
|
276
|
+
let { callee: t, arguments: i } = r;
|
|
277
|
+
if (c.isMemberExpression(t) && c.isIdentifier(t.object) && c.isIdentifier(t.property) && t.property.name === "bind" && (i.length === 0 ||
|
|
278
|
+
i.length === 1 && c.isObjectExpression(i[0]) && i[0].properties.length === 0)) {
|
|
279
279
|
let { name: o } = t.object;
|
|
280
|
-
|
|
280
|
+
r = this._templates[o];
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
return
|
|
283
|
+
return r;
|
|
284
284
|
}
|
|
285
285
|
parse() {
|
|
286
286
|
let e = this;
|
|
287
287
|
if (Ge(this._ast, {
|
|
288
288
|
ExportDefaultDeclaration: {
|
|
289
289
|
enter(t) {
|
|
290
|
-
let { node:
|
|
291
|
-
if (e._options.transformInlineMeta && !
|
|
290
|
+
let { node: i, parent: o } = t, a = c.isIdentifier(i.declaration) && c.isProgram(o);
|
|
291
|
+
if (e._options.transformInlineMeta && !a && c.isExpression(i.declaration)) {
|
|
292
292
|
let d = t.scope.generateUidIdentifier("meta");
|
|
293
293
|
e._metaVariableName = d.name;
|
|
294
|
-
let
|
|
295
|
-
c.variableDeclaration("const", [c.variableDeclarator(d,
|
|
294
|
+
let m = [
|
|
295
|
+
c.variableDeclaration("const", [c.variableDeclarator(d, i.declaration)]),
|
|
296
296
|
c.exportDefaultDeclaration(d)
|
|
297
297
|
];
|
|
298
|
-
|
|
298
|
+
m.forEach((x) => x.loc = t.node.loc), t.replaceWithMultiple(m);
|
|
299
299
|
return;
|
|
300
300
|
}
|
|
301
|
-
let
|
|
302
|
-
if (
|
|
303
|
-
let d =
|
|
301
|
+
let l, p;
|
|
302
|
+
if (a) {
|
|
303
|
+
let d = i.declaration.name;
|
|
304
304
|
e._metaVariableName = d;
|
|
305
|
-
let
|
|
305
|
+
let m = /* @__PURE__ */ f((x) => c.isIdentifier(x.id) && x.id.name === d, "isVariableDeclarator");
|
|
306
306
|
e._metaStatement = e._ast.program.body.find(
|
|
307
|
-
(x) => c.isVariableDeclaration(x) && x.declarations.find(
|
|
307
|
+
(x) => c.isVariableDeclaration(x) && x.declarations.find(m)
|
|
308
308
|
), p = (e?._metaStatement?.declarations || []).find(
|
|
309
|
-
|
|
309
|
+
m
|
|
310
310
|
)?.init;
|
|
311
311
|
} else
|
|
312
|
-
e._metaStatement =
|
|
313
|
-
if (c.isObjectExpression(p) ?
|
|
312
|
+
e._metaStatement = i, p = i.declaration;
|
|
313
|
+
if (c.isObjectExpression(p) ? l = p : (
|
|
314
314
|
// export default { ... } as Meta<...>
|
|
315
|
-
(c.isTSAsExpression(p) || c.isTSSatisfiesExpression(p)) && c.isObjectExpression(p.expression) && (
|
|
316
|
-
),
|
|
315
|
+
(c.isTSAsExpression(p) || c.isTSSatisfiesExpression(p)) && c.isObjectExpression(p.expression) && (l = p.expression)
|
|
316
|
+
), l && c.isProgram(o) && e._parseMeta(l, o), e._metaStatement && !e._metaNode)
|
|
317
317
|
throw new q(
|
|
318
318
|
"default export must be an object",
|
|
319
319
|
e._metaStatement,
|
|
@@ -324,23 +324,23 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
324
324
|
},
|
|
325
325
|
ExportNamedDeclaration: {
|
|
326
326
|
enter(t) {
|
|
327
|
-
let { node:
|
|
328
|
-
c.isVariableDeclaration(
|
|
329
|
-
|
|
330
|
-
if (c.isIdentifier(
|
|
331
|
-
let p = !1, { name: d } =
|
|
332
|
-
if (d === "__namedExportsOrder" && c.isVariableDeclarator(
|
|
333
|
-
e._namedExportsOrder = He(
|
|
327
|
+
let { node: i, parent: o } = t, a;
|
|
328
|
+
c.isVariableDeclaration(i.declaration) ? a = i.declaration.declarations.filter((l) => c.isVariableDeclarator(l)) : c.isFunctionDeclaration(
|
|
329
|
+
i.declaration) && (a = [i.declaration]), a ? a.forEach((l) => {
|
|
330
|
+
if (c.isIdentifier(l.id)) {
|
|
331
|
+
let p = !1, { name: d } = l.id;
|
|
332
|
+
if (d === "__namedExportsOrder" && c.isVariableDeclarator(l)) {
|
|
333
|
+
e._namedExportsOrder = He(l.init);
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
|
-
e._storyExports[d] =
|
|
337
|
-
let
|
|
336
|
+
e._storyExports[d] = l, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
337
|
+
let m = oe(d);
|
|
338
338
|
e._storyAnnotations[d] ? ae.warn(
|
|
339
339
|
`Unexpected annotations for "${d}" before story declaration`
|
|
340
340
|
) : e._storyAnnotations[d] = {};
|
|
341
341
|
let x;
|
|
342
|
-
if (c.isVariableDeclarator(
|
|
343
|
-
x =
|
|
342
|
+
if (c.isVariableDeclarator(l) ? x = c.isTSAsExpression(l.init) || c.isTSSatisfiesExpression(l.init) ? l.init.expression : l.init :
|
|
343
|
+
x = l, c.isCallExpression(x) && c.isMemberExpression(x.callee) && c.isIdentifier(x.callee.property) && x.callee.property.name ===
|
|
344
344
|
"story" && (p = !0, x = x.arguments[0]), e._metaIsFactory && !p)
|
|
345
345
|
throw new B(
|
|
346
346
|
"expected factory story",
|
|
@@ -367,86 +367,90 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
367
367
|
e
|
|
368
368
|
);
|
|
369
369
|
else if (y.key.name === "name" && c.isStringLiteral(y.value))
|
|
370
|
-
|
|
370
|
+
m = y.value.value;
|
|
371
371
|
else if (y.key.name === "storyName" && c.isStringLiteral(y.value))
|
|
372
372
|
ae.warn(
|
|
373
373
|
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
374
374
|
);
|
|
375
375
|
else if (y.key.name === "parameters" && c.isObjectExpression(y.value)) {
|
|
376
|
-
let
|
|
376
|
+
let E = y.value.properties.find(
|
|
377
377
|
(D) => c.isObjectProperty(D) && c.isIdentifier(D.key) && D.key.name === "__id"
|
|
378
378
|
);
|
|
379
|
-
|
|
379
|
+
E && (b.__id = E.value.value);
|
|
380
380
|
}
|
|
381
381
|
e._storyAnnotations[d][y.key.name] = y.value;
|
|
382
382
|
}
|
|
383
383
|
})) : b.__isArgsStory = ce(x, o, e), e._stories[d] = {
|
|
384
384
|
id: "FIXME",
|
|
385
|
-
name:
|
|
385
|
+
name: m,
|
|
386
386
|
parameters: b,
|
|
387
387
|
__stats: {
|
|
388
388
|
factory: p
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
391
|
}
|
|
392
|
-
}) :
|
|
393
|
-
if (c.isExportSpecifier(
|
|
394
|
-
let { name: p } =
|
|
392
|
+
}) : i.specifiers.length > 0 && i.specifiers.forEach((l) => {
|
|
393
|
+
if (c.isExportSpecifier(l) && c.isIdentifier(l.exported)) {
|
|
394
|
+
let { name: p } = l.exported, { name: d } = l.local, m = c.isProgram(o) ? P(d, o) : l.local;
|
|
395
395
|
if (p === "default") {
|
|
396
396
|
let x;
|
|
397
|
-
c.isObjectExpression(
|
|
397
|
+
c.isObjectExpression(m) ? x = m : (
|
|
398
398
|
// export default { ... } as Meta<...>
|
|
399
|
-
c.isTSAsExpression(
|
|
399
|
+
c.isTSAsExpression(m) && c.isObjectExpression(m.expression) && (x = m.expression)
|
|
400
400
|
), x && c.isProgram(o) && e._parseMeta(x, o);
|
|
401
|
-
} else
|
|
402
|
-
|
|
401
|
+
} else {
|
|
402
|
+
let x = {}, b = m;
|
|
403
|
+
c.isObjectExpression(b) && b.properties.forEach((y) => {
|
|
404
|
+
c.isIdentifier(y.key) && (x[y.key.name] = y.value);
|
|
405
|
+
}), e._storyAnnotations[p] = x, e._storyStatements[p] = m, e._storyPaths[p] = t, e._stories[p] = {
|
|
403
406
|
id: "FIXME",
|
|
404
407
|
name: p,
|
|
405
408
|
localName: d,
|
|
406
409
|
parameters: {},
|
|
407
410
|
__stats: {}
|
|
408
411
|
};
|
|
412
|
+
}
|
|
409
413
|
}
|
|
410
414
|
});
|
|
411
415
|
}
|
|
412
416
|
},
|
|
413
417
|
ExpressionStatement: {
|
|
414
|
-
enter({ node: t, parent:
|
|
418
|
+
enter({ node: t, parent: i }) {
|
|
415
419
|
let { expression: o } = t;
|
|
416
|
-
if (c.isProgram(
|
|
420
|
+
if (c.isProgram(i) && c.isAssignmentExpression(o) && c.isMemberExpression(o.left) && c.isIdentifier(o.left.object) && c.isIdentifier(
|
|
417
421
|
o.left.property)) {
|
|
418
|
-
let
|
|
419
|
-
if (e._storyAnnotations[
|
|
420
|
-
c.isIdentifier(d.key) && (e._storyAnnotations[
|
|
421
|
-
}) : e._storyAnnotations[
|
|
422
|
-
let d = p.value,
|
|
423
|
-
if (!
|
|
422
|
+
let a = o.left.object.name, l = o.left.property.name, p = o.right;
|
|
423
|
+
if (e._storyAnnotations[a] && (l === "story" && c.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
424
|
+
c.isIdentifier(d.key) && (e._storyAnnotations[a][d.key.name] = d.value);
|
|
425
|
+
}) : e._storyAnnotations[a][l] = p), l === "storyName" && c.isStringLiteral(p)) {
|
|
426
|
+
let d = p.value, m = e._stories[a];
|
|
427
|
+
if (!m)
|
|
424
428
|
return;
|
|
425
|
-
|
|
429
|
+
m.name = d;
|
|
426
430
|
}
|
|
427
431
|
}
|
|
428
432
|
}
|
|
429
433
|
},
|
|
430
434
|
CallExpression: {
|
|
431
435
|
enter(t) {
|
|
432
|
-
let { node:
|
|
436
|
+
let { node: i } = t, { callee: o } = i;
|
|
433
437
|
if (c.isIdentifier(o) && o.name === "storiesOf")
|
|
434
438
|
throw new Error(O.dedent`
|
|
435
|
-
Unexpected \`storiesOf\` usage: ${
|
|
439
|
+
Unexpected \`storiesOf\` usage: ${v(i, e._options.fileName)}.
|
|
436
440
|
|
|
437
441
|
SB8 does not support \`storiesOf\`.
|
|
438
442
|
`);
|
|
439
|
-
if (c.isMemberExpression(o) && c.isIdentifier(o.property) && o.property.name === "meta" && c.isIdentifier(o.object) &&
|
|
443
|
+
if (c.isMemberExpression(o) && c.isIdentifier(o.property) && o.property.name === "meta" && c.isIdentifier(o.object) && i.arguments.
|
|
440
444
|
length > 0) {
|
|
441
|
-
let
|
|
442
|
-
if (c.isImportDeclaration(
|
|
443
|
-
if (Ke(
|
|
444
|
-
let p =
|
|
445
|
+
let l = t.scope.getBinding(o.object.name)?.path?.parentPath?.node;
|
|
446
|
+
if (c.isImportDeclaration(l))
|
|
447
|
+
if (Ke(l.source.value)) {
|
|
448
|
+
let p = i.arguments[0];
|
|
445
449
|
e._metaVariableName = o.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
446
450
|
} else
|
|
447
451
|
throw new W(
|
|
448
452
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
449
|
-
|
|
453
|
+
l,
|
|
450
454
|
e._options.fileName
|
|
451
455
|
);
|
|
452
456
|
}
|
|
@@ -454,37 +458,37 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
454
458
|
},
|
|
455
459
|
ImportDeclaration: {
|
|
456
460
|
enter({ node: t }) {
|
|
457
|
-
let { source:
|
|
458
|
-
if (c.isStringLiteral(
|
|
459
|
-
e.imports.push(
|
|
461
|
+
let { source: i } = t;
|
|
462
|
+
if (c.isStringLiteral(i))
|
|
463
|
+
e.imports.push(i.value);
|
|
460
464
|
else
|
|
461
465
|
throw new Error("CSF: unexpected import source");
|
|
462
466
|
}
|
|
463
467
|
}
|
|
464
468
|
}), !e._meta)
|
|
465
469
|
throw new q("missing default export", e._ast, e._options.fileName);
|
|
466
|
-
let
|
|
470
|
+
let r = Object.entries(e._stories);
|
|
467
471
|
if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
|
|
468
|
-
e._stories =
|
|
469
|
-
(t, [
|
|
470
|
-
if (!ne(
|
|
472
|
+
e._stories = r.reduce(
|
|
473
|
+
(t, [i, o]) => {
|
|
474
|
+
if (!ne(i, e._meta))
|
|
471
475
|
return t;
|
|
472
|
-
let
|
|
476
|
+
let a = o.parameters?.__id ?? ze(e._meta?.id || e._meta?.title, oe(i)), l = { ...o.parameters, __id: a }, { includeStories: p } = e.
|
|
473
477
|
_meta || {};
|
|
474
|
-
|
|
475
|
-
let d = e._storyAnnotations[
|
|
476
|
-
if (
|
|
477
|
-
let
|
|
478
|
-
t[
|
|
478
|
+
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (l.docsOnly = !0), t[i] = { ...o, id: a, parameters: l };
|
|
479
|
+
let d = e._storyAnnotations[i], { tags: m, play: x } = d;
|
|
480
|
+
if (m) {
|
|
481
|
+
let E = c.isIdentifier(m) ? P(m.name, this._ast.program) : m;
|
|
482
|
+
t[i].tags = le(E);
|
|
479
483
|
}
|
|
480
|
-
x && (t[
|
|
481
|
-
let b = t[
|
|
482
|
-
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((
|
|
483
|
-
b[
|
|
484
|
+
x && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
485
|
+
let b = t[i].__stats;
|
|
486
|
+
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((E) => {
|
|
487
|
+
b[E] = !!d[E] || !!e._metaAnnotations[E];
|
|
484
488
|
});
|
|
485
|
-
let y = e.getStoryExport(
|
|
489
|
+
let y = e.getStoryExport(i);
|
|
486
490
|
return b.storyFn = !!(c.isArrowFunctionExpression(y) || c.isFunctionDeclaration(y)), b.mount = Ye(d.play ?? e._metaAnnotations.play),
|
|
487
|
-
b.moduleMock = !!e.imports.find((
|
|
491
|
+
b.moduleMock = !!e.imports.find((E) => Qe(E)), t;
|
|
488
492
|
},
|
|
489
493
|
{}
|
|
490
494
|
), Object.keys(e._storyExports).forEach((t) => {
|
|
@@ -492,11 +496,11 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
492
496
|
}), e._namedExportsOrder) {
|
|
493
497
|
let t = Object.keys(e._storyExports);
|
|
494
498
|
e._storyExports = pe(e._storyExports, e._namedExportsOrder), e._stories = pe(e._stories, e._namedExportsOrder);
|
|
495
|
-
let
|
|
496
|
-
if (t.length !==
|
|
499
|
+
let i = Object.keys(e._storyExports);
|
|
500
|
+
if (t.length !== i.length)
|
|
497
501
|
throw new Error(
|
|
498
502
|
`Missing exports after sort: ${t.filter(
|
|
499
|
-
(o) => !
|
|
503
|
+
(o) => !i.includes(o)
|
|
500
504
|
)}`
|
|
501
505
|
);
|
|
502
506
|
}
|
|
@@ -515,17 +519,17 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
515
519
|
O.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
516
520
|
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
517
521
|
);
|
|
518
|
-
return Object.entries(this._stories).map(([
|
|
519
|
-
let
|
|
522
|
+
return Object.entries(this._stories).map(([r, t]) => {
|
|
523
|
+
let i = [...this._meta?.tags ?? [], ...t.tags ?? []];
|
|
520
524
|
return {
|
|
521
525
|
type: "story",
|
|
522
526
|
importPath: e,
|
|
523
527
|
rawComponentPath: this._rawComponentPath,
|
|
524
|
-
exportName:
|
|
528
|
+
exportName: r,
|
|
525
529
|
name: t.name,
|
|
526
530
|
title: this.meta?.title,
|
|
527
531
|
metaId: this.meta?.id,
|
|
528
|
-
tags:
|
|
532
|
+
tags: i,
|
|
529
533
|
__id: t.id,
|
|
530
534
|
__stats: t.__stats
|
|
531
535
|
};
|
|
@@ -534,16 +538,16 @@ var I = /* @__PURE__ */ f((s, e) => {
|
|
|
534
538
|
}, et = /* @__PURE__ */ f(({
|
|
535
539
|
code: s,
|
|
536
540
|
filename: e = "",
|
|
537
|
-
ast:
|
|
538
|
-
}) => new Be({ filename: e }, { code: s, ast:
|
|
539
|
-
let
|
|
540
|
-
return new J(
|
|
541
|
-
}, "loadCsf"),
|
|
542
|
-
let t = We(s._ast, e,
|
|
541
|
+
ast: r
|
|
542
|
+
}) => new Be({ filename: e }, { code: s, ast: r ?? fe(s) }), "babelParseFile"), Q = /* @__PURE__ */ f((s, e) => {
|
|
543
|
+
let r = fe(s), t = et({ code: s, filename: e.fileName, ast: r });
|
|
544
|
+
return new J(r, e, t);
|
|
545
|
+
}, "loadCsf"), ue = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, r) => {
|
|
546
|
+
let t = We(s._ast, e, r);
|
|
543
547
|
return e.sourceMaps ? t : t.code;
|
|
544
548
|
}, "formatCsf"), tt = /* @__PURE__ */ f((s, e = {}) => de.print(s._ast, e), "printCsf"), Ft = /* @__PURE__ */ f(async (s, e) => {
|
|
545
|
-
let
|
|
546
|
-
return Q(
|
|
549
|
+
let r = (await Ue(s, "utf-8")).toString();
|
|
550
|
+
return Q(r, { ...e, fileName: s });
|
|
547
551
|
}, "readCsf"), Ct = /* @__PURE__ */ f(async (s, e) => {
|
|
548
552
|
if (!(e || s._options.fileName))
|
|
549
553
|
throw new Error("Please specify a fileName for writeCsf");
|
|
@@ -555,7 +559,7 @@ var ye = U(V(), 1);
|
|
|
555
559
|
import { readFile as rt, writeFile as it } from "node:fs/promises";
|
|
556
560
|
import {
|
|
557
561
|
babelParse as xe,
|
|
558
|
-
generate as
|
|
562
|
+
generate as me,
|
|
559
563
|
recast as st,
|
|
560
564
|
types as n,
|
|
561
565
|
traverse as ge
|
|
@@ -563,66 +567,66 @@ import {
|
|
|
563
567
|
var H = console, Y = /* @__PURE__ */ f(({
|
|
564
568
|
expectedType: s,
|
|
565
569
|
foundType: e,
|
|
566
|
-
node:
|
|
570
|
+
node: r
|
|
567
571
|
}) => ye.dedent`
|
|
568
|
-
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${
|
|
572
|
+
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${r?.type}'.
|
|
569
573
|
`, "getCsfParsingErrorMessage"), w = /* @__PURE__ */ f((s) => n.isIdentifier(s.key) ? s.key.name : n.isStringLiteral(s.key) ? s.key.value :
|
|
570
574
|
null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSatisfiesExpression(s) ? G(s.expression) : s, "unwrap"), be = /* @__PURE__ */ f(
|
|
571
575
|
(s, e) => {
|
|
572
576
|
if (s.length === 0)
|
|
573
577
|
return e;
|
|
574
578
|
if (n.isObjectExpression(e)) {
|
|
575
|
-
let [
|
|
576
|
-
if (
|
|
577
|
-
return be(t,
|
|
579
|
+
let [r, ...t] = s, i = e.properties.find((o) => w(o) === r);
|
|
580
|
+
if (i)
|
|
581
|
+
return be(t, i.value);
|
|
578
582
|
}
|
|
579
|
-
}, "_getPath"),
|
|
583
|
+
}, "_getPath"), he = /* @__PURE__ */ f((s, e) => {
|
|
580
584
|
if (s.length === 0) {
|
|
581
585
|
if (n.isObjectExpression(e))
|
|
582
586
|
return e.properties;
|
|
583
587
|
throw new Error("Expected object expression");
|
|
584
588
|
}
|
|
585
589
|
if (n.isObjectExpression(e)) {
|
|
586
|
-
let [
|
|
587
|
-
if (
|
|
588
|
-
return t.length === 0 ? e.properties :
|
|
590
|
+
let [r, ...t] = s, i = e.properties.find((o) => w(o) === r);
|
|
591
|
+
if (i)
|
|
592
|
+
return t.length === 0 ? e.properties : he(t, i.value);
|
|
589
593
|
}
|
|
590
594
|
}, "_getPathProperties"), z = /* @__PURE__ */ f((s, e) => {
|
|
591
|
-
let
|
|
592
|
-
return e.body.find((
|
|
593
|
-
(t =
|
|
594
|
-
|
|
595
|
+
let r = null, t = null;
|
|
596
|
+
return e.body.find((i) => (n.isVariableDeclaration(i) ? t = i.declarations : n.isExportNamedDeclaration(i) && n.isVariableDeclaration(i.declaration) &&
|
|
597
|
+
(t = i.declaration.declarations), t && t.find((o) => n.isVariableDeclarator(o) && n.isIdentifier(o.id) && o.id.name === s ? (r = o, !0) : !1))),
|
|
598
|
+
r;
|
|
595
599
|
}, "_findVarDeclarator"), N = /* @__PURE__ */ f((s, e) => z(s, e)?.init, "_findVarInitialization"), R = /* @__PURE__ */ f((s, e) => {
|
|
596
600
|
if (s.length === 0)
|
|
597
601
|
return e;
|
|
598
|
-
let [
|
|
599
|
-
return n.objectExpression([n.objectProperty(n.identifier(
|
|
600
|
-
}, "_makeObjectExpression"), $ = /* @__PURE__ */ f((s, e,
|
|
601
|
-
let [t, ...
|
|
602
|
-
(
|
|
602
|
+
let [r, ...t] = s, i = R(t, e);
|
|
603
|
+
return n.objectExpression([n.objectProperty(n.identifier(r), i)]);
|
|
604
|
+
}, "_makeObjectExpression"), $ = /* @__PURE__ */ f((s, e, r) => {
|
|
605
|
+
let [t, ...i] = s, o = r.properties.find(
|
|
606
|
+
(a) => w(a) === t
|
|
603
607
|
);
|
|
604
|
-
o ? n.isObjectExpression(o.value) &&
|
|
605
|
-
n.objectProperty(n.identifier(t), R(
|
|
608
|
+
o ? n.isObjectExpression(o.value) && i.length > 0 ? $(i, e, o.value) : o.value = R(i, e) : r.properties.push(
|
|
609
|
+
n.objectProperty(n.identifier(t), R(i, e))
|
|
606
610
|
);
|
|
607
611
|
}, "_updateExportNode"), Z = class {
|
|
608
|
-
constructor(e,
|
|
612
|
+
constructor(e, r, t) {
|
|
609
613
|
this._exports = {};
|
|
610
614
|
// FIXME: this is a hack. this is only used in the case where the user is
|
|
611
615
|
// modifying a named export that's a scalar. The _exports map is not suitable
|
|
612
616
|
// for that. But rather than refactor the whole thing, we just use this as a stopgap.
|
|
613
617
|
this._exportDecls = {};
|
|
614
618
|
this.hasDefaultExport = !1;
|
|
615
|
-
this._ast = e, this._code =
|
|
619
|
+
this._ast = e, this._code = r, this.fileName = t;
|
|
616
620
|
}
|
|
617
621
|
static {
|
|
618
622
|
f(this, "ConfigFile");
|
|
619
623
|
}
|
|
620
624
|
_parseExportsObject(e) {
|
|
621
|
-
this._exportsObject = e, e.properties.forEach((
|
|
622
|
-
let t = w(
|
|
625
|
+
this._exportsObject = e, e.properties.forEach((r) => {
|
|
626
|
+
let t = w(r);
|
|
623
627
|
if (t) {
|
|
624
|
-
let
|
|
625
|
-
n.isIdentifier(
|
|
628
|
+
let i = r.value;
|
|
629
|
+
n.isIdentifier(i) && (i = N(i.name, this._ast.program)), this._exports[t] = i;
|
|
626
630
|
}
|
|
627
631
|
});
|
|
628
632
|
}
|
|
@@ -630,59 +634,59 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
630
634
|
let e = this;
|
|
631
635
|
return ge(this._ast, {
|
|
632
636
|
ExportDefaultDeclaration: {
|
|
633
|
-
enter({ node:
|
|
637
|
+
enter({ node: r, parent: t }) {
|
|
634
638
|
e.hasDefaultExport = !0;
|
|
635
|
-
let
|
|
636
|
-
|
|
637
|
-
|
|
639
|
+
let i = n.isIdentifier(r.declaration) && n.isProgram(t) ? N(r.declaration.name, t) : r.declaration;
|
|
640
|
+
i = G(i), n.isCallExpression(i) && n.isObjectExpression(i.arguments[0]) && (i = i.arguments[0]), n.isObjectExpression(i) ? e._parseExportsObject(
|
|
641
|
+
i) : H.warn(
|
|
638
642
|
Y({
|
|
639
643
|
expectedType: "ObjectExpression",
|
|
640
|
-
foundType:
|
|
641
|
-
node:
|
|
644
|
+
foundType: i?.type,
|
|
645
|
+
node: i || r.declaration
|
|
642
646
|
})
|
|
643
647
|
);
|
|
644
648
|
}
|
|
645
649
|
},
|
|
646
650
|
ExportNamedDeclaration: {
|
|
647
|
-
enter({ node:
|
|
648
|
-
if (n.isVariableDeclaration(
|
|
649
|
-
|
|
650
|
-
if (n.isVariableDeclarator(
|
|
651
|
-
let { name: o } =
|
|
652
|
-
n.isIdentifier(
|
|
651
|
+
enter({ node: r, parent: t }) {
|
|
652
|
+
if (n.isVariableDeclaration(r.declaration))
|
|
653
|
+
r.declaration.declarations.forEach((i) => {
|
|
654
|
+
if (n.isVariableDeclarator(i) && n.isIdentifier(i.id)) {
|
|
655
|
+
let { name: o } = i.id, a = i.init;
|
|
656
|
+
n.isIdentifier(a) && (a = N(a.name, t)), e._exports[o] = a, e._exportDecls[o] = i;
|
|
653
657
|
}
|
|
654
658
|
});
|
|
655
|
-
else if (n.isFunctionDeclaration(
|
|
656
|
-
let
|
|
657
|
-
if (n.isIdentifier(
|
|
658
|
-
let { name: o } =
|
|
659
|
-
e._exportDecls[o] =
|
|
659
|
+
else if (n.isFunctionDeclaration(r.declaration)) {
|
|
660
|
+
let i = r.declaration;
|
|
661
|
+
if (n.isIdentifier(i.id)) {
|
|
662
|
+
let { name: o } = i.id;
|
|
663
|
+
e._exportDecls[o] = i;
|
|
660
664
|
}
|
|
661
|
-
} else
|
|
662
|
-
if (n.isExportSpecifier(
|
|
663
|
-
let { name: o } =
|
|
664
|
-
|
|
665
|
+
} else r.specifiers ? r.specifiers.forEach((i) => {
|
|
666
|
+
if (n.isExportSpecifier(i) && n.isIdentifier(i.local) && n.isIdentifier(i.exported)) {
|
|
667
|
+
let { name: o } = i.local, { name: a } = i.exported, l = z(o, t);
|
|
668
|
+
l && (e._exports[a] = l.init, e._exportDecls[a] = l);
|
|
665
669
|
}
|
|
666
670
|
}) : H.warn(
|
|
667
671
|
Y({
|
|
668
672
|
expectedType: "VariableDeclaration",
|
|
669
|
-
foundType:
|
|
670
|
-
node:
|
|
673
|
+
foundType: r.declaration?.type,
|
|
674
|
+
node: r.declaration
|
|
671
675
|
})
|
|
672
676
|
);
|
|
673
677
|
}
|
|
674
678
|
},
|
|
675
679
|
ExpressionStatement: {
|
|
676
|
-
enter({ node:
|
|
677
|
-
if (n.isAssignmentExpression(
|
|
678
|
-
let { left:
|
|
679
|
-
if (n.isMemberExpression(
|
|
680
|
+
enter({ node: r, parent: t }) {
|
|
681
|
+
if (n.isAssignmentExpression(r.expression) && r.expression.operator === "=") {
|
|
682
|
+
let { left: i, right: o } = r.expression;
|
|
683
|
+
if (n.isMemberExpression(i) && n.isIdentifier(i.object) && i.object.name === "module" && n.isIdentifier(i.property) && i.property.
|
|
680
684
|
name === "exports") {
|
|
681
|
-
let
|
|
682
|
-
n.isIdentifier(o) && (
|
|
683
|
-
let p = w(
|
|
685
|
+
let a = o;
|
|
686
|
+
n.isIdentifier(o) && (a = N(o.name, t)), a = G(a), n.isObjectExpression(a) ? (e._exportsObject = a, a.properties.forEach((l) => {
|
|
687
|
+
let p = w(l);
|
|
684
688
|
if (p) {
|
|
685
|
-
let d =
|
|
689
|
+
let d = l.value;
|
|
686
690
|
n.isIdentifier(d) && (d = N(
|
|
687
691
|
d.name,
|
|
688
692
|
t
|
|
@@ -691,8 +695,8 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
691
695
|
})) : H.warn(
|
|
692
696
|
Y({
|
|
693
697
|
expectedType: "ObjectExpression",
|
|
694
|
-
foundType:
|
|
695
|
-
node:
|
|
698
|
+
foundType: a?.type,
|
|
699
|
+
node: a
|
|
696
700
|
})
|
|
697
701
|
);
|
|
698
702
|
}
|
|
@@ -700,27 +704,27 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
700
704
|
}
|
|
701
705
|
},
|
|
702
706
|
CallExpression: {
|
|
703
|
-
enter: /* @__PURE__ */ f(({ node:
|
|
704
|
-
n.isIdentifier(
|
|
705
|
-
e._parseExportsObject(
|
|
707
|
+
enter: /* @__PURE__ */ f(({ node: r }) => {
|
|
708
|
+
n.isIdentifier(r.callee) && r.callee.name === "definePreview" && r.arguments.length === 1 && n.isObjectExpression(r.arguments[0]) &&
|
|
709
|
+
e._parseExportsObject(r.arguments[0]);
|
|
706
710
|
}, "enter")
|
|
707
711
|
}
|
|
708
712
|
}), e;
|
|
709
713
|
}
|
|
710
714
|
getFieldNode(e) {
|
|
711
|
-
let [
|
|
712
|
-
if (
|
|
713
|
-
return be(t,
|
|
715
|
+
let [r, ...t] = e, i = this._exports[r];
|
|
716
|
+
if (i)
|
|
717
|
+
return be(t, i);
|
|
714
718
|
}
|
|
715
719
|
getFieldProperties(e) {
|
|
716
|
-
let [
|
|
717
|
-
if (
|
|
718
|
-
return
|
|
720
|
+
let [r, ...t] = e, i = this._exports[r];
|
|
721
|
+
if (i)
|
|
722
|
+
return he(t, i);
|
|
719
723
|
}
|
|
720
724
|
getFieldValue(e) {
|
|
721
|
-
let
|
|
722
|
-
if (
|
|
723
|
-
let { code: t } =
|
|
725
|
+
let r = this.getFieldNode(e);
|
|
726
|
+
if (r) {
|
|
727
|
+
let { code: t } = me(r, {});
|
|
724
728
|
return (0, eval)(`(() => (${t}))()`);
|
|
725
729
|
}
|
|
726
730
|
}
|
|
@@ -730,32 +734,32 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
730
734
|
} catch {
|
|
731
735
|
}
|
|
732
736
|
}
|
|
733
|
-
setFieldNode(e,
|
|
734
|
-
let [t, ...
|
|
737
|
+
setFieldNode(e, r) {
|
|
738
|
+
let [t, ...i] = e, o = this._exports[t];
|
|
735
739
|
if (this._exportsObject) {
|
|
736
740
|
let p = this._exportsObject.properties.find((d) => w(d) === t);
|
|
737
741
|
if (p && n.isIdentifier(p.value)) {
|
|
738
742
|
let d = z(p.value.name, this._ast.program);
|
|
739
743
|
if (d && n.isObjectExpression(d.init)) {
|
|
740
|
-
$(
|
|
744
|
+
$(i, r, d.init);
|
|
741
745
|
return;
|
|
742
746
|
}
|
|
743
747
|
}
|
|
744
|
-
$(e,
|
|
748
|
+
$(e, r, this._exportsObject), this._exports[e[0]] = r;
|
|
745
749
|
return;
|
|
746
750
|
}
|
|
747
|
-
if (o && n.isObjectExpression(o) &&
|
|
748
|
-
$(
|
|
751
|
+
if (o && n.isObjectExpression(o) && i.length > 0) {
|
|
752
|
+
$(i, r, o);
|
|
749
753
|
return;
|
|
750
754
|
}
|
|
751
|
-
let
|
|
752
|
-
if (
|
|
753
|
-
$(
|
|
755
|
+
let a = z(t, this._ast.program);
|
|
756
|
+
if (a && n.isObjectExpression(a.init)) {
|
|
757
|
+
$(i, r, a.init);
|
|
754
758
|
return;
|
|
755
759
|
}
|
|
756
|
-
if (o &&
|
|
757
|
-
let
|
|
758
|
-
n.isVariableDeclarator(
|
|
760
|
+
if (o && i.length === 0 && this._exportDecls[e[0]]) {
|
|
761
|
+
let l = this._exportDecls[e[0]];
|
|
762
|
+
n.isVariableDeclarator(l) && (l.init = R([], r));
|
|
759
763
|
} else {
|
|
760
764
|
if (this.hasDefaultExport)
|
|
761
765
|
throw new Error(
|
|
@@ -764,10 +768,10 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
764
768
|
)}" field as the default export is not an object in this file.`
|
|
765
769
|
);
|
|
766
770
|
{
|
|
767
|
-
let
|
|
768
|
-
n.variableDeclaration("const", [n.variableDeclarator(n.identifier(t),
|
|
771
|
+
let l = R(i, r), p = n.exportNamedDeclaration(
|
|
772
|
+
n.variableDeclaration("const", [n.variableDeclarator(n.identifier(t), l)])
|
|
769
773
|
);
|
|
770
|
-
this._exports[t] =
|
|
774
|
+
this._exports[t] = l, this._ast.program.body.push(p);
|
|
771
775
|
}
|
|
772
776
|
}
|
|
773
777
|
}
|
|
@@ -783,9 +787,9 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
783
787
|
* @returns The name of a node in a given path, supporting the following formats:
|
|
784
788
|
*/
|
|
785
789
|
getNameFromPath(e) {
|
|
786
|
-
let
|
|
787
|
-
if (
|
|
788
|
-
return this._getPresetValue(
|
|
790
|
+
let r = this.getFieldNode(e);
|
|
791
|
+
if (r)
|
|
792
|
+
return this._getPresetValue(r, "name");
|
|
789
793
|
}
|
|
790
794
|
/**
|
|
791
795
|
* Returns an array of names of a node in a given path, supporting the following formats:
|
|
@@ -801,19 +805,19 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
801
805
|
* ```
|
|
802
806
|
*/
|
|
803
807
|
getNamesFromPath(e) {
|
|
804
|
-
let
|
|
805
|
-
if (!
|
|
808
|
+
let r = this.getFieldNode(e);
|
|
809
|
+
if (!r)
|
|
806
810
|
return;
|
|
807
811
|
let t = [];
|
|
808
|
-
return n.isArrayExpression(
|
|
809
|
-
t.push(this._getPresetValue(
|
|
812
|
+
return n.isArrayExpression(r) && r.elements.forEach((i) => {
|
|
813
|
+
t.push(this._getPresetValue(i, "name"));
|
|
810
814
|
}), t;
|
|
811
815
|
}
|
|
812
816
|
_getPnpWrappedValue(e) {
|
|
813
817
|
if (n.isCallExpression(e)) {
|
|
814
|
-
let
|
|
815
|
-
if (n.isStringLiteral(
|
|
816
|
-
return
|
|
818
|
+
let r = e.arguments[0];
|
|
819
|
+
if (n.isStringLiteral(r))
|
|
820
|
+
return r.value;
|
|
817
821
|
}
|
|
818
822
|
}
|
|
819
823
|
/**
|
|
@@ -822,63 +826,63 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
822
826
|
* 1. `{ node: 'value' }`
|
|
823
827
|
* 2. `{ node: { fallbackProperty: 'value' } }`
|
|
824
828
|
*/
|
|
825
|
-
_getPresetValue(e,
|
|
829
|
+
_getPresetValue(e, r) {
|
|
826
830
|
let t;
|
|
827
|
-
if (n.isStringLiteral(e) ? t = e.value : n.isObjectExpression(e) ? e.properties.forEach((
|
|
828
|
-
n.isObjectProperty(
|
|
829
|
-
|
|
831
|
+
if (n.isStringLiteral(e) ? t = e.value : n.isObjectExpression(e) ? e.properties.forEach((i) => {
|
|
832
|
+
n.isObjectProperty(i) && n.isIdentifier(i.key) && i.key.name === r && (n.isStringLiteral(i.value) ? t = i.value.value : t = this._getPnpWrappedValue(
|
|
833
|
+
i.value)), n.isObjectProperty(i) && n.isStringLiteral(i.key) && i.key.value === "name" && n.isStringLiteral(i.value) && (t = i.value.value);
|
|
830
834
|
}) : n.isCallExpression(e) && (t = this._getPnpWrappedValue(e)), !t)
|
|
831
835
|
throw new Error(
|
|
832
|
-
`The given node must be a string literal or an object expression with a "${
|
|
836
|
+
`The given node must be a string literal or an object expression with a "${r}" property that is a string literal.`
|
|
833
837
|
);
|
|
834
838
|
return t;
|
|
835
839
|
}
|
|
836
840
|
removeField(e) {
|
|
837
|
-
let
|
|
838
|
-
let
|
|
839
|
-
(
|
|
841
|
+
let r = /* @__PURE__ */ f((i, o) => {
|
|
842
|
+
let a = i.findIndex(
|
|
843
|
+
(l) => n.isIdentifier(l.key) && l.key.name === o || n.isStringLiteral(l.key) && l.key.value === o
|
|
840
844
|
);
|
|
841
|
-
|
|
845
|
+
a >= 0 && i.splice(a, 1);
|
|
842
846
|
}, "removeProperty");
|
|
843
847
|
if (e.length === 1) {
|
|
844
|
-
let
|
|
848
|
+
let i = !1;
|
|
845
849
|
if (this._ast.program.body.forEach((o) => {
|
|
846
850
|
if (n.isExportNamedDeclaration(o) && n.isVariableDeclaration(o.declaration)) {
|
|
847
|
-
let
|
|
848
|
-
n.isIdentifier(
|
|
851
|
+
let a = o.declaration.declarations[0];
|
|
852
|
+
n.isIdentifier(a.id) && a.id.name === e[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(o), 1), i = !0);
|
|
849
853
|
}
|
|
850
854
|
if (n.isExportDefaultDeclaration(o)) {
|
|
851
|
-
let
|
|
852
|
-
if (n.isIdentifier(
|
|
853
|
-
let
|
|
854
|
-
|
|
855
|
+
let a = o.declaration;
|
|
856
|
+
if (n.isIdentifier(a) && (a = N(a.name, this._ast.program)), a = G(a), n.isObjectExpression(a)) {
|
|
857
|
+
let l = a.properties;
|
|
858
|
+
r(l, e[0]), i = !0;
|
|
855
859
|
}
|
|
856
860
|
}
|
|
857
861
|
if (n.isExpressionStatement(o) && n.isAssignmentExpression(o.expression) && n.isMemberExpression(o.expression.left) && n.isIdentifier(
|
|
858
862
|
o.expression.left.object) && o.expression.left.object.name === "module" && n.isIdentifier(o.expression.left.property) && o.expression.
|
|
859
863
|
left.property.name === "exports" && n.isObjectExpression(o.expression.right)) {
|
|
860
|
-
let
|
|
861
|
-
|
|
864
|
+
let a = o.expression.right.properties;
|
|
865
|
+
r(a, e[0]), i = !0;
|
|
862
866
|
}
|
|
863
|
-
}),
|
|
867
|
+
}), i)
|
|
864
868
|
return;
|
|
865
869
|
}
|
|
866
870
|
let t = this.getFieldProperties(e);
|
|
867
871
|
if (t) {
|
|
868
|
-
let
|
|
869
|
-
|
|
872
|
+
let i = e.at(-1);
|
|
873
|
+
r(t, i);
|
|
870
874
|
}
|
|
871
875
|
}
|
|
872
|
-
appendValueToArray(e,
|
|
873
|
-
let t = this.valueToNode(
|
|
876
|
+
appendValueToArray(e, r) {
|
|
877
|
+
let t = this.valueToNode(r);
|
|
874
878
|
t && this.appendNodeToArray(e, t);
|
|
875
879
|
}
|
|
876
|
-
appendNodeToArray(e,
|
|
880
|
+
appendNodeToArray(e, r) {
|
|
877
881
|
let t = this.getFieldNode(e);
|
|
878
882
|
if (!t)
|
|
879
|
-
this.setFieldNode(e, n.arrayExpression([
|
|
883
|
+
this.setFieldNode(e, n.arrayExpression([r]));
|
|
880
884
|
else if (n.isArrayExpression(t))
|
|
881
|
-
t.elements.push(
|
|
885
|
+
t.elements.push(r);
|
|
882
886
|
else
|
|
883
887
|
throw new Error(`Expected array at '${e.join(".")}', got '${t.type}'`);
|
|
884
888
|
}
|
|
@@ -886,23 +890,23 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
886
890
|
* Specialized helper to remove addons or other array entries that can either be strings or
|
|
887
891
|
* objects with a name property.
|
|
888
892
|
*/
|
|
889
|
-
removeEntryFromArray(e,
|
|
893
|
+
removeEntryFromArray(e, r) {
|
|
890
894
|
let t = this.getFieldNode(e);
|
|
891
895
|
if (t)
|
|
892
896
|
if (n.isArrayExpression(t)) {
|
|
893
|
-
let
|
|
894
|
-
|
|
895
|
-
if (
|
|
896
|
-
t.elements.splice(
|
|
897
|
+
let i = t.elements.findIndex((o) => n.isStringLiteral(o) ? o.value === r : n.isObjectExpression(o) ? this._getPresetValue(o, "name") ===
|
|
898
|
+
r : this._getPnpWrappedValue(o) === r);
|
|
899
|
+
if (i >= 0)
|
|
900
|
+
t.elements.splice(i, 1);
|
|
897
901
|
else
|
|
898
|
-
throw new Error(`Could not find '${
|
|
902
|
+
throw new Error(`Could not find '${r}' in array at '${e.join(".")}'`);
|
|
899
903
|
} else
|
|
900
904
|
throw new Error(`Expected array at '${e.join(".")}', got '${t.type}'`);
|
|
901
905
|
}
|
|
902
906
|
_inferQuotes() {
|
|
903
907
|
if (!this._quotes) {
|
|
904
908
|
let e = (this._ast.tokens || []).slice(0, 500).reduce(
|
|
905
|
-
(
|
|
909
|
+
(r, t) => (t.type.label === "string" && (r[this._code[t.start]] += 1), r),
|
|
906
910
|
{ "'": 0, '"': 0 }
|
|
907
911
|
);
|
|
908
912
|
this._quotes = e["'"] > e['"'] ? "single" : "double";
|
|
@@ -910,14 +914,14 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
910
914
|
return this._quotes;
|
|
911
915
|
}
|
|
912
916
|
valueToNode(e) {
|
|
913
|
-
let
|
|
914
|
-
if (
|
|
915
|
-
let { code:
|
|
917
|
+
let r = this._inferQuotes(), t;
|
|
918
|
+
if (r === "single") {
|
|
919
|
+
let { code: i } = me(n.valueToNode(e), { jsescOption: { quotes: r } }), o = xe(`const __x = ${i}`);
|
|
916
920
|
ge(o, {
|
|
917
921
|
VariableDeclaration: {
|
|
918
|
-
enter({ node:
|
|
919
|
-
|
|
920
|
-
id.name === "__x" && (t =
|
|
922
|
+
enter({ node: a }) {
|
|
923
|
+
a.declarations.length === 1 && n.isVariableDeclarator(a.declarations[0]) && n.isIdentifier(a.declarations[0].id) && a.declarations[0].
|
|
924
|
+
id.name === "__x" && (t = a.declarations[0].init);
|
|
921
925
|
}
|
|
922
926
|
}
|
|
923
927
|
});
|
|
@@ -925,10 +929,10 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
925
929
|
t = n.valueToNode(e);
|
|
926
930
|
return t;
|
|
927
931
|
}
|
|
928
|
-
setFieldValue(e,
|
|
929
|
-
let t = this.valueToNode(
|
|
932
|
+
setFieldValue(e, r) {
|
|
933
|
+
let t = this.valueToNode(r);
|
|
930
934
|
if (!t)
|
|
931
|
-
throw new Error(`Unexpected value ${JSON.stringify(
|
|
935
|
+
throw new Error(`Unexpected value ${JSON.stringify(r)}`);
|
|
932
936
|
this.setFieldNode(e, t);
|
|
933
937
|
}
|
|
934
938
|
getBodyDeclarations() {
|
|
@@ -954,40 +958,42 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
954
958
|
* import will be set. Otherwise, an array of named imports will be set
|
|
955
959
|
* @param fromImport - The module to import from
|
|
956
960
|
*/
|
|
957
|
-
setRequireImport(e,
|
|
958
|
-
let t = this._ast.program.body.find(
|
|
959
|
-
|
|
960
|
-
declarations[0].init) && n.isIdentifier(
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
),
|
|
965
|
-
|
|
961
|
+
setRequireImport(e, r) {
|
|
962
|
+
let t = this._ast.program.body.find((a) => {
|
|
963
|
+
let l = n.isVariableDeclaration(a) && a.declarations.length === 1 && n.isVariableDeclarator(a.declarations[0]) && n.isCallExpression(a.
|
|
964
|
+
declarations[0].init) && n.isIdentifier(a.declarations[0].init.callee) && a.declarations[0].init.callee.name === "require" && n.isStringLiteral(
|
|
965
|
+
a.declarations[0].init.arguments[0]) && (a.declarations[0].init.arguments[0].value === r || a.declarations[0].init.arguments[0].value ===
|
|
966
|
+
r.split("node:")[1]);
|
|
967
|
+
return l && (r = a.declarations[0].init.arguments[0].value), l;
|
|
968
|
+
}), i = /* @__PURE__ */ f((a) => n.isObjectPattern(t?.declarations[0].id) && t?.declarations[0].id.properties.find(
|
|
969
|
+
(l) => n.isObjectProperty(l) && n.isIdentifier(l.key) && l.key.name === a
|
|
970
|
+
), "hasRequireSpecifier"), o = /* @__PURE__ */ f((a, l) => a.declarations.length === 1 && n.isVariableDeclarator(a.declarations[0]) && n.
|
|
971
|
+
isIdentifier(a.declarations[0].id) && a.declarations[0].id.name === l, "hasDefaultRequireSpecifier");
|
|
966
972
|
if (typeof e == "string") {
|
|
967
|
-
let
|
|
973
|
+
let a = /* @__PURE__ */ f(() => {
|
|
968
974
|
this._ast.program.body.unshift(
|
|
969
975
|
n.variableDeclaration("const", [
|
|
970
976
|
n.variableDeclarator(
|
|
971
977
|
n.identifier(e),
|
|
972
|
-
n.callExpression(n.identifier("require"), [n.stringLiteral(
|
|
978
|
+
n.callExpression(n.identifier("require"), [n.stringLiteral(r)])
|
|
973
979
|
)
|
|
974
980
|
])
|
|
975
981
|
);
|
|
976
982
|
}, "addDefaultRequireSpecifier");
|
|
977
|
-
t && o(t, e) ||
|
|
978
|
-
} else t ? e.forEach((
|
|
979
|
-
|
|
980
|
-
n.objectProperty(n.identifier(
|
|
983
|
+
t && o(t, e) || a();
|
|
984
|
+
} else t ? e.forEach((a) => {
|
|
985
|
+
i(a) || t.declarations[0].id.properties.push(
|
|
986
|
+
n.objectProperty(n.identifier(a), n.identifier(a), void 0, !0)
|
|
981
987
|
);
|
|
982
988
|
}) : this._ast.program.body.unshift(
|
|
983
989
|
n.variableDeclaration("const", [
|
|
984
990
|
n.variableDeclarator(
|
|
985
991
|
n.objectPattern(
|
|
986
992
|
e.map(
|
|
987
|
-
(
|
|
993
|
+
(a) => n.objectProperty(n.identifier(a), n.identifier(a), void 0, !0)
|
|
988
994
|
)
|
|
989
995
|
),
|
|
990
|
-
n.callExpression(n.identifier("require"), [n.stringLiteral(
|
|
996
|
+
n.callExpression(n.identifier("require"), [n.stringLiteral(r)])
|
|
991
997
|
)
|
|
992
998
|
])
|
|
993
999
|
);
|
|
@@ -1017,78 +1023,79 @@ null, "propKey"), G = /* @__PURE__ */ f((s) => n.isTSAsExpression(s) || n.isTSSa
|
|
|
1017
1023
|
* import will be set. Otherwise, an array of named imports will be set
|
|
1018
1024
|
* @param fromImport - The module to import from
|
|
1019
1025
|
*/
|
|
1020
|
-
setImport(e,
|
|
1021
|
-
let t =
|
|
1026
|
+
setImport(e, r) {
|
|
1027
|
+
let t = this._ast.program.body.find((p) => {
|
|
1028
|
+
let d = n.isImportDeclaration(p) && (p.source.value === r || p.source.value === r.split("node:")[1]);
|
|
1029
|
+
return d && (r = p.source.value), d;
|
|
1030
|
+
}), i = /* @__PURE__ */ f((p) => n.importSpecifier(n.identifier(p), n.identifier(p)), "getNewImportSpecifier"), o = /* @__PURE__ */ f((p, d) => p.
|
|
1022
1031
|
specifiers.find(
|
|
1023
|
-
(
|
|
1024
|
-
), "hasImportSpecifier"),
|
|
1025
|
-
(
|
|
1026
|
-
), "hasNamespaceImportSpecifier")
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
(
|
|
1030
|
-
)
|
|
1031
|
-
e === null ? a || this._ast.program.body.unshift(n.importDeclaration([], n.stringLiteral(i))) : typeof e == "string" ? a ? l(a, e) || a.
|
|
1032
|
-
specifiers.push(
|
|
1032
|
+
(m) => n.isImportSpecifier(m) && n.isIdentifier(m.imported) && m.imported.name === d
|
|
1033
|
+
), "hasImportSpecifier"), a = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1034
|
+
(m) => n.isImportNamespaceSpecifier(m) && n.isIdentifier(m.local) && m.local.name === d
|
|
1035
|
+
), "hasNamespaceImportSpecifier");
|
|
1036
|
+
e === null ? t || this._ast.program.body.unshift(n.importDeclaration([], n.stringLiteral(r))) : typeof e == "string" ? t ? (/* @__PURE__ */ f(
|
|
1037
|
+
(p, d) => p.specifiers.find(
|
|
1038
|
+
(m) => n.isImportDefaultSpecifier(m) && n.isIdentifier(m.local) && m.local.name === d
|
|
1039
|
+
), "hasDefaultImportSpecifier"))(t, e) || t.specifiers.push(
|
|
1033
1040
|
n.importDefaultSpecifier(n.identifier(e))
|
|
1034
1041
|
) : this._ast.program.body.unshift(
|
|
1035
1042
|
n.importDeclaration(
|
|
1036
1043
|
[n.importDefaultSpecifier(n.identifier(e))],
|
|
1037
|
-
n.stringLiteral(
|
|
1044
|
+
n.stringLiteral(r)
|
|
1038
1045
|
)
|
|
1039
|
-
) : Array.isArray(e) ?
|
|
1040
|
-
|
|
1046
|
+
) : Array.isArray(e) ? t ? e.forEach((p) => {
|
|
1047
|
+
o(t, p) || t.specifiers.push(i(p));
|
|
1041
1048
|
}) : this._ast.program.body.unshift(
|
|
1042
1049
|
n.importDeclaration(
|
|
1043
|
-
e.map(
|
|
1044
|
-
n.stringLiteral(
|
|
1050
|
+
e.map(i),
|
|
1051
|
+
n.stringLiteral(r)
|
|
1045
1052
|
)
|
|
1046
|
-
) : e.namespace && (
|
|
1053
|
+
) : e.namespace && (t ? a(t, e.namespace) || t.specifiers.push(
|
|
1047
1054
|
n.importNamespaceSpecifier(n.identifier(e.namespace))
|
|
1048
1055
|
) : this._ast.program.body.unshift(
|
|
1049
1056
|
n.importDeclaration(
|
|
1050
1057
|
[n.importNamespaceSpecifier(n.identifier(e.namespace))],
|
|
1051
|
-
n.stringLiteral(
|
|
1058
|
+
n.stringLiteral(r)
|
|
1052
1059
|
)
|
|
1053
1060
|
));
|
|
1054
1061
|
}
|
|
1055
1062
|
}, nt = /* @__PURE__ */ f((s, e) => {
|
|
1056
|
-
let
|
|
1057
|
-
return new Z(
|
|
1063
|
+
let r = xe(s);
|
|
1064
|
+
return new Z(r, s, e);
|
|
1058
1065
|
}, "loadConfig"), ot = /* @__PURE__ */ f((s) => at(s).code, "formatConfig"), at = /* @__PURE__ */ f((s, e = {}) => st.print(s._ast, e), "pri\
|
|
1059
1066
|
ntConfig"), $t = /* @__PURE__ */ f(async (s) => {
|
|
1060
1067
|
let e = (await rt(s, "utf-8")).toString();
|
|
1061
1068
|
return nt(e, s).parse();
|
|
1062
1069
|
}, "readConfig"), Rt = /* @__PURE__ */ f(async (s, e) => {
|
|
1063
|
-
let
|
|
1064
|
-
if (!
|
|
1070
|
+
let r = e || s.fileName;
|
|
1071
|
+
if (!r)
|
|
1065
1072
|
throw new Error("Please specify a fileName for writeConfig");
|
|
1066
|
-
await it(
|
|
1067
|
-
}, "writeConfig"), Lt = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((
|
|
1068
|
-
rybook") &&
|
|
1073
|
+
await it(r, ot(s));
|
|
1074
|
+
}, "writeConfig"), Lt = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((r) => n.isImportDeclaration(r) && r.source.value.includes("@sto\
|
|
1075
|
+
rybook") && r.specifiers.some((t) => n.isImportSpecifier(t) && n.isIdentifier(t.imported) && t.imported.name === "definePreview")), "isCsfFa\
|
|
1069
1076
|
ctoryPreview");
|
|
1070
1077
|
|
|
1071
1078
|
// src/csf-tools/getStorySortParameter.ts
|
|
1072
1079
|
var je = U(V(), 1);
|
|
1073
|
-
import { babelParse as lt, generate as
|
|
1080
|
+
import { babelParse as lt, generate as Ee, types as h, traverse as ct } from "storybook/internal/babel";
|
|
1074
1081
|
var pt = console, ee = /* @__PURE__ */ f((s, e) => {
|
|
1075
|
-
let
|
|
1082
|
+
let r;
|
|
1076
1083
|
return s.properties.forEach((t) => {
|
|
1077
|
-
|
|
1078
|
-
}),
|
|
1084
|
+
h.isIdentifier(t.key) && t.key.name === e && (r = t.value);
|
|
1085
|
+
}), r;
|
|
1079
1086
|
}, "getValue"), te = /* @__PURE__ */ f((s) => {
|
|
1080
1087
|
let e = L(s);
|
|
1081
|
-
if (
|
|
1082
|
-
return e.elements.map((
|
|
1083
|
-
if (
|
|
1084
|
-
return e.properties.reduce((
|
|
1085
|
-
if (
|
|
1088
|
+
if (h.isArrayExpression(e))
|
|
1089
|
+
return e.elements.map((r) => te(r));
|
|
1090
|
+
if (h.isObjectExpression(e))
|
|
1091
|
+
return e.properties.reduce((r, t) => (h.isIdentifier(t.key) && (r[t.key.name] = te(t.value)), r), {});
|
|
1092
|
+
if (h.isLiteral(e))
|
|
1086
1093
|
return e.value;
|
|
1087
|
-
if (
|
|
1094
|
+
if (h.isIdentifier(e))
|
|
1088
1095
|
return F(e.name, !0);
|
|
1089
1096
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1090
1097
|
}, "parseValue"), F = /* @__PURE__ */ f((s, e) => {
|
|
1091
|
-
let
|
|
1098
|
+
let r = je.dedent`
|
|
1092
1099
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1093
1100
|
|
|
1094
1101
|
export default {
|
|
@@ -1100,159 +1107,159 @@ var pt = console, ee = /* @__PURE__ */ f((s, e) => {
|
|
|
1100
1107
|
};
|
|
1101
1108
|
`;
|
|
1102
1109
|
if (e)
|
|
1103
|
-
throw new Error(
|
|
1104
|
-
pt.info(
|
|
1105
|
-
}, "unsupported"), L = /* @__PURE__ */ f((s) =>
|
|
1110
|
+
throw new Error(r);
|
|
1111
|
+
pt.info(r);
|
|
1112
|
+
}, "unsupported"), L = /* @__PURE__ */ f((s) => h.isTSAsExpression(s) || h.isTSSatisfiesExpression(s) ? s.expression : s, "stripTSModifiers"),
|
|
1106
1113
|
Se = /* @__PURE__ */ f((s) => {
|
|
1107
1114
|
let e = L(s);
|
|
1108
|
-
if (
|
|
1109
|
-
let
|
|
1110
|
-
if (
|
|
1111
|
-
if (
|
|
1112
|
-
return ee(
|
|
1115
|
+
if (h.isObjectExpression(e)) {
|
|
1116
|
+
let r = ee(e, "options");
|
|
1117
|
+
if (r) {
|
|
1118
|
+
if (h.isObjectExpression(r))
|
|
1119
|
+
return ee(r, "storySort");
|
|
1113
1120
|
F("options", !0);
|
|
1114
1121
|
}
|
|
1115
1122
|
}
|
|
1116
1123
|
}, "parseParameters"), _e = /* @__PURE__ */ f((s, e) => {
|
|
1117
|
-
let
|
|
1118
|
-
if (
|
|
1119
|
-
let t = ee(
|
|
1120
|
-
if (
|
|
1124
|
+
let r = L(s);
|
|
1125
|
+
if (h.isObjectExpression(r)) {
|
|
1126
|
+
let t = ee(r, "parameters");
|
|
1127
|
+
if (h.isIdentifier(t) && (t = P(t.name, e)), t)
|
|
1121
1128
|
return Se(t);
|
|
1122
1129
|
} else
|
|
1123
1130
|
F("default", !0);
|
|
1124
1131
|
}, "parseDefault"), Wt = /* @__PURE__ */ f((s) => {
|
|
1125
1132
|
if (!s.includes("storySort"))
|
|
1126
1133
|
return;
|
|
1127
|
-
let e,
|
|
1128
|
-
if (ct(
|
|
1134
|
+
let e, r = lt(s);
|
|
1135
|
+
if (ct(r, {
|
|
1129
1136
|
ExportNamedDeclaration: {
|
|
1130
1137
|
enter({ node: t }) {
|
|
1131
|
-
|
|
1132
|
-
if (
|
|
1133
|
-
let { name: o } =
|
|
1134
|
-
if (o === "parameters" &&
|
|
1135
|
-
let
|
|
1136
|
-
e = Se(
|
|
1138
|
+
h.isVariableDeclaration(t.declaration) ? t.declaration.declarations.forEach((i) => {
|
|
1139
|
+
if (h.isVariableDeclarator(i) && h.isIdentifier(i.id)) {
|
|
1140
|
+
let { name: o } = i.id;
|
|
1141
|
+
if (o === "parameters" && i.init) {
|
|
1142
|
+
let a = L(i.init);
|
|
1143
|
+
e = Se(a);
|
|
1137
1144
|
}
|
|
1138
1145
|
}
|
|
1139
|
-
}) : t.specifiers.forEach((
|
|
1140
|
-
|
|
1146
|
+
}) : t.specifiers.forEach((i) => {
|
|
1147
|
+
h.isIdentifier(i.exported) && i.exported.name === "parameters" && F("parameters", !1);
|
|
1141
1148
|
});
|
|
1142
1149
|
}
|
|
1143
1150
|
},
|
|
1144
1151
|
ExportDefaultDeclaration: {
|
|
1145
1152
|
enter({ node: t }) {
|
|
1146
|
-
let
|
|
1147
|
-
|
|
1148
|
-
|
|
1153
|
+
let i = t.declaration;
|
|
1154
|
+
h.isIdentifier(i) && (i = P(i.name, r.program)), i = L(i), h.isCallExpression(i) && h.isObjectExpression(i.arguments?.[0]) ? e = _e(
|
|
1155
|
+
i.arguments[0], r.program) : h.isObjectExpression(i) ? e = _e(i, r.program) : F("default", !1);
|
|
1149
1156
|
}
|
|
1150
1157
|
}
|
|
1151
1158
|
}), !!e) {
|
|
1152
|
-
if (
|
|
1153
|
-
let { code: t } =
|
|
1159
|
+
if (h.isArrowFunctionExpression(e)) {
|
|
1160
|
+
let { code: t } = Ee(e, {});
|
|
1154
1161
|
return (0, eval)(t);
|
|
1155
1162
|
}
|
|
1156
|
-
if (
|
|
1157
|
-
let { code: t } =
|
|
1163
|
+
if (h.isFunctionExpression(e)) {
|
|
1164
|
+
let { code: t } = Ee(e, {}), i = e.id?.name, o = `(a, b) => {
|
|
1158
1165
|
${t};
|
|
1159
|
-
return ${
|
|
1166
|
+
return ${i}(a, b)
|
|
1160
1167
|
}`;
|
|
1161
1168
|
return (0, eval)(o);
|
|
1162
1169
|
}
|
|
1163
|
-
return
|
|
1170
|
+
return h.isLiteral(e) || h.isArrayExpression(e) || h.isObjectExpression(e) ? te(e) : F("storySort", !0);
|
|
1164
1171
|
}
|
|
1165
1172
|
}, "getStorySortParameter");
|
|
1166
1173
|
|
|
1167
1174
|
// src/csf-tools/enrichCsf.ts
|
|
1168
|
-
import { generate as ft, types as
|
|
1169
|
-
var dt = /* @__PURE__ */ f((s, e,
|
|
1170
|
-
let
|
|
1171
|
-
name === "meta",
|
|
1172
|
-
|
|
1173
|
-
p.push(
|
|
1174
|
-
let x =
|
|
1175
|
-
|
|
1176
|
-
|
|
1175
|
+
import { generate as ft, types as g } from "storybook/internal/babel";
|
|
1176
|
+
var dt = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1177
|
+
let i = e.getStoryExport(r), o = g.isCallExpression(i) && g.isMemberExpression(i.callee) && g.isIdentifier(i.callee.object) && i.callee.object.
|
|
1178
|
+
name === "meta", a = !t?.disableSource && mt(i), l = !t?.disableDescription && Oe(e._storyStatements[r]), p = [], d = o ? g.memberExpression(
|
|
1179
|
+
g.identifier(r), g.identifier("input")) : g.identifier(r), m = g.memberExpression(d, g.identifier("parameters"));
|
|
1180
|
+
p.push(g.spreadElement(m));
|
|
1181
|
+
let x = g.optionalMemberExpression(
|
|
1182
|
+
m,
|
|
1183
|
+
g.identifier("docs"),
|
|
1177
1184
|
!1,
|
|
1178
1185
|
!0
|
|
1179
1186
|
), b = [];
|
|
1180
|
-
if (
|
|
1181
|
-
let y =
|
|
1187
|
+
if (a) {
|
|
1188
|
+
let y = g.optionalMemberExpression(
|
|
1182
1189
|
x,
|
|
1183
|
-
|
|
1190
|
+
g.identifier("source"),
|
|
1184
1191
|
!1,
|
|
1185
1192
|
!0
|
|
1186
1193
|
);
|
|
1187
1194
|
b.push(
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1195
|
+
g.objectProperty(
|
|
1196
|
+
g.identifier("source"),
|
|
1197
|
+
g.objectExpression([
|
|
1198
|
+
g.objectProperty(g.identifier("originalSource"), g.stringLiteral(a)),
|
|
1199
|
+
g.spreadElement(y)
|
|
1193
1200
|
])
|
|
1194
1201
|
)
|
|
1195
1202
|
);
|
|
1196
1203
|
}
|
|
1197
|
-
if (
|
|
1198
|
-
let y =
|
|
1204
|
+
if (l) {
|
|
1205
|
+
let y = g.optionalMemberExpression(
|
|
1199
1206
|
x,
|
|
1200
|
-
|
|
1207
|
+
g.identifier("description"),
|
|
1201
1208
|
!1,
|
|
1202
1209
|
!0
|
|
1203
1210
|
);
|
|
1204
1211
|
b.push(
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1212
|
+
g.objectProperty(
|
|
1213
|
+
g.identifier("description"),
|
|
1214
|
+
g.objectExpression([
|
|
1215
|
+
g.objectProperty(g.identifier("story"), g.stringLiteral(l)),
|
|
1216
|
+
g.spreadElement(y)
|
|
1210
1217
|
])
|
|
1211
1218
|
)
|
|
1212
1219
|
);
|
|
1213
1220
|
}
|
|
1214
1221
|
if (b.length > 0) {
|
|
1215
1222
|
p.push(
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1223
|
+
g.objectProperty(
|
|
1224
|
+
g.identifier("docs"),
|
|
1225
|
+
g.objectExpression([g.spreadElement(x), ...b])
|
|
1219
1226
|
)
|
|
1220
1227
|
);
|
|
1221
|
-
let y =
|
|
1222
|
-
|
|
1228
|
+
let y = g.expressionStatement(
|
|
1229
|
+
g.assignmentExpression("=", m, g.objectExpression(p))
|
|
1223
1230
|
);
|
|
1224
1231
|
s._ast.program.body.push(y);
|
|
1225
1232
|
}
|
|
1226
|
-
}, "enrichCsfStory"), Pe = /* @__PURE__ */ f((s, e,
|
|
1233
|
+
}, "enrichCsfStory"), Pe = /* @__PURE__ */ f((s, e, r) => {
|
|
1227
1234
|
if (!e.length) {
|
|
1228
1235
|
s.properties.find(
|
|
1229
|
-
(p) =>
|
|
1230
|
-
) || s.properties.unshift(
|
|
1236
|
+
(p) => g.isObjectProperty(p) && g.isIdentifier(p.key) && p.key.name === "component"
|
|
1237
|
+
) || s.properties.unshift(r);
|
|
1231
1238
|
return;
|
|
1232
1239
|
}
|
|
1233
|
-
let [t, ...
|
|
1234
|
-
(
|
|
1235
|
-
),
|
|
1236
|
-
o ?
|
|
1237
|
-
}, "addComponentDescription"),
|
|
1238
|
-
let t = !
|
|
1240
|
+
let [t, ...i] = e, o = s.properties.find(
|
|
1241
|
+
(l) => g.isObjectProperty(l) && g.isIdentifier(l.key) && l.key.name === t && g.isObjectExpression(l.value)
|
|
1242
|
+
), a;
|
|
1243
|
+
o ? a = o.value : (a = g.objectExpression([]), s.properties.push(g.objectProperty(g.identifier(t), a))), Pe(a, i, r);
|
|
1244
|
+
}, "addComponentDescription"), ut = /* @__PURE__ */ f((s, e, r) => {
|
|
1245
|
+
let t = !r?.disableDescription && Oe(e._metaStatement);
|
|
1239
1246
|
if (t) {
|
|
1240
|
-
let
|
|
1241
|
-
|
|
1242
|
-
|
|
1247
|
+
let i = s._metaNode;
|
|
1248
|
+
i && g.isObjectExpression(i) && Pe(
|
|
1249
|
+
i,
|
|
1243
1250
|
["parameters", "docs", "description"],
|
|
1244
|
-
|
|
1251
|
+
g.objectProperty(g.identifier("component"), g.stringLiteral(t))
|
|
1245
1252
|
);
|
|
1246
1253
|
}
|
|
1247
|
-
}, "enrichCsfMeta"), Kt = /* @__PURE__ */ f((s, e,
|
|
1248
|
-
|
|
1249
|
-
dt(s, e, t,
|
|
1254
|
+
}, "enrichCsfMeta"), Kt = /* @__PURE__ */ f((s, e, r) => {
|
|
1255
|
+
ut(s, e, r), Object.keys(s._storyExports).forEach((t) => {
|
|
1256
|
+
dt(s, e, t, r);
|
|
1250
1257
|
});
|
|
1251
|
-
}, "enrichCsf"),
|
|
1252
|
-
let e =
|
|
1253
|
-
return
|
|
1254
|
-
}, "extractSource"), Oe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((
|
|
1255
|
-
"*") ? null :
|
|
1258
|
+
}, "enrichCsf"), mt = /* @__PURE__ */ f((s) => {
|
|
1259
|
+
let e = g.isVariableDeclarator(s) ? s.init : s, { code: r } = ft(e, {});
|
|
1260
|
+
return r;
|
|
1261
|
+
}, "extractSource"), Oe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((r) => r.type === "CommentLine" || !r.value.startsWith(
|
|
1262
|
+
"*") ? null : r.value.split(`
|
|
1256
1263
|
`).map((t) => t.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
|
|
1257
1264
|
`).trim()).filter(Boolean).join(`
|
|
1258
1265
|
`) : "", "extractDescription");
|
|
@@ -1262,42 +1269,42 @@ import { babelParse as cr } from "storybook/internal/babel";
|
|
|
1262
1269
|
|
|
1263
1270
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1264
1271
|
var re = U(V(), 1);
|
|
1265
|
-
import { types as
|
|
1272
|
+
import { types as u } from "storybook/internal/babel";
|
|
1266
1273
|
import { getStoryTitle as gt } from "storybook/internal/common";
|
|
1267
1274
|
import { combineTags as xt } from "storybook/internal/csf";
|
|
1268
|
-
var
|
|
1269
|
-
includes(
|
|
1275
|
+
var ve = console, yt = /* @__PURE__ */ f((s, e) => !(e.include.length && !e.include.some((r) => s?.includes(r)) || e.exclude.some((r) => s?.
|
|
1276
|
+
includes(r))), "isValidTest");
|
|
1270
1277
|
async function bt({
|
|
1271
1278
|
code: s,
|
|
1272
1279
|
fileName: e,
|
|
1273
|
-
configDir:
|
|
1280
|
+
configDir: r,
|
|
1274
1281
|
stories: t,
|
|
1275
|
-
tagsFilter:
|
|
1282
|
+
tagsFilter: i,
|
|
1276
1283
|
previewLevelTags: o = []
|
|
1277
1284
|
}) {
|
|
1278
1285
|
if (!/\.stor(y|ies)\./.test(e))
|
|
1279
1286
|
return s;
|
|
1280
|
-
let
|
|
1287
|
+
let l = Q(s, {
|
|
1281
1288
|
fileName: e,
|
|
1282
1289
|
transformInlineMeta: !0,
|
|
1283
1290
|
makeTitle: /* @__PURE__ */ f((_) => {
|
|
1284
1291
|
let S = gt({
|
|
1285
1292
|
storyFilePath: e,
|
|
1286
|
-
configDir:
|
|
1293
|
+
configDir: r,
|
|
1287
1294
|
stories: t,
|
|
1288
1295
|
userTitle: _
|
|
1289
1296
|
}) || "unknown";
|
|
1290
|
-
return S === "unknown" &&
|
|
1297
|
+
return S === "unknown" && ve.warn(
|
|
1291
1298
|
re.dedent`
|
|
1292
1299
|
[Storybook]: Could not calculate story title for "${e}".
|
|
1293
|
-
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${
|
|
1300
|
+
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${r}".
|
|
1294
1301
|
`
|
|
1295
1302
|
), S;
|
|
1296
1303
|
}, "makeTitle")
|
|
1297
|
-
}).parse(), p =
|
|
1298
|
-
(_) =>
|
|
1299
|
-
), b =
|
|
1300
|
-
if (x ?
|
|
1304
|
+
}).parse(), p = l._ast, d = l._metaVariableName, m = l._metaNode, x = m.properties.find(
|
|
1305
|
+
(_) => u.isObjectProperty(_) && u.isIdentifier(_.key) && _.key.name === "title"
|
|
1306
|
+
), b = u.stringLiteral(l._meta?.title || "unknown");
|
|
1307
|
+
if (x ? u.isObjectProperty(x) && (x.value = b) : m.properties.push(u.objectProperty(u.identifier("title"), b)), !m || !l._meta)
|
|
1301
1308
|
throw new Error(
|
|
1302
1309
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
1303
1310
|
|
|
@@ -1305,90 +1312,90 @@ Please make sure you have a default export with the meta object. If you are usin
|
|
|
1305
1312
|
le an issue with details about your use case.`
|
|
1306
1313
|
);
|
|
1307
1314
|
let y = {};
|
|
1308
|
-
Object.keys(
|
|
1315
|
+
Object.keys(l._stories).map((_) => {
|
|
1309
1316
|
let S = xt(
|
|
1310
1317
|
"test",
|
|
1311
1318
|
"dev",
|
|
1312
1319
|
...o,
|
|
1313
|
-
...
|
|
1314
|
-
...
|
|
1320
|
+
...l.meta?.tags || [],
|
|
1321
|
+
...l._stories[_].tags || []
|
|
1315
1322
|
);
|
|
1316
|
-
yt(S,
|
|
1323
|
+
yt(S, i) && (y[_] = l._storyStatements[_]);
|
|
1317
1324
|
});
|
|
1318
|
-
let
|
|
1325
|
+
let E = l._file.path.scope.generateUidIdentifier("test"), D = l._file.path.scope.generateUidIdentifier("describe");
|
|
1319
1326
|
if (Object.keys(y).length === 0) {
|
|
1320
|
-
let _ =
|
|
1321
|
-
|
|
1322
|
-
|
|
1327
|
+
let _ = u.expressionStatement(
|
|
1328
|
+
u.callExpression(u.memberExpression(D, u.identifier("skip")), [
|
|
1329
|
+
u.stringLiteral("No valid tests found")
|
|
1323
1330
|
])
|
|
1324
1331
|
);
|
|
1325
1332
|
p.program.body.push(_);
|
|
1326
1333
|
let S = [
|
|
1327
|
-
|
|
1334
|
+
u.importDeclaration(
|
|
1328
1335
|
[
|
|
1329
|
-
|
|
1330
|
-
|
|
1336
|
+
u.importSpecifier(E, u.identifier("test")),
|
|
1337
|
+
u.importSpecifier(D, u.identifier("describe"))
|
|
1331
1338
|
],
|
|
1332
|
-
|
|
1339
|
+
u.stringLiteral("vitest")
|
|
1333
1340
|
)
|
|
1334
1341
|
];
|
|
1335
1342
|
p.program.body.unshift(...S);
|
|
1336
1343
|
} else {
|
|
1337
1344
|
let ie = function() {
|
|
1338
|
-
let j =
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
), C =
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
), T =
|
|
1345
|
+
let j = l._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), I = u.memberExpression(
|
|
1346
|
+
u.callExpression(u.memberExpression(_, u.identifier("getState")), []),
|
|
1347
|
+
u.identifier("testPath")
|
|
1348
|
+
), C = u.memberExpression(
|
|
1349
|
+
u.memberExpression(u.identifier("globalThis"), u.identifier("__vitest_worker__")),
|
|
1350
|
+
u.identifier("filepath")
|
|
1351
|
+
), T = u.logicalExpression(
|
|
1345
1352
|
"??",
|
|
1346
1353
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1347
1354
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1348
1355
|
C,
|
|
1349
|
-
|
|
1350
|
-
), M =
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
+
I
|
|
1357
|
+
), M = u.callExpression(
|
|
1358
|
+
u.memberExpression(
|
|
1359
|
+
u.callExpression(u.identifier("convertToFilePath"), [
|
|
1360
|
+
u.memberExpression(
|
|
1361
|
+
u.memberExpression(u.identifier("import"), u.identifier("meta")),
|
|
1362
|
+
u.identifier("url")
|
|
1356
1363
|
)
|
|
1357
1364
|
]),
|
|
1358
|
-
|
|
1365
|
+
u.identifier("includes")
|
|
1359
1366
|
),
|
|
1360
1367
|
[T]
|
|
1361
1368
|
);
|
|
1362
|
-
return { isRunningFromThisFileDeclaration:
|
|
1363
|
-
|
|
1369
|
+
return { isRunningFromThisFileDeclaration: u.variableDeclaration("const", [
|
|
1370
|
+
u.variableDeclarator(j, M)
|
|
1364
1371
|
]), isRunningFromThisFileId: j };
|
|
1365
1372
|
};
|
|
1366
|
-
var
|
|
1373
|
+
var ht = ie;
|
|
1367
1374
|
f(ie, "getTestGuardDeclaration");
|
|
1368
|
-
let _ =
|
|
1369
|
-
JSON.stringify(
|
|
1370
|
-
p.program.body.push(
|
|
1375
|
+
let _ = l._file.path.scope.generateUidIdentifier("expect"), S = l._file.path.scope.generateUidIdentifier("testStory"), De = u.identifier(
|
|
1376
|
+
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Ie, isRunningFromThisFileId: Ne } = ie();
|
|
1377
|
+
p.program.body.push(Ie);
|
|
1371
1378
|
let we = /* @__PURE__ */ f(({
|
|
1372
1379
|
localName: j,
|
|
1373
|
-
exportName:
|
|
1380
|
+
exportName: I,
|
|
1374
1381
|
testTitle: C,
|
|
1375
1382
|
node: T
|
|
1376
1383
|
}) => {
|
|
1377
|
-
let M =
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
+
let M = u.expressionStatement(
|
|
1385
|
+
u.callExpression(E, [
|
|
1386
|
+
u.stringLiteral(C),
|
|
1387
|
+
u.callExpression(S, [
|
|
1388
|
+
u.stringLiteral(I),
|
|
1389
|
+
u.identifier(j),
|
|
1390
|
+
u.identifier(d),
|
|
1384
1391
|
De
|
|
1385
1392
|
])
|
|
1386
1393
|
])
|
|
1387
1394
|
);
|
|
1388
1395
|
return M.loc = T.loc, M;
|
|
1389
|
-
}, "getTestStatementForStory"), Fe = Object.entries(y).map(([j,
|
|
1390
|
-
if (
|
|
1391
|
-
|
|
1396
|
+
}, "getTestStatementForStory"), Fe = Object.entries(y).map(([j, I]) => {
|
|
1397
|
+
if (I === null) {
|
|
1398
|
+
ve.warn(
|
|
1392
1399
|
re.dedent`
|
|
1393
1400
|
[Storybook]: Could not transform "${j}" story into test at "${e}".
|
|
1394
1401
|
Please make sure to define stories in the same file and not re-export stories coming from other files".
|
|
@@ -1396,29 +1403,29 @@ le an issue with details about your use case.`
|
|
|
1396
1403
|
);
|
|
1397
1404
|
return;
|
|
1398
1405
|
}
|
|
1399
|
-
let C =
|
|
1400
|
-
return we({ testTitle: T, localName: C, exportName: j, node:
|
|
1401
|
-
}).filter((j) => !!j), Ce =
|
|
1406
|
+
let C = l._stories[j].localName ?? j, T = l._stories[j].name ?? j;
|
|
1407
|
+
return we({ testTitle: T, localName: C, exportName: j, node: I });
|
|
1408
|
+
}).filter((j) => !!j), Ce = u.ifStatement(Ne, u.blockStatement(Fe));
|
|
1402
1409
|
p.program.body.push(Ce);
|
|
1403
1410
|
let Te = [
|
|
1404
|
-
|
|
1411
|
+
u.importDeclaration(
|
|
1405
1412
|
[
|
|
1406
|
-
|
|
1407
|
-
|
|
1413
|
+
u.importSpecifier(E, u.identifier("test")),
|
|
1414
|
+
u.importSpecifier(_, u.identifier("expect"))
|
|
1408
1415
|
],
|
|
1409
|
-
|
|
1416
|
+
u.stringLiteral("vitest")
|
|
1410
1417
|
),
|
|
1411
|
-
|
|
1418
|
+
u.importDeclaration(
|
|
1412
1419
|
[
|
|
1413
|
-
|
|
1414
|
-
|
|
1420
|
+
u.importSpecifier(S, u.identifier("testStory")),
|
|
1421
|
+
u.importSpecifier(u.identifier("convertToFilePath"), u.identifier("convertToFilePath"))
|
|
1415
1422
|
],
|
|
1416
|
-
|
|
1423
|
+
u.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1417
1424
|
)
|
|
1418
1425
|
];
|
|
1419
1426
|
p.program.body.unshift(...Te);
|
|
1420
1427
|
}
|
|
1421
|
-
return
|
|
1428
|
+
return ue(l, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1422
1429
|
}
|
|
1423
1430
|
f(bt, "vitestTransform");
|
|
1424
1431
|
export {
|
|
@@ -1431,12 +1438,12 @@ export {
|
|
|
1431
1438
|
cr as babelParse,
|
|
1432
1439
|
et as babelParseFile,
|
|
1433
1440
|
Kt as enrichCsf,
|
|
1434
|
-
|
|
1441
|
+
ut as enrichCsfMeta,
|
|
1435
1442
|
dt as enrichCsfStory,
|
|
1436
1443
|
Oe as extractDescription,
|
|
1437
|
-
|
|
1444
|
+
mt as extractSource,
|
|
1438
1445
|
ot as formatConfig,
|
|
1439
|
-
|
|
1446
|
+
ue as formatCsf,
|
|
1440
1447
|
Wt as getStorySortParameter,
|
|
1441
1448
|
Lt as isCsfFactoryPreview,
|
|
1442
1449
|
Qe as isModuleMock,
|