storybook 10.1.0-alpha.9 → 10.1.0-beta.1
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/_browser-chunks/Color-FTG7SQDA.js +1097 -0
- package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
- package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
- package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-2XZMBGTA.js} +44 -109
- package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
- package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
- package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
- package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
- package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
- package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
- package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
- package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
- package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
- package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
- package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
- package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
- package/dist/_browser-chunks/chunk-FQ7SLVLR.js +66 -0
- package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
- package/dist/_browser-chunks/chunk-GFY5R5EY.js +47 -0
- package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
- package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
- package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
- package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
- package/dist/_browser-chunks/{chunk-OWPZQM2D.js → chunk-L4RMQ7D7.js} +60 -110
- package/dist/_browser-chunks/chunk-P4F4UVXX.js +951 -0
- package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
- package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
- package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
- package/dist/_browser-chunks/chunk-SS2NHR7W.js +2969 -0
- package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
- package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
- package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
- package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
- package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
- package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
- package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
- package/dist/_browser-chunks/{syntaxhighlighter-CAVLW7PM.js → syntaxhighlighter-IQDEPFLK.js} +704 -1848
- package/dist/_node-chunks/{builder-manager-SM3UWERX.js → builder-manager-FTVC2JL7.js} +510 -1019
- package/dist/_node-chunks/camelcase-3SMT5WKC.js +37 -0
- package/dist/_node-chunks/chunk-2OVULPK3.js +54 -0
- package/dist/_node-chunks/chunk-3JJPSDXI.js +3043 -0
- package/dist/_node-chunks/chunk-54NMJ4II.js +1564 -0
- package/dist/_node-chunks/chunk-5V4A6MSI.js +943 -0
- package/dist/_node-chunks/chunk-6DEMT5VX.js +299 -0
- package/dist/_node-chunks/{chunk-HHSTA6QS.js → chunk-6L7FFBOW.js} +8 -10
- package/dist/_node-chunks/chunk-6ULDIDXV.js +46662 -0
- package/dist/_node-chunks/chunk-AREL5IXS.js +603 -0
- package/dist/_node-chunks/chunk-DWA53E73.js +23 -0
- package/dist/_node-chunks/chunk-FNYKBULZ.js +765 -0
- package/dist/_node-chunks/chunk-IUYZQKSX.js +70 -0
- package/dist/_node-chunks/{chunk-F6EFOEC7.js → chunk-K673CX4Q.js} +469 -983
- package/dist/_node-chunks/chunk-KJAFCNZ3.js +61 -0
- package/dist/_node-chunks/chunk-N3BJOOY5.js +78 -0
- package/dist/_node-chunks/{chunk-EBUEXRH5.js → chunk-O5FMCQHP.js} +116 -276
- package/dist/_node-chunks/chunk-RIKQZHV3.js +29 -0
- package/dist/_node-chunks/chunk-RURZIE3W.js +3780 -0
- package/dist/_node-chunks/chunk-RVII4SK6.js +919 -0
- package/dist/_node-chunks/chunk-S3PBHOVC.js +6024 -0
- package/dist/_node-chunks/chunk-SQSFX47N.js +61 -0
- package/dist/_node-chunks/{chunk-SGM3ZCCT.js → chunk-TURUTKVH.js} +292 -688
- package/dist/_node-chunks/chunk-VRICJPXY.js +72 -0
- package/dist/_node-chunks/chunk-WIWWMCEU.js +119 -0
- package/dist/_node-chunks/{chunk-ATDHMMIZ.js → chunk-XGNRK7QB.js} +15 -24
- package/dist/_node-chunks/chunk-Y2FOTPAE.js +4523 -0
- package/dist/_node-chunks/{chunk-GHIBZRKD.js → chunk-Y4UYN72K.js} +8133 -8887
- package/dist/_node-chunks/chunk-Z4BMBA5L.js +18 -0
- package/dist/_node-chunks/chunk-ZMCJS2GU.js +20 -0
- package/dist/_node-chunks/dist-TZLZ3T6L.js +121 -0
- package/dist/_node-chunks/globby-22GFCZQD.js +3452 -0
- package/dist/_node-chunks/lib-37NQ4ZIJ.js +366 -0
- package/dist/_node-chunks/mdx-N42X6CFJ-2TRB7OEH.js +14329 -0
- package/dist/_node-chunks/p-limit-UD7TYFDW.js +116 -0
- package/dist/actions/decorator.js +21 -42
- package/dist/actions/index.js +3 -3
- package/dist/babel/index.d.ts +671 -335
- package/dist/babel/index.js +10 -11
- package/dist/bin/core.js +602 -1549
- package/dist/bin/dispatcher.js +36 -36
- package/dist/bin/loader.js +24 -38
- package/dist/channels/index.js +98 -234
- package/dist/cli/index.d.ts +1479 -133
- package/dist/cli/index.js +30 -8540
- package/dist/client-logger/index.js +31 -61
- package/dist/common/index.d.ts +139 -62
- package/dist/common/index.js +66 -51
- package/dist/components/index.d.ts +575 -273
- package/dist/components/index.js +14863 -4313
- package/dist/core-events/index.js +2 -66
- package/dist/core-server/index.d.ts +3 -2
- package/dist/core-server/index.js +2911 -8519
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +2521 -5233
- package/dist/core-server/presets/common-override-preset.js +31 -60
- package/dist/core-server/presets/common-preset.js +663 -962
- package/dist/csf/index.js +534 -1179
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +6 -6
- package/dist/highlight/index.js +2 -2
- package/dist/instrumenter/index.js +199 -415
- package/dist/manager/globals-runtime.js +59044 -67141
- package/dist/manager/globals.js +2 -3
- package/dist/manager/manager-stores.d.ts +1 -0
- package/dist/manager/manager-stores.js +23 -0
- package/dist/manager/runtime.js +11569 -10953
- package/dist/manager-api/index.d.ts +1813 -2
- package/dist/manager-api/index.js +1348 -2401
- package/dist/manager-errors.d.ts +9 -0
- package/dist/manager-errors.js +3 -3
- package/dist/mocking-utils/index.d.ts +1126 -0
- package/dist/mocking-utils/index.js +1181 -0
- package/dist/node-logger/index.d.ts +192 -24
- package/dist/node-logger/index.js +23 -4471
- package/dist/preview/globals.js +2 -3
- package/dist/preview/runtime.js +10799 -22393
- package/dist/preview-api/index.d.ts +1 -1
- package/dist/preview-api/index.js +13 -13
- package/dist/preview-errors.d.ts +9 -0
- package/dist/preview-errors.js +4 -4
- package/dist/router/index.js +347 -899
- package/dist/server-errors.d.ts +34 -1
- package/dist/server-errors.js +17 -10
- package/dist/telemetry/index.d.ts +24 -3
- package/dist/telemetry/index.js +25 -24
- package/dist/test/index.js +6131 -11916
- package/dist/theming/create.d.ts +1 -0
- package/dist/theming/create.js +4 -4
- package/dist/theming/index.d.ts +3366 -2599
- package/dist/theming/index.js +501 -1091
- package/dist/types/index.d.ts +72 -8
- package/dist/types/index.js +27 -12
- package/dist/viewport/index.js +3 -3
- package/package.json +26 -17
- package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
- package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
- package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
- package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
- package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
- package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
- package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
- package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
- package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
- package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
- package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
- package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
- package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
- package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
- package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
- package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
- package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
- package/dist/_browser-chunks/chunk-RW5PKMWM.js +0 -4182
- package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
- package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
- package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
- package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
- package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
- package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
- package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
- package/dist/_node-chunks/camelcase-H5QSGQLK.js +0 -18
- package/dist/_node-chunks/chunk-3THWHQOC.js +0 -61
- package/dist/_node-chunks/chunk-45YUOLTU.js +0 -69
- package/dist/_node-chunks/chunk-4QSNCPAU.js +0 -64656
- package/dist/_node-chunks/chunk-744PQSOU.js +0 -79
- package/dist/_node-chunks/chunk-74Z2U7QG.js +0 -1544
- package/dist/_node-chunks/chunk-7MB7TFPO.js +0 -1198
- package/dist/_node-chunks/chunk-A7GS4RFT.js +0 -697
- package/dist/_node-chunks/chunk-BIA3A5UM.js +0 -61
- package/dist/_node-chunks/chunk-C5G7CLWX.js +0 -1657
- package/dist/_node-chunks/chunk-DLFUKMYJ.js +0 -1531
- package/dist/_node-chunks/chunk-EMRGRXKT.js +0 -111
- package/dist/_node-chunks/chunk-EX46EHHY.js +0 -420
- package/dist/_node-chunks/chunk-F76QKNOJ.js +0 -304
- package/dist/_node-chunks/chunk-HDCRUTEF.js +0 -220
- package/dist/_node-chunks/chunk-HUYAOIPH.js +0 -90
- package/dist/_node-chunks/chunk-IBJZQZJC.js +0 -101
- package/dist/_node-chunks/chunk-KZN2RDDT.js +0 -6712
- package/dist/_node-chunks/chunk-LYUNFU3F.js +0 -4741
- package/dist/_node-chunks/chunk-N44SIS6K.js +0 -28
- package/dist/_node-chunks/chunk-NILZM6KR.js +0 -18
- package/dist/_node-chunks/chunk-PC4ZRP6W.js +0 -34
- package/dist/_node-chunks/chunk-TJNGOQUH.js +0 -4272
- package/dist/_node-chunks/chunk-UBSYLHIL.js +0 -1250
- package/dist/_node-chunks/chunk-UTCLXPOC.js +0 -1518
- package/dist/_node-chunks/chunk-WOXXODXP.js +0 -5029
- package/dist/_node-chunks/chunk-XC4MEUA6.js +0 -1586
- package/dist/_node-chunks/chunk-YRXXMKRR.js +0 -2256
- package/dist/_node-chunks/dist-SL73W244.js +0 -175
- package/dist/_node-chunks/globby-ZSHAUQZ5.js +0 -5222
- package/dist/_node-chunks/lib-U2VIPUTI.js +0 -518
- package/dist/_node-chunks/mdx-N42X6CFJ-ZLHD33JK.js +0 -22017
- package/dist/_node-chunks/p-limit-K5BS5MSV.js +0 -168
- package/dist/_node-chunks/plugin-5PD4YIUH.js +0 -129
- package/dist/_node-chunks/plugin-MONDT2WL.js +0 -159
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-EUZJRG3W.js +0 -69102
- package/dist/_node-chunks/webpack-mock-plugin-T4LDXEHE.js +0 -124
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +0 -36
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +0 -33
|
@@ -0,0 +1,1181 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_jdojl2z4eei from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_jdojl2z4eei from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_jdojl2z4eei from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_jdojl2z4eei.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_jdojl2z4eei.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_jdojl2z4eei.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
basename,
|
|
14
|
+
dirname,
|
|
15
|
+
isAbsolute,
|
|
16
|
+
join,
|
|
17
|
+
normalize,
|
|
18
|
+
resolve
|
|
19
|
+
} from "../_node-chunks/chunk-WIWWMCEU.js";
|
|
20
|
+
import "../_node-chunks/chunk-2OVULPK3.js";
|
|
21
|
+
|
|
22
|
+
// ../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
23
|
+
var comma = 44, semicolon = 59, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
|
|
24
|
+
for (let i = 0; i < chars.length; i++) {
|
|
25
|
+
let c = chars.charCodeAt(i);
|
|
26
|
+
intToChar[i] = c, charToInt[c] = i;
|
|
27
|
+
}
|
|
28
|
+
function encodeInteger(builder, num, relative) {
|
|
29
|
+
let delta = num - relative;
|
|
30
|
+
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
31
|
+
do {
|
|
32
|
+
let clamped = delta & 31;
|
|
33
|
+
delta >>>= 5, delta > 0 && (clamped |= 32), builder.write(intToChar[clamped]);
|
|
34
|
+
} while (delta > 0);
|
|
35
|
+
return num;
|
|
36
|
+
}
|
|
37
|
+
var bufLength = 1024 * 16, td = typeof TextDecoder < "u" ? new TextDecoder() : typeof Buffer < "u" ? {
|
|
38
|
+
decode(buf) {
|
|
39
|
+
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
40
|
+
}
|
|
41
|
+
} : {
|
|
42
|
+
decode(buf) {
|
|
43
|
+
let out = "";
|
|
44
|
+
for (let i = 0; i < buf.length; i++)
|
|
45
|
+
out += String.fromCharCode(buf[i]);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
}, StringWriter = class {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.pos = 0, this.out = "", this.buffer = new Uint8Array(bufLength);
|
|
51
|
+
}
|
|
52
|
+
write(v) {
|
|
53
|
+
let { buffer } = this;
|
|
54
|
+
buffer[this.pos++] = v, this.pos === bufLength && (this.out += td.decode(buffer), this.pos = 0);
|
|
55
|
+
}
|
|
56
|
+
flush() {
|
|
57
|
+
let { buffer, out, pos } = this;
|
|
58
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function encode(decoded) {
|
|
62
|
+
let writer = new StringWriter(), sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
|
|
63
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
64
|
+
let line = decoded[i];
|
|
65
|
+
if (i > 0 && writer.write(semicolon), line.length === 0) continue;
|
|
66
|
+
let genColumn = 0;
|
|
67
|
+
for (let j = 0; j < line.length; j++) {
|
|
68
|
+
let segment = line[j];
|
|
69
|
+
j > 0 && writer.write(comma), genColumn = encodeInteger(writer, segment[0], genColumn), segment.length !== 1 && (sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex), sourceLine = encodeInteger(writer, segment[2], sourceLine), sourceColumn = encodeInteger(writer, segment[3], sourceColumn), segment.length !== 4 && (namesIndex = encodeInteger(writer, segment[4], namesIndex)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return writer.flush();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ../node_modules/magic-string/dist/magic-string.es.mjs
|
|
76
|
+
var BitSet = class _BitSet {
|
|
77
|
+
constructor(arg) {
|
|
78
|
+
this.bits = arg instanceof _BitSet ? arg.bits.slice() : [];
|
|
79
|
+
}
|
|
80
|
+
add(n3) {
|
|
81
|
+
this.bits[n3 >> 5] |= 1 << (n3 & 31);
|
|
82
|
+
}
|
|
83
|
+
has(n3) {
|
|
84
|
+
return !!(this.bits[n3 >> 5] & 1 << (n3 & 31));
|
|
85
|
+
}
|
|
86
|
+
}, Chunk = class _Chunk {
|
|
87
|
+
constructor(start, end, content) {
|
|
88
|
+
this.start = start, this.end = end, this.original = content, this.intro = "", this.outro = "", this.content = content, this.storeName = !1, this.edited = !1, this.previous = null, this.next = null;
|
|
89
|
+
}
|
|
90
|
+
appendLeft(content) {
|
|
91
|
+
this.outro += content;
|
|
92
|
+
}
|
|
93
|
+
appendRight(content) {
|
|
94
|
+
this.intro = this.intro + content;
|
|
95
|
+
}
|
|
96
|
+
clone() {
|
|
97
|
+
let chunk = new _Chunk(this.start, this.end, this.original);
|
|
98
|
+
return chunk.intro = this.intro, chunk.outro = this.outro, chunk.content = this.content, chunk.storeName = this.storeName, chunk.edited = this.edited, chunk;
|
|
99
|
+
}
|
|
100
|
+
contains(index) {
|
|
101
|
+
return this.start < index && index < this.end;
|
|
102
|
+
}
|
|
103
|
+
eachNext(fn) {
|
|
104
|
+
let chunk = this;
|
|
105
|
+
for (; chunk; )
|
|
106
|
+
fn(chunk), chunk = chunk.next;
|
|
107
|
+
}
|
|
108
|
+
eachPrevious(fn) {
|
|
109
|
+
let chunk = this;
|
|
110
|
+
for (; chunk; )
|
|
111
|
+
fn(chunk), chunk = chunk.previous;
|
|
112
|
+
}
|
|
113
|
+
edit(content, storeName, contentOnly) {
|
|
114
|
+
return this.content = content, contentOnly || (this.intro = "", this.outro = ""), this.storeName = storeName, this.edited = !0, this;
|
|
115
|
+
}
|
|
116
|
+
prependLeft(content) {
|
|
117
|
+
this.outro = content + this.outro;
|
|
118
|
+
}
|
|
119
|
+
prependRight(content) {
|
|
120
|
+
this.intro = content + this.intro;
|
|
121
|
+
}
|
|
122
|
+
reset() {
|
|
123
|
+
this.intro = "", this.outro = "", this.edited && (this.content = this.original, this.storeName = !1, this.edited = !1);
|
|
124
|
+
}
|
|
125
|
+
split(index) {
|
|
126
|
+
let sliceIndex = index - this.start, originalBefore = this.original.slice(0, sliceIndex), originalAfter = this.original.slice(sliceIndex);
|
|
127
|
+
this.original = originalBefore;
|
|
128
|
+
let newChunk = new _Chunk(index, this.end, originalAfter);
|
|
129
|
+
return newChunk.outro = this.outro, this.outro = "", this.end = index, this.edited ? (newChunk.edit("", !1), this.content = "") : this.content = originalBefore, newChunk.next = this.next, newChunk.next && (newChunk.next.previous = newChunk), newChunk.previous = this, this.next = newChunk, newChunk;
|
|
130
|
+
}
|
|
131
|
+
toString() {
|
|
132
|
+
return this.intro + this.content + this.outro;
|
|
133
|
+
}
|
|
134
|
+
trimEnd(rx) {
|
|
135
|
+
if (this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
136
|
+
let trimmed = this.content.replace(rx, "");
|
|
137
|
+
if (trimmed.length)
|
|
138
|
+
return trimmed !== this.content && (this.split(this.start + trimmed.length).edit("", void 0, !0), this.edited && this.edit(trimmed, this.storeName, !0)), !0;
|
|
139
|
+
if (this.edit("", void 0, !0), this.intro = this.intro.replace(rx, ""), this.intro.length) return !0;
|
|
140
|
+
}
|
|
141
|
+
trimStart(rx) {
|
|
142
|
+
if (this.intro = this.intro.replace(rx, ""), this.intro.length) return !0;
|
|
143
|
+
let trimmed = this.content.replace(rx, "");
|
|
144
|
+
if (trimmed.length) {
|
|
145
|
+
if (trimmed !== this.content) {
|
|
146
|
+
let newChunk = this.split(this.end - trimmed.length);
|
|
147
|
+
this.edited && newChunk.edit(trimmed, this.storeName, !0), this.edit("", void 0, !0);
|
|
148
|
+
}
|
|
149
|
+
return !0;
|
|
150
|
+
} else if (this.edit("", void 0, !0), this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
function getBtoa() {
|
|
154
|
+
return typeof globalThis < "u" && typeof globalThis.btoa == "function" ? (str) => globalThis.btoa(unescape(encodeURIComponent(str))) : typeof Buffer == "function" ? (str) => Buffer.from(str, "utf-8").toString("base64") : () => {
|
|
155
|
+
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
var btoa = getBtoa(), SourceMap = class {
|
|
159
|
+
constructor(properties) {
|
|
160
|
+
this.version = 3, this.file = properties.file, this.sources = properties.sources, this.sourcesContent = properties.sourcesContent, this.names = properties.names, this.mappings = encode(properties.mappings), typeof properties.x_google_ignoreList < "u" && (this.x_google_ignoreList = properties.x_google_ignoreList), typeof properties.debugId < "u" && (this.debugId = properties.debugId);
|
|
161
|
+
}
|
|
162
|
+
toString() {
|
|
163
|
+
return JSON.stringify(this);
|
|
164
|
+
}
|
|
165
|
+
toUrl() {
|
|
166
|
+
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
function guessIndent(code) {
|
|
170
|
+
let lines = code.split(`
|
|
171
|
+
`), tabbed = lines.filter((line) => /^\t+/.test(line)), spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
172
|
+
if (tabbed.length === 0 && spaced.length === 0)
|
|
173
|
+
return null;
|
|
174
|
+
if (tabbed.length >= spaced.length)
|
|
175
|
+
return " ";
|
|
176
|
+
let min = spaced.reduce((previous, current) => {
|
|
177
|
+
let numSpaces = /^ +/.exec(current)[0].length;
|
|
178
|
+
return Math.min(numSpaces, previous);
|
|
179
|
+
}, 1 / 0);
|
|
180
|
+
return new Array(min + 1).join(" ");
|
|
181
|
+
}
|
|
182
|
+
function getRelativePath(from, to) {
|
|
183
|
+
let fromParts = from.split(/[/\\]/), toParts = to.split(/[/\\]/);
|
|
184
|
+
for (fromParts.pop(); fromParts[0] === toParts[0]; )
|
|
185
|
+
fromParts.shift(), toParts.shift();
|
|
186
|
+
if (fromParts.length) {
|
|
187
|
+
let i = fromParts.length;
|
|
188
|
+
for (; i--; ) fromParts[i] = "..";
|
|
189
|
+
}
|
|
190
|
+
return fromParts.concat(toParts).join("/");
|
|
191
|
+
}
|
|
192
|
+
var toString = Object.prototype.toString;
|
|
193
|
+
function isObject(thing) {
|
|
194
|
+
return toString.call(thing) === "[object Object]";
|
|
195
|
+
}
|
|
196
|
+
function getLocator(source) {
|
|
197
|
+
let originalLines = source.split(`
|
|
198
|
+
`), lineOffsets = [];
|
|
199
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++)
|
|
200
|
+
lineOffsets.push(pos), pos += originalLines[i].length + 1;
|
|
201
|
+
return function(index) {
|
|
202
|
+
let i = 0, j = lineOffsets.length;
|
|
203
|
+
for (; i < j; ) {
|
|
204
|
+
let m = i + j >> 1;
|
|
205
|
+
index < lineOffsets[m] ? j = m : i = m + 1;
|
|
206
|
+
}
|
|
207
|
+
let line = i - 1, column = index - lineOffsets[line];
|
|
208
|
+
return { line, column };
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
var wordRegex = /\w/, Mappings = class {
|
|
212
|
+
constructor(hires) {
|
|
213
|
+
this.hires = hires, this.generatedCodeLine = 0, this.generatedCodeColumn = 0, this.raw = [], this.rawSegments = this.raw[this.generatedCodeLine] = [], this.pending = null;
|
|
214
|
+
}
|
|
215
|
+
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
216
|
+
if (content.length) {
|
|
217
|
+
let contentLengthMinusOne = content.length - 1, contentLineEnd = content.indexOf(`
|
|
218
|
+
`, 0), previousContentLineEnd = -1;
|
|
219
|
+
for (; contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd; ) {
|
|
220
|
+
let segment2 = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
221
|
+
nameIndex >= 0 && segment2.push(nameIndex), this.rawSegments.push(segment2), this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, previousContentLineEnd = contentLineEnd, contentLineEnd = content.indexOf(`
|
|
222
|
+
`, contentLineEnd + 1);
|
|
223
|
+
}
|
|
224
|
+
let segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
225
|
+
nameIndex >= 0 && segment.push(nameIndex), this.rawSegments.push(segment), this.advance(content.slice(previousContentLineEnd + 1));
|
|
226
|
+
} else this.pending && (this.rawSegments.push(this.pending), this.advance(content));
|
|
227
|
+
this.pending = null;
|
|
228
|
+
}
|
|
229
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
230
|
+
let originalCharIndex = chunk.start, first = !0, charInHiresBoundary = !1;
|
|
231
|
+
for (; originalCharIndex < chunk.end; ) {
|
|
232
|
+
if (original[originalCharIndex] === `
|
|
233
|
+
`)
|
|
234
|
+
loc.line += 1, loc.column = 0, this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, first = !0, charInHiresBoundary = !1;
|
|
235
|
+
else {
|
|
236
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
237
|
+
let segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
238
|
+
this.hires === "boundary" ? wordRegex.test(original[originalCharIndex]) ? charInHiresBoundary || (this.rawSegments.push(segment), charInHiresBoundary = !0) : (this.rawSegments.push(segment), charInHiresBoundary = !1) : this.rawSegments.push(segment);
|
|
239
|
+
}
|
|
240
|
+
loc.column += 1, this.generatedCodeColumn += 1, first = !1;
|
|
241
|
+
}
|
|
242
|
+
originalCharIndex += 1;
|
|
243
|
+
}
|
|
244
|
+
this.pending = null;
|
|
245
|
+
}
|
|
246
|
+
advance(str) {
|
|
247
|
+
if (!str) return;
|
|
248
|
+
let lines = str.split(`
|
|
249
|
+
`);
|
|
250
|
+
if (lines.length > 1) {
|
|
251
|
+
for (let i = 0; i < lines.length - 1; i++)
|
|
252
|
+
this.generatedCodeLine++, this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
253
|
+
this.generatedCodeColumn = 0;
|
|
254
|
+
}
|
|
255
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
256
|
+
}
|
|
257
|
+
}, n = `
|
|
258
|
+
`, warned = {
|
|
259
|
+
insertLeft: !1,
|
|
260
|
+
insertRight: !1,
|
|
261
|
+
storeName: !1
|
|
262
|
+
}, MagicString = class _MagicString {
|
|
263
|
+
constructor(string, options = {}) {
|
|
264
|
+
let chunk = new Chunk(0, string.length, string);
|
|
265
|
+
Object.defineProperties(this, {
|
|
266
|
+
original: { writable: !0, value: string },
|
|
267
|
+
outro: { writable: !0, value: "" },
|
|
268
|
+
intro: { writable: !0, value: "" },
|
|
269
|
+
firstChunk: { writable: !0, value: chunk },
|
|
270
|
+
lastChunk: { writable: !0, value: chunk },
|
|
271
|
+
lastSearchedChunk: { writable: !0, value: chunk },
|
|
272
|
+
byStart: { writable: !0, value: {} },
|
|
273
|
+
byEnd: { writable: !0, value: {} },
|
|
274
|
+
filename: { writable: !0, value: options.filename },
|
|
275
|
+
indentExclusionRanges: { writable: !0, value: options.indentExclusionRanges },
|
|
276
|
+
sourcemapLocations: { writable: !0, value: new BitSet() },
|
|
277
|
+
storedNames: { writable: !0, value: {} },
|
|
278
|
+
indentStr: { writable: !0, value: void 0 },
|
|
279
|
+
ignoreList: { writable: !0, value: options.ignoreList },
|
|
280
|
+
offset: { writable: !0, value: options.offset || 0 }
|
|
281
|
+
}), this.byStart[0] = chunk, this.byEnd[string.length] = chunk;
|
|
282
|
+
}
|
|
283
|
+
addSourcemapLocation(char) {
|
|
284
|
+
this.sourcemapLocations.add(char);
|
|
285
|
+
}
|
|
286
|
+
append(content) {
|
|
287
|
+
if (typeof content != "string") throw new TypeError("outro content must be a string");
|
|
288
|
+
return this.outro += content, this;
|
|
289
|
+
}
|
|
290
|
+
appendLeft(index, content) {
|
|
291
|
+
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
292
|
+
this._split(index);
|
|
293
|
+
let chunk = this.byEnd[index];
|
|
294
|
+
return chunk ? chunk.appendLeft(content) : this.intro += content, this;
|
|
295
|
+
}
|
|
296
|
+
appendRight(index, content) {
|
|
297
|
+
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
298
|
+
this._split(index);
|
|
299
|
+
let chunk = this.byStart[index];
|
|
300
|
+
return chunk ? chunk.appendRight(content) : this.outro += content, this;
|
|
301
|
+
}
|
|
302
|
+
clone() {
|
|
303
|
+
let cloned = new _MagicString(this.original, { filename: this.filename, offset: this.offset }), originalChunk = this.firstChunk, clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
304
|
+
for (; originalChunk; ) {
|
|
305
|
+
cloned.byStart[clonedChunk.start] = clonedChunk, cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
306
|
+
let nextOriginalChunk = originalChunk.next, nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
307
|
+
nextClonedChunk && (clonedChunk.next = nextClonedChunk, nextClonedChunk.previous = clonedChunk, clonedChunk = nextClonedChunk), originalChunk = nextOriginalChunk;
|
|
308
|
+
}
|
|
309
|
+
return cloned.lastChunk = clonedChunk, this.indentExclusionRanges && (cloned.indentExclusionRanges = this.indentExclusionRanges.slice()), cloned.sourcemapLocations = new BitSet(this.sourcemapLocations), cloned.intro = this.intro, cloned.outro = this.outro, cloned;
|
|
310
|
+
}
|
|
311
|
+
generateDecodedMap(options) {
|
|
312
|
+
options = options || {};
|
|
313
|
+
let sourceIndex = 0, names = Object.keys(this.storedNames), mappings = new Mappings(options.hires), locate = getLocator(this.original);
|
|
314
|
+
return this.intro && mappings.advance(this.intro), this.firstChunk.eachNext((chunk) => {
|
|
315
|
+
let loc = locate(chunk.start);
|
|
316
|
+
chunk.intro.length && mappings.advance(chunk.intro), chunk.edited ? mappings.addEdit(
|
|
317
|
+
sourceIndex,
|
|
318
|
+
chunk.content,
|
|
319
|
+
loc,
|
|
320
|
+
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
321
|
+
) : mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations), chunk.outro.length && mappings.advance(chunk.outro);
|
|
322
|
+
}), this.outro && mappings.advance(this.outro), {
|
|
323
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
324
|
+
sources: [
|
|
325
|
+
options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
|
|
326
|
+
],
|
|
327
|
+
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
328
|
+
names,
|
|
329
|
+
mappings: mappings.raw,
|
|
330
|
+
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
generateMap(options) {
|
|
334
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
335
|
+
}
|
|
336
|
+
_ensureindentStr() {
|
|
337
|
+
this.indentStr === void 0 && (this.indentStr = guessIndent(this.original));
|
|
338
|
+
}
|
|
339
|
+
_getRawIndentString() {
|
|
340
|
+
return this._ensureindentStr(), this.indentStr;
|
|
341
|
+
}
|
|
342
|
+
getIndentString() {
|
|
343
|
+
return this._ensureindentStr(), this.indentStr === null ? " " : this.indentStr;
|
|
344
|
+
}
|
|
345
|
+
indent(indentStr, options) {
|
|
346
|
+
let pattern = /^[^\r\n]/gm;
|
|
347
|
+
if (isObject(indentStr) && (options = indentStr, indentStr = void 0), indentStr === void 0 && (this._ensureindentStr(), indentStr = this.indentStr || " "), indentStr === "") return this;
|
|
348
|
+
options = options || {};
|
|
349
|
+
let isExcluded = {};
|
|
350
|
+
options.exclude && (typeof options.exclude[0] == "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
351
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1)
|
|
352
|
+
isExcluded[i] = !0;
|
|
353
|
+
});
|
|
354
|
+
let shouldIndentNextCharacter = options.indentStart !== !1, replacer = (match) => shouldIndentNextCharacter ? `${indentStr}${match}` : (shouldIndentNextCharacter = !0, match);
|
|
355
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
356
|
+
let charIndex = 0, chunk = this.firstChunk;
|
|
357
|
+
for (; chunk; ) {
|
|
358
|
+
let end = chunk.end;
|
|
359
|
+
if (chunk.edited)
|
|
360
|
+
isExcluded[charIndex] || (chunk.content = chunk.content.replace(pattern, replacer), chunk.content.length && (shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === `
|
|
361
|
+
`));
|
|
362
|
+
else
|
|
363
|
+
for (charIndex = chunk.start; charIndex < end; ) {
|
|
364
|
+
if (!isExcluded[charIndex]) {
|
|
365
|
+
let char = this.original[charIndex];
|
|
366
|
+
char === `
|
|
367
|
+
` ? shouldIndentNextCharacter = !0 : char !== "\r" && shouldIndentNextCharacter && (shouldIndentNextCharacter = !1, charIndex === chunk.start || (this._splitChunk(chunk, charIndex), chunk = chunk.next), chunk.prependRight(indentStr));
|
|
368
|
+
}
|
|
369
|
+
charIndex += 1;
|
|
370
|
+
}
|
|
371
|
+
charIndex = chunk.end, chunk = chunk.next;
|
|
372
|
+
}
|
|
373
|
+
return this.outro = this.outro.replace(pattern, replacer), this;
|
|
374
|
+
}
|
|
375
|
+
insert() {
|
|
376
|
+
throw new Error(
|
|
377
|
+
"magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
insertLeft(index, content) {
|
|
381
|
+
return warned.insertLeft || (console.warn(
|
|
382
|
+
"magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
|
|
383
|
+
), warned.insertLeft = !0), this.appendLeft(index, content);
|
|
384
|
+
}
|
|
385
|
+
insertRight(index, content) {
|
|
386
|
+
return warned.insertRight || (console.warn(
|
|
387
|
+
"magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
|
|
388
|
+
), warned.insertRight = !0), this.prependRight(index, content);
|
|
389
|
+
}
|
|
390
|
+
move(start, end, index) {
|
|
391
|
+
if (start = start + this.offset, end = end + this.offset, index = index + this.offset, index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
392
|
+
this._split(start), this._split(end), this._split(index);
|
|
393
|
+
let first = this.byStart[start], last = this.byEnd[end], oldLeft = first.previous, oldRight = last.next, newRight = this.byStart[index];
|
|
394
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
395
|
+
let newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
396
|
+
return oldLeft && (oldLeft.next = oldRight), oldRight && (oldRight.previous = oldLeft), newLeft && (newLeft.next = first), newRight && (newRight.previous = last), first.previous || (this.firstChunk = last.next), last.next || (this.lastChunk = first.previous, this.lastChunk.next = null), first.previous = newLeft, last.next = newRight || null, newLeft || (this.firstChunk = first), newRight || (this.lastChunk = last), this;
|
|
397
|
+
}
|
|
398
|
+
overwrite(start, end, content, options) {
|
|
399
|
+
return options = options || {}, this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
400
|
+
}
|
|
401
|
+
update(start, end, content, options) {
|
|
402
|
+
if (start = start + this.offset, end = end + this.offset, typeof content != "string") throw new TypeError("replacement content must be a string");
|
|
403
|
+
if (this.original.length !== 0) {
|
|
404
|
+
for (; start < 0; ) start += this.original.length;
|
|
405
|
+
for (; end < 0; ) end += this.original.length;
|
|
406
|
+
}
|
|
407
|
+
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
408
|
+
if (start === end)
|
|
409
|
+
throw new Error(
|
|
410
|
+
"Cannot overwrite a zero-length range \u2013 use appendLeft or prependRight instead"
|
|
411
|
+
);
|
|
412
|
+
this._split(start), this._split(end), options === !0 && (warned.storeName || (console.warn(
|
|
413
|
+
"The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
|
|
414
|
+
), warned.storeName = !0), options = { storeName: !0 });
|
|
415
|
+
let storeName = options !== void 0 ? options.storeName : !1, overwrite = options !== void 0 ? options.overwrite : !1;
|
|
416
|
+
if (storeName) {
|
|
417
|
+
let original = this.original.slice(start, end);
|
|
418
|
+
Object.defineProperty(this.storedNames, original, {
|
|
419
|
+
writable: !0,
|
|
420
|
+
value: !0,
|
|
421
|
+
enumerable: !0
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
let first = this.byStart[start], last = this.byEnd[end];
|
|
425
|
+
if (first) {
|
|
426
|
+
let chunk = first;
|
|
427
|
+
for (; chunk !== last; ) {
|
|
428
|
+
if (chunk.next !== this.byStart[chunk.end])
|
|
429
|
+
throw new Error("Cannot overwrite across a split point");
|
|
430
|
+
chunk = chunk.next, chunk.edit("", !1);
|
|
431
|
+
}
|
|
432
|
+
first.edit(content, storeName, !overwrite);
|
|
433
|
+
} else {
|
|
434
|
+
let newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
435
|
+
last.next = newChunk, newChunk.previous = last;
|
|
436
|
+
}
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
prepend(content) {
|
|
440
|
+
if (typeof content != "string") throw new TypeError("outro content must be a string");
|
|
441
|
+
return this.intro = content + this.intro, this;
|
|
442
|
+
}
|
|
443
|
+
prependLeft(index, content) {
|
|
444
|
+
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
445
|
+
this._split(index);
|
|
446
|
+
let chunk = this.byEnd[index];
|
|
447
|
+
return chunk ? chunk.prependLeft(content) : this.intro = content + this.intro, this;
|
|
448
|
+
}
|
|
449
|
+
prependRight(index, content) {
|
|
450
|
+
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
451
|
+
this._split(index);
|
|
452
|
+
let chunk = this.byStart[index];
|
|
453
|
+
return chunk ? chunk.prependRight(content) : this.outro = content + this.outro, this;
|
|
454
|
+
}
|
|
455
|
+
remove(start, end) {
|
|
456
|
+
if (start = start + this.offset, end = end + this.offset, this.original.length !== 0) {
|
|
457
|
+
for (; start < 0; ) start += this.original.length;
|
|
458
|
+
for (; end < 0; ) end += this.original.length;
|
|
459
|
+
}
|
|
460
|
+
if (start === end) return this;
|
|
461
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
462
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
463
|
+
this._split(start), this._split(end);
|
|
464
|
+
let chunk = this.byStart[start];
|
|
465
|
+
for (; chunk; )
|
|
466
|
+
chunk.intro = "", chunk.outro = "", chunk.edit(""), chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
reset(start, end) {
|
|
470
|
+
if (start = start + this.offset, end = end + this.offset, this.original.length !== 0) {
|
|
471
|
+
for (; start < 0; ) start += this.original.length;
|
|
472
|
+
for (; end < 0; ) end += this.original.length;
|
|
473
|
+
}
|
|
474
|
+
if (start === end) return this;
|
|
475
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
476
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
477
|
+
this._split(start), this._split(end);
|
|
478
|
+
let chunk = this.byStart[start];
|
|
479
|
+
for (; chunk; )
|
|
480
|
+
chunk.reset(), chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
lastChar() {
|
|
484
|
+
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
485
|
+
let chunk = this.lastChunk;
|
|
486
|
+
do {
|
|
487
|
+
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
488
|
+
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
489
|
+
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
490
|
+
} while (chunk = chunk.previous);
|
|
491
|
+
return this.intro.length ? this.intro[this.intro.length - 1] : "";
|
|
492
|
+
}
|
|
493
|
+
lastLine() {
|
|
494
|
+
let lineIndex = this.outro.lastIndexOf(n);
|
|
495
|
+
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
496
|
+
let lineStr = this.outro, chunk = this.lastChunk;
|
|
497
|
+
do {
|
|
498
|
+
if (chunk.outro.length > 0) {
|
|
499
|
+
if (lineIndex = chunk.outro.lastIndexOf(n), lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
500
|
+
lineStr = chunk.outro + lineStr;
|
|
501
|
+
}
|
|
502
|
+
if (chunk.content.length > 0) {
|
|
503
|
+
if (lineIndex = chunk.content.lastIndexOf(n), lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
504
|
+
lineStr = chunk.content + lineStr;
|
|
505
|
+
}
|
|
506
|
+
if (chunk.intro.length > 0) {
|
|
507
|
+
if (lineIndex = chunk.intro.lastIndexOf(n), lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
508
|
+
lineStr = chunk.intro + lineStr;
|
|
509
|
+
}
|
|
510
|
+
} while (chunk = chunk.previous);
|
|
511
|
+
return lineIndex = this.intro.lastIndexOf(n), lineIndex !== -1 ? this.intro.substr(lineIndex + 1) + lineStr : this.intro + lineStr;
|
|
512
|
+
}
|
|
513
|
+
slice(start = 0, end = this.original.length - this.offset) {
|
|
514
|
+
if (start = start + this.offset, end = end + this.offset, this.original.length !== 0) {
|
|
515
|
+
for (; start < 0; ) start += this.original.length;
|
|
516
|
+
for (; end < 0; ) end += this.original.length;
|
|
517
|
+
}
|
|
518
|
+
let result = "", chunk = this.firstChunk;
|
|
519
|
+
for (; chunk && (chunk.start > start || chunk.end <= start); ) {
|
|
520
|
+
if (chunk.start < end && chunk.end >= end)
|
|
521
|
+
return result;
|
|
522
|
+
chunk = chunk.next;
|
|
523
|
+
}
|
|
524
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
525
|
+
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
526
|
+
let startChunk = chunk;
|
|
527
|
+
for (; chunk; ) {
|
|
528
|
+
chunk.intro && (startChunk !== chunk || chunk.start === start) && (result += chunk.intro);
|
|
529
|
+
let containsEnd = chunk.start < end && chunk.end >= end;
|
|
530
|
+
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
531
|
+
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
532
|
+
let sliceStart = startChunk === chunk ? start - chunk.start : 0, sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
533
|
+
if (result += chunk.content.slice(sliceStart, sliceEnd), chunk.outro && (!containsEnd || chunk.end === end) && (result += chunk.outro), containsEnd)
|
|
534
|
+
break;
|
|
535
|
+
chunk = chunk.next;
|
|
536
|
+
}
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
// TODO deprecate this? not really very useful
|
|
540
|
+
snip(start, end) {
|
|
541
|
+
let clone = this.clone();
|
|
542
|
+
return clone.remove(0, start), clone.remove(end, clone.original.length), clone;
|
|
543
|
+
}
|
|
544
|
+
_split(index) {
|
|
545
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
546
|
+
let chunk = this.lastSearchedChunk, previousChunk = chunk, searchForward = index > chunk.end;
|
|
547
|
+
for (; chunk; ) {
|
|
548
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
549
|
+
if (chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start], chunk === previousChunk) return;
|
|
550
|
+
previousChunk = chunk;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
_splitChunk(chunk, index) {
|
|
554
|
+
if (chunk.edited && chunk.content.length) {
|
|
555
|
+
let loc = getLocator(this.original)(index);
|
|
556
|
+
throw new Error(
|
|
557
|
+
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
let newChunk = chunk.split(index);
|
|
561
|
+
return this.byEnd[index] = chunk, this.byStart[index] = newChunk, this.byEnd[newChunk.end] = newChunk, chunk === this.lastChunk && (this.lastChunk = newChunk), this.lastSearchedChunk = chunk, !0;
|
|
562
|
+
}
|
|
563
|
+
toString() {
|
|
564
|
+
let str = this.intro, chunk = this.firstChunk;
|
|
565
|
+
for (; chunk; )
|
|
566
|
+
str += chunk.toString(), chunk = chunk.next;
|
|
567
|
+
return str + this.outro;
|
|
568
|
+
}
|
|
569
|
+
isEmpty() {
|
|
570
|
+
let chunk = this.firstChunk;
|
|
571
|
+
do
|
|
572
|
+
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
|
|
573
|
+
return !1;
|
|
574
|
+
while (chunk = chunk.next);
|
|
575
|
+
return !0;
|
|
576
|
+
}
|
|
577
|
+
length() {
|
|
578
|
+
let chunk = this.firstChunk, length = 0;
|
|
579
|
+
do
|
|
580
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
581
|
+
while (chunk = chunk.next);
|
|
582
|
+
return length;
|
|
583
|
+
}
|
|
584
|
+
trimLines() {
|
|
585
|
+
return this.trim("[\\r\\n]");
|
|
586
|
+
}
|
|
587
|
+
trim(charType) {
|
|
588
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
589
|
+
}
|
|
590
|
+
trimEndAborted(charType) {
|
|
591
|
+
let rx = new RegExp((charType || "\\s") + "+$");
|
|
592
|
+
if (this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
593
|
+
let chunk = this.lastChunk;
|
|
594
|
+
do {
|
|
595
|
+
let end = chunk.end, aborted = chunk.trimEnd(rx);
|
|
596
|
+
if (chunk.end !== end && (this.lastChunk === chunk && (this.lastChunk = chunk.next), this.byEnd[chunk.end] = chunk, this.byStart[chunk.next.start] = chunk.next, this.byEnd[chunk.next.end] = chunk.next), aborted) return !0;
|
|
597
|
+
chunk = chunk.previous;
|
|
598
|
+
} while (chunk);
|
|
599
|
+
return !1;
|
|
600
|
+
}
|
|
601
|
+
trimEnd(charType) {
|
|
602
|
+
return this.trimEndAborted(charType), this;
|
|
603
|
+
}
|
|
604
|
+
trimStartAborted(charType) {
|
|
605
|
+
let rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
606
|
+
if (this.intro = this.intro.replace(rx, ""), this.intro.length) return !0;
|
|
607
|
+
let chunk = this.firstChunk;
|
|
608
|
+
do {
|
|
609
|
+
let end = chunk.end, aborted = chunk.trimStart(rx);
|
|
610
|
+
if (chunk.end !== end && (chunk === this.lastChunk && (this.lastChunk = chunk.next), this.byEnd[chunk.end] = chunk, this.byStart[chunk.next.start] = chunk.next, this.byEnd[chunk.next.end] = chunk.next), aborted) return !0;
|
|
611
|
+
chunk = chunk.next;
|
|
612
|
+
} while (chunk);
|
|
613
|
+
return !1;
|
|
614
|
+
}
|
|
615
|
+
trimStart(charType) {
|
|
616
|
+
return this.trimStartAborted(charType), this;
|
|
617
|
+
}
|
|
618
|
+
hasChanged() {
|
|
619
|
+
return this.original !== this.toString();
|
|
620
|
+
}
|
|
621
|
+
_replaceRegexp(searchValue, replacement) {
|
|
622
|
+
function getReplacement(match, str) {
|
|
623
|
+
return typeof replacement == "string" ? replacement.replace(/\$(\$|&|\d+)/g, (_, i) => i === "$" ? "$" : i === "&" ? match[0] : +i < match.length ? match[+i] : `$${i}`) : replacement(...match, match.index, str, match.groups);
|
|
624
|
+
}
|
|
625
|
+
function matchAll(re, str) {
|
|
626
|
+
let match, matches = [];
|
|
627
|
+
for (; match = re.exec(str); )
|
|
628
|
+
matches.push(match);
|
|
629
|
+
return matches;
|
|
630
|
+
}
|
|
631
|
+
if (searchValue.global)
|
|
632
|
+
matchAll(searchValue, this.original).forEach((match) => {
|
|
633
|
+
if (match.index != null) {
|
|
634
|
+
let replacement2 = getReplacement(match, this.original);
|
|
635
|
+
replacement2 !== match[0] && this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
else {
|
|
639
|
+
let match = this.original.match(searchValue);
|
|
640
|
+
if (match && match.index != null) {
|
|
641
|
+
let replacement2 = getReplacement(match, this.original);
|
|
642
|
+
replacement2 !== match[0] && this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return this;
|
|
646
|
+
}
|
|
647
|
+
_replaceString(string, replacement) {
|
|
648
|
+
let { original } = this, index = original.indexOf(string);
|
|
649
|
+
return index !== -1 && (typeof replacement == "function" && (replacement = replacement(string, index, original)), string !== replacement && this.overwrite(index, index + string.length, replacement)), this;
|
|
650
|
+
}
|
|
651
|
+
replace(searchValue, replacement) {
|
|
652
|
+
return typeof searchValue == "string" ? this._replaceString(searchValue, replacement) : this._replaceRegexp(searchValue, replacement);
|
|
653
|
+
}
|
|
654
|
+
_replaceAllString(string, replacement) {
|
|
655
|
+
let { original } = this, stringLength = string.length;
|
|
656
|
+
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
657
|
+
let previous = original.slice(index, index + stringLength), _replacement = replacement;
|
|
658
|
+
typeof replacement == "function" && (_replacement = replacement(previous, index, original)), previous !== _replacement && this.overwrite(index, index + stringLength, _replacement);
|
|
659
|
+
}
|
|
660
|
+
return this;
|
|
661
|
+
}
|
|
662
|
+
replaceAll(searchValue, replacement) {
|
|
663
|
+
if (typeof searchValue == "string")
|
|
664
|
+
return this._replaceAllString(searchValue, replacement);
|
|
665
|
+
if (!searchValue.global)
|
|
666
|
+
throw new TypeError(
|
|
667
|
+
"MagicString.prototype.replaceAll called with a non-global RegExp argument"
|
|
668
|
+
);
|
|
669
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
// ../node_modules/estree-walker/src/walker.js
|
|
674
|
+
var WalkerBase = class {
|
|
675
|
+
constructor() {
|
|
676
|
+
this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.context = {
|
|
677
|
+
skip: () => this.should_skip = !0,
|
|
678
|
+
remove: () => this.should_remove = !0,
|
|
679
|
+
replace: (node) => this.replacement = node
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* @template {Node} Parent
|
|
684
|
+
* @param {Parent | null | undefined} parent
|
|
685
|
+
* @param {keyof Parent | null | undefined} prop
|
|
686
|
+
* @param {number | null | undefined} index
|
|
687
|
+
* @param {Node} node
|
|
688
|
+
*/
|
|
689
|
+
replace(parent, prop, index, node) {
|
|
690
|
+
parent && prop && (index != null ? parent[prop][index] = node : parent[prop] = node);
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* @template {Node} Parent
|
|
694
|
+
* @param {Parent | null | undefined} parent
|
|
695
|
+
* @param {keyof Parent | null | undefined} prop
|
|
696
|
+
* @param {number | null | undefined} index
|
|
697
|
+
*/
|
|
698
|
+
remove(parent, prop, index) {
|
|
699
|
+
parent && prop && (index != null ? parent[prop].splice(index, 1) : delete parent[prop]);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
// ../node_modules/estree-walker/src/sync.js
|
|
704
|
+
var SyncWalker = class extends WalkerBase {
|
|
705
|
+
/**
|
|
706
|
+
*
|
|
707
|
+
* @param {SyncHandler} [enter]
|
|
708
|
+
* @param {SyncHandler} [leave]
|
|
709
|
+
*/
|
|
710
|
+
constructor(enter, leave) {
|
|
711
|
+
super(), this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.context = {
|
|
712
|
+
skip: () => this.should_skip = !0,
|
|
713
|
+
remove: () => this.should_remove = !0,
|
|
714
|
+
replace: (node) => this.replacement = node
|
|
715
|
+
}, this.enter = enter, this.leave = leave;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* @template {Node} Parent
|
|
719
|
+
* @param {Node} node
|
|
720
|
+
* @param {Parent | null} parent
|
|
721
|
+
* @param {keyof Parent} [prop]
|
|
722
|
+
* @param {number | null} [index]
|
|
723
|
+
* @returns {Node | null}
|
|
724
|
+
*/
|
|
725
|
+
visit(node, parent, prop, index) {
|
|
726
|
+
if (node) {
|
|
727
|
+
if (this.enter) {
|
|
728
|
+
let _should_skip = this.should_skip, _should_remove = this.should_remove, _replacement = this.replacement;
|
|
729
|
+
this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.enter.call(this.context, node, parent, prop, index), this.replacement && (node = this.replacement, this.replace(parent, prop, index, node)), this.should_remove && this.remove(parent, prop, index);
|
|
730
|
+
let skipped = this.should_skip, removed = this.should_remove;
|
|
731
|
+
if (this.should_skip = _should_skip, this.should_remove = _should_remove, this.replacement = _replacement, skipped) return node;
|
|
732
|
+
if (removed) return null;
|
|
733
|
+
}
|
|
734
|
+
let key;
|
|
735
|
+
for (key in node) {
|
|
736
|
+
let value = node[key];
|
|
737
|
+
if (value && typeof value == "object")
|
|
738
|
+
if (Array.isArray(value)) {
|
|
739
|
+
let nodes = (
|
|
740
|
+
/** @type {Array<unknown>} */
|
|
741
|
+
value
|
|
742
|
+
);
|
|
743
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
744
|
+
let item = nodes[i];
|
|
745
|
+
isNode(item) && (this.visit(item, node, key, i) || i--);
|
|
746
|
+
}
|
|
747
|
+
} else isNode(value) && this.visit(value, node, key, null);
|
|
748
|
+
}
|
|
749
|
+
if (this.leave) {
|
|
750
|
+
let _replacement = this.replacement, _should_remove = this.should_remove;
|
|
751
|
+
this.replacement = null, this.should_remove = !1, this.leave.call(this.context, node, parent, prop, index), this.replacement && (node = this.replacement, this.replace(parent, prop, index, node)), this.should_remove && this.remove(parent, prop, index);
|
|
752
|
+
let removed = this.should_remove;
|
|
753
|
+
if (this.replacement = _replacement, this.should_remove = _should_remove, removed) return null;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return node;
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
function isNode(value) {
|
|
760
|
+
return value !== null && typeof value == "object" && "type" in value && typeof value.type == "string";
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// ../node_modules/estree-walker/src/index.js
|
|
764
|
+
function walk(ast, { enter, leave }) {
|
|
765
|
+
return new SyncWalker(enter, leave).visit(ast, null);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/mocking-utils/esmWalker.ts
|
|
769
|
+
var isNodeInPatternWeakSet = /* @__PURE__ */ new WeakSet();
|
|
770
|
+
function setIsNodeInPattern(node) {
|
|
771
|
+
return isNodeInPatternWeakSet.add(node);
|
|
772
|
+
}
|
|
773
|
+
function isNodeInPattern(node) {
|
|
774
|
+
return isNodeInPatternWeakSet.has(node);
|
|
775
|
+
}
|
|
776
|
+
function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallExpression }) {
|
|
777
|
+
let parentStack = [], varKindStack = [], scopeMap = /* @__PURE__ */ new WeakMap(), identifiers = [], setScope = (node, name) => {
|
|
778
|
+
let scopeIds = scopeMap.get(node);
|
|
779
|
+
scopeIds && scopeIds.has(name) || (scopeIds || (scopeIds = /* @__PURE__ */ new Set(), scopeMap.set(node, scopeIds)), scopeIds.add(name));
|
|
780
|
+
};
|
|
781
|
+
function isInScope(name, parents) {
|
|
782
|
+
return parents.some((node) => node && scopeMap.get(node)?.has(name));
|
|
783
|
+
}
|
|
784
|
+
function handlePattern(p, parentScope) {
|
|
785
|
+
p.type === "Identifier" ? setScope(parentScope, p.name) : p.type === "RestElement" ? handlePattern(p.argument, parentScope) : p.type === "ObjectPattern" ? p.properties.forEach((property) => {
|
|
786
|
+
property.type === "RestElement" ? setScope(parentScope, property.argument.name) : handlePattern(property.value, parentScope);
|
|
787
|
+
}) : p.type === "ArrayPattern" ? p.elements.forEach((element) => {
|
|
788
|
+
element && handlePattern(element, parentScope);
|
|
789
|
+
}) : p.type === "AssignmentPattern" ? handlePattern(p.left, parentScope) : setScope(parentScope, p.name);
|
|
790
|
+
}
|
|
791
|
+
walk(root, {
|
|
792
|
+
enter(node, parent) {
|
|
793
|
+
if (node.type === "ImportDeclaration")
|
|
794
|
+
return this.skip();
|
|
795
|
+
if (parent && !(parent.type === "IfStatement" && node === parent.alternate) && parentStack.unshift(parent), node.type === "VariableDeclaration" && varKindStack.unshift(node.kind), node.type === "CallExpression" && onCallExpression?.(node), node.type === "MetaProperty" && node.meta.name === "import" ? onImportMeta?.(node) : node.type === "ImportExpression" && onDynamicImport?.(node), node.type === "Identifier")
|
|
796
|
+
!isInScope(node.name, parentStack) && isRefIdentifier(node, parent, parentStack) && identifiers.push([node, parentStack.slice(0)]);
|
|
797
|
+
else if (isFunctionNode(node)) {
|
|
798
|
+
if (node.type === "FunctionDeclaration") {
|
|
799
|
+
let parentScope = findParentScope(parentStack);
|
|
800
|
+
parentScope && setScope(parentScope, node.id.name);
|
|
801
|
+
}
|
|
802
|
+
node.params.forEach((p) => {
|
|
803
|
+
if (p.type === "ObjectPattern" || p.type === "ArrayPattern") {
|
|
804
|
+
handlePattern(p, node);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
walk(p.type === "AssignmentPattern" ? p.left : p, {
|
|
808
|
+
enter(child, parent2) {
|
|
809
|
+
if (parent2?.type === "AssignmentPattern" && parent2?.right === child)
|
|
810
|
+
return this.skip();
|
|
811
|
+
child.type === "Identifier" && (isStaticPropertyKey(child, parent2) || parent2?.type === "TemplateLiteral" && parent2?.expressions.includes(child) || parent2?.type === "CallExpression" && parent2?.callee === child || setScope(node, child.name));
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
} else if (node.type === "Property" && parent.type === "ObjectPattern")
|
|
816
|
+
setIsNodeInPattern(node);
|
|
817
|
+
else if (node.type === "VariableDeclarator") {
|
|
818
|
+
let parentFunction = findParentScope(parentStack, varKindStack[0] === "var");
|
|
819
|
+
parentFunction && handlePattern(node.id, parentFunction);
|
|
820
|
+
} else node.type === "CatchClause" && node.param && handlePattern(node.param, node);
|
|
821
|
+
},
|
|
822
|
+
leave(node, parent) {
|
|
823
|
+
parent && !(parent.type === "IfStatement" && node === parent.alternate) && parentStack.shift(), node.type === "VariableDeclaration" && varKindStack.shift();
|
|
824
|
+
}
|
|
825
|
+
}), identifiers.forEach(([node, stack]) => {
|
|
826
|
+
if (!isInScope(node.name, stack)) {
|
|
827
|
+
let parent = stack[0], grandparent = stack[1], hasBindingShortcut = isStaticProperty(parent) && parent.shorthand && (!isNodeInPattern(parent) || isInDestructuringAssignment(parent, parentStack)), classDeclaration = parent.type === "PropertyDefinition" && grandparent?.type === "ClassBody" || parent.type === "ClassDeclaration" && node === parent.superClass, classExpression = parent.type === "ClassExpression" && node === parent.id;
|
|
828
|
+
onIdentifier?.(
|
|
829
|
+
node,
|
|
830
|
+
{
|
|
831
|
+
hasBindingShortcut,
|
|
832
|
+
classDeclaration,
|
|
833
|
+
classExpression
|
|
834
|
+
},
|
|
835
|
+
stack
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
function isRefIdentifier(id, parent, parentStack) {
|
|
841
|
+
return !(parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id || isFunctionNode(parent) && (parent.id === id || parent.params.includes(id)) || parent.type === "MethodDefinition" && !parent.computed || isStaticPropertyKey(id, parent) || isNodeInPattern(parent) && parent.value === id || parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack) || parent.type === "MemberExpression" && parent.property === id && !parent.computed || parent.type === "ExportSpecifier" || id.name === "arguments");
|
|
842
|
+
}
|
|
843
|
+
function isStaticProperty(node) {
|
|
844
|
+
return node && node.type === "Property" && !node.computed;
|
|
845
|
+
}
|
|
846
|
+
function isStaticPropertyKey(node, parent) {
|
|
847
|
+
return isStaticProperty(parent) && parent.key === node;
|
|
848
|
+
}
|
|
849
|
+
var functionNodeTypeRE = /Function(?:Expression|Declaration)$|Method$/;
|
|
850
|
+
function isFunctionNode(node) {
|
|
851
|
+
return functionNodeTypeRE.test(node.type);
|
|
852
|
+
}
|
|
853
|
+
var blockNodeTypeRE = /^BlockStatement$|^For(?:In|Of)?Statement$/;
|
|
854
|
+
function isBlock(node) {
|
|
855
|
+
return blockNodeTypeRE.test(node.type);
|
|
856
|
+
}
|
|
857
|
+
function findParentScope(parentStack, isVar = !1) {
|
|
858
|
+
return parentStack.find(isVar ? isFunctionNode : isBlock);
|
|
859
|
+
}
|
|
860
|
+
function isInDestructuringAssignment(parent, parentStack) {
|
|
861
|
+
return parent && (parent.type === "Property" || parent.type === "ArrayPattern") ? parentStack.some((i) => i.type === "AssignmentExpression") : !1;
|
|
862
|
+
}
|
|
863
|
+
function getArbitraryModuleIdentifier(node) {
|
|
864
|
+
return node.type === "Identifier" ? node.name : node.raw;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// src/mocking-utils/automock.ts
|
|
868
|
+
var __STORYBOOK_GLOBAL_THIS_ACCESSOR__ = "__vitest_mocker__";
|
|
869
|
+
function getAutomockCode(originalCode, isSpy, parse) {
|
|
870
|
+
return automockModule(originalCode, isSpy ? "autospy" : "automock", parse, {
|
|
871
|
+
globalThisAccessor: JSON.stringify(__STORYBOOK_GLOBAL_THIS_ACCESSOR__)
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
function automockModule(code, mockType, parse, options = {}) {
|
|
875
|
+
let globalThisAccessor = options.globalThisAccessor || JSON.stringify(__STORYBOOK_GLOBAL_THIS_ACCESSOR__), ast = parse(code), m = new MagicString(code), allSpecifiers = [], importIndex = 0;
|
|
876
|
+
for (let _node of ast.body) {
|
|
877
|
+
if (_node.type === "ExportAllDeclaration")
|
|
878
|
+
throw new Error(
|
|
879
|
+
"automocking files with `export *` is not supported in browser mode because it cannot be statically analysed"
|
|
880
|
+
);
|
|
881
|
+
if (_node.type === "ExportNamedDeclaration") {
|
|
882
|
+
let traversePattern2 = function(expression) {
|
|
883
|
+
if (expression.type === "Identifier")
|
|
884
|
+
allSpecifiers.push({ name: expression.name });
|
|
885
|
+
else if (expression.type === "ArrayPattern")
|
|
886
|
+
expression.elements.forEach((element) => {
|
|
887
|
+
element && traversePattern2(element);
|
|
888
|
+
});
|
|
889
|
+
else if (expression.type === "ObjectPattern")
|
|
890
|
+
expression.properties.forEach((property) => {
|
|
891
|
+
property.type === "RestElement" ? traversePattern2(property) : property.type === "Property" && traversePattern2(property.value);
|
|
892
|
+
});
|
|
893
|
+
else if (expression.type === "RestElement")
|
|
894
|
+
traversePattern2(expression.argument);
|
|
895
|
+
else {
|
|
896
|
+
if (expression.type === "AssignmentPattern")
|
|
897
|
+
throw new Error("AssignmentPattern is not supported. Please open a new bug report.");
|
|
898
|
+
if (expression.type === "MemberExpression")
|
|
899
|
+
throw new Error("MemberExpression is not supported. Please open a new bug report.");
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
var traversePattern = traversePattern2;
|
|
903
|
+
let node = _node, declaration = node.declaration;
|
|
904
|
+
declaration && (declaration.type === "FunctionDeclaration" ? allSpecifiers.push({ name: declaration.id.name }) : declaration.type === "VariableDeclaration" ? declaration.declarations.forEach((declaration2) => {
|
|
905
|
+
traversePattern2(declaration2.id);
|
|
906
|
+
}) : declaration.type === "ClassDeclaration" && allSpecifiers.push({ name: declaration.id.name }), m.remove(node.start, declaration.start));
|
|
907
|
+
let specifiers = node.specifiers || [], source = node.source;
|
|
908
|
+
if (!source && specifiers.length)
|
|
909
|
+
specifiers.forEach((specifier) => {
|
|
910
|
+
allSpecifiers.push({
|
|
911
|
+
alias: getArbitraryModuleIdentifier(specifier.exported),
|
|
912
|
+
name: getArbitraryModuleIdentifier(specifier.local)
|
|
913
|
+
});
|
|
914
|
+
}), m.remove(node.start, node.end);
|
|
915
|
+
else if (source && specifiers.length) {
|
|
916
|
+
let importNames = [];
|
|
917
|
+
specifiers.forEach((specifier) => {
|
|
918
|
+
let importedName = `__vitest_imported_${importIndex++}__`;
|
|
919
|
+
importNames.push([getArbitraryModuleIdentifier(specifier.local), importedName]), allSpecifiers.push({
|
|
920
|
+
name: importedName,
|
|
921
|
+
alias: getArbitraryModuleIdentifier(specifier.exported)
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
let importString = `import { ${importNames.map(([name, alias]) => `${name} as ${alias}`).join(", ")} } from '${source.value}'`;
|
|
925
|
+
m.overwrite(node.start, node.end, importString);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
if (_node.type === "ExportDefaultDeclaration") {
|
|
929
|
+
let node = _node, declaration = node.declaration;
|
|
930
|
+
allSpecifiers.push({ name: "__vitest_default", alias: "default" }), m.overwrite(node.start, declaration.start, "const __vitest_default = ");
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
let moduleObject = `
|
|
934
|
+
const __vitest_current_es_module__ = {
|
|
935
|
+
__esModule: true,
|
|
936
|
+
${allSpecifiers.map(({ name }) => `["${name}"]: ${name},`).join(`
|
|
937
|
+
`)}
|
|
938
|
+
}
|
|
939
|
+
const __vitest_mocked_module__ = globalThis[${globalThisAccessor}].mockObject(__vitest_current_es_module__, "${mockType}")
|
|
940
|
+
`, assigning = allSpecifiers.map(({ name }, index) => `const __vitest_mocked_${index}__ = __vitest_mocked_module__["${name}"]`).join(`
|
|
941
|
+
`), specifiersExports = `
|
|
942
|
+
export {
|
|
943
|
+
${allSpecifiers.map(({ name, alias }, index) => ` __vitest_mocked_${index}__ as ${alias || name},`).join(`
|
|
944
|
+
`)}
|
|
945
|
+
}
|
|
946
|
+
`;
|
|
947
|
+
return m.append(moduleObject + assigning + specifiersExports), m;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/mocking-utils/extract.ts
|
|
951
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
952
|
+
import { generate, parser, types as t2 } from "storybook/internal/babel";
|
|
953
|
+
import { logger } from "storybook/internal/node-logger";
|
|
954
|
+
import { telemetry } from "storybook/internal/telemetry";
|
|
955
|
+
import { transformSync } from "esbuild";
|
|
956
|
+
|
|
957
|
+
// src/mocking-utils/resolve.ts
|
|
958
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
959
|
+
import { createRequire } from "node:module";
|
|
960
|
+
|
|
961
|
+
// ../node_modules/resolve.exports/dist/index.mjs
|
|
962
|
+
function e(e2, n3, r2) {
|
|
963
|
+
throw new Error(r2 ? `No known conditions for "${n3}" specifier in "${e2}" package` : `Missing "${n3}" specifier in "${e2}" package`);
|
|
964
|
+
}
|
|
965
|
+
function n2(n3, i, o2, f) {
|
|
966
|
+
let s, u, l = r(n3, o2), c = (function(e2) {
|
|
967
|
+
let n4 = /* @__PURE__ */ new Set(["default", ...e2.conditions || []]);
|
|
968
|
+
return e2.unsafe || n4.add(e2.require ? "require" : "import"), e2.unsafe || n4.add(e2.browser ? "browser" : "node"), n4;
|
|
969
|
+
})(f || {}), a = i[l];
|
|
970
|
+
if (a === void 0) {
|
|
971
|
+
let e2, n4, r2, t3;
|
|
972
|
+
for (t3 in i) n4 && t3.length < n4.length || (t3[t3.length - 1] === "/" && l.startsWith(t3) ? (u = l.substring(t3.length), n4 = t3) : t3.length > 1 && (r2 = t3.indexOf("*", 1), ~r2 && (e2 = RegExp("^" + t3.substring(0, r2) + "(.*)" + t3.substring(1 + r2) + "$").exec(l), e2 && e2[1] && (u = e2[1], n4 = t3))));
|
|
973
|
+
a = i[n4];
|
|
974
|
+
}
|
|
975
|
+
return a || e(n3, l), s = t(a, c), s || e(n3, l, 1), u && (function(e2, n4) {
|
|
976
|
+
let r2, t3 = 0, i2 = e2.length, o3 = /[*]/g, f2 = /[/]$/;
|
|
977
|
+
for (; t3 < i2; t3++) e2[t3] = o3.test(r2 = e2[t3]) ? r2.replace(o3, n4) : f2.test(r2) ? r2 + n4 : r2;
|
|
978
|
+
})(s, u), s;
|
|
979
|
+
}
|
|
980
|
+
function r(e2, n3, r2) {
|
|
981
|
+
if (e2 === n3 || n3 === ".") return ".";
|
|
982
|
+
let t3 = e2 + "/", i = t3.length, o2 = n3.slice(0, i) === t3, f = o2 ? n3.slice(i) : n3;
|
|
983
|
+
return f[0] === "#" ? f : o2 || !r2 ? f.slice(0, 2) === "./" ? f : "./" + f : f;
|
|
984
|
+
}
|
|
985
|
+
function t(e2, n3, r2) {
|
|
986
|
+
if (e2) {
|
|
987
|
+
if (typeof e2 == "string") return r2 && r2.add(e2), [e2];
|
|
988
|
+
let i, o2;
|
|
989
|
+
if (Array.isArray(e2)) {
|
|
990
|
+
for (o2 = r2 || /* @__PURE__ */ new Set(), i = 0; i < e2.length; i++) t(e2[i], n3, o2);
|
|
991
|
+
if (!r2 && o2.size) return [...o2];
|
|
992
|
+
} else for (i in e2) if (n3.has(i)) return t(e2[i], n3, r2);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
function o(e2, r2, t3) {
|
|
996
|
+
let i, o2 = e2.exports;
|
|
997
|
+
if (o2) {
|
|
998
|
+
if (typeof o2 == "string") o2 = { ".": o2 };
|
|
999
|
+
else for (i in o2) {
|
|
1000
|
+
i[0] !== "." && (o2 = { ".": o2 });
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
return n2(e2.name, o2, r2 || ".", t3);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/mocking-utils/resolve.ts
|
|
1008
|
+
var require2 = createRequire(import.meta.url);
|
|
1009
|
+
function findPackageJson(specifier, basedir) {
|
|
1010
|
+
let packageJsonPath = require2.resolve(`${specifier}/package.json`, { paths: [basedir] });
|
|
1011
|
+
return {
|
|
1012
|
+
path: packageJsonPath,
|
|
1013
|
+
data: JSON.parse(readFileSync(packageJsonPath, "utf-8"))
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function resolveExternalModule(path, root) {
|
|
1017
|
+
let parts = path.split("/"), packageName = path.startsWith("@") ? `${parts[0]}/${parts[1]}` : parts[0], entry = `.${path.slice(packageName.length)}`, { path: packageJsonPath, data: pkg } = findPackageJson(packageName, root), packageDir = dirname(packageJsonPath);
|
|
1018
|
+
if (pkg.exports) {
|
|
1019
|
+
let result = o(pkg, entry, {
|
|
1020
|
+
browser: !0
|
|
1021
|
+
});
|
|
1022
|
+
if (result)
|
|
1023
|
+
return join(packageDir, result[0]);
|
|
1024
|
+
}
|
|
1025
|
+
return require2.resolve(path, { paths: [root] });
|
|
1026
|
+
}
|
|
1027
|
+
function getIsExternal(path, importer) {
|
|
1028
|
+
try {
|
|
1029
|
+
return !isAbsolute(path) && isModuleDirectory(require2.resolve(path, { paths: [importer] }));
|
|
1030
|
+
} catch {
|
|
1031
|
+
return !1;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
function resolveMock(path, root, importer, findMockRedirect) {
|
|
1035
|
+
let isExternal2 = getIsExternal(path, root), externalPath = isExternal2 ? path : null, absolutePath = isExternal2 ? resolveExternalModule(path, root) : require2.resolve(path, { paths: [dirname(importer)] }), normalizedAbsolutePath = resolve(absolutePath), redirectPath = findMockRedirect(root, normalizedAbsolutePath, externalPath);
|
|
1036
|
+
return {
|
|
1037
|
+
absolutePath: normalizedAbsolutePath,
|
|
1038
|
+
redirectPath
|
|
1039
|
+
// will be null if no __mocks__ file is found
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function isExternal(path, from) {
|
|
1043
|
+
try {
|
|
1044
|
+
return !isAbsolute(path) && isModuleDirectory(require2.resolve(path, { paths: [from] }));
|
|
1045
|
+
} catch {
|
|
1046
|
+
return !1;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
function getRealPath(path, preserveSymlinks) {
|
|
1050
|
+
try {
|
|
1051
|
+
return preserveSymlinks ? realpathSync(path) : path;
|
|
1052
|
+
} catch {
|
|
1053
|
+
return path;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
function resolveWithExtensions(path, from) {
|
|
1057
|
+
let extensions = [".js", ".ts", ".tsx", ".mjs", ".cjs", ".svelte", ".vue"];
|
|
1058
|
+
for (let extension of extensions)
|
|
1059
|
+
try {
|
|
1060
|
+
return require2.resolve(path + extension, { paths: [from] });
|
|
1061
|
+
} catch {
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
return require2.resolve(path, { paths: [from] });
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/mocking-utils/extract.ts
|
|
1068
|
+
var DEFAULT_MODULE_DIRECTORIES = ["/node_modules/"];
|
|
1069
|
+
function isModuleDirectory(path) {
|
|
1070
|
+
let normalizedPath = normalize(path);
|
|
1071
|
+
return DEFAULT_MODULE_DIRECTORIES.some((dir) => normalizedPath.includes(dir));
|
|
1072
|
+
}
|
|
1073
|
+
var babelParser = (code) => parser.parse(code, {
|
|
1074
|
+
sourceType: "module",
|
|
1075
|
+
// Enable plugins to handle modern JavaScript features, including TSX.
|
|
1076
|
+
plugins: ["typescript", "jsx", "classProperties", "objectRestSpread"],
|
|
1077
|
+
errorRecovery: !0
|
|
1078
|
+
}).program;
|
|
1079
|
+
function rewriteSbMockImportCalls(code) {
|
|
1080
|
+
let ast = babelParser(code);
|
|
1081
|
+
return walk(ast, {
|
|
1082
|
+
enter(node) {
|
|
1083
|
+
node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "sb" && node.callee.property.type === "Identifier" && node.callee.property.name === "mock" && node.arguments.length > 0 && node.arguments[0].type === "CallExpression" && node.arguments[0].callee.type === "Import" && node.arguments[0].arguments.length === 1 && node.arguments[0].arguments[0].type === "StringLiteral" && (node.arguments[0] = t2.stringLiteral(node.arguments[0].arguments[0].value));
|
|
1084
|
+
}
|
|
1085
|
+
}), generate(ast, {}, code);
|
|
1086
|
+
}
|
|
1087
|
+
function extractMockCalls(options, parse, root, findMockRedirect) {
|
|
1088
|
+
try {
|
|
1089
|
+
let hasSpyTrue2 = function(objectExpression) {
|
|
1090
|
+
if (!objectExpression || !objectExpression.properties)
|
|
1091
|
+
return !1;
|
|
1092
|
+
for (let prop of objectExpression.properties)
|
|
1093
|
+
if (prop.type === "ObjectProperty" && (prop.key.type === "Identifier" && prop.key.name === "spy" || prop.key.type === "StringLiteral" && prop.key.value === "spy") && prop.value.type === "BooleanLiteral" && prop.value.value === !0)
|
|
1094
|
+
return !0;
|
|
1095
|
+
return !1;
|
|
1096
|
+
};
|
|
1097
|
+
var hasSpyTrue = hasSpyTrue2;
|
|
1098
|
+
let previewConfigCode = readFileSync2(options.previewConfigPath, "utf-8"), { code: jsCode } = transformSync(previewConfigCode, { loader: "tsx", format: "esm" }), ast = parse(jsCode), mocks = [];
|
|
1099
|
+
return walk(ast, {
|
|
1100
|
+
// @ts-expect-error - Node comes from babel
|
|
1101
|
+
async enter(node) {
|
|
1102
|
+
if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression" || node.callee.object.type !== "Identifier" || node.callee.object.name !== "sb" || node.callee.property.type !== "Identifier" || node.callee.property.name !== "mock" || node.arguments.length === 0)
|
|
1103
|
+
return;
|
|
1104
|
+
let path;
|
|
1105
|
+
if (node.arguments[0].type === "StringLiteral")
|
|
1106
|
+
path = node.arguments[0].value;
|
|
1107
|
+
else if (node.arguments[0].type === "CallExpression" && node.arguments[0].callee.type === "Import" && node.arguments[0].arguments[0].type === "StringLiteral")
|
|
1108
|
+
path = node.arguments[0].arguments[0].value;
|
|
1109
|
+
else
|
|
1110
|
+
return;
|
|
1111
|
+
let spy = node.arguments.length > 1 && node.arguments[1].type === "ObjectExpression" && hasSpyTrue2(node.arguments[1]), { absolutePath, redirectPath } = resolveMock(
|
|
1112
|
+
path,
|
|
1113
|
+
root,
|
|
1114
|
+
options.previewConfigPath,
|
|
1115
|
+
findMockRedirect
|
|
1116
|
+
), pathWithoutExtension = path.replace(/\.[^/.]+$/, ""), basenameAbsolutePath = basename(absolutePath), basenamePath = basename(path), pathWithoutExtensionAndBasename = basenameAbsolutePath === basenamePath ? pathWithoutExtension : path;
|
|
1117
|
+
mocks.push({
|
|
1118
|
+
path: pathWithoutExtensionAndBasename,
|
|
1119
|
+
absolutePath,
|
|
1120
|
+
redirectPath,
|
|
1121
|
+
spy
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
}), options.coreOptions?.disableTelemetry || telemetry(
|
|
1125
|
+
"mocking",
|
|
1126
|
+
{
|
|
1127
|
+
modulesMocked: mocks.length,
|
|
1128
|
+
modulesSpied: mocks.map((mock) => mock.spy).filter(Boolean).length,
|
|
1129
|
+
modulesManuallyMocked: mocks.map((mock) => !!mock.redirectPath).filter(Boolean).length
|
|
1130
|
+
},
|
|
1131
|
+
{ configDir: options.configDir }
|
|
1132
|
+
), mocks;
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
return logger.debug("Error extracting mock calls: " + String(error)), [];
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// src/mocking-utils/runtime.ts
|
|
1139
|
+
import { resolvePackageDir } from "storybook/internal/common";
|
|
1140
|
+
import { buildSync } from "esbuild";
|
|
1141
|
+
var runtimeTemplatePath = join(
|
|
1142
|
+
resolvePackageDir("storybook"),
|
|
1143
|
+
"assets",
|
|
1144
|
+
"server",
|
|
1145
|
+
"mocker-runtime.template.js"
|
|
1146
|
+
);
|
|
1147
|
+
function getMockerRuntime() {
|
|
1148
|
+
return buildSync({
|
|
1149
|
+
entryPoints: [runtimeTemplatePath],
|
|
1150
|
+
bundle: !0,
|
|
1151
|
+
write: !1,
|
|
1152
|
+
// Return the result in memory instead of writing to disk
|
|
1153
|
+
format: "esm",
|
|
1154
|
+
target: "es2020",
|
|
1155
|
+
external: ["msw/browser", "msw/core/http"]
|
|
1156
|
+
}).outputFiles[0].text;
|
|
1157
|
+
}
|
|
1158
|
+
export {
|
|
1159
|
+
__STORYBOOK_GLOBAL_THIS_ACCESSOR__,
|
|
1160
|
+
automockModule,
|
|
1161
|
+
babelParser,
|
|
1162
|
+
esmWalker,
|
|
1163
|
+
extractMockCalls,
|
|
1164
|
+
getArbitraryModuleIdentifier,
|
|
1165
|
+
getAutomockCode,
|
|
1166
|
+
getIsExternal,
|
|
1167
|
+
getMockerRuntime,
|
|
1168
|
+
getRealPath,
|
|
1169
|
+
isExternal,
|
|
1170
|
+
isFunctionNode,
|
|
1171
|
+
isInDestructuringAssignment,
|
|
1172
|
+
isModuleDirectory,
|
|
1173
|
+
isNodeInPattern,
|
|
1174
|
+
isStaticProperty,
|
|
1175
|
+
isStaticPropertyKey,
|
|
1176
|
+
resolveExternalModule,
|
|
1177
|
+
resolveMock,
|
|
1178
|
+
resolveWithExtensions,
|
|
1179
|
+
rewriteSbMockImportCalls,
|
|
1180
|
+
setIsNodeInPattern
|
|
1181
|
+
};
|