@rasputin-ai/browser 0.6.0
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/README.md +111 -0
- package/dist/browser-frames.d.ts +11 -0
- package/dist/browser-frames.d.ts.map +1 -0
- package/dist/browser-ingest-event.d.ts +10 -0
- package/dist/browser-ingest-event.d.ts.map +1 -0
- package/dist/browser-recorder.d.ts +36 -0
- package/dist/browser-recorder.d.ts.map +1 -0
- package/dist/browser-runtime-types.d.ts +207 -0
- package/dist/browser-runtime-types.d.ts.map +1 -0
- package/dist/browser-runtime.d.ts +14 -0
- package/dist/browser-runtime.d.ts.map +1 -0
- package/dist/browser-transport.d.ts +36 -0
- package/dist/browser-transport.d.ts.map +1 -0
- package/dist/captured-value.d.ts +48 -0
- package/dist/captured-value.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3706 -0
- package/dist/ingest-types.d.ts +75 -0
- package/dist/ingest-types.d.ts.map +1 -0
- package/dist/install-browser-handlers.d.ts +14 -0
- package/dist/install-browser-handlers.d.ts.map +1 -0
- package/dist/install-browser-runtime.d.ts +11 -0
- package/dist/install-browser-runtime.d.ts.map +1 -0
- package/dist/map-runtime-state.d.ts +4 -0
- package/dist/map-runtime-state.d.ts.map +1 -0
- package/dist/native-json-producer.d.ts +40 -0
- package/dist/native-json-producer.d.ts.map +1 -0
- package/dist/public-types.d.ts +116 -0
- package/dist/public-types.d.ts.map +1 -0
- package/dist/rasputin-init.d.ts +7 -0
- package/dist/rasputin-init.d.ts.map +1 -0
- package/dist/sdk-meta.d.ts +4 -0
- package/dist/sdk-meta.d.ts.map +1 -0
- package/dist/stack/fold-synthetic-frames.d.ts +9 -0
- package/dist/stack/fold-synthetic-frames.d.ts.map +1 -0
- package/dist/stack/parse-stack.d.ts +3 -0
- package/dist/stack/parse-stack.d.ts.map +1 -0
- package/dist/stack/raw-frame.d.ts +7 -0
- package/dist/stack/raw-frame.d.ts.map +1 -0
- package/dist/vite/artifacts.d.ts +102 -0
- package/dist/vite/artifacts.d.ts.map +1 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +4666 -0
- package/dist/vite/plugin.d.ts +48 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/resolve-build-identity.d.ts +8 -0
- package/dist/vite/resolve-build-identity.d.ts.map +1 -0
- package/dist/vite/upload-browser-artifacts.d.ts +10 -0
- package/dist/vite/upload-browser-artifacts.d.ts.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,4666 @@
|
|
|
1
|
+
// src/vite/plugin.ts
|
|
2
|
+
import { isAbsolute as isAbsolute2, relative as relative2, resolve as resolve5 } from "node:path";
|
|
3
|
+
|
|
4
|
+
// ../instrumentation/src/classify-function.ts
|
|
5
|
+
import { resolve as resolve3 } from "node:path";
|
|
6
|
+
|
|
7
|
+
// ../recorder/src/encoded-function-plan.ts
|
|
8
|
+
var compactRuntimeFunctionId = (moduleIndex, planIndex) => `${moduleIndex}.${planIndex}`;
|
|
9
|
+
|
|
10
|
+
// ../core/src/create-ingest-event/truncate-ingest-message.ts
|
|
11
|
+
var MAX_MESSAGE_BYTES = 8 * 1024;
|
|
12
|
+
|
|
13
|
+
// ../core/src/source-identity/source-identity.ts
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
var packageBoundaryByDirectory = /* @__PURE__ */ new Map();
|
|
19
|
+
var toPosix = (path) => path.replaceAll("\\", "/");
|
|
20
|
+
var physicalPath = (file) => {
|
|
21
|
+
if (!file.startsWith("file://")) return resolve(file);
|
|
22
|
+
try {
|
|
23
|
+
return fileURLToPath(file);
|
|
24
|
+
} catch {
|
|
25
|
+
return resolve(file.replace(/^file:\/\//, ""));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var readPackageBoundary = (directory) => {
|
|
29
|
+
const visited = [];
|
|
30
|
+
let current = resolve(directory);
|
|
31
|
+
while (true) {
|
|
32
|
+
const cached = packageBoundaryByDirectory.get(current);
|
|
33
|
+
if (cached !== void 0) {
|
|
34
|
+
for (const path of visited) packageBoundaryByDirectory.set(path, cached);
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
visited.push(current);
|
|
38
|
+
const packageJson = resolve(current, "package.json");
|
|
39
|
+
if (existsSync(packageJson)) {
|
|
40
|
+
let name;
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
43
|
+
if (typeof parsed.name === "string" && parsed.name.trim()) name = parsed.name.trim();
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
const boundary = { root: current, ...name ? { name } : {} };
|
|
47
|
+
for (const path of visited) packageBoundaryByDirectory.set(path, boundary);
|
|
48
|
+
return boundary;
|
|
49
|
+
}
|
|
50
|
+
const parent = dirname(current);
|
|
51
|
+
if (parent === current) {
|
|
52
|
+
for (const path of visited) packageBoundaryByDirectory.set(path, null);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
current = parent;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var sourceLocatorFromFile = (file) => {
|
|
59
|
+
if (!file || /^(node:|bun:|https?:|webpack:|blob:|data:|native$)/i.test(file)) return void 0;
|
|
60
|
+
const absolute = physicalPath(file.split("?")[0] ?? file);
|
|
61
|
+
const boundary = readPackageBoundary(dirname(absolute));
|
|
62
|
+
if (!boundary) return void 0;
|
|
63
|
+
const fromPackage = relative(boundary.root, absolute);
|
|
64
|
+
if (!fromPackage || fromPackage === ".." || fromPackage.startsWith(`..${sep}`) || isAbsolute(fromPackage)) {
|
|
65
|
+
return { packageRelativePath: basename(absolute) };
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
...boundary.name ? { packageName: boundary.name } : {},
|
|
69
|
+
packageRelativePath: toPosix(fromPackage)
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var runtimeFunctionId = (definition) => {
|
|
73
|
+
const source = definition.source;
|
|
74
|
+
const identity = [
|
|
75
|
+
definition.name,
|
|
76
|
+
source?.packageName ?? "",
|
|
77
|
+
source?.packageRelativePath ?? "",
|
|
78
|
+
String(source?.line ?? ""),
|
|
79
|
+
String(source?.column ?? "")
|
|
80
|
+
].join("\0");
|
|
81
|
+
return `rf_${createHash("sha256").update(identity).digest("base64url").slice(0, 24)}`;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// ../node_modules/.bun/@jridgewell+sourcemap-codec@1.6.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
85
|
+
var comma = ",".charCodeAt(0);
|
|
86
|
+
var semicolon = ";".charCodeAt(0);
|
|
87
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
88
|
+
var intToChar = new Uint8Array(64);
|
|
89
|
+
var charToInt = new Uint8Array(128);
|
|
90
|
+
for (let i = 0; i < chars.length; i++) {
|
|
91
|
+
const c = chars.charCodeAt(i);
|
|
92
|
+
intToChar[i] = c;
|
|
93
|
+
charToInt[c] = i;
|
|
94
|
+
}
|
|
95
|
+
function decodeInteger(reader) {
|
|
96
|
+
let value = 0;
|
|
97
|
+
let shift = 0;
|
|
98
|
+
let integer = 0;
|
|
99
|
+
do {
|
|
100
|
+
const c = reader.next();
|
|
101
|
+
integer = charToInt[c];
|
|
102
|
+
value |= (integer & 31) << shift;
|
|
103
|
+
shift += 5;
|
|
104
|
+
} while (integer & 32);
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
function decodeSign(num) {
|
|
108
|
+
return num & 1 ? -2147483648 | -(num >>> 1) : num >>> 1;
|
|
109
|
+
}
|
|
110
|
+
function encodeInteger(builder, num) {
|
|
111
|
+
do {
|
|
112
|
+
let clamped = num & 31;
|
|
113
|
+
num >>>= 5;
|
|
114
|
+
if (num > 0) clamped |= 32;
|
|
115
|
+
builder.write(intToChar[clamped]);
|
|
116
|
+
} while (num > 0);
|
|
117
|
+
}
|
|
118
|
+
function encodeSign(num) {
|
|
119
|
+
return num < 0 ? -num << 1 | 1 : num << 1;
|
|
120
|
+
}
|
|
121
|
+
function hasMoreVlq(reader, max) {
|
|
122
|
+
if (reader.pos >= max) return false;
|
|
123
|
+
return reader.peek() !== comma;
|
|
124
|
+
}
|
|
125
|
+
var bufLength = 1024 * 16;
|
|
126
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
|
|
127
|
+
decode(buf) {
|
|
128
|
+
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
129
|
+
return out.toString();
|
|
130
|
+
}
|
|
131
|
+
} : {
|
|
132
|
+
decode(buf) {
|
|
133
|
+
let out = "";
|
|
134
|
+
for (let i = 0; i < buf.length; i++) {
|
|
135
|
+
out += String.fromCharCode(buf[i]);
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var StringWriter = class {
|
|
141
|
+
constructor() {
|
|
142
|
+
this.pos = 0;
|
|
143
|
+
this.out = "";
|
|
144
|
+
this.buffer = new Uint8Array(bufLength);
|
|
145
|
+
}
|
|
146
|
+
write(v) {
|
|
147
|
+
const { buffer } = this;
|
|
148
|
+
buffer[this.pos++] = v;
|
|
149
|
+
if (this.pos === bufLength) {
|
|
150
|
+
this.out += td.decode(buffer);
|
|
151
|
+
this.pos = 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
flush() {
|
|
155
|
+
const { buffer, out, pos } = this;
|
|
156
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var StringReader = class {
|
|
160
|
+
constructor(buffer) {
|
|
161
|
+
this.pos = 0;
|
|
162
|
+
this.buffer = buffer;
|
|
163
|
+
}
|
|
164
|
+
next() {
|
|
165
|
+
return this.buffer.charCodeAt(this.pos++);
|
|
166
|
+
}
|
|
167
|
+
peek() {
|
|
168
|
+
return this.buffer.charCodeAt(this.pos);
|
|
169
|
+
}
|
|
170
|
+
indexOf(char) {
|
|
171
|
+
const { buffer, pos } = this;
|
|
172
|
+
const idx = buffer.indexOf(char, pos);
|
|
173
|
+
return idx === -1 ? buffer.length : idx;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
function decode(mappings) {
|
|
177
|
+
const { length } = mappings;
|
|
178
|
+
const reader = new StringReader(mappings);
|
|
179
|
+
const decoded = [];
|
|
180
|
+
let genColumn = 0;
|
|
181
|
+
let sourcesIndex = 0;
|
|
182
|
+
let sourceLine = 0;
|
|
183
|
+
let sourceColumn = 0;
|
|
184
|
+
let namesIndex = 0;
|
|
185
|
+
do {
|
|
186
|
+
const semi = reader.indexOf(";");
|
|
187
|
+
const line = [];
|
|
188
|
+
let sorted = true;
|
|
189
|
+
let lastCol = 0;
|
|
190
|
+
genColumn = 0;
|
|
191
|
+
while (reader.pos < semi) {
|
|
192
|
+
let seg;
|
|
193
|
+
genColumn += decodeSign(decodeInteger(reader));
|
|
194
|
+
if (genColumn < lastCol) sorted = false;
|
|
195
|
+
lastCol = genColumn;
|
|
196
|
+
if (hasMoreVlq(reader, semi)) {
|
|
197
|
+
sourcesIndex += decodeSign(decodeInteger(reader));
|
|
198
|
+
sourceLine += decodeSign(decodeInteger(reader));
|
|
199
|
+
sourceColumn += decodeSign(decodeInteger(reader));
|
|
200
|
+
if (hasMoreVlq(reader, semi)) {
|
|
201
|
+
namesIndex += decodeSign(decodeInteger(reader));
|
|
202
|
+
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
|
|
203
|
+
} else {
|
|
204
|
+
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
seg = [genColumn];
|
|
208
|
+
}
|
|
209
|
+
line.push(seg);
|
|
210
|
+
reader.pos++;
|
|
211
|
+
}
|
|
212
|
+
if (!sorted) sort(line);
|
|
213
|
+
decoded.push(line);
|
|
214
|
+
reader.pos = semi + 1;
|
|
215
|
+
} while (reader.pos <= length);
|
|
216
|
+
return decoded;
|
|
217
|
+
}
|
|
218
|
+
function sort(line) {
|
|
219
|
+
line.sort(sortComparator);
|
|
220
|
+
}
|
|
221
|
+
function sortComparator(a, b) {
|
|
222
|
+
return a[0] - b[0];
|
|
223
|
+
}
|
|
224
|
+
function encode(decoded) {
|
|
225
|
+
const writer = new StringWriter();
|
|
226
|
+
let sourcesIndex = 0;
|
|
227
|
+
let sourceLine = 0;
|
|
228
|
+
let sourceColumn = 0;
|
|
229
|
+
let namesIndex = 0;
|
|
230
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
231
|
+
const line = decoded[i];
|
|
232
|
+
if (i > 0) writer.write(semicolon);
|
|
233
|
+
if (line.length === 0) continue;
|
|
234
|
+
let genColumn = 0;
|
|
235
|
+
for (let j = 0; j < line.length; j++) {
|
|
236
|
+
const segment = line[j];
|
|
237
|
+
if (j > 0) writer.write(comma);
|
|
238
|
+
encodeInteger(writer, encodeSign(segment[0] - genColumn));
|
|
239
|
+
genColumn = segment[0];
|
|
240
|
+
if (segment.length === 1) continue;
|
|
241
|
+
encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
|
|
242
|
+
encodeInteger(writer, encodeSign(segment[2] - sourceLine));
|
|
243
|
+
encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
|
|
244
|
+
sourcesIndex = segment[1];
|
|
245
|
+
sourceLine = segment[2];
|
|
246
|
+
sourceColumn = segment[3];
|
|
247
|
+
if (segment.length === 4) continue;
|
|
248
|
+
encodeInteger(writer, encodeSign(segment[4] - namesIndex));
|
|
249
|
+
namesIndex = segment[4];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return writer.flush();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ../node_modules/.bun/@jridgewell+resolve-uri@3.1.2/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
|
|
256
|
+
var schemeRegex = /^[\w+.-]+:\/\//;
|
|
257
|
+
var urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
258
|
+
var fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
259
|
+
function isAbsoluteUrl(input) {
|
|
260
|
+
return schemeRegex.test(input);
|
|
261
|
+
}
|
|
262
|
+
function isSchemeRelativeUrl(input) {
|
|
263
|
+
return input.startsWith("//");
|
|
264
|
+
}
|
|
265
|
+
function isAbsolutePath(input) {
|
|
266
|
+
return input.startsWith("/");
|
|
267
|
+
}
|
|
268
|
+
function isFileUrl(input) {
|
|
269
|
+
return input.startsWith("file:");
|
|
270
|
+
}
|
|
271
|
+
function isRelative(input) {
|
|
272
|
+
return /^[.?#]/.test(input);
|
|
273
|
+
}
|
|
274
|
+
function parseAbsoluteUrl(input) {
|
|
275
|
+
const match = urlRegex.exec(input);
|
|
276
|
+
return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
|
|
277
|
+
}
|
|
278
|
+
function parseFileUrl(input) {
|
|
279
|
+
const match = fileRegex.exec(input);
|
|
280
|
+
const path = match[2];
|
|
281
|
+
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
|
|
282
|
+
}
|
|
283
|
+
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
284
|
+
return {
|
|
285
|
+
scheme,
|
|
286
|
+
user,
|
|
287
|
+
host,
|
|
288
|
+
port,
|
|
289
|
+
path,
|
|
290
|
+
query,
|
|
291
|
+
hash,
|
|
292
|
+
type: 7
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function parseUrl(input) {
|
|
296
|
+
if (isSchemeRelativeUrl(input)) {
|
|
297
|
+
const url2 = parseAbsoluteUrl("http:" + input);
|
|
298
|
+
url2.scheme = "";
|
|
299
|
+
url2.type = 6;
|
|
300
|
+
return url2;
|
|
301
|
+
}
|
|
302
|
+
if (isAbsolutePath(input)) {
|
|
303
|
+
const url2 = parseAbsoluteUrl("http://foo.com" + input);
|
|
304
|
+
url2.scheme = "";
|
|
305
|
+
url2.host = "";
|
|
306
|
+
url2.type = 5;
|
|
307
|
+
return url2;
|
|
308
|
+
}
|
|
309
|
+
if (isFileUrl(input))
|
|
310
|
+
return parseFileUrl(input);
|
|
311
|
+
if (isAbsoluteUrl(input))
|
|
312
|
+
return parseAbsoluteUrl(input);
|
|
313
|
+
const url = parseAbsoluteUrl("http://foo.com/" + input);
|
|
314
|
+
url.scheme = "";
|
|
315
|
+
url.host = "";
|
|
316
|
+
url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
|
|
317
|
+
return url;
|
|
318
|
+
}
|
|
319
|
+
function stripPathFilename(path) {
|
|
320
|
+
if (path.endsWith("/.."))
|
|
321
|
+
return path;
|
|
322
|
+
const index = path.lastIndexOf("/");
|
|
323
|
+
return path.slice(0, index + 1);
|
|
324
|
+
}
|
|
325
|
+
function mergePaths(url, base) {
|
|
326
|
+
normalizePath(base, base.type);
|
|
327
|
+
if (url.path === "/") {
|
|
328
|
+
url.path = base.path;
|
|
329
|
+
} else {
|
|
330
|
+
url.path = stripPathFilename(base.path) + url.path;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function normalizePath(url, type) {
|
|
334
|
+
const rel = type <= 4;
|
|
335
|
+
const pieces = url.path.split("/");
|
|
336
|
+
let pointer = 1;
|
|
337
|
+
let positive = 0;
|
|
338
|
+
let addTrailingSlash = false;
|
|
339
|
+
for (let i = 1; i < pieces.length; i++) {
|
|
340
|
+
const piece = pieces[i];
|
|
341
|
+
if (!piece) {
|
|
342
|
+
addTrailingSlash = true;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
addTrailingSlash = false;
|
|
346
|
+
if (piece === ".")
|
|
347
|
+
continue;
|
|
348
|
+
if (piece === "..") {
|
|
349
|
+
if (positive) {
|
|
350
|
+
addTrailingSlash = true;
|
|
351
|
+
positive--;
|
|
352
|
+
pointer--;
|
|
353
|
+
} else if (rel) {
|
|
354
|
+
pieces[pointer++] = piece;
|
|
355
|
+
}
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
pieces[pointer++] = piece;
|
|
359
|
+
positive++;
|
|
360
|
+
}
|
|
361
|
+
let path = "";
|
|
362
|
+
for (let i = 1; i < pointer; i++) {
|
|
363
|
+
path += "/" + pieces[i];
|
|
364
|
+
}
|
|
365
|
+
if (!path || addTrailingSlash && !path.endsWith("/..")) {
|
|
366
|
+
path += "/";
|
|
367
|
+
}
|
|
368
|
+
url.path = path;
|
|
369
|
+
}
|
|
370
|
+
function resolve2(input, base) {
|
|
371
|
+
if (!input && !base)
|
|
372
|
+
return "";
|
|
373
|
+
const url = parseUrl(input);
|
|
374
|
+
let inputType = url.type;
|
|
375
|
+
if (base && inputType !== 7) {
|
|
376
|
+
const baseUrl = parseUrl(base);
|
|
377
|
+
const baseType = baseUrl.type;
|
|
378
|
+
switch (inputType) {
|
|
379
|
+
case 1:
|
|
380
|
+
url.hash = baseUrl.hash;
|
|
381
|
+
// fall through
|
|
382
|
+
case 2:
|
|
383
|
+
url.query = baseUrl.query;
|
|
384
|
+
// fall through
|
|
385
|
+
case 3:
|
|
386
|
+
case 4:
|
|
387
|
+
mergePaths(url, baseUrl);
|
|
388
|
+
// fall through
|
|
389
|
+
case 5:
|
|
390
|
+
url.user = baseUrl.user;
|
|
391
|
+
url.host = baseUrl.host;
|
|
392
|
+
url.port = baseUrl.port;
|
|
393
|
+
// fall through
|
|
394
|
+
case 6:
|
|
395
|
+
url.scheme = baseUrl.scheme;
|
|
396
|
+
}
|
|
397
|
+
if (baseType > inputType)
|
|
398
|
+
inputType = baseType;
|
|
399
|
+
}
|
|
400
|
+
normalizePath(url, inputType);
|
|
401
|
+
const queryHash = url.query + url.hash;
|
|
402
|
+
switch (inputType) {
|
|
403
|
+
// This is impossible, because of the empty checks at the start of the function.
|
|
404
|
+
// case UrlType.Empty:
|
|
405
|
+
case 2:
|
|
406
|
+
case 3:
|
|
407
|
+
return queryHash;
|
|
408
|
+
case 4: {
|
|
409
|
+
const path = url.path.slice(1);
|
|
410
|
+
if (!path)
|
|
411
|
+
return queryHash || ".";
|
|
412
|
+
if (isRelative(base || input) && !isRelative(path)) {
|
|
413
|
+
return "./" + path + queryHash;
|
|
414
|
+
}
|
|
415
|
+
return path + queryHash;
|
|
416
|
+
}
|
|
417
|
+
case 5:
|
|
418
|
+
return url.path + queryHash;
|
|
419
|
+
default:
|
|
420
|
+
return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ../node_modules/.bun/@jridgewell+trace-mapping@0.3.31/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
|
|
425
|
+
function stripFilename(path) {
|
|
426
|
+
if (!path) return "";
|
|
427
|
+
const index = path.lastIndexOf("/");
|
|
428
|
+
return path.slice(0, index + 1);
|
|
429
|
+
}
|
|
430
|
+
function resolver(mapUrl, sourceRoot) {
|
|
431
|
+
const from = stripFilename(mapUrl);
|
|
432
|
+
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
433
|
+
return (source) => resolve2(prefix + (source || ""), from);
|
|
434
|
+
}
|
|
435
|
+
var COLUMN = 0;
|
|
436
|
+
var SOURCES_INDEX = 1;
|
|
437
|
+
var SOURCE_LINE = 2;
|
|
438
|
+
var SOURCE_COLUMN = 3;
|
|
439
|
+
var NAMES_INDEX = 4;
|
|
440
|
+
function maybeSort(mappings, owned) {
|
|
441
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
442
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
443
|
+
if (!owned) mappings = mappings.slice();
|
|
444
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
445
|
+
mappings[i] = sortSegments(mappings[i], owned);
|
|
446
|
+
}
|
|
447
|
+
return mappings;
|
|
448
|
+
}
|
|
449
|
+
function nextUnsortedSegmentLine(mappings, start) {
|
|
450
|
+
for (let i = start; i < mappings.length; i++) {
|
|
451
|
+
if (!isSorted(mappings[i])) return i;
|
|
452
|
+
}
|
|
453
|
+
return mappings.length;
|
|
454
|
+
}
|
|
455
|
+
function isSorted(line) {
|
|
456
|
+
for (let j = 1; j < line.length; j++) {
|
|
457
|
+
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
function sortSegments(line, owned) {
|
|
464
|
+
if (!owned) line = line.slice();
|
|
465
|
+
return line.sort(sortComparator2);
|
|
466
|
+
}
|
|
467
|
+
function sortComparator2(a, b) {
|
|
468
|
+
return a[COLUMN] - b[COLUMN];
|
|
469
|
+
}
|
|
470
|
+
var found = false;
|
|
471
|
+
function binarySearch(haystack, needle, low, high) {
|
|
472
|
+
while (low <= high) {
|
|
473
|
+
const mid = low + (high - low >> 1);
|
|
474
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
475
|
+
if (cmp === 0) {
|
|
476
|
+
found = true;
|
|
477
|
+
return mid;
|
|
478
|
+
}
|
|
479
|
+
if (cmp < 0) {
|
|
480
|
+
low = mid + 1;
|
|
481
|
+
} else {
|
|
482
|
+
high = mid - 1;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
found = false;
|
|
486
|
+
return low - 1;
|
|
487
|
+
}
|
|
488
|
+
function upperBound(haystack, needle, index) {
|
|
489
|
+
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
490
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
491
|
+
}
|
|
492
|
+
return index;
|
|
493
|
+
}
|
|
494
|
+
function lowerBound(haystack, needle, index) {
|
|
495
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
496
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
497
|
+
}
|
|
498
|
+
return index;
|
|
499
|
+
}
|
|
500
|
+
function memoizedState() {
|
|
501
|
+
return {
|
|
502
|
+
lastKey: -1,
|
|
503
|
+
lastNeedle: -1,
|
|
504
|
+
lastIndex: -1
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
508
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
509
|
+
let low = 0;
|
|
510
|
+
let high = haystack.length - 1;
|
|
511
|
+
if (key === lastKey) {
|
|
512
|
+
if (needle === lastNeedle) {
|
|
513
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
514
|
+
return lastIndex;
|
|
515
|
+
}
|
|
516
|
+
if (needle >= lastNeedle) {
|
|
517
|
+
low = lastIndex === -1 ? 0 : lastIndex;
|
|
518
|
+
} else {
|
|
519
|
+
high = lastIndex;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
state.lastKey = key;
|
|
523
|
+
state.lastNeedle = needle;
|
|
524
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
525
|
+
}
|
|
526
|
+
function parse(map) {
|
|
527
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
528
|
+
}
|
|
529
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
530
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
531
|
+
var LEAST_UPPER_BOUND = -1;
|
|
532
|
+
var GREATEST_LOWER_BOUND = 1;
|
|
533
|
+
var TraceMap = class {
|
|
534
|
+
constructor(map, mapUrl) {
|
|
535
|
+
const isString = typeof map === "string";
|
|
536
|
+
if (!isString && map._decodedMemo) return map;
|
|
537
|
+
const parsed = parse(map);
|
|
538
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
539
|
+
this.version = version;
|
|
540
|
+
this.file = file;
|
|
541
|
+
this.names = names || [];
|
|
542
|
+
this.sourceRoot = sourceRoot;
|
|
543
|
+
this.sources = sources;
|
|
544
|
+
this.sourcesContent = sourcesContent;
|
|
545
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
546
|
+
const resolve6 = resolver(mapUrl, sourceRoot);
|
|
547
|
+
this.resolvedSources = sources.map(resolve6);
|
|
548
|
+
const { mappings } = parsed;
|
|
549
|
+
if (typeof mappings === "string") {
|
|
550
|
+
this._encoded = mappings;
|
|
551
|
+
this._decoded = void 0;
|
|
552
|
+
} else if (Array.isArray(mappings)) {
|
|
553
|
+
this._encoded = void 0;
|
|
554
|
+
this._decoded = maybeSort(mappings, isString);
|
|
555
|
+
} else if (parsed.sections) {
|
|
556
|
+
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
557
|
+
} else {
|
|
558
|
+
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
559
|
+
}
|
|
560
|
+
this._decodedMemo = memoizedState();
|
|
561
|
+
this._bySources = void 0;
|
|
562
|
+
this._bySourceMemos = void 0;
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
function cast(map) {
|
|
566
|
+
return map;
|
|
567
|
+
}
|
|
568
|
+
function decodedMappings(map) {
|
|
569
|
+
var _a;
|
|
570
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
571
|
+
}
|
|
572
|
+
function originalPositionFor(map, needle) {
|
|
573
|
+
let { line, column, bias } = needle;
|
|
574
|
+
line--;
|
|
575
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
576
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
577
|
+
const decoded = decodedMappings(map);
|
|
578
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
579
|
+
const segments = decoded[line];
|
|
580
|
+
const index = traceSegmentInternal(
|
|
581
|
+
segments,
|
|
582
|
+
cast(map)._decodedMemo,
|
|
583
|
+
line,
|
|
584
|
+
column,
|
|
585
|
+
bias || GREATEST_LOWER_BOUND
|
|
586
|
+
);
|
|
587
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
588
|
+
const segment = segments[index];
|
|
589
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
590
|
+
const { names, resolvedSources } = map;
|
|
591
|
+
return OMapping(
|
|
592
|
+
resolvedSources[segment[SOURCES_INDEX]],
|
|
593
|
+
segment[SOURCE_LINE] + 1,
|
|
594
|
+
segment[SOURCE_COLUMN],
|
|
595
|
+
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
function OMapping(source, line, column, name) {
|
|
599
|
+
return { source, line, column, name };
|
|
600
|
+
}
|
|
601
|
+
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
602
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
603
|
+
if (found) {
|
|
604
|
+
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
605
|
+
} else if (bias === LEAST_UPPER_BOUND) index++;
|
|
606
|
+
if (index === -1 || index === segments.length) return -1;
|
|
607
|
+
return index;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// ../core/src/resolve-source-maps/resolve-source-maps.ts
|
|
611
|
+
var MAX_MAP_CACHE_BYTES = 8 * 1024 * 1024;
|
|
612
|
+
|
|
613
|
+
// ../core/src/transport/process-shutdown-hooks.ts
|
|
614
|
+
var SIGNAL_EXIT_CODES = { SIGTERM: 143, SIGINT: 130 };
|
|
615
|
+
var RASPUTIN_PROCESS_LISTENER = Symbol.for("rasputin.process.listener.v1");
|
|
616
|
+
var removeProcessListener = process.off.bind(process);
|
|
617
|
+
var tagListener = (listener) => {
|
|
618
|
+
Object.defineProperty(listener, RASPUTIN_PROCESS_LISTENER, { value: true });
|
|
619
|
+
return listener;
|
|
620
|
+
};
|
|
621
|
+
var hostProcessListenerCount = (event) => {
|
|
622
|
+
const listeners = event === "beforeExit" ? process.listeners("beforeExit") : process.listeners(event);
|
|
623
|
+
return listeners.filter((listener) => !(RASPUTIN_PROCESS_LISTENER in listener)).length;
|
|
624
|
+
};
|
|
625
|
+
var exitAfterFlush = (done, code) => {
|
|
626
|
+
void done.finally(() => {
|
|
627
|
+
process.exit(code);
|
|
628
|
+
});
|
|
629
|
+
};
|
|
630
|
+
var participants = /* @__PURE__ */ new Set();
|
|
631
|
+
var shuttingDown = false;
|
|
632
|
+
var onBeforeExit = tagListener(() => {
|
|
633
|
+
for (const participant of participants) participant.onBeforeExit();
|
|
634
|
+
});
|
|
635
|
+
var handleSignal = (signal) => {
|
|
636
|
+
if (shuttingDown) return;
|
|
637
|
+
shuttingDown = true;
|
|
638
|
+
const hostOwns = hostProcessListenerCount(signal) > 0;
|
|
639
|
+
const snapshot = [...participants];
|
|
640
|
+
const done = Promise.all(snapshot.map((participant) => participant.onSignal().catch(() => {
|
|
641
|
+
}))).then(() => {
|
|
642
|
+
for (const participant of snapshot) participant.dropRemaining();
|
|
643
|
+
}).then(() => {
|
|
644
|
+
});
|
|
645
|
+
if (!hostOwns) exitAfterFlush(done, SIGNAL_EXIT_CODES[signal] ?? 143);
|
|
646
|
+
};
|
|
647
|
+
var onTerm = tagListener(() => {
|
|
648
|
+
handleSignal("SIGTERM");
|
|
649
|
+
});
|
|
650
|
+
var onInt = tagListener(() => {
|
|
651
|
+
handleSignal("SIGINT");
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// ../core/src/transport/create-transport.ts
|
|
655
|
+
var DEFAULTS = {
|
|
656
|
+
enabled: true,
|
|
657
|
+
maxQueueSize: 500,
|
|
658
|
+
maxQueueBytes: 8 * 1024 * 1024,
|
|
659
|
+
batchSize: 30,
|
|
660
|
+
flushIntervalMs: 5e3,
|
|
661
|
+
gzipThresholdBytes: 10 * 1024,
|
|
662
|
+
maxRetries: 5,
|
|
663
|
+
installSignalHandlers: true,
|
|
664
|
+
maxBatchReplays: 8,
|
|
665
|
+
maxRetryBatchAgeMs: 6e4,
|
|
666
|
+
shutdownFlushMs: 2e3
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// ../core/src/derivation/sensitive-property-name.ts
|
|
670
|
+
var DEFAULT_SENSITIVE_PROPERTY_NAMES = [
|
|
671
|
+
"password",
|
|
672
|
+
"passwd",
|
|
673
|
+
"pwd",
|
|
674
|
+
"passphrase",
|
|
675
|
+
"token",
|
|
676
|
+
"accesstoken",
|
|
677
|
+
"refreshtoken",
|
|
678
|
+
"sessiontoken",
|
|
679
|
+
"authorization",
|
|
680
|
+
"auth",
|
|
681
|
+
"bearer",
|
|
682
|
+
"cookie",
|
|
683
|
+
"cookies",
|
|
684
|
+
"signedcookies",
|
|
685
|
+
"setcookie",
|
|
686
|
+
"secret",
|
|
687
|
+
"secrets",
|
|
688
|
+
"clientsecret",
|
|
689
|
+
"apikey",
|
|
690
|
+
"xapikey",
|
|
691
|
+
"credential",
|
|
692
|
+
"credentials",
|
|
693
|
+
"privatekey",
|
|
694
|
+
"privkey",
|
|
695
|
+
"pem",
|
|
696
|
+
"jwt",
|
|
697
|
+
"otp",
|
|
698
|
+
"totp",
|
|
699
|
+
"pin",
|
|
700
|
+
"mfacode",
|
|
701
|
+
"sessionid",
|
|
702
|
+
"sid",
|
|
703
|
+
"databaseurl",
|
|
704
|
+
"connectionstring",
|
|
705
|
+
"dsn",
|
|
706
|
+
"mongouri",
|
|
707
|
+
"redisurl",
|
|
708
|
+
"signingkey",
|
|
709
|
+
"encryptionkey",
|
|
710
|
+
"cvv",
|
|
711
|
+
"cvc",
|
|
712
|
+
"cardnumber",
|
|
713
|
+
"ssn",
|
|
714
|
+
"creditcard",
|
|
715
|
+
"securitycode",
|
|
716
|
+
"twofactorcode",
|
|
717
|
+
"masterkey",
|
|
718
|
+
"servicerolekey",
|
|
719
|
+
"stripekey",
|
|
720
|
+
"rawheaders"
|
|
721
|
+
];
|
|
722
|
+
var DEFAULT_SENSITIVE_PROPERTY_NAME_SET = new Set(DEFAULT_SENSITIVE_PROPERTY_NAMES);
|
|
723
|
+
var SENSITIVE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
724
|
+
"password",
|
|
725
|
+
"passwd",
|
|
726
|
+
"pwd",
|
|
727
|
+
"passphrase",
|
|
728
|
+
"token",
|
|
729
|
+
"secret",
|
|
730
|
+
"cookie",
|
|
731
|
+
"cookies",
|
|
732
|
+
"authorization",
|
|
733
|
+
"auth",
|
|
734
|
+
"bearer",
|
|
735
|
+
"credential",
|
|
736
|
+
"credentials",
|
|
737
|
+
"jwt",
|
|
738
|
+
"otp",
|
|
739
|
+
"totp",
|
|
740
|
+
"pin",
|
|
741
|
+
"sid",
|
|
742
|
+
"dsn",
|
|
743
|
+
"pem",
|
|
744
|
+
"privkey",
|
|
745
|
+
"cvv",
|
|
746
|
+
"cvc",
|
|
747
|
+
"ssn",
|
|
748
|
+
"secrets"
|
|
749
|
+
]);
|
|
750
|
+
var SENSITIVE_SUFFIXES = [
|
|
751
|
+
"password",
|
|
752
|
+
"passwd",
|
|
753
|
+
"token",
|
|
754
|
+
"secret",
|
|
755
|
+
"apikey",
|
|
756
|
+
"privatekey",
|
|
757
|
+
"credential",
|
|
758
|
+
"credentials",
|
|
759
|
+
"cookie"
|
|
760
|
+
];
|
|
761
|
+
var compactKey = (key) => {
|
|
762
|
+
let compacted = "";
|
|
763
|
+
for (let index = 0; index < key.length; index++) {
|
|
764
|
+
const code = key.charCodeAt(index);
|
|
765
|
+
if (code === 45 || code === 46 || code === 95) continue;
|
|
766
|
+
compacted += code >= 65 && code <= 90 ? String.fromCharCode(code + 32) : key[index];
|
|
767
|
+
}
|
|
768
|
+
return compacted;
|
|
769
|
+
};
|
|
770
|
+
var stripTrailingDigits = (value) => {
|
|
771
|
+
let end = value.length;
|
|
772
|
+
while (end > 0) {
|
|
773
|
+
const code = value.charCodeAt(end - 1);
|
|
774
|
+
if (code < 48 || code > 57) break;
|
|
775
|
+
end--;
|
|
776
|
+
}
|
|
777
|
+
return end === 0 ? value : value.slice(0, end);
|
|
778
|
+
};
|
|
779
|
+
var segmentsOf = (key) => {
|
|
780
|
+
const segments = [];
|
|
781
|
+
let current = "";
|
|
782
|
+
for (let index = 0; index < key.length; index++) {
|
|
783
|
+
const char = key[index] ?? "";
|
|
784
|
+
const code = key.charCodeAt(index);
|
|
785
|
+
if (code === 45 || code === 46 || code === 95) {
|
|
786
|
+
if (current) segments.push(current.toLowerCase());
|
|
787
|
+
current = "";
|
|
788
|
+
continue;
|
|
789
|
+
}
|
|
790
|
+
if (current && code >= 65 && code <= 90) {
|
|
791
|
+
const prev = current.charCodeAt(current.length - 1);
|
|
792
|
+
const prevIsLower = prev >= 97 && prev <= 122;
|
|
793
|
+
const next = key.charCodeAt(index + 1);
|
|
794
|
+
const nextIsLower = next >= 97 && next <= 122;
|
|
795
|
+
if (prevIsLower || nextIsLower) {
|
|
796
|
+
segments.push(current.toLowerCase());
|
|
797
|
+
current = char;
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
current += char;
|
|
802
|
+
}
|
|
803
|
+
if (current) segments.push(current.toLowerCase());
|
|
804
|
+
return segments;
|
|
805
|
+
};
|
|
806
|
+
var adjacentPairsSensitive = (left, right) => left === "api" && right === "key" || left === "private" && right === "key" || left === "client" && right === "secret" || left === "set" && right === "cookie" || left === "database" && right === "url" || left === "connection" && right === "string" || left === "mongo" && (right === "uri" || right === "url") || left === "mongodb" && (right === "uri" || right === "url") || left === "redis" && (right === "uri" || right === "url") || left === "postgres" && (right === "uri" || right === "url") || left === "database" && right === "uri" || left === "signing" && right === "key" || left === "master" && right === "key" || left === "stripe" && right === "key" || left === "service" && right === "role" || left === "security" && right === "code" || left === "two" && right === "factor" || left === "encryption" && right === "key" || left === "session" && (right === "id" || right === "key" || right === "token") || left === "card" && right === "number" || left === "mfa" && right === "code";
|
|
807
|
+
var propertyNameIsSensitive = (key) => {
|
|
808
|
+
const compacted = compactKey(key);
|
|
809
|
+
const compactForms = [compacted, stripTrailingDigits(compacted)].filter(
|
|
810
|
+
(value, index, values) => value.length > 0 && values.indexOf(value) === index
|
|
811
|
+
);
|
|
812
|
+
for (const form of compactForms) {
|
|
813
|
+
if (DEFAULT_SENSITIVE_PROPERTY_NAME_SET.has(form)) return true;
|
|
814
|
+
for (const suffix of SENSITIVE_SUFFIXES) {
|
|
815
|
+
if (form.endsWith(suffix)) return true;
|
|
816
|
+
}
|
|
817
|
+
if (form.includes("apikey") || form.includes("xapikey")) return true;
|
|
818
|
+
}
|
|
819
|
+
const segments = segmentsOf(key).map((segment) => stripTrailingDigits(segment) || segment);
|
|
820
|
+
for (const segment of segments) {
|
|
821
|
+
if (SENSITIVE_SEGMENTS.has(segment)) return true;
|
|
822
|
+
}
|
|
823
|
+
for (let index = 0; index < segments.length - 1; index++) {
|
|
824
|
+
const left = segments[index];
|
|
825
|
+
const right = segments[index + 1];
|
|
826
|
+
if (left && right && adjacentPairsSensitive(left, right)) return true;
|
|
827
|
+
}
|
|
828
|
+
return false;
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// ../recorder/src/function-plan.ts
|
|
832
|
+
var encodeFunctionPlan = (source) => {
|
|
833
|
+
const locator = sourceLocatorFromFile(source.filePath);
|
|
834
|
+
const definition = {
|
|
835
|
+
name: source.name,
|
|
836
|
+
...locator ? { source: { ...locator, line: source.line, column: source.column } } : {}
|
|
837
|
+
};
|
|
838
|
+
return [
|
|
839
|
+
runtimeFunctionId(definition),
|
|
840
|
+
source.name,
|
|
841
|
+
locator?.packageName ?? null,
|
|
842
|
+
locator?.packageRelativePath ?? null,
|
|
843
|
+
source.line,
|
|
844
|
+
source.column
|
|
845
|
+
];
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
// ../recorder/src/runtime-symbol.ts
|
|
849
|
+
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
850
|
+
|
|
851
|
+
// ../instrumentation/src/classify-function.ts
|
|
852
|
+
import ts4 from "typescript";
|
|
853
|
+
|
|
854
|
+
// ../instrumentation/src/collect-instrumentation-delta.ts
|
|
855
|
+
import ts from "typescript";
|
|
856
|
+
var paramBindingFromName = (name, sourceFile) => {
|
|
857
|
+
if (ts.isIdentifier(name)) return { kind: "identifier", name: name.text };
|
|
858
|
+
if (ts.isArrayBindingPattern(name)) {
|
|
859
|
+
const elements = name.elements.map(
|
|
860
|
+
(element) => {
|
|
861
|
+
if (ts.isOmittedExpression(element)) return { kind: "omitted" };
|
|
862
|
+
const binding = paramBindingFromName(element.name, sourceFile);
|
|
863
|
+
if (element.dotDotDotToken) return { kind: "rest", binding };
|
|
864
|
+
return binding;
|
|
865
|
+
}
|
|
866
|
+
);
|
|
867
|
+
return { kind: "array", elements };
|
|
868
|
+
}
|
|
869
|
+
const properties = name.elements.map((element) => {
|
|
870
|
+
const binding = paramBindingFromName(element.name, sourceFile);
|
|
871
|
+
const key = element.propertyName ? element.propertyName.getText(sourceFile).replace(/^['"]|['"]$/g, "") : ts.isIdentifier(element.name) ? element.name.text : element.name.getText(sourceFile);
|
|
872
|
+
if (element.dotDotDotToken) {
|
|
873
|
+
const rest = { kind: "rest", binding };
|
|
874
|
+
return { key, binding: rest };
|
|
875
|
+
}
|
|
876
|
+
return { key, binding };
|
|
877
|
+
});
|
|
878
|
+
return { kind: "object", properties };
|
|
879
|
+
};
|
|
880
|
+
var collectFunctionParams = (node, sourceFile) => {
|
|
881
|
+
const params = [];
|
|
882
|
+
for (const parameter of node.parameters) {
|
|
883
|
+
if (ts.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
884
|
+
const binding = paramBindingFromName(parameter.name, sourceFile);
|
|
885
|
+
params.push(parameter.dotDotDotToken ? { kind: "rest", binding } : binding);
|
|
886
|
+
}
|
|
887
|
+
return { params, paramNames: identifierNames(params) };
|
|
888
|
+
};
|
|
889
|
+
var identifierNames = (bindings) => {
|
|
890
|
+
const names = /* @__PURE__ */ new Set();
|
|
891
|
+
const walk = (node) => {
|
|
892
|
+
if (node.kind === "identifier") {
|
|
893
|
+
names.add(node.name);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (node.kind === "rest") {
|
|
897
|
+
walk(node.binding);
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
if (node.kind === "object") {
|
|
901
|
+
for (const property of node.properties) walk(property.binding);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
if (node.kind === "array") {
|
|
905
|
+
for (const element of node.elements) {
|
|
906
|
+
if (element.kind !== "omitted") walk(element);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
for (const item of bindings) walk(item);
|
|
911
|
+
return names;
|
|
912
|
+
};
|
|
913
|
+
var mappedLocation = (sourceFile, position, absolutePath, mapLocation) => {
|
|
914
|
+
const generated = sourceFile.getLineAndCharacterOfPosition(position);
|
|
915
|
+
const raw = {
|
|
916
|
+
filePath: absolutePath,
|
|
917
|
+
line: generated.line + 1,
|
|
918
|
+
column: generated.character + 1
|
|
919
|
+
};
|
|
920
|
+
return mapLocation ? mapLocation(raw) : raw;
|
|
921
|
+
};
|
|
922
|
+
var unwrapExpression = (expression) => {
|
|
923
|
+
let current = expression;
|
|
924
|
+
while (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current)) {
|
|
925
|
+
current = current.expression;
|
|
926
|
+
}
|
|
927
|
+
if (ts.isAwaitExpression(current)) return unwrapExpression(current.expression);
|
|
928
|
+
return current;
|
|
929
|
+
};
|
|
930
|
+
var calleeFromExpression = (expression, sourceFile) => {
|
|
931
|
+
const current = unwrapExpression(expression);
|
|
932
|
+
if (ts.isIdentifier(current)) {
|
|
933
|
+
return { calleeName: current.text, calleeText: current.text };
|
|
934
|
+
}
|
|
935
|
+
if (ts.isPropertyAccessExpression(current) && ts.isIdentifier(current.name)) {
|
|
936
|
+
return {
|
|
937
|
+
calleeName: current.name.text,
|
|
938
|
+
calleeText: current.getText(sourceFile).replace(/\s+/g, "")
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
return null;
|
|
942
|
+
};
|
|
943
|
+
var resultBindingForCall = (call) => {
|
|
944
|
+
let node = call.parent;
|
|
945
|
+
if (ts.isAwaitExpression(node)) node = node.parent;
|
|
946
|
+
if (!ts.isVariableDeclaration(node)) return null;
|
|
947
|
+
if (!ts.isIdentifier(node.name)) return null;
|
|
948
|
+
const initializer = node.initializer;
|
|
949
|
+
if (!initializer) return null;
|
|
950
|
+
const inner = unwrapExpression(initializer);
|
|
951
|
+
if (inner !== call) return null;
|
|
952
|
+
return node.name.text;
|
|
953
|
+
};
|
|
954
|
+
var argIdentifiersForCall = (call) => {
|
|
955
|
+
const identifiers = [];
|
|
956
|
+
call.arguments?.forEach((argument, index) => {
|
|
957
|
+
if (ts.isIdentifier(argument)) {
|
|
958
|
+
identifiers.push({ index, kind: "identifier", name: argument.text });
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (!ts.isObjectLiteralExpression(argument)) return;
|
|
962
|
+
const properties = [];
|
|
963
|
+
for (const property of argument.properties) {
|
|
964
|
+
if (ts.isShorthandPropertyAssignment(property)) {
|
|
965
|
+
properties.push({ key: property.name.text, name: property.name.text });
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && ts.isIdentifier(property.initializer)) {
|
|
969
|
+
properties.push({ key: property.name.text, name: property.initializer.text });
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (properties.length > 0) {
|
|
973
|
+
identifiers.push({ index, kind: "object", properties });
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
return identifiers;
|
|
977
|
+
};
|
|
978
|
+
var collectCallSite = (call, caller, context) => {
|
|
979
|
+
const callee = calleeFromExpression(call.expression, context.sourceFile);
|
|
980
|
+
if (!callee) return null;
|
|
981
|
+
const start = mappedLocation(
|
|
982
|
+
context.sourceFile,
|
|
983
|
+
call.getStart(context.sourceFile),
|
|
984
|
+
context.absolutePath,
|
|
985
|
+
context.mapLocation
|
|
986
|
+
);
|
|
987
|
+
const end = mappedLocation(
|
|
988
|
+
context.sourceFile,
|
|
989
|
+
call.end,
|
|
990
|
+
context.absolutePath,
|
|
991
|
+
context.mapLocation
|
|
992
|
+
);
|
|
993
|
+
if (!start || !end) return null;
|
|
994
|
+
return {
|
|
995
|
+
callerFunctionId: caller.functionId,
|
|
996
|
+
calleeName: callee.calleeName,
|
|
997
|
+
calleeText: callee.calleeText,
|
|
998
|
+
filePath: start.filePath,
|
|
999
|
+
line: start.line,
|
|
1000
|
+
column: start.column,
|
|
1001
|
+
endLine: end.line,
|
|
1002
|
+
endColumn: end.column,
|
|
1003
|
+
resultBinding: resultBindingForCall(call),
|
|
1004
|
+
argIdentifiers: argIdentifiersForCall(call)
|
|
1005
|
+
};
|
|
1006
|
+
};
|
|
1007
|
+
var collectParamDestructure = (declaration, caller, context) => {
|
|
1008
|
+
if (!declaration.initializer || !ts.isIdentifier(declaration.initializer)) return null;
|
|
1009
|
+
if (!ts.isObjectBindingPattern(declaration.name) && !ts.isArrayBindingPattern(declaration.name)) {
|
|
1010
|
+
return null;
|
|
1011
|
+
}
|
|
1012
|
+
const sourceParam = declaration.initializer.text;
|
|
1013
|
+
if (!caller.paramNames.has(sourceParam)) return null;
|
|
1014
|
+
const start = mappedLocation(
|
|
1015
|
+
context.sourceFile,
|
|
1016
|
+
declaration.getStart(context.sourceFile),
|
|
1017
|
+
context.absolutePath,
|
|
1018
|
+
context.mapLocation
|
|
1019
|
+
);
|
|
1020
|
+
if (!start) return null;
|
|
1021
|
+
return {
|
|
1022
|
+
callerFunctionId: caller.functionId,
|
|
1023
|
+
sourceParam,
|
|
1024
|
+
filePath: start.filePath,
|
|
1025
|
+
line: start.line,
|
|
1026
|
+
column: start.column,
|
|
1027
|
+
binding: paramBindingFromName(declaration.name, context.sourceFile)
|
|
1028
|
+
};
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
// ../instrumentation/src/parse-source.ts
|
|
1032
|
+
import ts2 from "typescript";
|
|
1033
|
+
var scriptKindFor = (filePath) => {
|
|
1034
|
+
if (/\.tsx$/i.test(filePath)) return ts2.ScriptKind.TSX;
|
|
1035
|
+
if (/\.jsx$/i.test(filePath)) return ts2.ScriptKind.JSX;
|
|
1036
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts2.ScriptKind.TS;
|
|
1037
|
+
return ts2.ScriptKind.JS;
|
|
1038
|
+
};
|
|
1039
|
+
var parseSource = (source, filePath) => ts2.createSourceFile(filePath, source, ts2.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
1040
|
+
var peel = (expression) => {
|
|
1041
|
+
let current = expression;
|
|
1042
|
+
while (ts2.isParenthesizedExpression(current) || ts2.isNonNullExpression(current) || ts2.isAsExpression(current) || ts2.isTypeAssertionExpression(current) || ts2.isSatisfiesExpression(current)) {
|
|
1043
|
+
current = current.expression;
|
|
1044
|
+
}
|
|
1045
|
+
return current;
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
// ../instrumentation/src/svelte-generated.ts
|
|
1049
|
+
import ts3 from "typescript";
|
|
1050
|
+
var SVELTE_TEMPLATE_FACTORIES = /* @__PURE__ */ new Set(["from_html", "from_svg", "template"]);
|
|
1051
|
+
var SVELTE_PROP_GETTERS = /* @__PURE__ */ new Set(["prop", "prop_source"]);
|
|
1052
|
+
var isFunctionLike = (node) => ts3.isFunctionDeclaration(node) || ts3.isFunctionExpression(node) || ts3.isArrowFunction(node) || ts3.isMethodDeclaration(node) || ts3.isGetAccessorDeclaration(node) || ts3.isSetAccessorDeclaration(node);
|
|
1053
|
+
var isDescendant = (root, node) => {
|
|
1054
|
+
let current = node;
|
|
1055
|
+
while (current) {
|
|
1056
|
+
if (current === root) return true;
|
|
1057
|
+
current = current.parent;
|
|
1058
|
+
}
|
|
1059
|
+
return false;
|
|
1060
|
+
};
|
|
1061
|
+
var svelteCallMethod = (call) => {
|
|
1062
|
+
const callee = call.expression;
|
|
1063
|
+
if (!ts3.isPropertyAccessExpression(callee) || !ts3.isIdentifier(callee.expression)) {
|
|
1064
|
+
return void 0;
|
|
1065
|
+
}
|
|
1066
|
+
if (callee.expression.text !== "$" || !ts3.isIdentifier(callee.name)) return void 0;
|
|
1067
|
+
return callee.name.text;
|
|
1068
|
+
};
|
|
1069
|
+
var svelteRuntimeMethod = (node) => {
|
|
1070
|
+
const parent = node.parent;
|
|
1071
|
+
if (!parent || !ts3.isCallExpression(parent)) return void 0;
|
|
1072
|
+
if (!parent.arguments.some((argument) => argument === node)) return void 0;
|
|
1073
|
+
return svelteCallMethod(parent);
|
|
1074
|
+
};
|
|
1075
|
+
var enclosingSvelteRuntimeMethod = (node) => {
|
|
1076
|
+
const direct = svelteRuntimeMethod(node);
|
|
1077
|
+
if (direct) return direct;
|
|
1078
|
+
let current = node;
|
|
1079
|
+
let parent = node.parent;
|
|
1080
|
+
while (parent) {
|
|
1081
|
+
if (isFunctionLike(parent) && parent.body) {
|
|
1082
|
+
if (current === parent.body || isDescendant(parent.body, current)) return void 0;
|
|
1083
|
+
}
|
|
1084
|
+
if (ts3.isCallExpression(parent)) {
|
|
1085
|
+
const method = svelteCallMethod(parent);
|
|
1086
|
+
if (method && parent.arguments.some((argument) => argument === current || isDescendant(argument, current))) {
|
|
1087
|
+
return method;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
current = parent;
|
|
1091
|
+
parent = parent.parent;
|
|
1092
|
+
}
|
|
1093
|
+
return void 0;
|
|
1094
|
+
};
|
|
1095
|
+
var svelteGeneratedIdentifierCallees = (sourceFile) => {
|
|
1096
|
+
const names = /* @__PURE__ */ new Set();
|
|
1097
|
+
const visit = (node) => {
|
|
1098
|
+
if (ts3.isVariableDeclaration(node) && ts3.isIdentifier(node.name) && node.initializer && ts3.isCallExpression(node.initializer)) {
|
|
1099
|
+
const method = svelteCallMethod(node.initializer);
|
|
1100
|
+
if (method && (SVELTE_TEMPLATE_FACTORIES.has(method) || SVELTE_PROP_GETTERS.has(method))) {
|
|
1101
|
+
names.add(node.name.text);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
ts3.forEachChild(node, visit);
|
|
1105
|
+
};
|
|
1106
|
+
visit(sourceFile);
|
|
1107
|
+
return names;
|
|
1108
|
+
};
|
|
1109
|
+
var isSvelteCompilerCall = (call, sourceFile, identifierCallees) => {
|
|
1110
|
+
if (svelteCallMethod(call)) return true;
|
|
1111
|
+
if (!ts3.isCallExpression(call) || !ts3.isIdentifier(call.expression)) return false;
|
|
1112
|
+
if (call.expression.text.startsWith("$$")) return true;
|
|
1113
|
+
const names = identifierCallees ?? svelteGeneratedIdentifierCallees(sourceFile);
|
|
1114
|
+
return names.has(call.expression.text);
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
// ../instrumentation/src/svelte-module-path.ts
|
|
1118
|
+
var isSvelteCompiledPath = (idOrPath) => {
|
|
1119
|
+
const path = idOrPath.split("?")[0]?.replaceAll("\\", "/") ?? "";
|
|
1120
|
+
return path.endsWith(".svelte") || path.endsWith(".svelte.ts") || path.endsWith(".svelte.js");
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1123
|
+
// ../instrumentation/src/classify-function.ts
|
|
1124
|
+
var ALLOWED_STATIC_CALLS = /* @__PURE__ */ new Map([
|
|
1125
|
+
["Array", /* @__PURE__ */ new Set(["isArray"])],
|
|
1126
|
+
["Boolean", /* @__PURE__ */ new Set()],
|
|
1127
|
+
["Number", /* @__PURE__ */ new Set(["isNaN", "isFinite"])],
|
|
1128
|
+
["Object", /* @__PURE__ */ new Set(["is"])]
|
|
1129
|
+
]);
|
|
1130
|
+
var functionName = (node, sourceFile) => {
|
|
1131
|
+
if (ts4.isConstructorDeclaration(node)) return "constructor";
|
|
1132
|
+
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
1133
|
+
const parent = node.parent;
|
|
1134
|
+
if (ts4.isVariableDeclaration(parent) && ts4.isIdentifier(parent.name)) return parent.name.text;
|
|
1135
|
+
if (ts4.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
1136
|
+
if (ts4.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
1137
|
+
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
1138
|
+
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
1139
|
+
};
|
|
1140
|
+
var functionLocationPosition = (node, sourceFile) => {
|
|
1141
|
+
if (node.name) return node.name.getStart(sourceFile);
|
|
1142
|
+
const parent = node.parent;
|
|
1143
|
+
if ((ts4.isVariableDeclaration(parent) || ts4.isPropertyAssignment(parent)) && parent.name) {
|
|
1144
|
+
return parent.name.getStart(sourceFile);
|
|
1145
|
+
}
|
|
1146
|
+
return node.getStart(sourceFile);
|
|
1147
|
+
};
|
|
1148
|
+
var isSupportedFunction = (node) => {
|
|
1149
|
+
if (!ts4.isFunctionDeclaration(node) && !ts4.isFunctionExpression(node) && !ts4.isArrowFunction(node) && !ts4.isMethodDeclaration(node) && !ts4.isGetAccessorDeclaration(node) && !ts4.isSetAccessorDeclaration(node)) {
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
1153
|
+
return true;
|
|
1154
|
+
};
|
|
1155
|
+
var singleReturnedExpression = (body) => {
|
|
1156
|
+
if (!ts4.isBlock(body)) return body;
|
|
1157
|
+
if (body.statements.length === 0) return void 0;
|
|
1158
|
+
if (body.statements.length !== 1) return void 0;
|
|
1159
|
+
const statement = body.statements[0];
|
|
1160
|
+
if (!statement || !ts4.isReturnStatement(statement)) return void 0;
|
|
1161
|
+
return statement.expression;
|
|
1162
|
+
};
|
|
1163
|
+
var isLiteralExpression = (expression) => {
|
|
1164
|
+
const node = peel(expression);
|
|
1165
|
+
if (ts4.isStringLiteral(node) || ts4.isNoSubstitutionTemplateLiteral(node)) return true;
|
|
1166
|
+
if (ts4.isNumericLiteral(node)) return true;
|
|
1167
|
+
if (node.kind === ts4.SyntaxKind.TrueKeyword || node.kind === ts4.SyntaxKind.FalseKeyword || node.kind === ts4.SyntaxKind.NullKeyword) {
|
|
1168
|
+
return true;
|
|
1169
|
+
}
|
|
1170
|
+
if (ts4.isIdentifier(node) && (node.text === "undefined" || node.text === "NaN")) return true;
|
|
1171
|
+
return false;
|
|
1172
|
+
};
|
|
1173
|
+
var isLiteralOnlyBody = (body) => {
|
|
1174
|
+
if (ts4.isBlock(body)) {
|
|
1175
|
+
if (body.statements.length === 0) return true;
|
|
1176
|
+
if (body.statements.length !== 1) return false;
|
|
1177
|
+
const statement = body.statements[0];
|
|
1178
|
+
if (!statement || !ts4.isReturnStatement(statement)) return false;
|
|
1179
|
+
return !statement.expression || isLiteralExpression(statement.expression);
|
|
1180
|
+
}
|
|
1181
|
+
return isLiteralExpression(body);
|
|
1182
|
+
};
|
|
1183
|
+
var identifierParams = (node) => {
|
|
1184
|
+
const names = [];
|
|
1185
|
+
for (const parameter of node.parameters) {
|
|
1186
|
+
if (ts4.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
1187
|
+
if (!ts4.isIdentifier(parameter.name) || parameter.dotDotDotToken) return [];
|
|
1188
|
+
names.push(parameter.name.text);
|
|
1189
|
+
}
|
|
1190
|
+
return names;
|
|
1191
|
+
};
|
|
1192
|
+
var isIdentityFunction = (node) => {
|
|
1193
|
+
const params = identifierParams(node);
|
|
1194
|
+
if (params.length !== 1 || !node.body) return false;
|
|
1195
|
+
const returned = singleReturnedExpression(node.body);
|
|
1196
|
+
if (!returned) return false;
|
|
1197
|
+
const value = peel(returned);
|
|
1198
|
+
return ts4.isIdentifier(value) && value.text === params[0];
|
|
1199
|
+
};
|
|
1200
|
+
var isAllowedTypeCall = (expression) => {
|
|
1201
|
+
const callee = peel(expression);
|
|
1202
|
+
if (ts4.isIdentifier(callee)) {
|
|
1203
|
+
return callee.text === "Boolean";
|
|
1204
|
+
}
|
|
1205
|
+
if (!ts4.isPropertyAccessExpression(callee) || !ts4.isIdentifier(callee.expression)) return false;
|
|
1206
|
+
const allowed = ALLOWED_STATIC_CALLS.get(callee.expression.text);
|
|
1207
|
+
return !!allowed && ts4.isIdentifier(callee.name) && allowed.has(callee.name.text);
|
|
1208
|
+
};
|
|
1209
|
+
var isPredicateAtom = (expression) => {
|
|
1210
|
+
const node = peel(expression);
|
|
1211
|
+
if (isLiteralExpression(node) || ts4.isIdentifier(node)) return true;
|
|
1212
|
+
if (node.kind === ts4.SyntaxKind.ThisKeyword) return true;
|
|
1213
|
+
if (ts4.isPropertyAccessExpression(node)) return isPredicateAtom(node.expression);
|
|
1214
|
+
if (ts4.isElementAccessExpression(node)) {
|
|
1215
|
+
return isPredicateAtom(node.expression) && isPredicateAtom(node.argumentExpression);
|
|
1216
|
+
}
|
|
1217
|
+
return false;
|
|
1218
|
+
};
|
|
1219
|
+
var isPredicateExpression = (expression) => {
|
|
1220
|
+
const node = peel(expression);
|
|
1221
|
+
if (ts4.isTypeOfExpression(node)) return isPredicateAtom(node.expression);
|
|
1222
|
+
if (ts4.isPrefixUnaryExpression(node) && node.operator === ts4.SyntaxKind.ExclamationToken) {
|
|
1223
|
+
return isPredicateExpression(node.operand) || isPredicateAtom(node.operand);
|
|
1224
|
+
}
|
|
1225
|
+
if (ts4.isBinaryExpression(node)) {
|
|
1226
|
+
const kind = node.operatorToken.kind;
|
|
1227
|
+
if (kind === ts4.SyntaxKind.EqualsEqualsEqualsToken || kind === ts4.SyntaxKind.ExclamationEqualsEqualsToken || kind === ts4.SyntaxKind.EqualsEqualsToken || kind === ts4.SyntaxKind.ExclamationEqualsToken || kind === ts4.SyntaxKind.LessThanToken || kind === ts4.SyntaxKind.GreaterThanToken || kind === ts4.SyntaxKind.LessThanEqualsToken || kind === ts4.SyntaxKind.GreaterThanEqualsToken || kind === ts4.SyntaxKind.AmpersandAmpersandToken || kind === ts4.SyntaxKind.BarBarToken || kind === ts4.SyntaxKind.QuestionQuestionToken || kind === ts4.SyntaxKind.InstanceOfKeyword) {
|
|
1228
|
+
const side = (value) => isPredicateExpression(value) || isPredicateAtom(value);
|
|
1229
|
+
return side(node.left) && side(node.right);
|
|
1230
|
+
}
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1233
|
+
if (ts4.isCallExpression(node)) {
|
|
1234
|
+
return isAllowedTypeCall(node.expression) && node.arguments.every(
|
|
1235
|
+
(argument) => isPredicateExpression(argument) || isPredicateAtom(argument)
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
return false;
|
|
1239
|
+
};
|
|
1240
|
+
var bodyHasDisallowedControl = (body) => {
|
|
1241
|
+
let found2 = false;
|
|
1242
|
+
const visit = (node) => {
|
|
1243
|
+
if (found2) return;
|
|
1244
|
+
if (ts4.isAwaitExpression(node) || ts4.isYieldExpression(node) || ts4.isThrowStatement(node) || ts4.isTryStatement(node) || ts4.isNewExpression(node)) {
|
|
1245
|
+
found2 = true;
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
if (ts4.isBinaryExpression(node) && node.operatorToken.kind === ts4.SyntaxKind.EqualsToken) {
|
|
1249
|
+
found2 = true;
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
ts4.forEachChild(node, visit);
|
|
1253
|
+
};
|
|
1254
|
+
visit(body);
|
|
1255
|
+
return found2;
|
|
1256
|
+
};
|
|
1257
|
+
var isObjectEntriesWrapper = (body) => {
|
|
1258
|
+
const returned = singleReturnedExpression(body);
|
|
1259
|
+
if (!returned) return false;
|
|
1260
|
+
let current = peel(returned);
|
|
1261
|
+
while (ts4.isCallExpression(current) && ts4.isPropertyAccessExpression(current.expression)) {
|
|
1262
|
+
const method = current.expression.name.getText();
|
|
1263
|
+
if (method === "filter" || method === "map" || method === "flatMap") {
|
|
1264
|
+
current = peel(current.expression.expression);
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
break;
|
|
1268
|
+
}
|
|
1269
|
+
if (!ts4.isCallExpression(current) || !ts4.isPropertyAccessExpression(current.expression)) {
|
|
1270
|
+
return false;
|
|
1271
|
+
}
|
|
1272
|
+
return ts4.isIdentifier(current.expression.expression) && current.expression.expression.text === "Object" && ts4.isIdentifier(current.expression.name) && (current.expression.name.text === "entries" || current.expression.name.text === "keys" || current.expression.name.text === "values");
|
|
1273
|
+
};
|
|
1274
|
+
var SVELTE_REACTIVE_CALLBACKS = /* @__PURE__ */ new Map([
|
|
1275
|
+
["derived", { name: "$derived", reason: "svelte $derived callback", kind: "derived" }],
|
|
1276
|
+
["user_effect", { name: "$effect", reason: "svelte $effect callback", kind: "effect" }],
|
|
1277
|
+
[
|
|
1278
|
+
"user_pre_effect",
|
|
1279
|
+
{ name: "$effect.pre", reason: "svelte $effect.pre callback", kind: "effect.pre" }
|
|
1280
|
+
]
|
|
1281
|
+
]);
|
|
1282
|
+
var SVELTE_EVENT_CALLBACKS = /* @__PURE__ */ new Set(["delegated", "event"]);
|
|
1283
|
+
var parameterNames = (node) => {
|
|
1284
|
+
const names = [];
|
|
1285
|
+
for (const parameter of node.parameters) {
|
|
1286
|
+
if (ts4.isIdentifier(parameter.name)) names.push(parameter.name.text);
|
|
1287
|
+
}
|
|
1288
|
+
return names;
|
|
1289
|
+
};
|
|
1290
|
+
var isSvelteComponentWrapper = (node) => {
|
|
1291
|
+
const names = parameterNames(node);
|
|
1292
|
+
return names.includes("$$anchor") && names.includes("$$props");
|
|
1293
|
+
};
|
|
1294
|
+
var isSvelteGeneratedBlock = (node) => {
|
|
1295
|
+
const names = parameterNames(node);
|
|
1296
|
+
if (names.includes("$$props")) return false;
|
|
1297
|
+
return names.includes("$$anchor") || names.includes("$$render");
|
|
1298
|
+
};
|
|
1299
|
+
var isSvelteChildPropThunk = (node) => {
|
|
1300
|
+
const parent = node.parent;
|
|
1301
|
+
if (!parent || !ts4.isPropertyAssignment(parent)) return false;
|
|
1302
|
+
const object = parent.parent;
|
|
1303
|
+
if (!object || !ts4.isObjectLiteralExpression(object)) return false;
|
|
1304
|
+
const call = object.parent;
|
|
1305
|
+
if (!call || !ts4.isCallExpression(call)) return false;
|
|
1306
|
+
return call.arguments.some((argument) => argument === object);
|
|
1307
|
+
};
|
|
1308
|
+
var isSimpleReadBody = (body) => {
|
|
1309
|
+
const returned = singleReturnedExpression(body);
|
|
1310
|
+
if (!returned || bodyHasDisallowedControl(body)) return false;
|
|
1311
|
+
const value = peel(returned);
|
|
1312
|
+
if (ts4.isIdentifier(value)) return true;
|
|
1313
|
+
if (ts4.isPropertyAccessExpression(value) && isPredicateAtom(value)) return true;
|
|
1314
|
+
if (!ts4.isCallExpression(value) || value.arguments.length !== 1) return false;
|
|
1315
|
+
const argument = value.arguments[0];
|
|
1316
|
+
if (!argument) return false;
|
|
1317
|
+
if (!ts4.isPropertyAccessExpression(value.expression) || !ts4.isIdentifier(value.expression.expression)) {
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1320
|
+
return value.expression.expression.text === "$" && ts4.isIdentifier(value.expression.name) && value.expression.name.text === "get" && ts4.isIdentifier(peel(argument));
|
|
1321
|
+
};
|
|
1322
|
+
var classifyBody = (node, name, sourceFile, filePath) => {
|
|
1323
|
+
if (isSvelteComponentWrapper(node)) {
|
|
1324
|
+
return { captureClass: "structure", captureReason: "svelte component wrapper" };
|
|
1325
|
+
}
|
|
1326
|
+
if (isSvelteCompiledPath(filePath) && /^\$[A-Za-z]/.test(name)) {
|
|
1327
|
+
return { captureClass: "skip", captureReason: "svelte store subscription" };
|
|
1328
|
+
}
|
|
1329
|
+
if (isSvelteCompiledPath(filePath)) {
|
|
1330
|
+
if (ts4.isGetAccessorDeclaration(node) || ts4.isSetAccessorDeclaration(node)) {
|
|
1331
|
+
return { captureClass: "skip", captureReason: "svelte generated accessor" };
|
|
1332
|
+
}
|
|
1333
|
+
if (isSvelteGeneratedBlock(node)) {
|
|
1334
|
+
return { captureClass: "skip", captureReason: "svelte generated block" };
|
|
1335
|
+
}
|
|
1336
|
+
if (isSvelteChildPropThunk(node)) {
|
|
1337
|
+
const returned2 = singleReturnedExpression(node.body);
|
|
1338
|
+
if (isLiteralOnlyBody(node.body) || isIdentityFunction(node) || isSimpleReadBody(node.body) || returned2 !== void 0 && isPredicateExpression(returned2) && !bodyHasDisallowedControl(node.body)) {
|
|
1339
|
+
return { captureClass: "skip", captureReason: "svelte prop thunk" };
|
|
1340
|
+
}
|
|
1341
|
+
return { captureClass: "full", captureReason: "svelte user callback" };
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
if (isSvelteCompiledPath(filePath)) {
|
|
1345
|
+
const runtimeMethod = svelteRuntimeMethod(node);
|
|
1346
|
+
if (runtimeMethod) {
|
|
1347
|
+
const reactive = SVELTE_REACTIVE_CALLBACKS.get(runtimeMethod);
|
|
1348
|
+
if (reactive) {
|
|
1349
|
+
if (isLiteralOnlyBody(node.body)) {
|
|
1350
|
+
return { captureClass: "skip", captureReason: "literal-only return" };
|
|
1351
|
+
}
|
|
1352
|
+
return {
|
|
1353
|
+
captureClass: "reactive-sparse",
|
|
1354
|
+
captureReason: reactive.reason,
|
|
1355
|
+
inferredName: name === "anonymous" ? reactive.name : void 0,
|
|
1356
|
+
reactiveKind: reactive.kind
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
if (SVELTE_EVENT_CALLBACKS.has(runtimeMethod)) {
|
|
1360
|
+
if (isLiteralOnlyBody(node.body)) {
|
|
1361
|
+
return { captureClass: "skip", captureReason: "literal-only return" };
|
|
1362
|
+
}
|
|
1363
|
+
return { captureClass: "full", captureReason: "svelte user callback" };
|
|
1364
|
+
}
|
|
1365
|
+
return { captureClass: "skip", captureReason: "svelte generated callback" };
|
|
1366
|
+
}
|
|
1367
|
+
if (enclosingSvelteRuntimeMethod(node)) {
|
|
1368
|
+
return { captureClass: "skip", captureReason: "svelte generated callback" };
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
if (isLiteralOnlyBody(node.body)) {
|
|
1372
|
+
return { captureClass: "skip", captureReason: "literal-only return" };
|
|
1373
|
+
}
|
|
1374
|
+
if (isIdentityFunction(node)) {
|
|
1375
|
+
return { captureClass: "structure", captureReason: "identity wrapper" };
|
|
1376
|
+
}
|
|
1377
|
+
const returned = singleReturnedExpression(node.body);
|
|
1378
|
+
if (returned && isPredicateExpression(returned) && !bodyHasDisallowedControl(node.body)) {
|
|
1379
|
+
return { captureClass: "structure", captureReason: "tiny predicate" };
|
|
1380
|
+
}
|
|
1381
|
+
if (isObjectEntriesWrapper(node.body) && !bodyHasDisallowedControl(node.body)) {
|
|
1382
|
+
return { captureClass: "structure", captureReason: "object-entries wrapper" };
|
|
1383
|
+
}
|
|
1384
|
+
if (name === "anonymous" && node.body.getText(sourceFile).length < 80 && !bodyHasDisallowedControl(node.body)) {
|
|
1385
|
+
return { captureClass: "structure", captureReason: "tiny anonymous helper" };
|
|
1386
|
+
}
|
|
1387
|
+
return { captureClass: "full", captureReason: "application function" };
|
|
1388
|
+
};
|
|
1389
|
+
var classifyFunctions = (source, filePath, mapLocation) => {
|
|
1390
|
+
const sourceFile = parseSource(source, filePath);
|
|
1391
|
+
const absolutePath = resolve3(filePath);
|
|
1392
|
+
const classifications = [];
|
|
1393
|
+
const visit = (node) => {
|
|
1394
|
+
if (isSupportedFunction(node) && node.body) {
|
|
1395
|
+
let location;
|
|
1396
|
+
if (isSvelteComponentWrapper(node)) {
|
|
1397
|
+
location = { filePath: absolutePath, line: 1, column: 1 };
|
|
1398
|
+
} else {
|
|
1399
|
+
location = mappedLocation(
|
|
1400
|
+
sourceFile,
|
|
1401
|
+
functionLocationPosition(node, sourceFile),
|
|
1402
|
+
absolutePath,
|
|
1403
|
+
mapLocation
|
|
1404
|
+
);
|
|
1405
|
+
if (!location) {
|
|
1406
|
+
ts4.forEachChild(node, visit);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
const rawName = functionName(node, sourceFile).replace(/@\d+:\d+$/, "");
|
|
1411
|
+
const classified = classifyBody(node, rawName, sourceFile, filePath);
|
|
1412
|
+
const name = classified.inferredName ?? rawName;
|
|
1413
|
+
const plan = encodeFunctionPlan({
|
|
1414
|
+
filePath: location.filePath,
|
|
1415
|
+
name,
|
|
1416
|
+
line: location.line,
|
|
1417
|
+
column: location.column
|
|
1418
|
+
});
|
|
1419
|
+
classifications.push({
|
|
1420
|
+
functionId: plan[0],
|
|
1421
|
+
name,
|
|
1422
|
+
captureClass: classified.captureClass,
|
|
1423
|
+
captureReason: classified.captureReason,
|
|
1424
|
+
line: location.line,
|
|
1425
|
+
column: location.column,
|
|
1426
|
+
filePath: location.filePath,
|
|
1427
|
+
start: node.getStart(sourceFile),
|
|
1428
|
+
end: node.end,
|
|
1429
|
+
bodyStart: node.body.getStart(sourceFile),
|
|
1430
|
+
bodyEnd: node.body.end,
|
|
1431
|
+
...classified.reactiveKind ? { reactiveKind: classified.reactiveKind } : {}
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
ts4.forEachChild(node, visit);
|
|
1435
|
+
};
|
|
1436
|
+
visit(sourceFile);
|
|
1437
|
+
const hasUserWork = classifications.some(
|
|
1438
|
+
(item) => item.captureClass === "full" || item.captureClass === "reactive-sparse"
|
|
1439
|
+
);
|
|
1440
|
+
if (!hasUserWork) {
|
|
1441
|
+
for (const item of classifications) {
|
|
1442
|
+
if (item.captureReason === "svelte component wrapper") {
|
|
1443
|
+
item.captureClass = "skip";
|
|
1444
|
+
item.captureReason = "svelte presentational wrapper";
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
return classifications;
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// ../instrumentation/src/edits.ts
|
|
1452
|
+
var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
1453
|
+
var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
1454
|
+
var separateFromPreviousToken = (source, position, text) => {
|
|
1455
|
+
if (position <= 0 || text.length === 0) return text;
|
|
1456
|
+
if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
|
|
1457
|
+
return ` ${text}`;
|
|
1458
|
+
}
|
|
1459
|
+
return text;
|
|
1460
|
+
};
|
|
1461
|
+
var uniqueName = (source, base) => {
|
|
1462
|
+
let name = base;
|
|
1463
|
+
while (source.includes(name)) name += "_";
|
|
1464
|
+
return name;
|
|
1465
|
+
};
|
|
1466
|
+
var wrap = (edits, start, end, open, close, depth) => {
|
|
1467
|
+
const width = Math.max(0, end - start);
|
|
1468
|
+
edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
|
|
1469
|
+
edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
|
|
1470
|
+
};
|
|
1471
|
+
var compareEdits = (left, right) => {
|
|
1472
|
+
if (left.position !== right.position) return right.position - left.position;
|
|
1473
|
+
if (left.kind !== right.kind) {
|
|
1474
|
+
const rank = { replace: 0, close: 1, open: 2 };
|
|
1475
|
+
return rank[left.kind] - rank[right.kind];
|
|
1476
|
+
}
|
|
1477
|
+
if (left.kind === "close") {
|
|
1478
|
+
if (left.width !== right.width) return right.width - left.width;
|
|
1479
|
+
return left.depth - right.depth;
|
|
1480
|
+
}
|
|
1481
|
+
if (left.kind === "open") {
|
|
1482
|
+
if (left.width !== right.width) return left.width - right.width;
|
|
1483
|
+
return right.depth - left.depth;
|
|
1484
|
+
}
|
|
1485
|
+
return 0;
|
|
1486
|
+
};
|
|
1487
|
+
var applyEdits = (source, edits) => {
|
|
1488
|
+
const ordered = [...edits].sort(compareEdits);
|
|
1489
|
+
let transformed = source;
|
|
1490
|
+
for (const edit of ordered) {
|
|
1491
|
+
const text = separateFromPreviousToken(transformed, edit.position, textOf(edit));
|
|
1492
|
+
transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
|
|
1493
|
+
}
|
|
1494
|
+
return transformed;
|
|
1495
|
+
};
|
|
1496
|
+
var textOf = (edit) => edit.text;
|
|
1497
|
+
|
|
1498
|
+
// ../node_modules/.bun/@jridgewell+gen-mapping@0.3.13/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
|
|
1499
|
+
var SetArray = class {
|
|
1500
|
+
constructor() {
|
|
1501
|
+
this._indexes = { __proto__: null };
|
|
1502
|
+
this.array = [];
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
function cast2(set) {
|
|
1506
|
+
return set;
|
|
1507
|
+
}
|
|
1508
|
+
function get(setarr, key) {
|
|
1509
|
+
return cast2(setarr)._indexes[key];
|
|
1510
|
+
}
|
|
1511
|
+
function put(setarr, key) {
|
|
1512
|
+
const index = get(setarr, key);
|
|
1513
|
+
if (index !== void 0) return index;
|
|
1514
|
+
const { array, _indexes: indexes } = cast2(setarr);
|
|
1515
|
+
const length = array.push(key);
|
|
1516
|
+
return indexes[key] = length - 1;
|
|
1517
|
+
}
|
|
1518
|
+
var COLUMN2 = 0;
|
|
1519
|
+
var SOURCES_INDEX2 = 1;
|
|
1520
|
+
var SOURCE_LINE2 = 2;
|
|
1521
|
+
var SOURCE_COLUMN2 = 3;
|
|
1522
|
+
var NAMES_INDEX2 = 4;
|
|
1523
|
+
var NO_NAME = -1;
|
|
1524
|
+
var GenMapping = class {
|
|
1525
|
+
constructor({ file, sourceRoot } = {}) {
|
|
1526
|
+
this._names = new SetArray();
|
|
1527
|
+
this._sources = new SetArray();
|
|
1528
|
+
this._sourcesContent = [];
|
|
1529
|
+
this._mappings = [];
|
|
1530
|
+
this.file = file;
|
|
1531
|
+
this.sourceRoot = sourceRoot;
|
|
1532
|
+
this._ignoreList = new SetArray();
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
function cast22(map) {
|
|
1536
|
+
return map;
|
|
1537
|
+
}
|
|
1538
|
+
function addSegment(map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|
1539
|
+
return addSegmentInternal(
|
|
1540
|
+
false,
|
|
1541
|
+
map,
|
|
1542
|
+
genLine,
|
|
1543
|
+
genColumn,
|
|
1544
|
+
source,
|
|
1545
|
+
sourceLine,
|
|
1546
|
+
sourceColumn,
|
|
1547
|
+
name,
|
|
1548
|
+
content
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
function toDecodedMap(map) {
|
|
1552
|
+
const {
|
|
1553
|
+
_mappings: mappings,
|
|
1554
|
+
_sources: sources,
|
|
1555
|
+
_sourcesContent: sourcesContent,
|
|
1556
|
+
_names: names,
|
|
1557
|
+
_ignoreList: ignoreList
|
|
1558
|
+
// _originalScopes: originalScopes,
|
|
1559
|
+
// _generatedRanges: generatedRanges,
|
|
1560
|
+
} = cast22(map);
|
|
1561
|
+
removeEmptyFinalLines(mappings);
|
|
1562
|
+
return {
|
|
1563
|
+
version: 3,
|
|
1564
|
+
file: map.file || void 0,
|
|
1565
|
+
names: names.array,
|
|
1566
|
+
sourceRoot: map.sourceRoot || void 0,
|
|
1567
|
+
sources: sources.array,
|
|
1568
|
+
sourcesContent,
|
|
1569
|
+
mappings,
|
|
1570
|
+
// originalScopes,
|
|
1571
|
+
// generatedRanges,
|
|
1572
|
+
ignoreList: ignoreList.array
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
function toEncodedMap(map) {
|
|
1576
|
+
const decoded = toDecodedMap(map);
|
|
1577
|
+
return Object.assign({}, decoded, {
|
|
1578
|
+
// originalScopes: decoded.originalScopes.map((os) => encodeOriginalScopes(os)),
|
|
1579
|
+
// generatedRanges: encodeGeneratedRanges(decoded.generatedRanges as GeneratedRange[]),
|
|
1580
|
+
mappings: encode(decoded.mappings)
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|
1584
|
+
const {
|
|
1585
|
+
_mappings: mappings,
|
|
1586
|
+
_sources: sources,
|
|
1587
|
+
_sourcesContent: sourcesContent,
|
|
1588
|
+
_names: names
|
|
1589
|
+
// _originalScopes: originalScopes,
|
|
1590
|
+
} = cast22(map);
|
|
1591
|
+
const line = getIndex(mappings, genLine);
|
|
1592
|
+
const index = getColumnIndex(line, genColumn);
|
|
1593
|
+
if (!source) {
|
|
1594
|
+
if (skipable && skipSourceless(line, index)) return;
|
|
1595
|
+
return insert(line, index, [genColumn]);
|
|
1596
|
+
}
|
|
1597
|
+
assert(sourceLine);
|
|
1598
|
+
assert(sourceColumn);
|
|
1599
|
+
const sourcesIndex = put(sources, source);
|
|
1600
|
+
const namesIndex = name ? put(names, name) : NO_NAME;
|
|
1601
|
+
if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
|
|
1602
|
+
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
return insert(
|
|
1606
|
+
line,
|
|
1607
|
+
index,
|
|
1608
|
+
name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
function assert(_val) {
|
|
1612
|
+
}
|
|
1613
|
+
function getIndex(arr, index) {
|
|
1614
|
+
for (let i = arr.length; i <= index; i++) {
|
|
1615
|
+
arr[i] = [];
|
|
1616
|
+
}
|
|
1617
|
+
return arr[index];
|
|
1618
|
+
}
|
|
1619
|
+
function getColumnIndex(line, genColumn) {
|
|
1620
|
+
let index = line.length;
|
|
1621
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
1622
|
+
const current = line[i];
|
|
1623
|
+
if (genColumn >= current[COLUMN2]) break;
|
|
1624
|
+
}
|
|
1625
|
+
return index;
|
|
1626
|
+
}
|
|
1627
|
+
function insert(array, index, value) {
|
|
1628
|
+
for (let i = array.length; i > index; i--) {
|
|
1629
|
+
array[i] = array[i - 1];
|
|
1630
|
+
}
|
|
1631
|
+
array[index] = value;
|
|
1632
|
+
}
|
|
1633
|
+
function removeEmptyFinalLines(mappings) {
|
|
1634
|
+
const { length } = mappings;
|
|
1635
|
+
let len = length;
|
|
1636
|
+
for (let i = len - 1; i >= 0; len = i, i--) {
|
|
1637
|
+
if (mappings[i].length > 0) break;
|
|
1638
|
+
}
|
|
1639
|
+
if (len < length) mappings.length = len;
|
|
1640
|
+
}
|
|
1641
|
+
function skipSourceless(line, index) {
|
|
1642
|
+
if (index === 0) return true;
|
|
1643
|
+
const prev = line[index - 1];
|
|
1644
|
+
return prev.length === 1;
|
|
1645
|
+
}
|
|
1646
|
+
function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
|
|
1647
|
+
if (index === 0) return false;
|
|
1648
|
+
const prev = line[index - 1];
|
|
1649
|
+
if (prev.length === 1) return false;
|
|
1650
|
+
return sourcesIndex === prev[SOURCES_INDEX2] && sourceLine === prev[SOURCE_LINE2] && sourceColumn === prev[SOURCE_COLUMN2] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX2] : NO_NAME);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// ../instrumentation/src/exact-transform-map.ts
|
|
1654
|
+
var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
1655
|
+
var decodeInlineSourceMap = (url) => {
|
|
1656
|
+
const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
|
|
1657
|
+
if (base64?.[1]) {
|
|
1658
|
+
try {
|
|
1659
|
+
return Buffer.from(base64[1], "base64").toString("utf8");
|
|
1660
|
+
} catch {
|
|
1661
|
+
return void 0;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
|
|
1665
|
+
if (!raw?.[1]) return void 0;
|
|
1666
|
+
try {
|
|
1667
|
+
return decodeURIComponent(raw[1]);
|
|
1668
|
+
} catch {
|
|
1669
|
+
return void 0;
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
var upstreamTraceMap = (original) => {
|
|
1673
|
+
const match = SOURCEMAP_COMMENT.exec(original);
|
|
1674
|
+
const url = match?.[1] ?? match?.[2];
|
|
1675
|
+
if (!url) return void 0;
|
|
1676
|
+
const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
|
|
1677
|
+
if (!payload) return void 0;
|
|
1678
|
+
try {
|
|
1679
|
+
return new TraceMap(payload);
|
|
1680
|
+
} catch {
|
|
1681
|
+
return void 0;
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
var lineStartsOf = (text) => {
|
|
1685
|
+
const starts = [0];
|
|
1686
|
+
for (let index = 0; index < text.length; index++) {
|
|
1687
|
+
if (text[index] === "\n") starts.push(index + 1);
|
|
1688
|
+
}
|
|
1689
|
+
return starts;
|
|
1690
|
+
};
|
|
1691
|
+
var positionAt = (starts, offset) => {
|
|
1692
|
+
let low = 0;
|
|
1693
|
+
let high = starts.length - 1;
|
|
1694
|
+
while (low < high) {
|
|
1695
|
+
const mid = low + high + 1 >> 1;
|
|
1696
|
+
if ((starts[mid] ?? 0) <= offset) low = mid;
|
|
1697
|
+
else high = mid - 1;
|
|
1698
|
+
}
|
|
1699
|
+
return { line: low, column: offset - (starts[low] ?? 0) };
|
|
1700
|
+
};
|
|
1701
|
+
var sortedEdits = (edits) => [...edits].sort(compareEdits);
|
|
1702
|
+
var originalOffsetToGenerated = (originalOffset, edits) => {
|
|
1703
|
+
let generated = originalOffset;
|
|
1704
|
+
for (const edit of edits) {
|
|
1705
|
+
const delta = edit.text.length - edit.deleteCount;
|
|
1706
|
+
if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
|
|
1707
|
+
else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
|
|
1708
|
+
}
|
|
1709
|
+
return generated;
|
|
1710
|
+
};
|
|
1711
|
+
var mappingOffsets = (original, edits) => {
|
|
1712
|
+
const offsets = /* @__PURE__ */ new Set([0, original.length]);
|
|
1713
|
+
for (const start of lineStartsOf(original)) offsets.add(start);
|
|
1714
|
+
for (const edit of edits) {
|
|
1715
|
+
offsets.add(edit.position);
|
|
1716
|
+
offsets.add(edit.position + edit.deleteCount);
|
|
1717
|
+
}
|
|
1718
|
+
return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
|
|
1719
|
+
};
|
|
1720
|
+
var encodeColumnMappings = (original, generated, file, edits) => {
|
|
1721
|
+
const upstream = upstreamTraceMap(original);
|
|
1722
|
+
const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
|
|
1723
|
+
if (sources.length === 0) sources.push(file);
|
|
1724
|
+
const applied = sortedEdits(edits);
|
|
1725
|
+
const originalStarts = lineStartsOf(original);
|
|
1726
|
+
const generatedStarts = lineStartsOf(generated);
|
|
1727
|
+
const map = new GenMapping({ file });
|
|
1728
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1729
|
+
for (const originalOffset of mappingOffsets(original, edits)) {
|
|
1730
|
+
const generatedOffset = Math.min(
|
|
1731
|
+
originalOffsetToGenerated(originalOffset, applied),
|
|
1732
|
+
generated.length
|
|
1733
|
+
);
|
|
1734
|
+
const originalPosition = positionAt(originalStarts, originalOffset);
|
|
1735
|
+
const generatedPosition = positionAt(generatedStarts, generatedOffset);
|
|
1736
|
+
let source = sources[0] ?? file;
|
|
1737
|
+
let mappedLine = originalPosition.line;
|
|
1738
|
+
let mappedColumn = originalPosition.column;
|
|
1739
|
+
if (upstream) {
|
|
1740
|
+
const mapped = originalPositionFor(upstream, {
|
|
1741
|
+
line: originalPosition.line + 1,
|
|
1742
|
+
column: originalPosition.column
|
|
1743
|
+
});
|
|
1744
|
+
if (mapped.source && mapped.line != null && mapped.column != null) {
|
|
1745
|
+
source = mapped.source;
|
|
1746
|
+
mappedLine = mapped.line - 1;
|
|
1747
|
+
mappedColumn = mapped.column;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
const key = `${generatedPosition.line}:${generatedPosition.column}`;
|
|
1751
|
+
if (seen.has(key)) continue;
|
|
1752
|
+
seen.add(key);
|
|
1753
|
+
addSegment(
|
|
1754
|
+
map,
|
|
1755
|
+
generatedPosition.line,
|
|
1756
|
+
generatedPosition.column,
|
|
1757
|
+
source,
|
|
1758
|
+
mappedLine,
|
|
1759
|
+
mappedColumn
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
const encoded = toEncodedMap(map);
|
|
1763
|
+
return {
|
|
1764
|
+
sources: encoded.sources.filter((source) => Boolean(source)),
|
|
1765
|
+
mappings: encoded.mappings
|
|
1766
|
+
};
|
|
1767
|
+
};
|
|
1768
|
+
var exactTransformMap = (original, generated, file, edits) => {
|
|
1769
|
+
const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
|
|
1770
|
+
const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
|
|
1771
|
+
return { version: 3, file, sources, mappings };
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
// ../instrumentation/src/instrument-browser-source.ts
|
|
1775
|
+
import { basename as basename2 } from "node:path";
|
|
1776
|
+
|
|
1777
|
+
// ../instrumentation/src/browser-function-edits.ts
|
|
1778
|
+
import ts10 from "typescript";
|
|
1779
|
+
|
|
1780
|
+
// ../instrumentation/src/suspension-whitelist.ts
|
|
1781
|
+
import ts5 from "typescript";
|
|
1782
|
+
var nodeFlags = ts5.NodeFlags;
|
|
1783
|
+
var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
|
|
1784
|
+
var USING_FLAG = nodeFlags.Using ?? 0;
|
|
1785
|
+
var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
1786
|
+
"AwaitExpression",
|
|
1787
|
+
"AwaitKeyword",
|
|
1788
|
+
"YieldExpression",
|
|
1789
|
+
"YieldKeyword",
|
|
1790
|
+
"UsingKeyword"
|
|
1791
|
+
];
|
|
1792
|
+
var isFunctionLike2 = (node) => ts5.isFunctionLike(node);
|
|
1793
|
+
var isAsyncFunctionLike = (node) => (ts5.getCombinedModifierFlags(node) & ts5.ModifierFlags.Async) !== 0;
|
|
1794
|
+
var isAsyncGeneratorLike = (node) => isFunctionLike2(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
|
|
1795
|
+
var visitOwnBody = (node, visitNode) => {
|
|
1796
|
+
if (!node.body) return;
|
|
1797
|
+
const visit = (candidate) => {
|
|
1798
|
+
if (candidate !== node && isFunctionLike2(candidate)) {
|
|
1799
|
+
visitNode(candidate);
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
if (visitNode(candidate)) return;
|
|
1803
|
+
ts5.forEachChild(candidate, visit);
|
|
1804
|
+
};
|
|
1805
|
+
visit(node.body);
|
|
1806
|
+
};
|
|
1807
|
+
var nestedFunctionSpans = (node, sourceFile) => {
|
|
1808
|
+
const spans = [];
|
|
1809
|
+
visitOwnBody(node, (candidate) => {
|
|
1810
|
+
if (candidate !== node && isFunctionLike2(candidate)) {
|
|
1811
|
+
spans.push([candidate.getStart(sourceFile), candidate.end]);
|
|
1812
|
+
}
|
|
1813
|
+
return void 0;
|
|
1814
|
+
});
|
|
1815
|
+
return spans.sort((left, right) => left[0] - right[0]);
|
|
1816
|
+
};
|
|
1817
|
+
var slicesOutside = (start, end, spans) => {
|
|
1818
|
+
const slices = [];
|
|
1819
|
+
let cursor = start;
|
|
1820
|
+
for (const [from, to] of spans) {
|
|
1821
|
+
if (to <= cursor) continue;
|
|
1822
|
+
if (from >= end) break;
|
|
1823
|
+
if (from > cursor) slices.push([cursor, Math.min(from, end)]);
|
|
1824
|
+
cursor = Math.max(cursor, to);
|
|
1825
|
+
}
|
|
1826
|
+
if (cursor < end) slices.push([cursor, end]);
|
|
1827
|
+
return slices;
|
|
1828
|
+
};
|
|
1829
|
+
var sliceHasAwaitKeyword = (source, start, end) => {
|
|
1830
|
+
if (end <= start) return false;
|
|
1831
|
+
const scanner = ts5.createScanner(
|
|
1832
|
+
ts5.ScriptTarget.Latest,
|
|
1833
|
+
true,
|
|
1834
|
+
ts5.LanguageVariant.Standard,
|
|
1835
|
+
source.slice(start, end)
|
|
1836
|
+
);
|
|
1837
|
+
while (true) {
|
|
1838
|
+
const token = scanner.scan();
|
|
1839
|
+
if (token === ts5.SyntaxKind.EndOfFileToken) return false;
|
|
1840
|
+
if (token === ts5.SyntaxKind.AwaitKeyword) return true;
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
var ownBodyHasAwaitKeyword = (node, sourceFile) => {
|
|
1844
|
+
if (!node.body) return false;
|
|
1845
|
+
const spans = nestedFunctionSpans(node, sourceFile);
|
|
1846
|
+
for (const [start, end] of slicesOutside(node.body.getStart(sourceFile), node.body.end, spans)) {
|
|
1847
|
+
if (sliceHasAwaitKeyword(sourceFile.text, start, end)) return true;
|
|
1848
|
+
}
|
|
1849
|
+
return false;
|
|
1850
|
+
};
|
|
1851
|
+
var isAwaitUsingList = (node) => {
|
|
1852
|
+
const text = node.getText().trimStart();
|
|
1853
|
+
if (text.startsWith("await using")) return true;
|
|
1854
|
+
if (AWAIT_USING_FLAG === 0 || USING_FLAG === 0) return false;
|
|
1855
|
+
return (node.flags & AWAIT_USING_FLAG) === AWAIT_USING_FLAG && (node.flags & USING_FLAG) !== 0;
|
|
1856
|
+
};
|
|
1857
|
+
var unknownSuspensionKind = (node) => {
|
|
1858
|
+
const name = ts5.SyntaxKind[node.kind];
|
|
1859
|
+
if (typeof name !== "string" || !/Await|Yield|Using/.test(name)) return false;
|
|
1860
|
+
return !KNOWN_SUSPENSION_KIND_NAMES.includes(name);
|
|
1861
|
+
};
|
|
1862
|
+
var ownSuspensionFacts = (node, sourceFile) => {
|
|
1863
|
+
const facts = {
|
|
1864
|
+
awaitExpressions: false,
|
|
1865
|
+
forAwait: false,
|
|
1866
|
+
awaitUsing: false,
|
|
1867
|
+
unknown: false,
|
|
1868
|
+
awaitKeyword: ownBodyHasAwaitKeyword(node, sourceFile)
|
|
1869
|
+
};
|
|
1870
|
+
visitOwnBody(node, (candidate) => {
|
|
1871
|
+
if (ts5.isAwaitExpression(candidate)) facts.awaitExpressions = true;
|
|
1872
|
+
if (ts5.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
|
|
1873
|
+
if (ts5.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
|
|
1874
|
+
facts.awaitUsing = true;
|
|
1875
|
+
}
|
|
1876
|
+
if (unknownSuspensionKind(candidate)) facts.unknown = true;
|
|
1877
|
+
return void 0;
|
|
1878
|
+
});
|
|
1879
|
+
return facts;
|
|
1880
|
+
};
|
|
1881
|
+
var bodyHasDirectEval = (node) => {
|
|
1882
|
+
let found2 = false;
|
|
1883
|
+
visitOwnBody(node, (candidate) => {
|
|
1884
|
+
if (ts5.isCallExpression(candidate) && ts5.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
|
|
1885
|
+
found2 = true;
|
|
1886
|
+
}
|
|
1887
|
+
return found2;
|
|
1888
|
+
});
|
|
1889
|
+
return found2;
|
|
1890
|
+
};
|
|
1891
|
+
var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
1892
|
+
if (isAsyncGeneratorLike(node)) return { action: "skip", reason: "unsupported_async_generator" };
|
|
1893
|
+
if (!isAsyncFunctionLike(node)) return { action: "inline" };
|
|
1894
|
+
if (bodyHasDirectEval(node)) return { action: "skip", reason: "direct_eval" };
|
|
1895
|
+
const facts = ownSuspensionFacts(node, sourceFile);
|
|
1896
|
+
if (facts.unknown) return { action: "skip", reason: "unknown_suspension" };
|
|
1897
|
+
if (facts.forAwait) return { action: "skip", reason: "unsupported_for_await" };
|
|
1898
|
+
if (facts.awaitUsing) return { action: "skip", reason: "await_using" };
|
|
1899
|
+
if (facts.awaitKeyword && !facts.awaitExpressions) {
|
|
1900
|
+
return { action: "skip", reason: "unknown_suspension" };
|
|
1901
|
+
}
|
|
1902
|
+
if (facts.awaitExpressions) return { action: "suspend_resume" };
|
|
1903
|
+
return { action: "inline" };
|
|
1904
|
+
};
|
|
1905
|
+
|
|
1906
|
+
// ../instrumentation/src/transform-source.ts
|
|
1907
|
+
import ts9 from "typescript";
|
|
1908
|
+
|
|
1909
|
+
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
1910
|
+
import ts6 from "typescript";
|
|
1911
|
+
|
|
1912
|
+
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
1913
|
+
import ts7 from "typescript";
|
|
1914
|
+
|
|
1915
|
+
// ../instrumentation/src/verify-transformed-source.ts
|
|
1916
|
+
import ts8 from "typescript";
|
|
1917
|
+
var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
1918
|
+
compilerOptions: {
|
|
1919
|
+
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
1920
|
+
target: ts8.ScriptTarget.ES2020,
|
|
1921
|
+
module: ts8.ModuleKind.ESNext,
|
|
1922
|
+
allowJs: true,
|
|
1923
|
+
jsx: ts8.JsxEmit.React,
|
|
1924
|
+
experimentalDecorators: true
|
|
1925
|
+
},
|
|
1926
|
+
reportDiagnostics: true,
|
|
1927
|
+
fileName: filePath
|
|
1928
|
+
});
|
|
1929
|
+
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
1930
|
+
diagnostics?.some(
|
|
1931
|
+
(diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
1932
|
+
)
|
|
1933
|
+
);
|
|
1934
|
+
var scriptBodyForEngine = (emitted) => (
|
|
1935
|
+
// File loaders strip a leading shebang; `new Function` does not.
|
|
1936
|
+
emitted.replace(/^#![^\n]*\n/, "").replaceAll("import.meta", "({})")
|
|
1937
|
+
);
|
|
1938
|
+
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
1939
|
+
var scriptKindFor2 = (filePath) => {
|
|
1940
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
1941
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
1942
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
1943
|
+
return ts8.ScriptKind.JS;
|
|
1944
|
+
};
|
|
1945
|
+
var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
|
|
1946
|
+
var unwrapLabeled = (node) => {
|
|
1947
|
+
let current = node;
|
|
1948
|
+
while (ts8.isLabeledStatement(current)) current = current.statement;
|
|
1949
|
+
return current;
|
|
1950
|
+
};
|
|
1951
|
+
var hasInvalidLabelJump = (sourceFile) => {
|
|
1952
|
+
const visit = (node, labels) => {
|
|
1953
|
+
if (ts8.isFunctionLike(node)) {
|
|
1954
|
+
let nestedInvalid = false;
|
|
1955
|
+
ts8.forEachChild(node, (child) => {
|
|
1956
|
+
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
1957
|
+
});
|
|
1958
|
+
return nestedInvalid;
|
|
1959
|
+
}
|
|
1960
|
+
if (ts8.isLabeledStatement(node)) {
|
|
1961
|
+
const next = new Map(labels);
|
|
1962
|
+
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
1963
|
+
return visit(node.statement, next);
|
|
1964
|
+
}
|
|
1965
|
+
if (ts8.isContinueStatement(node) && node.label) {
|
|
1966
|
+
if (labels.get(node.label.text) !== true) return true;
|
|
1967
|
+
}
|
|
1968
|
+
if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
1969
|
+
return true;
|
|
1970
|
+
}
|
|
1971
|
+
let invalid = false;
|
|
1972
|
+
ts8.forEachChild(node, (child) => {
|
|
1973
|
+
if (visit(child, labels)) invalid = true;
|
|
1974
|
+
});
|
|
1975
|
+
return invalid;
|
|
1976
|
+
};
|
|
1977
|
+
return visit(sourceFile, /* @__PURE__ */ new Map());
|
|
1978
|
+
};
|
|
1979
|
+
var importSpecifier = `('[^']+'|"[^"]+")`;
|
|
1980
|
+
var importAttributes = String.raw`(?:\s+with\s*\{[^}]*\})?`;
|
|
1981
|
+
var stripModuleSyntax = (body) => body.replace(/\bexport\s+default\b/g, "var __rasputinVerifyDefault =").replace(new RegExp(String.raw`\bexport\s*\*[\s\S]*?from\s+${importSpecifier}`, "g"), "").replace(
|
|
1982
|
+
new RegExp(
|
|
1983
|
+
String.raw`\bexport\s*\{[^}]*\}\s*from\s+${importSpecifier}${importAttributes}`,
|
|
1984
|
+
"g"
|
|
1985
|
+
),
|
|
1986
|
+
""
|
|
1987
|
+
).replace(/\bexport\s*\{[^}]*\}/g, "").replace(/\bexport\s+/g, "").replace(
|
|
1988
|
+
new RegExp(
|
|
1989
|
+
String.raw`\bimport(?:\s+type)?\s+[\s\S]*?from\s+${importSpecifier}${importAttributes}`,
|
|
1990
|
+
"g"
|
|
1991
|
+
),
|
|
1992
|
+
""
|
|
1993
|
+
).replace(/\bimport\s+type\s+[\s\S]*?(?:;|\n)/g, "").replace(new RegExp(String.raw`\bimport\s+${importSpecifier}${importAttributes}`, "g"), "");
|
|
1994
|
+
var engineAccepts = (body) => {
|
|
1995
|
+
for (const candidate of [body, stripModuleSyntax(body)]) {
|
|
1996
|
+
try {
|
|
1997
|
+
new Function(candidate);
|
|
1998
|
+
return true;
|
|
1999
|
+
} catch {
|
|
2000
|
+
try {
|
|
2001
|
+
new Function(`return (async()=>{${candidate}
|
|
2002
|
+
})`);
|
|
2003
|
+
return true;
|
|
2004
|
+
} catch {
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
return false;
|
|
2009
|
+
};
|
|
2010
|
+
var GLUED_INSTRUMENTATION = /\b(?:return|await|throw|typeof|void|yield|new|delete|in|instanceof|of|from|as|case|else)__rasputin/;
|
|
2011
|
+
var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
2012
|
+
var transformedSourceIsInvalid = (filePath, code) => {
|
|
2013
|
+
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
2014
|
+
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
2015
|
+
const sourceFile = ts8.createSourceFile(
|
|
2016
|
+
filePath,
|
|
2017
|
+
code,
|
|
2018
|
+
ts8.ScriptTarget.Latest,
|
|
2019
|
+
true,
|
|
2020
|
+
scriptKindFor2(filePath)
|
|
2021
|
+
);
|
|
2022
|
+
if (hasInvalidLabelJump(sourceFile)) return true;
|
|
2023
|
+
const { diagnostics, outputText } = transpileForVerification(filePath, code);
|
|
2024
|
+
if (hasScanOrParseError(diagnostics)) return true;
|
|
2025
|
+
if (looksTyped(filePath)) return !engineAccepts(scriptBodyForEngine(outputText));
|
|
2026
|
+
if (engineAccepts(scriptBodyForEngine(code))) return false;
|
|
2027
|
+
return !engineAccepts(scriptBodyForEngine(outputText));
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
// ../instrumentation/src/transform-source.ts
|
|
2031
|
+
var RASPUTIN_INSTRUMENTATION_MARKER = "rasputin.instrumented.v3";
|
|
2032
|
+
var RASPUTIN_INSTRUMENTATION_PREAMBLE = `/*${RASPUTIN_INSTRUMENTATION_MARKER}*/`;
|
|
2033
|
+
var sourceIsRasputinInstrumented = (source) => source.includes(RASPUTIN_INSTRUMENTATION_PREAMBLE);
|
|
2034
|
+
|
|
2035
|
+
// ../instrumentation/src/browser-function-edits.ts
|
|
2036
|
+
var REACTIVE_HIT = "__rasputinR";
|
|
2037
|
+
var REACTIVE_LEAVE = "__rasputinL";
|
|
2038
|
+
var REACTIVE_THROW = "__rasputinT";
|
|
2039
|
+
var REACTIVE_DONE = "__rasputinD";
|
|
2040
|
+
var REACTIVE_REG = "__rasputinReg";
|
|
2041
|
+
var OBSERVE_GUARD = "globalThis.__rasputinO??=function(i,v){return v};";
|
|
2042
|
+
var STRUCT_GUARD = "globalThis.__rasputinK??=function(o){return o};";
|
|
2043
|
+
var REACTIVE_GUARD = "globalThis.__rasputinR??=function(){return 1};globalThis.__rasputinL??=function(i,v){return v};globalThis.__rasputinT??=function(){};globalThis.__rasputinD??=function(){};globalThis.__rasputinReg??=function(){};";
|
|
2044
|
+
var isWrapTarget = (node) => (ts10.isFunctionDeclaration(node) || ts10.isFunctionExpression(node) || ts10.isArrowFunction(node) || ts10.isMethodDeclaration(node) || ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node)) && node.body !== void 0;
|
|
2045
|
+
var isDirectivePrologue = (statement) => ts10.isExpressionStatement(statement) && ts10.isStringLiteral(statement.expression);
|
|
2046
|
+
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
2047
|
+
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
2048
|
+
let end = shebangEnd;
|
|
2049
|
+
for (const statement of sourceFile.statements) {
|
|
2050
|
+
if (!isDirectivePrologue(statement)) break;
|
|
2051
|
+
end = statement.end;
|
|
2052
|
+
}
|
|
2053
|
+
return end;
|
|
2054
|
+
};
|
|
2055
|
+
var preambleInsert = (source, position, preamble) => {
|
|
2056
|
+
if (position <= 0) return preamble;
|
|
2057
|
+
const previous = source[position - 1];
|
|
2058
|
+
return previous === ";" || previous === "\n" || previous === "\r" ? preamble : `;${preamble}`;
|
|
2059
|
+
};
|
|
2060
|
+
var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
2061
|
+
let end = body.getStart(sourceFile) + 1;
|
|
2062
|
+
for (const statement of body.statements) {
|
|
2063
|
+
if (!isDirectivePrologue(statement)) break;
|
|
2064
|
+
end = statement.end;
|
|
2065
|
+
}
|
|
2066
|
+
return end;
|
|
2067
|
+
};
|
|
2068
|
+
var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
2069
|
+
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
2070
|
+
for (const statement of body.statements) {
|
|
2071
|
+
if (isDirectivePrologue(statement)) continue;
|
|
2072
|
+
if (ts10.isExpressionStatement(statement) && ts10.isCallExpression(statement.expression) && statement.expression.expression.kind === ts10.SyntaxKind.SuperKeyword) {
|
|
2073
|
+
return statement.end;
|
|
2074
|
+
}
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
return end;
|
|
2078
|
+
};
|
|
2079
|
+
var functionRef = (node) => {
|
|
2080
|
+
if (node.name && ts10.isIdentifier(node.name)) {
|
|
2081
|
+
if (ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node) || ts10.isMethodDeclaration(node)) {
|
|
2082
|
+
return void 0;
|
|
2083
|
+
}
|
|
2084
|
+
return node.name.text;
|
|
2085
|
+
}
|
|
2086
|
+
const parent = node.parent;
|
|
2087
|
+
if (ts10.isVariableDeclaration(parent) && ts10.isIdentifier(parent.name) && parent.initializer === node) {
|
|
2088
|
+
return parent.name.text;
|
|
2089
|
+
}
|
|
2090
|
+
return void 0;
|
|
2091
|
+
};
|
|
2092
|
+
var matchingFunction = (sourceFile, item) => {
|
|
2093
|
+
let found2;
|
|
2094
|
+
const visit = (node) => {
|
|
2095
|
+
if (found2) return;
|
|
2096
|
+
if (isWrapTarget(node) && node.getStart(sourceFile) === item.start && node.end === item.end) {
|
|
2097
|
+
found2 = node;
|
|
2098
|
+
return;
|
|
2099
|
+
}
|
|
2100
|
+
ts10.forEachChild(node, visit);
|
|
2101
|
+
};
|
|
2102
|
+
visit(sourceFile);
|
|
2103
|
+
return found2;
|
|
2104
|
+
};
|
|
2105
|
+
var isStaticPropertyName = (name) => ts10.isIdentifier(name) || ts10.isStringLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name) || ts10.isNumericLiteral(name);
|
|
2106
|
+
var canReconstructBinding = (name) => {
|
|
2107
|
+
if (ts10.isIdentifier(name)) return true;
|
|
2108
|
+
if (ts10.isArrayBindingPattern(name)) {
|
|
2109
|
+
return name.elements.every(
|
|
2110
|
+
(element) => ts10.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
2113
|
+
return name.elements.every((element) => {
|
|
2114
|
+
if (element.propertyName && !isStaticPropertyName(element.propertyName)) return false;
|
|
2115
|
+
return canReconstructBinding(element.name);
|
|
2116
|
+
});
|
|
2117
|
+
};
|
|
2118
|
+
var REDACTED_ARG_EXPR = 'Symbol.for("rasputin.redacted.v1")';
|
|
2119
|
+
var staticBindingKey = (name) => {
|
|
2120
|
+
if (ts10.isIdentifier(name)) return name.text;
|
|
2121
|
+
if (ts10.isStringLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name)) return name.text;
|
|
2122
|
+
if (ts10.isNumericLiteral(name)) return name.text;
|
|
2123
|
+
return void 0;
|
|
2124
|
+
};
|
|
2125
|
+
var bindingHasSensitiveName = (name) => {
|
|
2126
|
+
if (ts10.isIdentifier(name)) return propertyNameIsSensitive(name.text);
|
|
2127
|
+
if (ts10.isArrayBindingPattern(name)) {
|
|
2128
|
+
return name.elements.some(
|
|
2129
|
+
(element) => !ts10.isOmittedExpression(element) && bindingHasSensitiveName(element.name)
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
return name.elements.some((element) => {
|
|
2133
|
+
const key = element.propertyName ? staticBindingKey(element.propertyName) : void 0;
|
|
2134
|
+
if (key && propertyNameIsSensitive(key)) return true;
|
|
2135
|
+
return bindingHasSensitiveName(element.name);
|
|
2136
|
+
});
|
|
2137
|
+
};
|
|
2138
|
+
var capturedBinding = (name, sourceFile) => {
|
|
2139
|
+
if (ts10.isIdentifier(name)) {
|
|
2140
|
+
return propertyNameIsSensitive(name.text) ? REDACTED_ARG_EXPR : name.text;
|
|
2141
|
+
}
|
|
2142
|
+
if (ts10.isArrayBindingPattern(name)) {
|
|
2143
|
+
const values = name.elements.map((element) => {
|
|
2144
|
+
if (ts10.isOmittedExpression(element)) return "";
|
|
2145
|
+
const value = capturedBinding(element.name, sourceFile);
|
|
2146
|
+
return element.dotDotDotToken ? `...${value}` : value;
|
|
2147
|
+
});
|
|
2148
|
+
return `[${values.join(",")}]`;
|
|
2149
|
+
}
|
|
2150
|
+
const properties = name.elements.map((element) => {
|
|
2151
|
+
const key = element.propertyName ? staticBindingKey(element.propertyName) : void 0;
|
|
2152
|
+
const sensitive = key !== void 0 && propertyNameIsSensitive(key) || ts10.isIdentifier(element.name) && propertyNameIsSensitive(element.name.text);
|
|
2153
|
+
if (element.dotDotDotToken) {
|
|
2154
|
+
return `...${sensitive ? REDACTED_ARG_EXPR : capturedBinding(element.name, sourceFile)}`;
|
|
2155
|
+
}
|
|
2156
|
+
if (!element.propertyName) {
|
|
2157
|
+
return sensitive && ts10.isIdentifier(element.name) ? `${element.name.text}:${REDACTED_ARG_EXPR}` : capturedBinding(element.name, sourceFile);
|
|
2158
|
+
}
|
|
2159
|
+
const printedKey = ts10.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
2160
|
+
return `${printedKey}:${sensitive ? REDACTED_ARG_EXPR : capturedBinding(element.name, sourceFile)}`;
|
|
2161
|
+
});
|
|
2162
|
+
return `{${properties.join(",")}}`;
|
|
2163
|
+
};
|
|
2164
|
+
var captureArgs = (node) => {
|
|
2165
|
+
const sourceFile = node.getSourceFile();
|
|
2166
|
+
const params = node.parameters.filter(
|
|
2167
|
+
(parameter) => !(ts10.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
2168
|
+
);
|
|
2169
|
+
const reconstructable = params.every((parameter) => canReconstructBinding(parameter.name));
|
|
2170
|
+
const sensitive = params.some((parameter) => bindingHasSensitiveName(parameter.name));
|
|
2171
|
+
if (!reconstructable) {
|
|
2172
|
+
if (ts10.isArrowFunction(node) || sensitive) {
|
|
2173
|
+
return {
|
|
2174
|
+
args: `[${Array.from({ length: params.length }, () => "void 0").join(",")}]`,
|
|
2175
|
+
omitValues: true
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
return { args: "arguments", omitValues: false };
|
|
2179
|
+
}
|
|
2180
|
+
if (!ts10.isArrowFunction(node) && !sensitive) {
|
|
2181
|
+
return { args: "arguments", omitValues: false };
|
|
2182
|
+
}
|
|
2183
|
+
const values = params.map((parameter) => {
|
|
2184
|
+
const value = capturedBinding(parameter.name, sourceFile);
|
|
2185
|
+
return parameter.dotDotDotToken ? `...${value}` : value;
|
|
2186
|
+
});
|
|
2187
|
+
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
2188
|
+
};
|
|
2189
|
+
var walkOwnBody = (node, visitNode) => {
|
|
2190
|
+
const visit = (candidate) => {
|
|
2191
|
+
if (candidate !== node && ts10.isFunctionLike(candidate)) return;
|
|
2192
|
+
visitNode(candidate);
|
|
2193
|
+
ts10.forEachChild(candidate, visit);
|
|
2194
|
+
};
|
|
2195
|
+
visit(node.body);
|
|
2196
|
+
};
|
|
2197
|
+
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
2198
|
+
if (!ts10.isBlock(node.body)) return;
|
|
2199
|
+
walkOwnBody(node, (candidate) => {
|
|
2200
|
+
if (!ts10.isReturnStatement(candidate) || !candidate.expression) return;
|
|
2201
|
+
wrap(
|
|
2202
|
+
edits,
|
|
2203
|
+
candidate.expression.getStart(sourceFile),
|
|
2204
|
+
candidate.expression.end,
|
|
2205
|
+
`(${handleName}.leave((`,
|
|
2206
|
+
")))",
|
|
2207
|
+
depth + 1
|
|
2208
|
+
);
|
|
2209
|
+
});
|
|
2210
|
+
};
|
|
2211
|
+
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
2212
|
+
walkOwnBody(node, (candidate) => {
|
|
2213
|
+
if (!ts10.isAwaitExpression(candidate)) return;
|
|
2214
|
+
wrap(
|
|
2215
|
+
edits,
|
|
2216
|
+
candidate.expression.getStart(sourceFile),
|
|
2217
|
+
candidate.expression.end,
|
|
2218
|
+
`${handleName}.suspend(`,
|
|
2219
|
+
")",
|
|
2220
|
+
depth + 3
|
|
2221
|
+
);
|
|
2222
|
+
wrap(
|
|
2223
|
+
edits,
|
|
2224
|
+
candidate.getStart(sourceFile),
|
|
2225
|
+
candidate.end,
|
|
2226
|
+
`${handleName}.resume(`,
|
|
2227
|
+
")",
|
|
2228
|
+
depth + 2
|
|
2229
|
+
);
|
|
2230
|
+
});
|
|
2231
|
+
};
|
|
2232
|
+
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
2233
|
+
walkOwnBody(node, (candidate) => {
|
|
2234
|
+
if (!ts10.isTryStatement(candidate)) return;
|
|
2235
|
+
for (const block of [candidate.catchClause?.block, candidate.finallyBlock]) {
|
|
2236
|
+
if (!block) continue;
|
|
2237
|
+
edits.push({
|
|
2238
|
+
position: block.getStart(sourceFile) + 1,
|
|
2239
|
+
text: `${handleName}.resume();`,
|
|
2240
|
+
deleteCount: 0,
|
|
2241
|
+
depth,
|
|
2242
|
+
width: 0,
|
|
2243
|
+
kind: "replace"
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
};
|
|
2248
|
+
var collectReactiveReturnWraps = (node, sourceFile, siteId, edits, depth) => {
|
|
2249
|
+
if (!ts10.isBlock(node.body)) return;
|
|
2250
|
+
walkOwnBody(node, (candidate) => {
|
|
2251
|
+
if (!ts10.isReturnStatement(candidate)) return;
|
|
2252
|
+
if (!candidate.expression) {
|
|
2253
|
+
edits.push({
|
|
2254
|
+
position: candidate.getStart(sourceFile),
|
|
2255
|
+
text: `return void ${REACTIVE_LEAVE}(${siteId});`,
|
|
2256
|
+
deleteCount: candidate.end - candidate.getStart(sourceFile),
|
|
2257
|
+
depth,
|
|
2258
|
+
width: 0,
|
|
2259
|
+
kind: "replace"
|
|
2260
|
+
});
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
wrap(
|
|
2264
|
+
edits,
|
|
2265
|
+
candidate.expression.getStart(sourceFile),
|
|
2266
|
+
candidate.expression.end,
|
|
2267
|
+
`${REACTIVE_LEAVE}(${siteId},`,
|
|
2268
|
+
")",
|
|
2269
|
+
depth + 1
|
|
2270
|
+
);
|
|
2271
|
+
});
|
|
2272
|
+
};
|
|
2273
|
+
var failEpilogue = (handleName, errorName, failArgs, restoreOnCatch) => `}catch(${errorName}){${restoreOnCatch ? `${handleName}.resume();` : ""}${handleName}.fail(${errorName}${failArgs});throw ${errorName};}finally{${handleName}.end();}`;
|
|
2274
|
+
var toManifestFunction = (item, node, sourceFile, asyncFunction, instrumented, mapLocation) => {
|
|
2275
|
+
const plan = encodeFunctionPlan({
|
|
2276
|
+
filePath: item.filePath,
|
|
2277
|
+
name: item.name,
|
|
2278
|
+
line: item.line,
|
|
2279
|
+
column: item.column
|
|
2280
|
+
});
|
|
2281
|
+
const { params, paramNames } = node ? collectFunctionParams(node, sourceFile) : { params: [], paramNames: /* @__PURE__ */ new Set() };
|
|
2282
|
+
const end = node ? mappedLocation(sourceFile, node.end, item.filePath, mapLocation) : { line: item.line, column: item.column };
|
|
2283
|
+
return {
|
|
2284
|
+
plan,
|
|
2285
|
+
functionId: item.functionId,
|
|
2286
|
+
filePath: item.filePath,
|
|
2287
|
+
name: item.name,
|
|
2288
|
+
startLine: item.line,
|
|
2289
|
+
startColumn: item.column,
|
|
2290
|
+
endLine: end?.line ?? item.line,
|
|
2291
|
+
endColumn: end?.column ?? item.column,
|
|
2292
|
+
params,
|
|
2293
|
+
paramNames,
|
|
2294
|
+
instrumented,
|
|
2295
|
+
asyncFunction
|
|
2296
|
+
};
|
|
2297
|
+
};
|
|
2298
|
+
var collectCallerSites = (sourceFile, classifications, functions, absolutePath, mapLocation) => {
|
|
2299
|
+
const bySpan = /* @__PURE__ */ new Map();
|
|
2300
|
+
const classified = new Map(
|
|
2301
|
+
classifications.map((item) => [`${item.start}:${item.end}`, item])
|
|
2302
|
+
);
|
|
2303
|
+
const byId = new Map(functions.map((fn) => [fn.functionId, fn]));
|
|
2304
|
+
for (const item of classifications) {
|
|
2305
|
+
const fn = byId.get(item.functionId);
|
|
2306
|
+
if (fn) bySpan.set(`${item.start}:${item.end}`, fn);
|
|
2307
|
+
}
|
|
2308
|
+
const callSites = [];
|
|
2309
|
+
const destructures = [];
|
|
2310
|
+
const collectContext = { sourceFile, absolutePath, mapLocation };
|
|
2311
|
+
const svelteFile = isSvelteCompiledPath(absolutePath);
|
|
2312
|
+
const identifierCallees = svelteFile ? svelteGeneratedIdentifierCallees(sourceFile) : void 0;
|
|
2313
|
+
const visit = (node, caller) => {
|
|
2314
|
+
if (isWrapTarget(node)) {
|
|
2315
|
+
const item = classified.get(`${node.getStart(sourceFile)}:${node.end}`);
|
|
2316
|
+
if (item) {
|
|
2317
|
+
const fn = bySpan.get(`${item.start}:${item.end}`);
|
|
2318
|
+
const next = fn && fn.instrumented !== false ? fn : caller;
|
|
2319
|
+
ts10.forEachChild(node, (child) => visit(child, next));
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
if (caller && (ts10.isCallExpression(node) || ts10.isNewExpression(node))) {
|
|
2324
|
+
if (svelteFile && isSvelteCompilerCall(node, sourceFile, identifierCallees)) {
|
|
2325
|
+
ts10.forEachChild(node, (child) => visit(child, caller));
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
const site = collectCallSite(node, caller, collectContext);
|
|
2329
|
+
if (site) callSites.push(site);
|
|
2330
|
+
}
|
|
2331
|
+
if (caller && ts10.isVariableDeclaration(node)) {
|
|
2332
|
+
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
2333
|
+
if (destructure) destructures.push(destructure);
|
|
2334
|
+
}
|
|
2335
|
+
ts10.forEachChild(node, (child) => visit(child, caller));
|
|
2336
|
+
};
|
|
2337
|
+
visit(sourceFile, void 0);
|
|
2338
|
+
return { callSites, destructures };
|
|
2339
|
+
};
|
|
2340
|
+
var compactRegister = (runName, moduleIndex, plans) => `const ${runName}=((g,k,m)=>{const e=g[k];const ok=e&&typeof e.register==="function"&&Array.isArray(e.runtimes)&&Array.isArray(e.modules);const stub={runtimes:[],modules:[],register(p,i){const d={run:(x,a,c)=>c(),enter(){return{leave(v){return v},fail(){},end(){},suspend(v){return v},resume(v){return v},run(c){return c()}}}};const n={plans:p,cell:d,moduleIndex:i??m};this.modules.push(n);const t=this.runtimes.at(-1);if(t)t.bind(n);const f=(x,a,c,l)=>d.run(x,a,c,l);f.enter=(x,a,l,n)=>d.enter(x,a,l,n);return f}};const r=ok?e:e==null?(g[k]=stub):stub;return r.register(${JSON.stringify(plans)},m)})(globalThis,Symbol.for(${JSON.stringify(AUTOMATIC_RUNTIME_SYMBOL)}),${moduleIndex});`;
|
|
2341
|
+
var collectBrowserFunctionEdits = (source, sourceFile, classifications, moduleIndex, reactiveIds, options) => {
|
|
2342
|
+
const edits = [];
|
|
2343
|
+
const functions = [];
|
|
2344
|
+
const identities = [];
|
|
2345
|
+
const runtimePlans = [];
|
|
2346
|
+
const reactiveSiteIds = [];
|
|
2347
|
+
const runName = uniqueName(source, "__rasputinRun__");
|
|
2348
|
+
const handleName = uniqueName(source, "__rasputinH__");
|
|
2349
|
+
const errorName = uniqueName(source, "__rasputinE__");
|
|
2350
|
+
const sampledName = uniqueName(source, "__rasputinS__");
|
|
2351
|
+
const valueName = uniqueName(source, "__rasputinV__");
|
|
2352
|
+
let planIndex = 0;
|
|
2353
|
+
let emittedRuntime = false;
|
|
2354
|
+
for (const item of classifications) {
|
|
2355
|
+
const node = matchingFunction(sourceFile, item);
|
|
2356
|
+
const asyncFunction = node ? isAsyncFunctionLike(node) : false;
|
|
2357
|
+
if (item.captureClass === "skip") {
|
|
2358
|
+
functions.push(
|
|
2359
|
+
toManifestFunction(item, node, sourceFile, asyncFunction, false, options.mapLocation)
|
|
2360
|
+
);
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
if (!node) {
|
|
2364
|
+
functions.push(
|
|
2365
|
+
toManifestFunction(item, void 0, sourceFile, asyncFunction, false, options.mapLocation)
|
|
2366
|
+
);
|
|
2367
|
+
continue;
|
|
2368
|
+
}
|
|
2369
|
+
const remember = (siteId) => {
|
|
2370
|
+
runtimePlans[planIndex] = encodeFunctionPlan({
|
|
2371
|
+
filePath: item.filePath,
|
|
2372
|
+
name: item.name,
|
|
2373
|
+
line: item.line,
|
|
2374
|
+
column: item.column
|
|
2375
|
+
});
|
|
2376
|
+
identities.push({
|
|
2377
|
+
compactId: compactRuntimeFunctionId(moduleIndex, planIndex),
|
|
2378
|
+
functionId: item.functionId,
|
|
2379
|
+
name: item.name,
|
|
2380
|
+
moduleIndex,
|
|
2381
|
+
planIndex,
|
|
2382
|
+
captureClass: item.captureClass,
|
|
2383
|
+
line: item.line,
|
|
2384
|
+
column: item.column,
|
|
2385
|
+
filePath: item.filePath,
|
|
2386
|
+
...siteId === void 0 ? {} : { siteId }
|
|
2387
|
+
});
|
|
2388
|
+
};
|
|
2389
|
+
if (item.captureClass === "reactive-sparse" && !isAsyncFunctionLike(node)) {
|
|
2390
|
+
const siteId = reactiveIds.value++;
|
|
2391
|
+
remember(siteId);
|
|
2392
|
+
const hit = `${REACTIVE_HIT}(${siteId})`;
|
|
2393
|
+
const leave = `${REACTIVE_LEAVE}(${siteId})`;
|
|
2394
|
+
const fail = `${REACTIVE_THROW}(${siteId},${errorName})`;
|
|
2395
|
+
const epilogue2 = `}catch(${errorName}){${fail};throw ${errorName};}finally{${REACTIVE_DONE}()}`;
|
|
2396
|
+
if (ts10.isBlock(node.body)) {
|
|
2397
|
+
wrap(
|
|
2398
|
+
edits,
|
|
2399
|
+
node.body.getStart(sourceFile) + 1,
|
|
2400
|
+
node.body.end - 1,
|
|
2401
|
+
`;var ${sampledName}=${hit};try{`,
|
|
2402
|
+
`;if(!${sampledName})${leave}${epilogue2}`,
|
|
2403
|
+
0
|
|
2404
|
+
);
|
|
2405
|
+
collectReactiveReturnWraps(node, sourceFile, siteId, edits, 0);
|
|
2406
|
+
} else {
|
|
2407
|
+
wrap(
|
|
2408
|
+
edits,
|
|
2409
|
+
node.body.getStart(sourceFile),
|
|
2410
|
+
node.body.end,
|
|
2411
|
+
`{try{var ${sampledName}=${hit},${valueName}=`,
|
|
2412
|
+
`;return ${sampledName}?${valueName}:${REACTIVE_LEAVE}(${siteId},${valueName})${epilogue2}}`,
|
|
2413
|
+
0
|
|
2414
|
+
);
|
|
2415
|
+
}
|
|
2416
|
+
reactiveSiteIds.push(siteId);
|
|
2417
|
+
functions.push(toManifestFunction(item, node, sourceFile, false, true, options.mapLocation));
|
|
2418
|
+
planIndex += 1;
|
|
2419
|
+
continue;
|
|
2420
|
+
}
|
|
2421
|
+
const decision = isAsyncFunctionLike(node) ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
2422
|
+
if (decision.action === "skip") {
|
|
2423
|
+
functions.push(toManifestFunction(item, node, sourceFile, true, false, options.mapLocation));
|
|
2424
|
+
continue;
|
|
2425
|
+
}
|
|
2426
|
+
remember();
|
|
2427
|
+
emittedRuntime = true;
|
|
2428
|
+
const structure = item.captureClass === "structure";
|
|
2429
|
+
const captured = structure ? { args: "void 0", omitValues: true } : captureArgs(node);
|
|
2430
|
+
const omitFlag = structure || captured.omitValues;
|
|
2431
|
+
const ref = functionRef(node);
|
|
2432
|
+
const enterCall = `${runName}.enter(${planIndex},${captured.args},${omitFlag}${ref ? `,${ref}` : ""})`;
|
|
2433
|
+
const failLive = structure ? captureArgs(node) : captured;
|
|
2434
|
+
const failArgs = `,${failLive.args}`;
|
|
2435
|
+
const epilogue = failEpilogue(
|
|
2436
|
+
handleName,
|
|
2437
|
+
errorName,
|
|
2438
|
+
failArgs,
|
|
2439
|
+
decision.action === "suspend_resume"
|
|
2440
|
+
);
|
|
2441
|
+
if (ts10.isBlock(node.body)) {
|
|
2442
|
+
const prologueAt = insertAfterSuperOrPrologue(node.body, sourceFile);
|
|
2443
|
+
const closeAt = node.body.end - 1;
|
|
2444
|
+
wrap(edits, prologueAt, closeAt, `;const ${handleName}=${enterCall};try{`, epilogue, 0);
|
|
2445
|
+
collectReturnWraps(node, sourceFile, handleName, edits, 0);
|
|
2446
|
+
if (decision.action === "suspend_resume") {
|
|
2447
|
+
collectAwaitWraps(node, sourceFile, handleName, edits, 0);
|
|
2448
|
+
collectCatchFinallyResumes(node, sourceFile, handleName, edits, 0);
|
|
2449
|
+
}
|
|
2450
|
+
} else {
|
|
2451
|
+
wrap(
|
|
2452
|
+
edits,
|
|
2453
|
+
node.body.getStart(sourceFile),
|
|
2454
|
+
node.body.end,
|
|
2455
|
+
`{;const ${handleName}=${enterCall};try{return (${handleName}.leave((`,
|
|
2456
|
+
`)));${epilogue}}`,
|
|
2457
|
+
0
|
|
2458
|
+
);
|
|
2459
|
+
if (decision.action === "suspend_resume") {
|
|
2460
|
+
collectAwaitWraps(node, sourceFile, handleName, edits, 0);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
functions.push(
|
|
2464
|
+
toManifestFunction(
|
|
2465
|
+
item,
|
|
2466
|
+
node,
|
|
2467
|
+
sourceFile,
|
|
2468
|
+
isAsyncFunctionLike(node),
|
|
2469
|
+
true,
|
|
2470
|
+
options.mapLocation
|
|
2471
|
+
)
|
|
2472
|
+
);
|
|
2473
|
+
planIndex += 1;
|
|
2474
|
+
}
|
|
2475
|
+
if (functions.length === 0 && !options.observe) {
|
|
2476
|
+
return {
|
|
2477
|
+
edits: [],
|
|
2478
|
+
delta: { functions: [], callSites: [], destructures: [] },
|
|
2479
|
+
identities: [],
|
|
2480
|
+
reactiveSiteIds: []
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
const insertAt = insertPositionAfterPrologue(source, sourceFile);
|
|
2484
|
+
const reactivePreamble = reactiveSiteIds.length > 0 ? `${REACTIVE_REG}([${reactiveSiteIds.join(",")}]);` : "";
|
|
2485
|
+
const preamble = `${RASPUTIN_INSTRUMENTATION_PREAMBLE}${options.observe ? OBSERVE_GUARD : ""}${options.struct ? STRUCT_GUARD : ""}${reactiveSiteIds.length > 0 ? REACTIVE_GUARD : ""}${emittedRuntime ? compactRegister(runName, moduleIndex, options.includePlans ? runtimePlans : []) : ""}${reactivePreamble}`;
|
|
2486
|
+
edits.push({
|
|
2487
|
+
position: insertAt,
|
|
2488
|
+
text: preambleInsert(source, insertAt, preamble),
|
|
2489
|
+
deleteCount: 0,
|
|
2490
|
+
depth: -1,
|
|
2491
|
+
width: 0,
|
|
2492
|
+
kind: "replace"
|
|
2493
|
+
});
|
|
2494
|
+
const sites = collectCallerSites(
|
|
2495
|
+
sourceFile,
|
|
2496
|
+
classifications,
|
|
2497
|
+
functions,
|
|
2498
|
+
classifications[0]?.filePath ?? "",
|
|
2499
|
+
options.mapLocation
|
|
2500
|
+
);
|
|
2501
|
+
return {
|
|
2502
|
+
edits,
|
|
2503
|
+
delta: { functions, callSites: sites.callSites, destructures: sites.destructures },
|
|
2504
|
+
identities,
|
|
2505
|
+
reactiveSiteIds
|
|
2506
|
+
};
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2509
|
+
// ../instrumentation/src/json-producer-sites.ts
|
|
2510
|
+
import ts11 from "typescript";
|
|
2511
|
+
var JSON_METHOD_CALLEE = "globalThis.__rasputinM";
|
|
2512
|
+
var JSON_AWAIT_CALLEE = "globalThis.__rasputinA";
|
|
2513
|
+
var JSON_ADOPT_CALLEE = "globalThis.__rasputinP";
|
|
2514
|
+
var JSON_PRODUCER_GUARD = "globalThis.__rasputinM??=function(r,f){return Reflect.apply(f,r,[].slice.call(arguments,2))};globalThis.__rasputinA??=function(v){return v};globalThis.__rasputinP??=function(p){return p};";
|
|
2515
|
+
var isSimpleReceiver = (expression) => {
|
|
2516
|
+
const receiver = peel(expression);
|
|
2517
|
+
return ts11.isIdentifier(receiver) || receiver.kind === ts11.SyntaxKind.ThisKeyword;
|
|
2518
|
+
};
|
|
2519
|
+
var isSimpleIdentifierCall = (node) => !node.questionDotToken && ts11.isIdentifier(node.expression);
|
|
2520
|
+
var isSimpleMethodCall = (node) => {
|
|
2521
|
+
if (node.questionDotToken) return false;
|
|
2522
|
+
const callee = node.expression;
|
|
2523
|
+
return ts11.isPropertyAccessExpression(callee) && !callee.questionDotToken && ts11.isIdentifier(callee.name) && !ts11.isPrivateIdentifier(callee.name) && isSimpleReceiver(callee.expression);
|
|
2524
|
+
};
|
|
2525
|
+
var isSimpleProvenanceCall = (node) => isSimpleIdentifierCall(node) || isSimpleMethodCall(node);
|
|
2526
|
+
var isJsonParseCall = (node) => {
|
|
2527
|
+
if (!isSimpleMethodCall(node)) return false;
|
|
2528
|
+
const callee = node.expression;
|
|
2529
|
+
if (!ts11.isPropertyAccessExpression(callee) || callee.name.text !== "parse") return false;
|
|
2530
|
+
const object = peel(callee.expression);
|
|
2531
|
+
return ts11.isIdentifier(object) && object.text === "JSON";
|
|
2532
|
+
};
|
|
2533
|
+
var methodName = (node) => {
|
|
2534
|
+
if (!isSimpleMethodCall(node)) return void 0;
|
|
2535
|
+
const callee = node.expression;
|
|
2536
|
+
return ts11.isPropertyAccessExpression(callee) ? callee.name.text : void 0;
|
|
2537
|
+
};
|
|
2538
|
+
var containsNestedAwaitOrFunction = (node) => {
|
|
2539
|
+
let found2 = false;
|
|
2540
|
+
const visit = (candidate) => {
|
|
2541
|
+
if (candidate !== node && (ts11.isAwaitExpression(candidate) || ts11.isFunctionLike(candidate))) {
|
|
2542
|
+
found2 = true;
|
|
2543
|
+
return;
|
|
2544
|
+
}
|
|
2545
|
+
if (!found2) ts11.forEachChild(candidate, visit);
|
|
2546
|
+
};
|
|
2547
|
+
visit(node);
|
|
2548
|
+
return found2;
|
|
2549
|
+
};
|
|
2550
|
+
var isSimpleProducerCall = (node) => {
|
|
2551
|
+
if (containsNestedAwaitOrFunction(node)) return false;
|
|
2552
|
+
if (isJsonParseCall(node)) return true;
|
|
2553
|
+
return methodName(node) === "json";
|
|
2554
|
+
};
|
|
2555
|
+
var isAwaitExpressionOf = (node) => {
|
|
2556
|
+
let current = node;
|
|
2557
|
+
while (current.parent) {
|
|
2558
|
+
const parent = current.parent;
|
|
2559
|
+
if (ts11.isParenthesizedExpression(parent) || ts11.isNonNullExpression(parent) || ts11.isAsExpression(parent) || ts11.isTypeAssertionExpression(parent) || ts11.isSatisfiesExpression(parent)) {
|
|
2560
|
+
current = parent;
|
|
2561
|
+
continue;
|
|
2562
|
+
}
|
|
2563
|
+
return ts11.isAwaitExpression(parent) && parent.expression === current;
|
|
2564
|
+
}
|
|
2565
|
+
return false;
|
|
2566
|
+
};
|
|
2567
|
+
var isDirectSuperCall = (node) => node.expression.kind === ts11.SyntaxKind.SuperKeyword;
|
|
2568
|
+
var SVELTE_RUNE_ROOTS = /* @__PURE__ */ new Set([
|
|
2569
|
+
"$state",
|
|
2570
|
+
"$derived",
|
|
2571
|
+
"$effect",
|
|
2572
|
+
"$props",
|
|
2573
|
+
"$bindable",
|
|
2574
|
+
"$inspect",
|
|
2575
|
+
"$host"
|
|
2576
|
+
]);
|
|
2577
|
+
var isSvelteRuneCall = (node) => {
|
|
2578
|
+
let current = peel(node.expression);
|
|
2579
|
+
while (ts11.isPropertyAccessExpression(current)) {
|
|
2580
|
+
current = peel(current.expression);
|
|
2581
|
+
}
|
|
2582
|
+
return ts11.isIdentifier(current) && SVELTE_RUNE_ROOTS.has(current.text);
|
|
2583
|
+
};
|
|
2584
|
+
var isSvelteSourcePath = (filePath) => filePath.includes(".svelte");
|
|
2585
|
+
var isSvelteCompilerCall2 = (node, filePath) => {
|
|
2586
|
+
if (isSvelteRuneCall(node)) return true;
|
|
2587
|
+
if (!isSvelteSourcePath(filePath)) return false;
|
|
2588
|
+
const callee = peel(node.expression);
|
|
2589
|
+
if (!ts11.isPropertyAccessExpression(callee)) return false;
|
|
2590
|
+
const object = peel(callee.expression);
|
|
2591
|
+
return ts11.isIdentifier(object) && object.text === "$";
|
|
2592
|
+
};
|
|
2593
|
+
var outerExpression = (node) => {
|
|
2594
|
+
let current = node;
|
|
2595
|
+
while (current.parent) {
|
|
2596
|
+
const parent = current.parent;
|
|
2597
|
+
if ((ts11.isParenthesizedExpression(parent) || ts11.isNonNullExpression(parent) || ts11.isAsExpression(parent) || ts11.isTypeAssertionExpression(parent) || ts11.isSatisfiesExpression(parent)) && parent.expression === current) {
|
|
2598
|
+
current = parent;
|
|
2599
|
+
continue;
|
|
2600
|
+
}
|
|
2601
|
+
break;
|
|
2602
|
+
}
|
|
2603
|
+
return current;
|
|
2604
|
+
};
|
|
2605
|
+
var isReturnedOrBoundCall = (node) => {
|
|
2606
|
+
const expression = outerExpression(node);
|
|
2607
|
+
const parent = expression.parent;
|
|
2608
|
+
if (!parent) return false;
|
|
2609
|
+
if (ts11.isReturnStatement(parent) && parent.expression === expression) return true;
|
|
2610
|
+
if (ts11.isVariableDeclaration(parent) && parent.initializer === expression) return true;
|
|
2611
|
+
if (ts11.isBinaryExpression(parent) && parent.right === expression && parent.operatorToken.kind === ts11.SyntaxKind.EqualsToken) {
|
|
2612
|
+
return true;
|
|
2613
|
+
}
|
|
2614
|
+
return false;
|
|
2615
|
+
};
|
|
2616
|
+
var NON_PROVENANCE_ROOTS = /* @__PURE__ */ new Set([
|
|
2617
|
+
"String",
|
|
2618
|
+
"Number",
|
|
2619
|
+
"Boolean",
|
|
2620
|
+
"Object",
|
|
2621
|
+
"Array",
|
|
2622
|
+
"Error",
|
|
2623
|
+
"TypeError",
|
|
2624
|
+
"RangeError",
|
|
2625
|
+
"SyntaxError",
|
|
2626
|
+
"URIError",
|
|
2627
|
+
"EvalError",
|
|
2628
|
+
"ReferenceError",
|
|
2629
|
+
"Symbol",
|
|
2630
|
+
"BigInt",
|
|
2631
|
+
"Math",
|
|
2632
|
+
"JSON",
|
|
2633
|
+
"Date",
|
|
2634
|
+
"Promise",
|
|
2635
|
+
"console",
|
|
2636
|
+
"parseInt",
|
|
2637
|
+
"parseFloat",
|
|
2638
|
+
"isNaN",
|
|
2639
|
+
"isFinite",
|
|
2640
|
+
"encodeURIComponent",
|
|
2641
|
+
"decodeURIComponent",
|
|
2642
|
+
"encodeURI",
|
|
2643
|
+
"decodeURI"
|
|
2644
|
+
]);
|
|
2645
|
+
var callCanCarryProvenance = (node) => {
|
|
2646
|
+
const name = methodName(node);
|
|
2647
|
+
if (name === "json" || name === "parse") return true;
|
|
2648
|
+
if (name === "call" || name === "apply") return false;
|
|
2649
|
+
const callee = node.expression;
|
|
2650
|
+
if (ts11.isIdentifier(callee)) return !NON_PROVENANCE_ROOTS.has(callee.text);
|
|
2651
|
+
if (ts11.isPropertyAccessExpression(callee)) {
|
|
2652
|
+
const object = peel(callee.expression);
|
|
2653
|
+
if (ts11.isIdentifier(object) && NON_PROVENANCE_ROOTS.has(object.text)) {
|
|
2654
|
+
return object.text === "JSON" && callee.name.text === "parse";
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
return true;
|
|
2658
|
+
};
|
|
2659
|
+
var shouldAdoptCall = (node, filePath) => {
|
|
2660
|
+
if (isAwaitExpressionOf(node) || isDirectSuperCall(node) || isSvelteCompilerCall2(node, filePath)) {
|
|
2661
|
+
return false;
|
|
2662
|
+
}
|
|
2663
|
+
if (ts11.isComputedPropertyName(outerExpression(node).parent)) return false;
|
|
2664
|
+
if (!isSimpleProvenanceCall(node)) return false;
|
|
2665
|
+
return isReturnedOrBoundCall(node) && callCanCarryProvenance(node);
|
|
2666
|
+
};
|
|
2667
|
+
var shouldAdoptAwaitCall = (node, filePath) => {
|
|
2668
|
+
if (isSvelteCompilerCall2(node, filePath) || !isSimpleProvenanceCall(node)) return false;
|
|
2669
|
+
return callCanCarryProvenance(node);
|
|
2670
|
+
};
|
|
2671
|
+
var replaceProducerCall = (node, sourceFile, receiverName) => {
|
|
2672
|
+
const callee = node.expression;
|
|
2673
|
+
if (!ts11.isPropertyAccessExpression(callee)) return node.getText(sourceFile);
|
|
2674
|
+
const args = node.arguments.map((argument) => argument.getText(sourceFile));
|
|
2675
|
+
const extra2 = args.length > 0 ? `,${args.join(",")}` : "";
|
|
2676
|
+
const receiver = callee.expression.getText(sourceFile);
|
|
2677
|
+
const method = `${receiverName}.${callee.name.text}`;
|
|
2678
|
+
return `((${receiverName})=>${JSON_METHOD_CALLEE}(${receiverName},${method}${extra2}))(${receiver})`;
|
|
2679
|
+
};
|
|
2680
|
+
var hasBlockBody = (node) => {
|
|
2681
|
+
if (!ts11.isFunctionDeclaration(node) && !ts11.isFunctionExpression(node) && !ts11.isArrowFunction(node) && !ts11.isMethodDeclaration(node) && !ts11.isConstructorDeclaration(node) && !ts11.isGetAccessorDeclaration(node) && !ts11.isSetAccessorDeclaration(node)) {
|
|
2682
|
+
return false;
|
|
2683
|
+
}
|
|
2684
|
+
return node.body !== void 0 && ts11.isBlock(node.body);
|
|
2685
|
+
};
|
|
2686
|
+
var owningFunctionBody = (node) => {
|
|
2687
|
+
let current = node;
|
|
2688
|
+
while (current) {
|
|
2689
|
+
if (hasBlockBody(current)) return current.body;
|
|
2690
|
+
current = current.parent;
|
|
2691
|
+
}
|
|
2692
|
+
return void 0;
|
|
2693
|
+
};
|
|
2694
|
+
var callOpenParen = (node, sourceFile) => {
|
|
2695
|
+
const text = sourceFile.text;
|
|
2696
|
+
for (let index = node.expression.getEnd(); index < node.end; index += 1) {
|
|
2697
|
+
if (text.charCodeAt(index) === 40) return index;
|
|
2698
|
+
}
|
|
2699
|
+
return node.arguments.pos;
|
|
2700
|
+
};
|
|
2701
|
+
var callCloseParen = (node, sourceFile) => {
|
|
2702
|
+
const text = sourceFile.text;
|
|
2703
|
+
for (let index = node.end - 1; index >= node.arguments.pos; index -= 1) {
|
|
2704
|
+
if (text.charCodeAt(index) === 41) return index;
|
|
2705
|
+
}
|
|
2706
|
+
return node.end - 1;
|
|
2707
|
+
};
|
|
2708
|
+
var adoptCall = (edits, node, sourceFile, receiverName, fnName, slotName, slot = false) => {
|
|
2709
|
+
const start = node.getStart(sourceFile);
|
|
2710
|
+
const end = node.end;
|
|
2711
|
+
const depth = slot ? 17 : 14;
|
|
2712
|
+
const wrapOpen = (inner) => slot ? `(${slotName}={p:${inner}` : inner;
|
|
2713
|
+
const wrapClose = (inner) => slot ? `${inner}},${slotName}.p)` : inner;
|
|
2714
|
+
const callee = node.expression;
|
|
2715
|
+
if (ts11.isIdentifier(callee)) {
|
|
2716
|
+
wrap(
|
|
2717
|
+
edits,
|
|
2718
|
+
start,
|
|
2719
|
+
end,
|
|
2720
|
+
wrapOpen(`((${fnName})=>${JSON_ADOPT_CALLEE}(`),
|
|
2721
|
+
wrapClose(`,${fnName}))(${callee.text})`),
|
|
2722
|
+
depth
|
|
2723
|
+
);
|
|
2724
|
+
edits.push({
|
|
2725
|
+
position: callee.getStart(sourceFile),
|
|
2726
|
+
text: fnName,
|
|
2727
|
+
deleteCount: callee.end - callee.getStart(sourceFile),
|
|
2728
|
+
depth: 18,
|
|
2729
|
+
width: callee.end - callee.getStart(sourceFile),
|
|
2730
|
+
kind: "replace"
|
|
2731
|
+
});
|
|
2732
|
+
return;
|
|
2733
|
+
}
|
|
2734
|
+
if (!isSimpleMethodCall(node) || !ts11.isPropertyAccessExpression(callee)) return;
|
|
2735
|
+
const receiver = callee.expression.getText(sourceFile);
|
|
2736
|
+
const method = callee.name.text;
|
|
2737
|
+
const open = callOpenParen(node, sourceFile);
|
|
2738
|
+
const close = callCloseParen(node, sourceFile);
|
|
2739
|
+
wrap(
|
|
2740
|
+
edits,
|
|
2741
|
+
start,
|
|
2742
|
+
end,
|
|
2743
|
+
wrapOpen(`((${receiverName})=>((${fnName})=>${JSON_ADOPT_CALLEE}(`),
|
|
2744
|
+
wrapClose(`,${fnName}))(${receiverName}.${method}))(${receiver})`),
|
|
2745
|
+
depth
|
|
2746
|
+
);
|
|
2747
|
+
edits.push({
|
|
2748
|
+
position: start,
|
|
2749
|
+
text: `Reflect.apply(${fnName},${receiverName},[`,
|
|
2750
|
+
deleteCount: open + 1 - start,
|
|
2751
|
+
depth: 18,
|
|
2752
|
+
width: open + 1 - start,
|
|
2753
|
+
kind: "replace"
|
|
2754
|
+
});
|
|
2755
|
+
edits.push({
|
|
2756
|
+
position: close,
|
|
2757
|
+
text: "])",
|
|
2758
|
+
deleteCount: 1,
|
|
2759
|
+
depth: 18,
|
|
2760
|
+
width: 1,
|
|
2761
|
+
kind: "replace"
|
|
2762
|
+
});
|
|
2763
|
+
};
|
|
2764
|
+
var skippedComplexCall = (node, filePath) => {
|
|
2765
|
+
if (isSvelteCompilerCall2(node, filePath) || isDirectSuperCall(node)) return false;
|
|
2766
|
+
if (isSimpleProvenanceCall(node)) return false;
|
|
2767
|
+
if (!callCanCarryProvenance(node)) return false;
|
|
2768
|
+
return true;
|
|
2769
|
+
};
|
|
2770
|
+
var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(source, filePath), options) => {
|
|
2771
|
+
const adoptCalls = options?.adoptCalls === true;
|
|
2772
|
+
const receiverName = uniqueName(source, "__rasputinJ");
|
|
2773
|
+
const adoptFnName = uniqueName(source, "__rasputinC");
|
|
2774
|
+
const slotName = uniqueName(source, "__rasputinS");
|
|
2775
|
+
const edits = [];
|
|
2776
|
+
const bodies = /* @__PURE__ */ new Set();
|
|
2777
|
+
let awaitWraps = 0;
|
|
2778
|
+
let callWraps = 0;
|
|
2779
|
+
let provenanceSkippedComplexCall = 0;
|
|
2780
|
+
const visit = (node) => {
|
|
2781
|
+
if (ts11.isCallExpression(node) && isSimpleProducerCall(node) && !isAwaitExpressionOf(node)) {
|
|
2782
|
+
edits.push({
|
|
2783
|
+
position: node.getStart(sourceFile),
|
|
2784
|
+
text: replaceProducerCall(node, sourceFile, receiverName),
|
|
2785
|
+
deleteCount: node.end - node.getStart(sourceFile),
|
|
2786
|
+
depth: 18,
|
|
2787
|
+
width: node.end - node.getStart(sourceFile),
|
|
2788
|
+
kind: "replace"
|
|
2789
|
+
});
|
|
2790
|
+
callWraps += 1;
|
|
2791
|
+
} else if (adoptCalls && ts11.isCallExpression(node) && shouldAdoptCall(node, filePath)) {
|
|
2792
|
+
adoptCall(edits, node, sourceFile, receiverName, adoptFnName, slotName);
|
|
2793
|
+
callWraps += 1;
|
|
2794
|
+
} else if (ts11.isCallExpression(node) && !isAwaitExpressionOf(node) && isReturnedOrBoundCall(node) && skippedComplexCall(node, filePath)) {
|
|
2795
|
+
provenanceSkippedComplexCall += 1;
|
|
2796
|
+
}
|
|
2797
|
+
if (ts11.isAwaitExpression(node)) {
|
|
2798
|
+
const inner = peel(node.expression);
|
|
2799
|
+
const producer = ts11.isCallExpression(inner) && isSimpleProducerCall(inner);
|
|
2800
|
+
const adoptInner = adoptCalls && ts11.isCallExpression(inner) && shouldAdoptAwaitCall(inner, filePath);
|
|
2801
|
+
const adoptValue = adoptCalls && !ts11.isCallExpression(inner);
|
|
2802
|
+
if (producer || adoptInner || adoptValue) {
|
|
2803
|
+
if (producer && ts11.isCallExpression(inner)) {
|
|
2804
|
+
edits.push({
|
|
2805
|
+
position: node.expression.getStart(sourceFile),
|
|
2806
|
+
text: `(${slotName}={p:${replaceProducerCall(inner, sourceFile, receiverName)}},${slotName}.p)`,
|
|
2807
|
+
deleteCount: node.expression.end - node.expression.getStart(sourceFile),
|
|
2808
|
+
depth: 17,
|
|
2809
|
+
width: node.expression.end - node.expression.getStart(sourceFile),
|
|
2810
|
+
kind: "replace"
|
|
2811
|
+
});
|
|
2812
|
+
callWraps += 1;
|
|
2813
|
+
} else if (adoptInner && ts11.isCallExpression(inner)) {
|
|
2814
|
+
if (node.expression === inner) {
|
|
2815
|
+
adoptCall(edits, inner, sourceFile, receiverName, adoptFnName, slotName, true);
|
|
2816
|
+
} else {
|
|
2817
|
+
wrap(
|
|
2818
|
+
edits,
|
|
2819
|
+
node.expression.getStart(sourceFile),
|
|
2820
|
+
node.expression.end,
|
|
2821
|
+
`(${slotName}={p:`,
|
|
2822
|
+
`},${slotName}.p)`,
|
|
2823
|
+
17
|
|
2824
|
+
);
|
|
2825
|
+
adoptCall(edits, inner, sourceFile, receiverName, adoptFnName, slotName);
|
|
2826
|
+
}
|
|
2827
|
+
callWraps += 1;
|
|
2828
|
+
} else {
|
|
2829
|
+
wrap(
|
|
2830
|
+
edits,
|
|
2831
|
+
node.expression.getStart(sourceFile),
|
|
2832
|
+
node.expression.end,
|
|
2833
|
+
`(${slotName}={p:${JSON_ADOPT_CALLEE}(`,
|
|
2834
|
+
`)},${slotName}.p)`,
|
|
2835
|
+
17
|
|
2836
|
+
);
|
|
2837
|
+
}
|
|
2838
|
+
wrap(
|
|
2839
|
+
edits,
|
|
2840
|
+
node.getStart(sourceFile),
|
|
2841
|
+
node.end,
|
|
2842
|
+
`${JSON_AWAIT_CALLEE}(`,
|
|
2843
|
+
`,${slotName}.p)`,
|
|
2844
|
+
16
|
|
2845
|
+
);
|
|
2846
|
+
awaitWraps += 1;
|
|
2847
|
+
const body = owningFunctionBody(node);
|
|
2848
|
+
if (body) bodies.add(body);
|
|
2849
|
+
} else if (ts11.isCallExpression(inner) && skippedComplexCall(inner, filePath)) {
|
|
2850
|
+
provenanceSkippedComplexCall += 1;
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
ts11.forEachChild(node, visit);
|
|
2854
|
+
};
|
|
2855
|
+
visit(sourceFile);
|
|
2856
|
+
if (edits.length > 0) {
|
|
2857
|
+
edits.push({
|
|
2858
|
+
position: 0,
|
|
2859
|
+
text: `${RASPUTIN_INSTRUMENTATION_PREAMBLE}${JSON_PRODUCER_GUARD}`,
|
|
2860
|
+
deleteCount: 0,
|
|
2861
|
+
depth: -1,
|
|
2862
|
+
width: 0,
|
|
2863
|
+
kind: "replace"
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
for (const body of bodies) {
|
|
2867
|
+
edits.push({
|
|
2868
|
+
position: body.getStart(sourceFile) + 1,
|
|
2869
|
+
text: `var ${slotName};`,
|
|
2870
|
+
deleteCount: 0,
|
|
2871
|
+
depth: 1,
|
|
2872
|
+
width: 0,
|
|
2873
|
+
kind: "replace"
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
return { edits, awaitWraps, callWraps, provenanceSkippedComplexCall };
|
|
2877
|
+
};
|
|
2878
|
+
|
|
2879
|
+
// ../instrumentation/src/literal-sites.ts
|
|
2880
|
+
import ts12 from "typescript";
|
|
2881
|
+
var STRUCT_CALLEE = "globalThis.__rasputinK";
|
|
2882
|
+
var owningFunction = (position, classifications) => {
|
|
2883
|
+
let owner;
|
|
2884
|
+
let span = Number.POSITIVE_INFINITY;
|
|
2885
|
+
for (const item of classifications) {
|
|
2886
|
+
if (position < item.bodyStart || position >= item.bodyEnd) continue;
|
|
2887
|
+
const size = item.bodyEnd - item.bodyStart;
|
|
2888
|
+
if (size < span) {
|
|
2889
|
+
owner = item;
|
|
2890
|
+
span = size;
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
return owner;
|
|
2894
|
+
};
|
|
2895
|
+
var allowsLiteralCapture = (owner) => owner.captureClass === "full" || owner.captureClass === "reactive-sparse";
|
|
2896
|
+
var walkPeelParent = (node) => {
|
|
2897
|
+
let current = node;
|
|
2898
|
+
while (current.parent) {
|
|
2899
|
+
const parent = current.parent;
|
|
2900
|
+
if ((ts12.isParenthesizedExpression(parent) || ts12.isNonNullExpression(parent) || ts12.isAsExpression(parent) || ts12.isTypeAssertionExpression(parent) || ts12.isSatisfiesExpression(parent)) && parent.expression === current) {
|
|
2901
|
+
current = parent;
|
|
2902
|
+
continue;
|
|
2903
|
+
}
|
|
2904
|
+
break;
|
|
2905
|
+
}
|
|
2906
|
+
return current;
|
|
2907
|
+
};
|
|
2908
|
+
var isCapturePosition = (node) => {
|
|
2909
|
+
const current = walkPeelParent(node);
|
|
2910
|
+
const parent = current.parent;
|
|
2911
|
+
if (!parent) return false;
|
|
2912
|
+
if (ts12.isReturnStatement(parent) && parent.expression === current) return true;
|
|
2913
|
+
if (ts12.isArrowFunction(parent) && parent.body === current) return true;
|
|
2914
|
+
if (ts12.isVariableDeclaration(parent) && parent.initializer === current) return true;
|
|
2915
|
+
if (ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.EqualsToken && parent.right === current) {
|
|
2916
|
+
return true;
|
|
2917
|
+
}
|
|
2918
|
+
if (ts12.isCallExpression(parent) || ts12.isNewExpression(parent)) {
|
|
2919
|
+
return parent.arguments?.some((argument) => argument === current) === true;
|
|
2920
|
+
}
|
|
2921
|
+
return false;
|
|
2922
|
+
};
|
|
2923
|
+
var isInAssignmentPattern = (node) => {
|
|
2924
|
+
let current = walkPeelParent(node);
|
|
2925
|
+
while (current.parent) {
|
|
2926
|
+
const parent = current.parent;
|
|
2927
|
+
if (ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.EqualsToken && parent.left === current) {
|
|
2928
|
+
return true;
|
|
2929
|
+
}
|
|
2930
|
+
if ((ts12.isForOfStatement(parent) || ts12.isForInStatement(parent)) && parent.initializer === current) {
|
|
2931
|
+
return true;
|
|
2932
|
+
}
|
|
2933
|
+
if (ts12.isPropertyAssignment(parent) || ts12.isShorthandPropertyAssignment(parent) || ts12.isSpreadAssignment(parent) || ts12.isObjectLiteralExpression(parent) || ts12.isArrayLiteralExpression(parent) || ts12.isParenthesizedExpression(parent) || ts12.isAsExpression(parent) || ts12.isTypeAssertionExpression(parent) || ts12.isNonNullExpression(parent) || ts12.isSatisfiesExpression(parent)) {
|
|
2934
|
+
current = walkPeelParent(parent);
|
|
2935
|
+
continue;
|
|
2936
|
+
}
|
|
2937
|
+
return false;
|
|
2938
|
+
}
|
|
2939
|
+
return false;
|
|
2940
|
+
};
|
|
2941
|
+
var isLiteralChild = (node) => {
|
|
2942
|
+
const current = walkPeelParent(node);
|
|
2943
|
+
const parent = current.parent;
|
|
2944
|
+
if (!parent) return false;
|
|
2945
|
+
if (ts12.isPropertyAssignment(parent) && parent.initializer === current) return true;
|
|
2946
|
+
if (ts12.isArrayLiteralExpression(parent)) return true;
|
|
2947
|
+
return false;
|
|
2948
|
+
};
|
|
2949
|
+
var shouldRewrite = (node, classifications, sourceFile) => {
|
|
2950
|
+
if (isInAssignmentPattern(node)) return false;
|
|
2951
|
+
const owner = owningFunction(node.getStart(sourceFile), classifications);
|
|
2952
|
+
if (!owner || !allowsLiteralCapture(owner)) return false;
|
|
2953
|
+
return isCapturePosition(node) || isLiteralChild(node);
|
|
2954
|
+
};
|
|
2955
|
+
var collectLiteralSiteEdits = (source, filePath, options, sourceFile = parseSource(source, filePath)) => {
|
|
2956
|
+
const edits = [];
|
|
2957
|
+
const visit = (node) => {
|
|
2958
|
+
if ((ts12.isObjectLiteralExpression(node) || ts12.isArrayLiteralExpression(node)) && shouldRewrite(node, options.classifications, sourceFile)) {
|
|
2959
|
+
wrap(edits, node.getStart(sourceFile), node.end, `${STRUCT_CALLEE}(`, ")", 15);
|
|
2960
|
+
}
|
|
2961
|
+
ts12.forEachChild(node, visit);
|
|
2962
|
+
};
|
|
2963
|
+
visit(sourceFile);
|
|
2964
|
+
return { edits };
|
|
2965
|
+
};
|
|
2966
|
+
|
|
2967
|
+
// ../instrumentation/src/observe-sites.ts
|
|
2968
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
2969
|
+
import { resolve as resolve4 } from "node:path";
|
|
2970
|
+
import ts13 from "typescript";
|
|
2971
|
+
var OBSERVE_CALLEE = "globalThis.__rasputinO";
|
|
2972
|
+
var siteIdFor = (filePath, line, column, text) => {
|
|
2973
|
+
const digest = createHash2("sha256").update(`${resolve4(filePath)}:${line}:${column}:${text}`).digest("base64url").slice(0, 16);
|
|
2974
|
+
return `rs_${digest}`;
|
|
2975
|
+
};
|
|
2976
|
+
var isAssignmentOperator = (kind) => kind === ts13.SyntaxKind.EqualsToken || kind === ts13.SyntaxKind.PlusEqualsToken || kind === ts13.SyntaxKind.MinusEqualsToken || kind === ts13.SyntaxKind.AsteriskEqualsToken || kind === ts13.SyntaxKind.SlashEqualsToken || kind === ts13.SyntaxKind.PercentEqualsToken || kind === ts13.SyntaxKind.AmpersandEqualsToken || kind === ts13.SyntaxKind.BarEqualsToken || kind === ts13.SyntaxKind.CaretEqualsToken || kind === ts13.SyntaxKind.LessThanLessThanEqualsToken || kind === ts13.SyntaxKind.GreaterThanGreaterThanEqualsToken || kind === ts13.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || kind === ts13.SyntaxKind.AsteriskAsteriskEqualsToken || kind === ts13.SyntaxKind.BarBarEqualsToken || kind === ts13.SyntaxKind.AmpersandAmpersandEqualsToken || kind === ts13.SyntaxKind.QuestionQuestionEqualsToken;
|
|
2977
|
+
var isSafeLiteral = (expression) => {
|
|
2978
|
+
const node = peel(expression);
|
|
2979
|
+
if (ts13.isStringLiteral(node) || ts13.isNoSubstitutionTemplateLiteral(node)) return true;
|
|
2980
|
+
if (ts13.isNumericLiteral(node)) return true;
|
|
2981
|
+
if (node.kind === ts13.SyntaxKind.TrueKeyword || node.kind === ts13.SyntaxKind.FalseKeyword || node.kind === ts13.SyntaxKind.NullKeyword) {
|
|
2982
|
+
return true;
|
|
2983
|
+
}
|
|
2984
|
+
if (ts13.isIdentifier(node) && (node.text === "undefined" || node.text === "NaN")) return true;
|
|
2985
|
+
if (ts13.isPrefixUnaryExpression(node) && node.operator === ts13.SyntaxKind.MinusToken && ts13.isNumericLiteral(node.operand)) {
|
|
2986
|
+
return true;
|
|
2987
|
+
}
|
|
2988
|
+
return ts13.isVoidExpression(node) && ts13.isNumericLiteral(peel(node.expression)) && peel(node.expression).getText() === "0";
|
|
2989
|
+
};
|
|
2990
|
+
var isPropertyRead = (node) => {
|
|
2991
|
+
if (ts13.isPropertyAccessExpression(node)) {
|
|
2992
|
+
return !ts13.isPrivateIdentifier(node.name) && node.expression.kind !== ts13.SyntaxKind.SuperKeyword;
|
|
2993
|
+
}
|
|
2994
|
+
if (ts13.isElementAccessExpression(node)) {
|
|
2995
|
+
return node.expression.kind !== ts13.SyntaxKind.SuperKeyword;
|
|
2996
|
+
}
|
|
2997
|
+
return false;
|
|
2998
|
+
};
|
|
2999
|
+
var isMetaChain = (node) => {
|
|
3000
|
+
if (ts13.isMetaProperty(node)) return true;
|
|
3001
|
+
if (ts13.isPropertyAccessExpression(node)) return isMetaChain(node.expression);
|
|
3002
|
+
if (ts13.isElementAccessExpression(node)) return isMetaChain(node.expression);
|
|
3003
|
+
return false;
|
|
3004
|
+
};
|
|
3005
|
+
var isPatternParent = (parent, child) => {
|
|
3006
|
+
if (ts13.isParenthesizedExpression(parent) && parent.expression === child) return true;
|
|
3007
|
+
if (ts13.isAsExpression(parent) && parent.expression === child) return true;
|
|
3008
|
+
if (ts13.isTypeAssertionExpression(parent) && parent.expression === child) return true;
|
|
3009
|
+
if (ts13.isNonNullExpression(parent) && parent.expression === child) return true;
|
|
3010
|
+
if (ts13.isSatisfiesExpression(parent) && parent.expression === child) return true;
|
|
3011
|
+
if (ts13.isPropertyAssignment(parent) && parent.initializer === child) return true;
|
|
3012
|
+
if (ts13.isShorthandPropertyAssignment(parent)) return true;
|
|
3013
|
+
if (ts13.isSpreadAssignment(parent) && parent.expression === child) return true;
|
|
3014
|
+
if (ts13.isSpreadElement(parent) && parent.expression === child) return true;
|
|
3015
|
+
if (ts13.isArrayLiteralExpression(parent)) return true;
|
|
3016
|
+
if (ts13.isObjectLiteralExpression(parent)) return true;
|
|
3017
|
+
return false;
|
|
3018
|
+
};
|
|
3019
|
+
var isAssignmentTarget = (node) => {
|
|
3020
|
+
let current = node;
|
|
3021
|
+
while (current.parent) {
|
|
3022
|
+
const parent = current.parent;
|
|
3023
|
+
if (ts13.isComputedPropertyName(parent) && parent.expression === current) return false;
|
|
3024
|
+
if (ts13.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3025
|
+
return parent.left === current;
|
|
3026
|
+
}
|
|
3027
|
+
if ((ts13.isForOfStatement(parent) || ts13.isForInStatement(parent)) && parent.initializer === current) {
|
|
3028
|
+
return true;
|
|
3029
|
+
}
|
|
3030
|
+
if (!isPatternParent(parent, current)) return false;
|
|
3031
|
+
current = parent;
|
|
3032
|
+
}
|
|
3033
|
+
return false;
|
|
3034
|
+
};
|
|
3035
|
+
var isValueContext = (node) => {
|
|
3036
|
+
if (isAssignmentTarget(node)) return false;
|
|
3037
|
+
const parent = node.parent;
|
|
3038
|
+
if (!parent) return false;
|
|
3039
|
+
if (ts13.isVariableDeclaration(parent) && parent.initializer === node) return true;
|
|
3040
|
+
if (ts13.isReturnStatement(parent) && parent.expression === node) return true;
|
|
3041
|
+
if (ts13.isPropertyAssignment(parent) && parent.initializer === node) return true;
|
|
3042
|
+
if (ts13.isParenthesizedExpression(parent) || ts13.isNonNullExpression(parent) || ts13.isAsExpression(parent) || ts13.isTypeAssertionExpression(parent) || ts13.isSatisfiesExpression(parent)) {
|
|
3043
|
+
return isValueContext(parent);
|
|
3044
|
+
}
|
|
3045
|
+
return false;
|
|
3046
|
+
};
|
|
3047
|
+
var isCoalesceWithLiteral = (node) => {
|
|
3048
|
+
if (!ts13.isBinaryExpression(node)) return false;
|
|
3049
|
+
const operator = node.operatorToken.kind;
|
|
3050
|
+
if (operator !== ts13.SyntaxKind.QuestionQuestionToken && operator !== ts13.SyntaxKind.BarBarToken) {
|
|
3051
|
+
return false;
|
|
3052
|
+
}
|
|
3053
|
+
return isSafeLiteral(node.right);
|
|
3054
|
+
};
|
|
3055
|
+
var shouldWrapPropertyRead = (node) => {
|
|
3056
|
+
if (isMetaChain(node)) return false;
|
|
3057
|
+
const parent = node.parent;
|
|
3058
|
+
if (!parent) return false;
|
|
3059
|
+
if (ts13.isPropertyAccessExpression(parent) && parent.expression === node) return false;
|
|
3060
|
+
if (ts13.isElementAccessExpression(parent) && parent.expression === node) return false;
|
|
3061
|
+
if (ts13.isCallExpression(parent) && parent.expression === node) return false;
|
|
3062
|
+
if (ts13.isNewExpression(parent) && parent.expression === node) return false;
|
|
3063
|
+
if (ts13.isTaggedTemplateExpression(parent) && parent.tag === node) return false;
|
|
3064
|
+
if (ts13.isDeleteExpression(parent)) return false;
|
|
3065
|
+
if (ts13.isPrefixUnaryExpression(parent) && (parent.operator === ts13.SyntaxKind.PlusPlusToken || parent.operator === ts13.SyntaxKind.MinusMinusToken)) {
|
|
3066
|
+
return false;
|
|
3067
|
+
}
|
|
3068
|
+
if (ts13.isPostfixUnaryExpression(parent) && (parent.operator === ts13.SyntaxKind.PlusPlusToken || parent.operator === ts13.SyntaxKind.MinusMinusToken)) {
|
|
3069
|
+
return false;
|
|
3070
|
+
}
|
|
3071
|
+
if (ts13.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3072
|
+
if (parent.left === node) return false;
|
|
3073
|
+
}
|
|
3074
|
+
if (isValueContext(node)) return true;
|
|
3075
|
+
if (isCoalesceWithLiteral(parent) && parent.left === node) {
|
|
3076
|
+
return isValueContext(parent);
|
|
3077
|
+
}
|
|
3078
|
+
return false;
|
|
3079
|
+
};
|
|
3080
|
+
var shouldWrapRead = (node, classifications, sourceFile) => {
|
|
3081
|
+
if (isAssignmentTarget(node)) return false;
|
|
3082
|
+
return shouldWrapPropertyRead(node) || isReactiveArrowValue(node, classifications, sourceFile);
|
|
3083
|
+
};
|
|
3084
|
+
var hasOptional = (node) => !!node.questionDotToken;
|
|
3085
|
+
var isInternalProperty = (node) => {
|
|
3086
|
+
if (ts13.isPropertyAccessExpression(node)) return node.name.text.startsWith("__");
|
|
3087
|
+
if (!ts13.isStringLiteral(node.argumentExpression) && !ts13.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
|
|
3088
|
+
return false;
|
|
3089
|
+
}
|
|
3090
|
+
return node.argumentExpression.text.startsWith("__");
|
|
3091
|
+
};
|
|
3092
|
+
var staticPropertyName = (node) => {
|
|
3093
|
+
if (ts13.isPropertyAccessExpression(node)) return node.name.text;
|
|
3094
|
+
if (ts13.isStringLiteral(node.argumentExpression) || ts13.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
|
|
3095
|
+
return node.argumentExpression.text;
|
|
3096
|
+
}
|
|
3097
|
+
return void 0;
|
|
3098
|
+
};
|
|
3099
|
+
var BROWSER_SENSITIVE_SURFACES = /* @__PURE__ */ new Set([
|
|
3100
|
+
"value",
|
|
3101
|
+
"textContent",
|
|
3102
|
+
"innerText",
|
|
3103
|
+
"innerHTML",
|
|
3104
|
+
"href",
|
|
3105
|
+
"search",
|
|
3106
|
+
"URL"
|
|
3107
|
+
]);
|
|
3108
|
+
var isSensitiveRead = (node) => {
|
|
3109
|
+
const name = staticPropertyName(node);
|
|
3110
|
+
if (name === void 0) return false;
|
|
3111
|
+
return propertyNameIsSensitive(name) || BROWSER_SENSITIVE_SURFACES.has(name);
|
|
3112
|
+
};
|
|
3113
|
+
var allowsExpressionCapture = (owner) => owner.captureClass === "full" || owner.captureClass === "reactive-sparse" || owner.captureReason === "svelte component wrapper";
|
|
3114
|
+
var isReactiveArrowValue = (node, classifications, sourceFile) => {
|
|
3115
|
+
let current = node;
|
|
3116
|
+
while (current) {
|
|
3117
|
+
const parent = current.parent;
|
|
3118
|
+
if (!parent) return false;
|
|
3119
|
+
if (ts13.isArrowFunction(parent) && parent.body === current) {
|
|
3120
|
+
const owner = owningFunction2(node.getStart(sourceFile), classifications);
|
|
3121
|
+
return owner?.captureClass === "reactive-sparse";
|
|
3122
|
+
}
|
|
3123
|
+
if (ts13.isBinaryExpression(parent) && (parent.left === current || parent.right === current) && !isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3124
|
+
current = parent;
|
|
3125
|
+
continue;
|
|
3126
|
+
}
|
|
3127
|
+
if (ts13.isParenthesizedExpression(parent) || ts13.isNonNullExpression(parent) || ts13.isAsExpression(parent) || ts13.isTypeAssertionExpression(parent) || ts13.isSatisfiesExpression(parent)) {
|
|
3128
|
+
current = parent;
|
|
3129
|
+
continue;
|
|
3130
|
+
}
|
|
3131
|
+
return false;
|
|
3132
|
+
}
|
|
3133
|
+
return false;
|
|
3134
|
+
};
|
|
3135
|
+
var owningFunction2 = (position, classifications) => {
|
|
3136
|
+
if (!classifications || classifications.length === 0) return void 0;
|
|
3137
|
+
let owner;
|
|
3138
|
+
let span = Number.POSITIVE_INFINITY;
|
|
3139
|
+
for (const item of classifications) {
|
|
3140
|
+
if (position < item.bodyStart || position >= item.bodyEnd) continue;
|
|
3141
|
+
const size = item.bodyEnd - item.bodyStart;
|
|
3142
|
+
if (size < span) {
|
|
3143
|
+
owner = item;
|
|
3144
|
+
span = size;
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3147
|
+
return owner;
|
|
3148
|
+
};
|
|
3149
|
+
var collectObserveSiteEdits = (source, filePath, options = {}, sourceFile = parseSource(source, filePath)) => {
|
|
3150
|
+
const absolutePath = resolve4(filePath);
|
|
3151
|
+
const emitIds = options.emitIds ?? { value: 1 };
|
|
3152
|
+
const queued = [];
|
|
3153
|
+
const visit = (node) => {
|
|
3154
|
+
if (isPropertyRead(node) && shouldWrapRead(node, options.classifications, sourceFile) && !isInternalProperty(node) && !isSensitiveRead(node)) {
|
|
3155
|
+
if (options.classifications) {
|
|
3156
|
+
const owner = owningFunction2(node.getStart(sourceFile), options.classifications);
|
|
3157
|
+
if (!owner || !allowsExpressionCapture(owner)) {
|
|
3158
|
+
ts13.forEachChild(node, visit);
|
|
3159
|
+
return;
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
const start = node.getStart(sourceFile);
|
|
3163
|
+
const text = node.getText(sourceFile);
|
|
3164
|
+
const location = sourceFile.getLineAndCharacterOfPosition(start);
|
|
3165
|
+
const line = location.line + 1;
|
|
3166
|
+
const column = location.character + 1;
|
|
3167
|
+
queued.push({
|
|
3168
|
+
start,
|
|
3169
|
+
end: node.end,
|
|
3170
|
+
site: {
|
|
3171
|
+
siteId: siteIdFor(absolutePath, line, column, text),
|
|
3172
|
+
emitId: emitIds.value++,
|
|
3173
|
+
filePath: absolutePath,
|
|
3174
|
+
line,
|
|
3175
|
+
column,
|
|
3176
|
+
kind: hasOptional(node) ? "optional-chain" : "property-read",
|
|
3177
|
+
sourceText: text.length > 80 ? `${text.slice(0, 77)}...` : text,
|
|
3178
|
+
start,
|
|
3179
|
+
end: node.end
|
|
3180
|
+
}
|
|
3181
|
+
});
|
|
3182
|
+
}
|
|
3183
|
+
ts13.forEachChild(node, visit);
|
|
3184
|
+
};
|
|
3185
|
+
visit(sourceFile);
|
|
3186
|
+
queued.sort((left, right) => right.start - left.start);
|
|
3187
|
+
const applied = [];
|
|
3188
|
+
const edits = [];
|
|
3189
|
+
let lastStart = Number.POSITIVE_INFINITY;
|
|
3190
|
+
for (const item of queued) {
|
|
3191
|
+
if (item.end > lastStart) continue;
|
|
3192
|
+
edits.push({
|
|
3193
|
+
position: item.start,
|
|
3194
|
+
text: `${OBSERVE_CALLEE}(${item.site.emitId},`,
|
|
3195
|
+
deleteCount: 0,
|
|
3196
|
+
depth: 20,
|
|
3197
|
+
width: item.end - item.start,
|
|
3198
|
+
kind: "open"
|
|
3199
|
+
});
|
|
3200
|
+
edits.push({
|
|
3201
|
+
position: item.end,
|
|
3202
|
+
text: ")",
|
|
3203
|
+
deleteCount: 0,
|
|
3204
|
+
depth: 20,
|
|
3205
|
+
width: item.end - item.start,
|
|
3206
|
+
kind: "close"
|
|
3207
|
+
});
|
|
3208
|
+
applied.push(item.site);
|
|
3209
|
+
lastStart = item.start;
|
|
3210
|
+
}
|
|
3211
|
+
applied.reverse();
|
|
3212
|
+
return { edits, sites: applied };
|
|
3213
|
+
};
|
|
3214
|
+
|
|
3215
|
+
// ../instrumentation/src/verify-browser-source.ts
|
|
3216
|
+
import ts14 from "typescript";
|
|
3217
|
+
var RASPUTIN_IDENT = /^__rasputin/;
|
|
3218
|
+
var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
3219
|
+
"__rasputinO",
|
|
3220
|
+
"__rasputinK",
|
|
3221
|
+
"__rasputinR",
|
|
3222
|
+
"__rasputinL",
|
|
3223
|
+
"__rasputinT",
|
|
3224
|
+
"__rasputinD",
|
|
3225
|
+
"__rasputinReg",
|
|
3226
|
+
"__rasputinM",
|
|
3227
|
+
"__rasputinA",
|
|
3228
|
+
"__rasputinP",
|
|
3229
|
+
"__rasputinN"
|
|
3230
|
+
]);
|
|
3231
|
+
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
3232
|
+
var identText = (node) => {
|
|
3233
|
+
if (ts14.isIdentifier(node)) return node.text;
|
|
3234
|
+
if (ts14.isPrivateIdentifier(node)) return node.text;
|
|
3235
|
+
return void 0;
|
|
3236
|
+
};
|
|
3237
|
+
var calleeName = (expression) => {
|
|
3238
|
+
if (ts14.isIdentifier(expression)) return expression.text;
|
|
3239
|
+
if (ts14.isPropertyAccessExpression(expression)) {
|
|
3240
|
+
const object = identText(expression.expression);
|
|
3241
|
+
const property = identText(expression.name);
|
|
3242
|
+
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
3243
|
+
if (object === "globalThis" && property && BROWSER_GLOBALS.has(property)) return property;
|
|
3244
|
+
}
|
|
3245
|
+
return void 0;
|
|
3246
|
+
};
|
|
3247
|
+
var isRasputinCall = (node) => {
|
|
3248
|
+
if (!ts14.isCallExpression(node)) return false;
|
|
3249
|
+
const name = calleeName(node.expression);
|
|
3250
|
+
return Boolean(name && (isRasputinName(name) || BROWSER_GLOBALS.has(name)));
|
|
3251
|
+
};
|
|
3252
|
+
var isRasputinAssignment = (node) => {
|
|
3253
|
+
if (!ts14.isBinaryExpression(node)) return false;
|
|
3254
|
+
const operator = node.operatorToken.kind;
|
|
3255
|
+
if (operator !== ts14.SyntaxKind.EqualsToken && operator !== ts14.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
3256
|
+
return false;
|
|
3257
|
+
}
|
|
3258
|
+
if (ts14.isPropertyAccessExpression(node.left)) {
|
|
3259
|
+
const object = identText(node.left.expression);
|
|
3260
|
+
const property = identText(node.left.name);
|
|
3261
|
+
return object === "globalThis" && property !== void 0 && BROWSER_GLOBALS.has(property);
|
|
3262
|
+
}
|
|
3263
|
+
const name = identText(node.left);
|
|
3264
|
+
return Boolean(name && isRasputinName(name));
|
|
3265
|
+
};
|
|
3266
|
+
var isRasputinOnlyInitializer = (expression) => {
|
|
3267
|
+
if (!expression) return true;
|
|
3268
|
+
const unwrapped = unwrapCall(expression);
|
|
3269
|
+
if (unwrapped !== expression) {
|
|
3270
|
+
return ts14.isExpression(unwrapped) ? isRasputinOnlyInitializer(unwrapped) : false;
|
|
3271
|
+
}
|
|
3272
|
+
return isRasputinCall(expression);
|
|
3273
|
+
};
|
|
3274
|
+
var jsonAwaitSlot = (node) => {
|
|
3275
|
+
if (node.operatorToken.kind !== ts14.SyntaxKind.CommaToken) return void 0;
|
|
3276
|
+
const assigned = node.left;
|
|
3277
|
+
if (!ts14.isBinaryExpression(assigned) || assigned.operatorToken.kind !== ts14.SyntaxKind.EqualsToken || !ts14.isIdentifier(assigned.left) || !isRasputinName(assigned.left.text) || !ts14.isObjectLiteralExpression(assigned.right)) {
|
|
3278
|
+
return void 0;
|
|
3279
|
+
}
|
|
3280
|
+
const property = assigned.right.properties[0];
|
|
3281
|
+
if (!property || !ts14.isPropertyAssignment(property) || !ts14.isIdentifier(property.name) || property.name.text !== "p") {
|
|
3282
|
+
return void 0;
|
|
3283
|
+
}
|
|
3284
|
+
if (!ts14.isPropertyAccessExpression(node.right) || !ts14.isIdentifier(node.right.expression) || !isRasputinName(node.right.expression.text) || node.right.name.text !== "p") {
|
|
3285
|
+
return void 0;
|
|
3286
|
+
}
|
|
3287
|
+
return property.initializer;
|
|
3288
|
+
};
|
|
3289
|
+
var peelParens = (node) => {
|
|
3290
|
+
let current = node;
|
|
3291
|
+
while (ts14.isParenthesizedExpression(current)) current = current.expression;
|
|
3292
|
+
return current;
|
|
3293
|
+
};
|
|
3294
|
+
var jsonMethodCall = (node) => {
|
|
3295
|
+
const receiver = node.arguments[0];
|
|
3296
|
+
const fn = node.arguments[1];
|
|
3297
|
+
if (!receiver || !fn) return void 0;
|
|
3298
|
+
const args = node.arguments.slice(2);
|
|
3299
|
+
if (!ts14.isPropertyAccessExpression(fn)) return void 0;
|
|
3300
|
+
return ts14.factory.createCallExpression(
|
|
3301
|
+
ts14.factory.createPropertyAccessExpression(receiver, fn.name),
|
|
3302
|
+
void 0,
|
|
3303
|
+
args
|
|
3304
|
+
);
|
|
3305
|
+
};
|
|
3306
|
+
var unwrapAdoptIife = (node) => {
|
|
3307
|
+
if (node.arguments.length !== 1) return void 0;
|
|
3308
|
+
const adopted = node.arguments[0];
|
|
3309
|
+
if (!adopted) return void 0;
|
|
3310
|
+
const callee = peelParens(node.expression);
|
|
3311
|
+
if (!ts14.isArrowFunction(callee) || callee.parameters.length !== 1 || ts14.isBlock(callee.body)) {
|
|
3312
|
+
return void 0;
|
|
3313
|
+
}
|
|
3314
|
+
const param = callee.parameters[0];
|
|
3315
|
+
if (!param || !ts14.isIdentifier(param.name) || param.dotDotDotToken || param.initializer) {
|
|
3316
|
+
return void 0;
|
|
3317
|
+
}
|
|
3318
|
+
const body = peelParens(callee.body);
|
|
3319
|
+
if (ts14.isCallExpression(body) && calleeName(body.expression) === "__rasputinP") {
|
|
3320
|
+
const invoked = body.arguments[0];
|
|
3321
|
+
if (invoked && ts14.isCallExpression(invoked) && ts14.isIdentifier(invoked.expression) && invoked.expression.text === param.name.text) {
|
|
3322
|
+
return ts14.factory.createCallExpression(adopted, void 0, invoked.arguments);
|
|
3323
|
+
}
|
|
3324
|
+
return void 0;
|
|
3325
|
+
}
|
|
3326
|
+
if (!ts14.isCallExpression(body) || body.arguments.length !== 1) return void 0;
|
|
3327
|
+
const methodLookup = body.arguments[0];
|
|
3328
|
+
if (!methodLookup) return void 0;
|
|
3329
|
+
const inner = peelParens(body.expression);
|
|
3330
|
+
if (!ts14.isArrowFunction(inner) || inner.parameters.length !== 1 || ts14.isBlock(inner.body)) {
|
|
3331
|
+
return void 0;
|
|
3332
|
+
}
|
|
3333
|
+
const fnParam = inner.parameters[0];
|
|
3334
|
+
if (!fnParam || !ts14.isIdentifier(fnParam.name) || fnParam.dotDotDotToken || fnParam.initializer) {
|
|
3335
|
+
return void 0;
|
|
3336
|
+
}
|
|
3337
|
+
const innerBody = peelParens(inner.body);
|
|
3338
|
+
if (!ts14.isCallExpression(innerBody) || calleeName(innerBody.expression) !== "__rasputinP") {
|
|
3339
|
+
return void 0;
|
|
3340
|
+
}
|
|
3341
|
+
const applied = innerBody.arguments[0];
|
|
3342
|
+
if (!applied || !ts14.isCallExpression(applied)) return void 0;
|
|
3343
|
+
const applyCallee = peelParens(applied.expression);
|
|
3344
|
+
if (!ts14.isPropertyAccessExpression(applyCallee) || applyCallee.name.text !== "apply" || !ts14.isIdentifier(applyCallee.expression) || applyCallee.expression.text !== "Reflect") {
|
|
3345
|
+
return void 0;
|
|
3346
|
+
}
|
|
3347
|
+
const appliedFn = applied.arguments[0];
|
|
3348
|
+
const thisArg = applied.arguments[1];
|
|
3349
|
+
const argsArg = applied.arguments[2];
|
|
3350
|
+
if (!appliedFn || !ts14.isIdentifier(appliedFn) || appliedFn.text !== fnParam.name.text) {
|
|
3351
|
+
return void 0;
|
|
3352
|
+
}
|
|
3353
|
+
if (!thisArg || !ts14.isIdentifier(thisArg) || thisArg.text !== param.name.text) return void 0;
|
|
3354
|
+
if (!argsArg || !ts14.isArrayLiteralExpression(argsArg)) return void 0;
|
|
3355
|
+
if (!ts14.isPropertyAccessExpression(methodLookup) || !ts14.isIdentifier(methodLookup.expression) || methodLookup.expression.text !== param.name.text || ts14.isPrivateIdentifier(methodLookup.name)) {
|
|
3356
|
+
return void 0;
|
|
3357
|
+
}
|
|
3358
|
+
return ts14.factory.createCallExpression(
|
|
3359
|
+
ts14.factory.createPropertyAccessExpression(adopted, methodLookup.name),
|
|
3360
|
+
void 0,
|
|
3361
|
+
[...argsArg.elements]
|
|
3362
|
+
);
|
|
3363
|
+
};
|
|
3364
|
+
var unwrapProducerIife = (node) => {
|
|
3365
|
+
if (node.arguments.length !== 1) return void 0;
|
|
3366
|
+
const receiver = node.arguments[0];
|
|
3367
|
+
if (!receiver) return void 0;
|
|
3368
|
+
const callee = peelParens(node.expression);
|
|
3369
|
+
if (!ts14.isArrowFunction(callee) || callee.parameters.length !== 1 || ts14.isBlock(callee.body)) {
|
|
3370
|
+
return void 0;
|
|
3371
|
+
}
|
|
3372
|
+
const param = callee.parameters[0];
|
|
3373
|
+
if (!param || !ts14.isIdentifier(param.name) || param.dotDotDotToken || param.initializer) {
|
|
3374
|
+
return void 0;
|
|
3375
|
+
}
|
|
3376
|
+
const body = peelParens(callee.body);
|
|
3377
|
+
if (!ts14.isCallExpression(body) || !isRasputinCall(body)) return void 0;
|
|
3378
|
+
if (calleeName(body.expression) !== "__rasputinM") return void 0;
|
|
3379
|
+
const bound = body.arguments[0];
|
|
3380
|
+
const fn = body.arguments[1];
|
|
3381
|
+
if (!bound || !fn || !ts14.isIdentifier(bound) || bound.text !== param.name.text) return void 0;
|
|
3382
|
+
if (!ts14.isPropertyAccessExpression(fn)) return void 0;
|
|
3383
|
+
if (!ts14.isIdentifier(fn.expression) || fn.expression.text !== param.name.text) return void 0;
|
|
3384
|
+
return ts14.factory.createCallExpression(
|
|
3385
|
+
ts14.factory.createPropertyAccessExpression(receiver, fn.name),
|
|
3386
|
+
void 0,
|
|
3387
|
+
body.arguments.slice(2)
|
|
3388
|
+
);
|
|
3389
|
+
};
|
|
3390
|
+
var unwrapCall = (node) => {
|
|
3391
|
+
let current = node;
|
|
3392
|
+
while (true) {
|
|
3393
|
+
if (ts14.isParenthesizedExpression(current)) {
|
|
3394
|
+
current = current.expression;
|
|
3395
|
+
continue;
|
|
3396
|
+
}
|
|
3397
|
+
if (ts14.isBinaryExpression(current)) {
|
|
3398
|
+
const slot = jsonAwaitSlot(current);
|
|
3399
|
+
if (slot) {
|
|
3400
|
+
current = slot;
|
|
3401
|
+
continue;
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
if (ts14.isConditionalExpression(current) && isRasputinName(identText(current.condition) ?? "")) {
|
|
3405
|
+
current = current.whenTrue;
|
|
3406
|
+
continue;
|
|
3407
|
+
}
|
|
3408
|
+
if (ts14.isCallExpression(current)) {
|
|
3409
|
+
const adopted = unwrapAdoptIife(current);
|
|
3410
|
+
if (adopted) {
|
|
3411
|
+
current = adopted;
|
|
3412
|
+
continue;
|
|
3413
|
+
}
|
|
3414
|
+
const producer = unwrapProducerIife(current);
|
|
3415
|
+
if (producer) {
|
|
3416
|
+
current = producer;
|
|
3417
|
+
continue;
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
if (ts14.isCallExpression(current) && isRasputinCall(current)) {
|
|
3421
|
+
const name = calleeName(current.expression);
|
|
3422
|
+
if ((name === "__rasputinO" || name === "__rasputinL") && current.arguments.length >= 2 && current.arguments[1]) {
|
|
3423
|
+
current = current.arguments[1];
|
|
3424
|
+
continue;
|
|
3425
|
+
}
|
|
3426
|
+
if ((name === "__rasputinA" || name === "__rasputinP") && current.arguments[0]) {
|
|
3427
|
+
current = current.arguments[0];
|
|
3428
|
+
continue;
|
|
3429
|
+
}
|
|
3430
|
+
if (name === "__rasputinK" && current.arguments[0]) {
|
|
3431
|
+
current = current.arguments[0];
|
|
3432
|
+
continue;
|
|
3433
|
+
}
|
|
3434
|
+
if (name === "__rasputinM") {
|
|
3435
|
+
const reconstructed = jsonMethodCall(current);
|
|
3436
|
+
if (reconstructed) {
|
|
3437
|
+
current = reconstructed;
|
|
3438
|
+
continue;
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
if (current.arguments.length === 1 && current.arguments[0] && name && (name.endsWith(".leave") || name.endsWith(".suspend") || name.endsWith(".resume"))) {
|
|
3442
|
+
current = current.arguments[0];
|
|
3443
|
+
continue;
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
break;
|
|
3447
|
+
}
|
|
3448
|
+
return current;
|
|
3449
|
+
};
|
|
3450
|
+
var isRasputinIf = (node) => {
|
|
3451
|
+
if (node.elseStatement) return false;
|
|
3452
|
+
const condition = node.expression;
|
|
3453
|
+
const negated = ts14.isPrefixUnaryExpression(condition) && condition.operator === ts14.SyntaxKind.ExclamationToken && isRasputinName(identText(condition.operand) ?? "");
|
|
3454
|
+
if (!negated) return false;
|
|
3455
|
+
const then = node.thenStatement;
|
|
3456
|
+
if (ts14.isExpressionStatement(then) && isRasputinCall(then.expression)) return true;
|
|
3457
|
+
return ts14.isBlock(then) && then.statements.every((statement) => isRasputinStatement(statement));
|
|
3458
|
+
};
|
|
3459
|
+
var isRasputinStatement = (node) => {
|
|
3460
|
+
if (ts14.isEmptyStatement(node)) return true;
|
|
3461
|
+
if (ts14.isVariableStatement(node)) {
|
|
3462
|
+
return node.declarationList.declarations.every((declaration) => {
|
|
3463
|
+
const name = identText(declaration.name);
|
|
3464
|
+
return Boolean(name && isRasputinName(name));
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
if (ts14.isExpressionStatement(node)) {
|
|
3468
|
+
if (isRasputinAssignment(node.expression)) return true;
|
|
3469
|
+
if (!isRasputinCall(node.expression)) return false;
|
|
3470
|
+
return unwrapCall(node.expression) === node.expression;
|
|
3471
|
+
}
|
|
3472
|
+
if (ts14.isIfStatement(node)) return isRasputinIf(node);
|
|
3473
|
+
return false;
|
|
3474
|
+
};
|
|
3475
|
+
var isRasputinTryWrapper = (node) => {
|
|
3476
|
+
const catchClause = node.catchClause;
|
|
3477
|
+
if (!catchClause || !node.finallyBlock) return false;
|
|
3478
|
+
const catchCalls = catchClause.block.statements.filter(
|
|
3479
|
+
(statement) => !isRasputinStatement(statement)
|
|
3480
|
+
);
|
|
3481
|
+
const leftover = catchCalls[0];
|
|
3482
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts14.isThrowStatement(leftover) && ts14.isIdentifier(leftover.expression);
|
|
3483
|
+
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
3484
|
+
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
3485
|
+
};
|
|
3486
|
+
var customerTempInit = (statement) => {
|
|
3487
|
+
if (!ts14.isVariableStatement(statement)) return void 0;
|
|
3488
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
3489
|
+
const name = identText(declaration.name);
|
|
3490
|
+
if (!name || !isRasputinName(name) || !declaration.initializer) continue;
|
|
3491
|
+
if (isRasputinOnlyInitializer(declaration.initializer)) continue;
|
|
3492
|
+
return { name, init: declaration.initializer };
|
|
3493
|
+
}
|
|
3494
|
+
return void 0;
|
|
3495
|
+
};
|
|
3496
|
+
var flattenStatements = (statements) => {
|
|
3497
|
+
const flattened = [];
|
|
3498
|
+
for (const statement of statements) {
|
|
3499
|
+
if (isRasputinStatement(statement)) continue;
|
|
3500
|
+
if (ts14.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
3501
|
+
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
3502
|
+
continue;
|
|
3503
|
+
}
|
|
3504
|
+
flattened.push(statement);
|
|
3505
|
+
}
|
|
3506
|
+
return flattened;
|
|
3507
|
+
};
|
|
3508
|
+
var isRememberIife = (node) => {
|
|
3509
|
+
if (!ts14.isCallExpression(node) || node.arguments.length > 0) return void 0;
|
|
3510
|
+
let callee = node.expression;
|
|
3511
|
+
if (ts14.isParenthesizedExpression(callee)) callee = callee.expression;
|
|
3512
|
+
if (!ts14.isArrowFunction(callee) || callee.parameters.length > 0 || !ts14.isBlock(callee.body)) {
|
|
3513
|
+
return void 0;
|
|
3514
|
+
}
|
|
3515
|
+
const statements = callee.body.statements;
|
|
3516
|
+
const last = statements.at(-1);
|
|
3517
|
+
if (!last || !ts14.isReturnStatement(last) || !last.expression) return void 0;
|
|
3518
|
+
let returned = last.expression;
|
|
3519
|
+
while (ts14.isParenthesizedExpression(returned)) returned = returned.expression;
|
|
3520
|
+
if (!ts14.isCallExpression(returned)) return void 0;
|
|
3521
|
+
const name = calleeName(returned.expression);
|
|
3522
|
+
if (name !== "__rasputinK") return void 0;
|
|
3523
|
+
const objectArg = returned.arguments[0];
|
|
3524
|
+
if (!objectArg || !ts14.isIdentifier(objectArg)) return void 0;
|
|
3525
|
+
const temps = /* @__PURE__ */ new Map();
|
|
3526
|
+
for (const statement of statements.slice(0, -1)) {
|
|
3527
|
+
if (!ts14.isVariableStatement(statement)) return void 0;
|
|
3528
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
3529
|
+
if (!ts14.isIdentifier(declaration.name) || !declaration.initializer) return void 0;
|
|
3530
|
+
temps.set(declaration.name.text, declaration.initializer);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
const object = temps.get(objectArg.text);
|
|
3534
|
+
if (!object) return void 0;
|
|
3535
|
+
return { object, temps };
|
|
3536
|
+
};
|
|
3537
|
+
var resolveRememberTemp = (expression, temps, seen) => {
|
|
3538
|
+
let current = expression;
|
|
3539
|
+
while (ts14.isParenthesizedExpression(current) || ts14.isNonNullExpression(current) || ts14.isAsExpression(current) || ts14.isTypeAssertionExpression(current) || ts14.isSatisfiesExpression(current)) {
|
|
3540
|
+
current = current.expression;
|
|
3541
|
+
}
|
|
3542
|
+
if (ts14.isIdentifier(current) && temps.has(current.text) && !seen.has(current.text)) {
|
|
3543
|
+
const next = temps.get(current.text);
|
|
3544
|
+
if (!next) return current;
|
|
3545
|
+
seen.add(current.text);
|
|
3546
|
+
return resolveRememberTemp(next, temps, seen);
|
|
3547
|
+
}
|
|
3548
|
+
return current;
|
|
3549
|
+
};
|
|
3550
|
+
var extra = (node) => {
|
|
3551
|
+
if (ts14.isIdentifier(node) || ts14.isPrivateIdentifier(node)) {
|
|
3552
|
+
return isRasputinName(node.text) ? "" : node.text;
|
|
3553
|
+
}
|
|
3554
|
+
if (ts14.isStringLiteral(node) || ts14.isNumericLiteral(node) || ts14.isNoSubstitutionTemplateLiteral(node)) {
|
|
3555
|
+
return node.text;
|
|
3556
|
+
}
|
|
3557
|
+
if (ts14.isToken(node) && !ts14.isIdentifier(node)) return ts14.SyntaxKind[node.kind] ?? "";
|
|
3558
|
+
return "";
|
|
3559
|
+
};
|
|
3560
|
+
var signatureOfSubstituted = (node, temps) => {
|
|
3561
|
+
const remembered = isRememberIife(node);
|
|
3562
|
+
if (remembered) return signatureOfSubstituted(remembered.object, remembered.temps);
|
|
3563
|
+
if (ts14.isObjectLiteralExpression(node)) {
|
|
3564
|
+
const parts = node.properties.map((property) => {
|
|
3565
|
+
if (ts14.isShorthandPropertyAssignment(property)) return signatureOf(property);
|
|
3566
|
+
if (!ts14.isPropertyAssignment(property)) return signatureOf(property);
|
|
3567
|
+
const init = resolveRememberTemp(property.initializer, temps, /* @__PURE__ */ new Set());
|
|
3568
|
+
if (ts14.isIdentifier(property.name) && ts14.isIdentifier(init) && property.name.text === init.text) {
|
|
3569
|
+
return signatureOf(ts14.factory.createShorthandPropertyAssignment(property.name));
|
|
3570
|
+
}
|
|
3571
|
+
if (ts14.isComputedPropertyName(property.name)) {
|
|
3572
|
+
const key = resolveRememberTemp(property.name.expression, temps, /* @__PURE__ */ new Set());
|
|
3573
|
+
return `PropertyAssignment[ComputedPropertyName[${signatureOfSubstituted(key, temps)}],${signatureOfSubstituted(init, temps)}]`;
|
|
3574
|
+
}
|
|
3575
|
+
return `PropertyAssignment[${signatureOf(property.name)},${signatureOfSubstituted(init, temps)}]`;
|
|
3576
|
+
});
|
|
3577
|
+
return `ObjectLiteralExpression[${parts.join(",")}]`;
|
|
3578
|
+
}
|
|
3579
|
+
if (ts14.isArrayLiteralExpression(node)) {
|
|
3580
|
+
const parts = node.elements.map(
|
|
3581
|
+
(element) => signatureOfSubstituted(resolveRememberTemp(element, temps, /* @__PURE__ */ new Set()), temps)
|
|
3582
|
+
);
|
|
3583
|
+
return `ArrayLiteralExpression[${parts.join(",")}]`;
|
|
3584
|
+
}
|
|
3585
|
+
return signatureOf(node);
|
|
3586
|
+
};
|
|
3587
|
+
var signatureOfRememberedLiteral = (node) => {
|
|
3588
|
+
const parsed = isRememberIife(node);
|
|
3589
|
+
if (!parsed) return void 0;
|
|
3590
|
+
return signatureOfSubstituted(parsed.object, parsed.temps);
|
|
3591
|
+
};
|
|
3592
|
+
var signatureOf = (node) => {
|
|
3593
|
+
const unwrapped = unwrapCall(node);
|
|
3594
|
+
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
3595
|
+
const remembered = signatureOfRememberedLiteral(unwrapped);
|
|
3596
|
+
if (remembered !== void 0) return remembered;
|
|
3597
|
+
if (ts14.isPropertyAssignment(unwrapped) && ts14.isIdentifier(unwrapped.name) && ts14.isIdentifier(unwrapped.initializer) && unwrapped.name.text === unwrapped.initializer.text) {
|
|
3598
|
+
return signatureOf(ts14.factory.createShorthandPropertyAssignment(unwrapped.name));
|
|
3599
|
+
}
|
|
3600
|
+
if (ts14.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
3601
|
+
if (ts14.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
3602
|
+
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
3603
|
+
}
|
|
3604
|
+
if (ts14.isCatchClause(unwrapped)) {
|
|
3605
|
+
const statements = flattenStatements(unwrapped.block.statements);
|
|
3606
|
+
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
3607
|
+
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
3608
|
+
}
|
|
3609
|
+
if (ts14.isBlock(unwrapped)) {
|
|
3610
|
+
const statements = flattenStatements(unwrapped.statements);
|
|
3611
|
+
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
3612
|
+
}
|
|
3613
|
+
if (ts14.isArrowFunction(unwrapped) && ts14.isBlock(unwrapped.body)) {
|
|
3614
|
+
const raw = unwrapped.body.statements;
|
|
3615
|
+
const tryWrap = raw.length === 1 && raw[0] && ts14.isTryStatement(raw[0]) ? raw[0] : void 0;
|
|
3616
|
+
const inner = tryWrap && isRasputinTryWrapper(tryWrap) ? tryWrap.tryBlock.statements : raw;
|
|
3617
|
+
const temp = inner[0] ? customerTempInit(inner[0]) : void 0;
|
|
3618
|
+
const returned = inner[1];
|
|
3619
|
+
if (temp && returned && ts14.isReturnStatement(returned) && returned.expression && inner.length === 2) {
|
|
3620
|
+
const value = unwrapCall(returned.expression);
|
|
3621
|
+
if (ts14.isIdentifier(value) && value.text === temp.name) {
|
|
3622
|
+
const parts2 = [];
|
|
3623
|
+
ts14.forEachChild(unwrapped, (child) => {
|
|
3624
|
+
if (child === unwrapped.body) {
|
|
3625
|
+
const part2 = signatureOf(temp.init);
|
|
3626
|
+
if (part2) parts2.push(part2);
|
|
3627
|
+
return;
|
|
3628
|
+
}
|
|
3629
|
+
const part = signatureOf(child);
|
|
3630
|
+
if (part) parts2.push(part);
|
|
3631
|
+
});
|
|
3632
|
+
return `ArrowFunction[${parts2.join(",")}]`;
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
const statements = flattenStatements(unwrapped.body.statements);
|
|
3636
|
+
const only = statements[0];
|
|
3637
|
+
const onlyExpression = only && ts14.isReturnStatement(only) ? only.expression : void 0;
|
|
3638
|
+
if (statements.length === 1 && onlyExpression) {
|
|
3639
|
+
const parts2 = [];
|
|
3640
|
+
ts14.forEachChild(unwrapped, (child) => {
|
|
3641
|
+
if (child === unwrapped.body) {
|
|
3642
|
+
const part2 = signatureOf(onlyExpression);
|
|
3643
|
+
if (part2) parts2.push(part2);
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
const part = signatureOf(child);
|
|
3647
|
+
if (part) parts2.push(part);
|
|
3648
|
+
});
|
|
3649
|
+
return `ArrowFunction[${parts2.join(",")}]`;
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
if (ts14.isReturnStatement(unwrapped)) {
|
|
3653
|
+
if (!unwrapped.expression) return "ReturnStatement[]";
|
|
3654
|
+
const expression = unwrapCall(unwrapped.expression);
|
|
3655
|
+
if (ts14.isVoidExpression(expression) && isRasputinCall(expression.expression)) {
|
|
3656
|
+
return "ReturnStatement[]";
|
|
3657
|
+
}
|
|
3658
|
+
return `Return[${signatureOf(unwrapped.expression)}]`;
|
|
3659
|
+
}
|
|
3660
|
+
const parts = [];
|
|
3661
|
+
ts14.forEachChild(unwrapped, (child) => {
|
|
3662
|
+
const part = signatureOf(child);
|
|
3663
|
+
if (part) parts.push(part);
|
|
3664
|
+
});
|
|
3665
|
+
const kind = ts14.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
3666
|
+
return `${kind}${extra(unwrapped)}[${parts.join(",")}]`;
|
|
3667
|
+
};
|
|
3668
|
+
var browserInstrumentationIsSafe = (filePath, original, transformed) => {
|
|
3669
|
+
if (transformedSourceIsInvalid(filePath, transformed)) return false;
|
|
3670
|
+
try {
|
|
3671
|
+
parseSource(transformed, filePath);
|
|
3672
|
+
} catch {
|
|
3673
|
+
return false;
|
|
3674
|
+
}
|
|
3675
|
+
return signatureOf(parseSource(original, filePath)) === signatureOf(parseSource(transformed, filePath));
|
|
3676
|
+
};
|
|
3677
|
+
|
|
3678
|
+
// ../instrumentation/src/instrument-browser-source.ts
|
|
3679
|
+
var refuse = (source, classifications) => ({
|
|
3680
|
+
code: source,
|
|
3681
|
+
delta: { functions: [], callSites: [], destructures: [] },
|
|
3682
|
+
classifications,
|
|
3683
|
+
sites: [],
|
|
3684
|
+
identities: [],
|
|
3685
|
+
verificationFailed: true
|
|
3686
|
+
});
|
|
3687
|
+
var instrumentBrowserSource = (source, filePath, emitIds, reactiveIds, moduleIndex = 0, options) => {
|
|
3688
|
+
if (source.includes("@rasputin-ignore-file") || sourceIsRasputinInstrumented(source)) {
|
|
3689
|
+
return {
|
|
3690
|
+
code: source,
|
|
3691
|
+
classifications: [],
|
|
3692
|
+
sites: [],
|
|
3693
|
+
identities: [],
|
|
3694
|
+
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
3695
|
+
};
|
|
3696
|
+
}
|
|
3697
|
+
const sourceFile = parseSource(source, filePath);
|
|
3698
|
+
const classifications = classifyFunctions(source, filePath, options?.mapLocation);
|
|
3699
|
+
const observe = collectObserveSiteEdits(
|
|
3700
|
+
source,
|
|
3701
|
+
filePath,
|
|
3702
|
+
{ classifications, emitIds },
|
|
3703
|
+
sourceFile
|
|
3704
|
+
);
|
|
3705
|
+
const literals = collectLiteralSiteEdits(source, filePath, { classifications }, sourceFile);
|
|
3706
|
+
const json = collectJsonProducerEdits(source, filePath, sourceFile, { adoptCalls: true });
|
|
3707
|
+
const functions = collectBrowserFunctionEdits(
|
|
3708
|
+
source,
|
|
3709
|
+
sourceFile,
|
|
3710
|
+
classifications,
|
|
3711
|
+
moduleIndex,
|
|
3712
|
+
reactiveIds ?? { value: 1 },
|
|
3713
|
+
{
|
|
3714
|
+
observe: observe.sites.length > 0,
|
|
3715
|
+
struct: literals.edits.length > 0,
|
|
3716
|
+
includePlans: options?.includePlans === true,
|
|
3717
|
+
mapLocation: options?.mapLocation
|
|
3718
|
+
}
|
|
3719
|
+
);
|
|
3720
|
+
const edits = [...observe.edits, ...literals.edits, ...json.edits, ...functions.edits];
|
|
3721
|
+
if (edits.length === 0) {
|
|
3722
|
+
return {
|
|
3723
|
+
code: source,
|
|
3724
|
+
classifications,
|
|
3725
|
+
sites: [],
|
|
3726
|
+
identities: [],
|
|
3727
|
+
delta: functions.delta
|
|
3728
|
+
};
|
|
3729
|
+
}
|
|
3730
|
+
const code = applyEdits(source, edits);
|
|
3731
|
+
if (!browserInstrumentationIsSafe(filePath, source, code)) {
|
|
3732
|
+
return refuse(source, classifications);
|
|
3733
|
+
}
|
|
3734
|
+
return {
|
|
3735
|
+
code,
|
|
3736
|
+
map: exactTransformMap(source, code, basename2(filePath), edits),
|
|
3737
|
+
delta: functions.delta,
|
|
3738
|
+
classifications,
|
|
3739
|
+
sites: observe.sites,
|
|
3740
|
+
identities: functions.identities
|
|
3741
|
+
};
|
|
3742
|
+
};
|
|
3743
|
+
|
|
3744
|
+
// ../instrumentation/src/instrument-provenance-source.ts
|
|
3745
|
+
import { basename as basename3 } from "node:path";
|
|
3746
|
+
|
|
3747
|
+
// ../instrumentation/src/provenance-function-edits.ts
|
|
3748
|
+
import ts15 from "typescript";
|
|
3749
|
+
var PROVENANCE_HANDLE_CALLEE = "globalThis.__rasputinN";
|
|
3750
|
+
var PROVENANCE_HANDLE_GUARD = "globalThis.__rasputinN??=function(){return{leave:function(v){return v},end:function(){},suspend:function(v){return v},resume:function(v){return v}}};";
|
|
3751
|
+
var isProvenanceTarget = (node) => (ts15.isFunctionDeclaration(node) || ts15.isFunctionExpression(node) || ts15.isArrowFunction(node) || ts15.isMethodDeclaration(node)) && node.body !== void 0 && !node.asteriskToken;
|
|
3752
|
+
var isDirectivePrologue2 = (statement) => ts15.isExpressionStatement(statement) && ts15.isStringLiteral(statement.expression);
|
|
3753
|
+
var insertPositionAfterPrologue2 = (source, sourceFile) => {
|
|
3754
|
+
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
3755
|
+
let end = shebangEnd;
|
|
3756
|
+
for (const statement of sourceFile.statements) {
|
|
3757
|
+
if (!isDirectivePrologue2(statement)) break;
|
|
3758
|
+
end = statement.end;
|
|
3759
|
+
}
|
|
3760
|
+
return end;
|
|
3761
|
+
};
|
|
3762
|
+
var preambleInsert2 = (source, position, preamble) => {
|
|
3763
|
+
if (position <= 0) return preamble;
|
|
3764
|
+
const previous = source[position - 1];
|
|
3765
|
+
return previous === ";" || previous === "\n" || previous === "\r" ? preamble : `;${preamble}`;
|
|
3766
|
+
};
|
|
3767
|
+
var functionBodyPrologueEnd2 = (body, sourceFile) => {
|
|
3768
|
+
let end = body.getStart(sourceFile) + 1;
|
|
3769
|
+
for (const statement of body.statements) {
|
|
3770
|
+
if (!isDirectivePrologue2(statement)) break;
|
|
3771
|
+
end = statement.end;
|
|
3772
|
+
}
|
|
3773
|
+
return end;
|
|
3774
|
+
};
|
|
3775
|
+
var walkOwnBody2 = (node, visitNode) => {
|
|
3776
|
+
if (!node.body) return;
|
|
3777
|
+
const visit = (candidate) => {
|
|
3778
|
+
if (candidate !== node && ts15.isFunctionLike(candidate)) return;
|
|
3779
|
+
visitNode(candidate);
|
|
3780
|
+
ts15.forEachChild(candidate, visit);
|
|
3781
|
+
};
|
|
3782
|
+
visit(node.body);
|
|
3783
|
+
};
|
|
3784
|
+
var producerName = (node) => {
|
|
3785
|
+
const callee = peel(node.expression);
|
|
3786
|
+
if (ts15.isPropertyAccessExpression(callee) && ts15.isIdentifier(callee.name)) {
|
|
3787
|
+
return callee.name.text;
|
|
3788
|
+
}
|
|
3789
|
+
return void 0;
|
|
3790
|
+
};
|
|
3791
|
+
var NON_PROVENANCE_ROOTS2 = /* @__PURE__ */ new Set([
|
|
3792
|
+
"String",
|
|
3793
|
+
"Number",
|
|
3794
|
+
"Boolean",
|
|
3795
|
+
"Object",
|
|
3796
|
+
"Array",
|
|
3797
|
+
"Error",
|
|
3798
|
+
"TypeError",
|
|
3799
|
+
"RangeError",
|
|
3800
|
+
"SyntaxError",
|
|
3801
|
+
"URIError",
|
|
3802
|
+
"EvalError",
|
|
3803
|
+
"ReferenceError",
|
|
3804
|
+
"Symbol",
|
|
3805
|
+
"BigInt",
|
|
3806
|
+
"Math",
|
|
3807
|
+
"JSON",
|
|
3808
|
+
"Date",
|
|
3809
|
+
"Promise",
|
|
3810
|
+
"console",
|
|
3811
|
+
"parseInt",
|
|
3812
|
+
"parseFloat",
|
|
3813
|
+
"isNaN",
|
|
3814
|
+
"isFinite",
|
|
3815
|
+
"encodeURIComponent",
|
|
3816
|
+
"decodeURIComponent",
|
|
3817
|
+
"encodeURI",
|
|
3818
|
+
"decodeURI"
|
|
3819
|
+
]);
|
|
3820
|
+
var callCanCarryProvenance2 = (node) => {
|
|
3821
|
+
const name = producerName(node);
|
|
3822
|
+
if (name === "json" || name === "parse") return true;
|
|
3823
|
+
if (name === "call" || name === "apply") return false;
|
|
3824
|
+
const callee = peel(node.expression);
|
|
3825
|
+
if (ts15.isIdentifier(callee)) return !NON_PROVENANCE_ROOTS2.has(callee.text);
|
|
3826
|
+
if (ts15.isPropertyAccessExpression(callee)) {
|
|
3827
|
+
const object = peel(callee.expression);
|
|
3828
|
+
if (ts15.isIdentifier(object) && NON_PROVENANCE_ROOTS2.has(object.text)) {
|
|
3829
|
+
return object.text === "JSON" && callee.name.text === "parse";
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
return true;
|
|
3833
|
+
};
|
|
3834
|
+
var returnedExpressionNeedsProvenance = (expression) => {
|
|
3835
|
+
const inner = peel(expression);
|
|
3836
|
+
if (ts15.isAwaitExpression(inner)) return true;
|
|
3837
|
+
if (ts15.isCallExpression(inner)) return callCanCarryProvenance2(inner);
|
|
3838
|
+
return false;
|
|
3839
|
+
};
|
|
3840
|
+
var functionNeedsProvenance = (node) => {
|
|
3841
|
+
if (ts15.isArrowFunction(node) && !ts15.isBlock(node.body)) {
|
|
3842
|
+
const body = peel(node.body);
|
|
3843
|
+
if (ts15.isAwaitExpression(body)) return true;
|
|
3844
|
+
if (ts15.isCallExpression(body)) return callCanCarryProvenance2(body);
|
|
3845
|
+
return false;
|
|
3846
|
+
}
|
|
3847
|
+
let needed = false;
|
|
3848
|
+
walkOwnBody2(node, (candidate) => {
|
|
3849
|
+
if (needed) return;
|
|
3850
|
+
if (ts15.isAwaitExpression(candidate)) {
|
|
3851
|
+
needed = true;
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
if (ts15.isReturnStatement(candidate) && candidate.expression) {
|
|
3855
|
+
if (returnedExpressionNeedsProvenance(candidate.expression)) needed = true;
|
|
3856
|
+
return;
|
|
3857
|
+
}
|
|
3858
|
+
if (ts15.isCallExpression(candidate)) {
|
|
3859
|
+
const name = producerName(candidate);
|
|
3860
|
+
if (name === "json" || name === "parse") needed = true;
|
|
3861
|
+
}
|
|
3862
|
+
});
|
|
3863
|
+
return needed;
|
|
3864
|
+
};
|
|
3865
|
+
var collectReturnWraps2 = (node, sourceFile, handleName, edits) => {
|
|
3866
|
+
if (!ts15.isBlock(node.body)) return;
|
|
3867
|
+
walkOwnBody2(node, (candidate) => {
|
|
3868
|
+
if (!ts15.isReturnStatement(candidate) || !candidate.expression) return;
|
|
3869
|
+
wrap(
|
|
3870
|
+
edits,
|
|
3871
|
+
candidate.expression.getStart(sourceFile),
|
|
3872
|
+
candidate.expression.end,
|
|
3873
|
+
`(${handleName}.leave((`,
|
|
3874
|
+
")))",
|
|
3875
|
+
1
|
|
3876
|
+
);
|
|
3877
|
+
});
|
|
3878
|
+
};
|
|
3879
|
+
var collectAwaitSuspends = (node, sourceFile, handleName, edits) => {
|
|
3880
|
+
walkOwnBody2(node, (candidate) => {
|
|
3881
|
+
if (!ts15.isAwaitExpression(candidate)) return;
|
|
3882
|
+
wrap(
|
|
3883
|
+
edits,
|
|
3884
|
+
candidate.expression.getStart(sourceFile),
|
|
3885
|
+
candidate.expression.end,
|
|
3886
|
+
`${handleName}.suspend(`,
|
|
3887
|
+
")",
|
|
3888
|
+
15
|
|
3889
|
+
);
|
|
3890
|
+
});
|
|
3891
|
+
};
|
|
3892
|
+
var functionRef2 = (node) => {
|
|
3893
|
+
if (node.name && ts15.isIdentifier(node.name)) {
|
|
3894
|
+
if (ts15.isMethodDeclaration(node)) return void 0;
|
|
3895
|
+
return node.name.text;
|
|
3896
|
+
}
|
|
3897
|
+
const parent = node.parent;
|
|
3898
|
+
if (ts15.isVariableDeclaration(parent) && ts15.isIdentifier(parent.name) && parent.initializer === node) {
|
|
3899
|
+
return parent.name.text;
|
|
3900
|
+
}
|
|
3901
|
+
return void 0;
|
|
3902
|
+
};
|
|
3903
|
+
var collectProvenanceFunctionEdits = (source, sourceFile) => {
|
|
3904
|
+
const edits = [];
|
|
3905
|
+
const handleName = uniqueName(source, "__rasputinPH__");
|
|
3906
|
+
const errorName = uniqueName(source, "__rasputinPE__");
|
|
3907
|
+
let functionWraps = 0;
|
|
3908
|
+
const visit = (node) => {
|
|
3909
|
+
if (isProvenanceTarget(node) && functionNeedsProvenance(node)) {
|
|
3910
|
+
const decision = isAsyncFunctionLike(node) ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
3911
|
+
if (decision.action !== "skip") {
|
|
3912
|
+
const ref = functionRef2(node);
|
|
3913
|
+
const enter = ref ? `${PROVENANCE_HANDLE_CALLEE}(${ref})` : `${PROVENANCE_HANDLE_CALLEE}()`;
|
|
3914
|
+
const epilogue = `}catch(${errorName}){throw ${errorName};}finally{${handleName}.end();}`;
|
|
3915
|
+
if (ts15.isBlock(node.body)) {
|
|
3916
|
+
const openAt = functionBodyPrologueEnd2(node.body, sourceFile);
|
|
3917
|
+
const closeAt = node.body.end - 1;
|
|
3918
|
+
wrap(edits, openAt, closeAt, `;const ${handleName}=${enter};try{`, epilogue, 0);
|
|
3919
|
+
collectReturnWraps2(node, sourceFile, handleName, edits);
|
|
3920
|
+
if (decision.action === "suspend_resume") {
|
|
3921
|
+
collectAwaitSuspends(node, sourceFile, handleName, edits);
|
|
3922
|
+
}
|
|
3923
|
+
} else {
|
|
3924
|
+
wrap(
|
|
3925
|
+
edits,
|
|
3926
|
+
node.body.getStart(sourceFile),
|
|
3927
|
+
node.body.end,
|
|
3928
|
+
`{;const ${handleName}=${enter};try{return (${handleName}.leave((`,
|
|
3929
|
+
`)));${epilogue}}`,
|
|
3930
|
+
0
|
|
3931
|
+
);
|
|
3932
|
+
if (decision.action === "suspend_resume") {
|
|
3933
|
+
collectAwaitSuspends(node, sourceFile, handleName, edits);
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
functionWraps += 1;
|
|
3937
|
+
}
|
|
3938
|
+
}
|
|
3939
|
+
ts15.forEachChild(node, visit);
|
|
3940
|
+
};
|
|
3941
|
+
visit(sourceFile);
|
|
3942
|
+
if (functionWraps > 0) {
|
|
3943
|
+
const insertAt = insertPositionAfterPrologue2(source, sourceFile);
|
|
3944
|
+
edits.push({
|
|
3945
|
+
position: insertAt,
|
|
3946
|
+
text: preambleInsert2(
|
|
3947
|
+
source,
|
|
3948
|
+
insertAt,
|
|
3949
|
+
`${RASPUTIN_INSTRUMENTATION_PREAMBLE}${PROVENANCE_HANDLE_GUARD}`
|
|
3950
|
+
),
|
|
3951
|
+
deleteCount: 0,
|
|
3952
|
+
depth: -1,
|
|
3953
|
+
width: 0,
|
|
3954
|
+
kind: "replace"
|
|
3955
|
+
});
|
|
3956
|
+
}
|
|
3957
|
+
return { edits, functionWraps };
|
|
3958
|
+
};
|
|
3959
|
+
|
|
3960
|
+
// ../instrumentation/src/instrument-provenance-source.ts
|
|
3961
|
+
var instrumentProvenanceSource = (source, filePath) => {
|
|
3962
|
+
if (source.includes("@rasputin-ignore-file") || sourceIsRasputinInstrumented(source)) {
|
|
3963
|
+
return {
|
|
3964
|
+
code: source,
|
|
3965
|
+
awaitWraps: 0,
|
|
3966
|
+
callWraps: 0,
|
|
3967
|
+
functionWraps: 0,
|
|
3968
|
+
provenanceSkippedComplexCall: 0
|
|
3969
|
+
};
|
|
3970
|
+
}
|
|
3971
|
+
const sourceFile = parseSource(source, filePath);
|
|
3972
|
+
const json = collectJsonProducerEdits(source, filePath, sourceFile, { adoptCalls: true });
|
|
3973
|
+
const functions = collectProvenanceFunctionEdits(source, sourceFile);
|
|
3974
|
+
const edits = [...json.edits, ...functions.edits];
|
|
3975
|
+
if (edits.length === 0) {
|
|
3976
|
+
return {
|
|
3977
|
+
code: source,
|
|
3978
|
+
awaitWraps: 0,
|
|
3979
|
+
callWraps: 0,
|
|
3980
|
+
functionWraps: 0,
|
|
3981
|
+
provenanceSkippedComplexCall: json.provenanceSkippedComplexCall
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
const code = applyEdits(source, edits);
|
|
3985
|
+
if (!browserInstrumentationIsSafe(filePath, source, code)) {
|
|
3986
|
+
return {
|
|
3987
|
+
code: source,
|
|
3988
|
+
awaitWraps: 0,
|
|
3989
|
+
callWraps: 0,
|
|
3990
|
+
functionWraps: 0,
|
|
3991
|
+
provenanceSkippedComplexCall: json.provenanceSkippedComplexCall,
|
|
3992
|
+
verificationFailed: true
|
|
3993
|
+
};
|
|
3994
|
+
}
|
|
3995
|
+
return {
|
|
3996
|
+
code,
|
|
3997
|
+
map: exactTransformMap(source, code, basename3(filePath), edits),
|
|
3998
|
+
awaitWraps: json.awaitWraps,
|
|
3999
|
+
callWraps: json.callWraps,
|
|
4000
|
+
functionWraps: functions.functionWraps,
|
|
4001
|
+
provenanceSkippedComplexCall: json.provenanceSkippedComplexCall
|
|
4002
|
+
};
|
|
4003
|
+
};
|
|
4004
|
+
|
|
4005
|
+
// ../instrumentation/src/provenance-coverage.ts
|
|
4006
|
+
var isRasputinSdkPath = (path) => path.includes("/@rasputin-ai/") || path.includes("/recorder/src/") || path.includes("/recorder/dist/") || path.includes("/instrumentation/src/") || path.includes("/instrumentation/dist/") || path.includes("/browser/src/") || path.includes("/browser/dist/") || path.includes("/core/src/") || path.includes("/core/dist/") || path.includes("/node/src/") || path.includes("/elysia/src/");
|
|
4007
|
+
var isBundledDependencyPath = (path) => /(^|\/)node_modules\//.test(path) || path.includes("/.vite/deps/") || path.includes("node_modules/.vite/deps/");
|
|
4008
|
+
var coverageForModule = (filePath, options) => {
|
|
4009
|
+
const path = filePath.replaceAll("\\", "/");
|
|
4010
|
+
if (!path || path.includes("\0")) return "none";
|
|
4011
|
+
if (options?.skipPaths?.some((segment) => path.includes(segment.replaceAll("\\", "/")))) {
|
|
4012
|
+
return "none";
|
|
4013
|
+
}
|
|
4014
|
+
if (isRasputinSdkPath(path)) return "none";
|
|
4015
|
+
if (isBundledDependencyPath(path)) {
|
|
4016
|
+
const mode = options?.dependencyCoverage ?? (options?.provenanceDependencies === true ? "provenance" : "none");
|
|
4017
|
+
if (mode === "full") return "full";
|
|
4018
|
+
if (mode === "provenance") return "provenance";
|
|
4019
|
+
return "none";
|
|
4020
|
+
}
|
|
4021
|
+
return "full";
|
|
4022
|
+
};
|
|
4023
|
+
|
|
4024
|
+
// ../instrumentation/src/source-map-location.ts
|
|
4025
|
+
import { dirname as dirname2, join } from "node:path";
|
|
4026
|
+
import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
|
|
4027
|
+
var baseName = (path) => path.replaceAll("\\", "/").split("/").pop()?.split("?")[0] ?? "";
|
|
4028
|
+
var isWindowsAbsolute = (path) => /^[A-Za-z]:[\\/]/.test(path);
|
|
4029
|
+
var sameSourceFile = (source, generatedPath) => {
|
|
4030
|
+
const sourceName = baseName(source);
|
|
4031
|
+
const generatedName = baseName(generatedPath);
|
|
4032
|
+
return sourceName.length > 0 && sourceName === generatedName;
|
|
4033
|
+
};
|
|
4034
|
+
var toFilePath = (source, generatedPath) => {
|
|
4035
|
+
if (sameSourceFile(source, generatedPath)) return generatedPath;
|
|
4036
|
+
if (source.startsWith("file:")) {
|
|
4037
|
+
try {
|
|
4038
|
+
return fileURLToPath2(source);
|
|
4039
|
+
} catch {
|
|
4040
|
+
return generatedPath;
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
if (isWindowsAbsolute(source) || source.startsWith("/")) return source;
|
|
4044
|
+
return join(dirname2(generatedPath), source);
|
|
4045
|
+
};
|
|
4046
|
+
var isSourceMapInput = (value) => {
|
|
4047
|
+
if (typeof value === "string") return true;
|
|
4048
|
+
if (!value || typeof value !== "object") return false;
|
|
4049
|
+
return value instanceof TraceMap || "mappings" in value;
|
|
4050
|
+
};
|
|
4051
|
+
var createSourceMapLocationMapper = (generatedPath, map) => {
|
|
4052
|
+
if (!isSourceMapInput(map)) return void 0;
|
|
4053
|
+
try {
|
|
4054
|
+
const traceMap = new TraceMap(map, pathToFileURL(generatedPath).href);
|
|
4055
|
+
return (generated) => {
|
|
4056
|
+
let original = originalPositionFor(traceMap, {
|
|
4057
|
+
line: generated.line,
|
|
4058
|
+
column: Math.max(0, generated.column - 1)
|
|
4059
|
+
});
|
|
4060
|
+
if (!original.source || original.line == null) {
|
|
4061
|
+
original = originalPositionFor(traceMap, {
|
|
4062
|
+
line: generated.line,
|
|
4063
|
+
column: 0
|
|
4064
|
+
});
|
|
4065
|
+
}
|
|
4066
|
+
if (!original.source || original.line == null) return void 0;
|
|
4067
|
+
return {
|
|
4068
|
+
filePath: toFilePath(original.source, generatedPath),
|
|
4069
|
+
line: original.line,
|
|
4070
|
+
column: (original.column ?? 0) + 1
|
|
4071
|
+
};
|
|
4072
|
+
};
|
|
4073
|
+
} catch {
|
|
4074
|
+
return void 0;
|
|
4075
|
+
}
|
|
4076
|
+
};
|
|
4077
|
+
|
|
4078
|
+
// src/vite/artifacts.ts
|
|
4079
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
4080
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4081
|
+
import { join as join2 } from "node:path";
|
|
4082
|
+
var contentDebugId = (source) => {
|
|
4083
|
+
const hex = createHash3("sha256").update(source).digest("hex");
|
|
4084
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
|
|
4085
|
+
};
|
|
4086
|
+
var contentHash = (value) => createHash3("sha256").update(JSON.stringify(value)).digest("hex");
|
|
4087
|
+
var summarizeClassification = (functions, expressionSites) => {
|
|
4088
|
+
const counts = {
|
|
4089
|
+
full: 0,
|
|
4090
|
+
structure: 0,
|
|
4091
|
+
skip: 0,
|
|
4092
|
+
reactiveSparse: 0,
|
|
4093
|
+
expressionSites: expressionSites.length
|
|
4094
|
+
};
|
|
4095
|
+
for (const fn of functions) {
|
|
4096
|
+
if (fn.captureClass === "structure") counts.structure += 1;
|
|
4097
|
+
else if (fn.captureClass === "skip") counts.skip += 1;
|
|
4098
|
+
else if (fn.captureClass === "reactive-sparse") counts.reactiveSparse += 1;
|
|
4099
|
+
else counts.full += 1;
|
|
4100
|
+
}
|
|
4101
|
+
return counts;
|
|
4102
|
+
};
|
|
4103
|
+
var writeLocalArtifacts = (directory, artifacts) => {
|
|
4104
|
+
mkdirSync(directory, { recursive: true });
|
|
4105
|
+
writeFileSync(join2(directory, "artifacts.json"), `${JSON.stringify(artifacts, null, " ")}
|
|
4106
|
+
`);
|
|
4107
|
+
writeFileSync(
|
|
4108
|
+
join2(directory, "classification.json"),
|
|
4109
|
+
`${JSON.stringify(
|
|
4110
|
+
{
|
|
4111
|
+
...artifacts.classification,
|
|
4112
|
+
functions: artifacts.functions.map((fn) => ({
|
|
4113
|
+
functionId: fn.functionId,
|
|
4114
|
+
name: fn.name,
|
|
4115
|
+
captureClass: fn.captureClass,
|
|
4116
|
+
captureReason: fn.captureReason,
|
|
4117
|
+
filePath: fn.filePath,
|
|
4118
|
+
line: fn.line,
|
|
4119
|
+
column: fn.column
|
|
4120
|
+
})),
|
|
4121
|
+
expressionSites: artifacts.expressionSites
|
|
4122
|
+
},
|
|
4123
|
+
null,
|
|
4124
|
+
" "
|
|
4125
|
+
)}
|
|
4126
|
+
`
|
|
4127
|
+
);
|
|
4128
|
+
};
|
|
4129
|
+
|
|
4130
|
+
// src/vite/resolve-build-identity.ts
|
|
4131
|
+
import { randomUUID } from "node:crypto";
|
|
4132
|
+
var isGitSha = (value) => /^[0-9a-f]{7,40}$/i.test(value.trim());
|
|
4133
|
+
var createBrowserCompileId = () => `b_${randomUUID()}`;
|
|
4134
|
+
var normalizeExplicitCompileId = (value) => {
|
|
4135
|
+
if (typeof value !== "string") return "";
|
|
4136
|
+
const trimmed = value.trim();
|
|
4137
|
+
if (!trimmed) return "";
|
|
4138
|
+
if (isGitSha(trimmed)) return "";
|
|
4139
|
+
return trimmed;
|
|
4140
|
+
};
|
|
4141
|
+
|
|
4142
|
+
// src/vite/upload-browser-artifacts.ts
|
|
4143
|
+
var DEFAULT_API_URL = "https://api.rasputinai.dev";
|
|
4144
|
+
var uploadBrowserArtifacts = async (input) => {
|
|
4145
|
+
const key = (input.projectApiKey ?? process.env.RASPUTIN_PROJECT_API_KEY ?? "").trim();
|
|
4146
|
+
if (key.length === 0 || key.startsWith("rdn_") || key.includes("@")) return "skipped";
|
|
4147
|
+
const apiUrl = (input.apiUrl ?? process.env.RASPUTIN_API_URL ?? DEFAULT_API_URL).replace(
|
|
4148
|
+
/\/+$/,
|
|
4149
|
+
""
|
|
4150
|
+
);
|
|
4151
|
+
try {
|
|
4152
|
+
const response = await fetch(`${apiUrl}/browserArtifacts`, {
|
|
4153
|
+
method: "POST",
|
|
4154
|
+
headers: {
|
|
4155
|
+
authorization: `Bearer ${key}`,
|
|
4156
|
+
"content-type": "application/json"
|
|
4157
|
+
},
|
|
4158
|
+
body: JSON.stringify({
|
|
4159
|
+
buildId: input.artifacts.buildId,
|
|
4160
|
+
release: input.release,
|
|
4161
|
+
contentHash: contentHash(input.artifacts),
|
|
4162
|
+
artifact: input.artifacts,
|
|
4163
|
+
...input.replace === true ? { replace: true } : {}
|
|
4164
|
+
})
|
|
4165
|
+
});
|
|
4166
|
+
if (response.status === 409) return "conflict";
|
|
4167
|
+
if (response.status === 200 || response.status === 201) {
|
|
4168
|
+
const body = await response.json().catch(() => ({}));
|
|
4169
|
+
if (body && typeof body === "object" && "duplicate" in body && body.duplicate === true) {
|
|
4170
|
+
return "duplicate";
|
|
4171
|
+
}
|
|
4172
|
+
return "uploaded";
|
|
4173
|
+
}
|
|
4174
|
+
console.warn(
|
|
4175
|
+
`[rasputin] artifact upload failed (${response.status}); the build still succeeded`
|
|
4176
|
+
);
|
|
4177
|
+
return "failed";
|
|
4178
|
+
} catch {
|
|
4179
|
+
console.warn("[rasputin] artifact upload failed; the build still succeeded");
|
|
4180
|
+
return "failed";
|
|
4181
|
+
}
|
|
4182
|
+
};
|
|
4183
|
+
|
|
4184
|
+
// src/vite/plugin.ts
|
|
4185
|
+
var isServerModule = (path) => path.includes(".server.") || path.endsWith("+server.ts") || path.endsWith("+server.js") || path.includes("/hooks.server.");
|
|
4186
|
+
var isRasputinSdkModule = (path) => path.includes("/@rasputin-ai/") || path.includes("/recorder/src/") || path.includes("/recorder/dist/") || path.includes("/instrumentation/src/") || path.includes("/instrumentation/dist/") || path.includes("/browser/src/") || path.includes("/browser/dist/") || path.includes("/core/src/") || path.includes("/core/dist/") || path.includes("/node/src/") || path.includes("/elysia/src/");
|
|
4187
|
+
var isRasputinBrowserRuntimeSource = (code) => code.includes("rasputin.browser.client.v1");
|
|
4188
|
+
var isJsModulePath = (path) => /\.[cm]?[jt]sx?$/.test(path) && !isSvelteCompiledPath(path);
|
|
4189
|
+
var MAX_PROVENANCE_SOURCE_CHARS = 15e5;
|
|
4190
|
+
var countToken = (code, token) => {
|
|
4191
|
+
let count = 0;
|
|
4192
|
+
let from = 0;
|
|
4193
|
+
while (true) {
|
|
4194
|
+
const at = code.indexOf(token, from);
|
|
4195
|
+
if (at === -1) return count;
|
|
4196
|
+
count += 1;
|
|
4197
|
+
from = at + token.length;
|
|
4198
|
+
}
|
|
4199
|
+
};
|
|
4200
|
+
var isApplicationModule = (id, onlyIfPathIncludes) => {
|
|
4201
|
+
const path = id.split("?")[0]?.replaceAll("\\", "/") ?? "";
|
|
4202
|
+
if (!path) return false;
|
|
4203
|
+
if (path.includes("/node_modules/")) return false;
|
|
4204
|
+
if (path.includes("\0")) return false;
|
|
4205
|
+
if (isRasputinSdkModule(path)) return false;
|
|
4206
|
+
if (path.includes("virtual:rasputin")) return false;
|
|
4207
|
+
if (isSvelteCompiledPath(path)) return false;
|
|
4208
|
+
if (isServerModule(path)) return false;
|
|
4209
|
+
if (onlyIfPathIncludes && onlyIfPathIncludes.length > 0) {
|
|
4210
|
+
if (!onlyIfPathIncludes.some((segment) => path.includes(segment.replaceAll("\\", "/")))) {
|
|
4211
|
+
return false;
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
return /\.[cm]?[jt]sx?$/.test(path);
|
|
4215
|
+
};
|
|
4216
|
+
var recoveredWindowsPath = (filePath) => {
|
|
4217
|
+
const path = filePath.replaceAll("\\", "/");
|
|
4218
|
+
const parts = path.split(/(?=[A-Za-z]:\/)/);
|
|
4219
|
+
return parts.length > 1 ? parts.at(-1) ?? path : path;
|
|
4220
|
+
};
|
|
4221
|
+
var artifactSourcePath = (filePath, projectRoot) => {
|
|
4222
|
+
const recovered = recoveredWindowsPath(filePath);
|
|
4223
|
+
if (projectRoot && (isAbsolute2(recovered) || /^[A-Za-z]:\//.test(recovered))) {
|
|
4224
|
+
return relative2(projectRoot, recovered).replaceAll("\\", "/");
|
|
4225
|
+
}
|
|
4226
|
+
return recovered.replace(/^\.\//, "");
|
|
4227
|
+
};
|
|
4228
|
+
var toArtifactCallSite = (site, projectRoot, packageName) => ({
|
|
4229
|
+
callerFunctionId: site.callerFunctionId,
|
|
4230
|
+
calleeName: site.calleeName,
|
|
4231
|
+
calleeText: site.calleeText,
|
|
4232
|
+
packageName,
|
|
4233
|
+
packageRelativePath: artifactSourcePath(site.filePath, projectRoot),
|
|
4234
|
+
line: site.line,
|
|
4235
|
+
column: site.column,
|
|
4236
|
+
endLine: site.endLine,
|
|
4237
|
+
endColumn: site.endColumn,
|
|
4238
|
+
resultBinding: site.resultBinding,
|
|
4239
|
+
argIdentifiers: site.argIdentifiers
|
|
4240
|
+
});
|
|
4241
|
+
var toArtifactDestructure = (destructure, projectRoot, packageName) => ({
|
|
4242
|
+
callerFunctionId: destructure.callerFunctionId,
|
|
4243
|
+
sourceParam: destructure.sourceParam,
|
|
4244
|
+
packageName,
|
|
4245
|
+
packageRelativePath: artifactSourcePath(destructure.filePath, projectRoot),
|
|
4246
|
+
line: destructure.line,
|
|
4247
|
+
column: destructure.column,
|
|
4248
|
+
binding: destructure.binding
|
|
4249
|
+
});
|
|
4250
|
+
var isCompiledSvelteModule = (id, onlyIfPathIncludes) => {
|
|
4251
|
+
const [filePath, query] = id.split("?");
|
|
4252
|
+
const path = filePath?.replaceAll("\\", "/") ?? "";
|
|
4253
|
+
if (!isSvelteCompiledPath(path)) return false;
|
|
4254
|
+
if (path.includes("/node_modules/")) return false;
|
|
4255
|
+
if (path.includes("\0")) return false;
|
|
4256
|
+
if (query?.includes("type=style") || query?.includes("type=preprocessed")) return false;
|
|
4257
|
+
if (isServerModule(path)) return false;
|
|
4258
|
+
if (onlyIfPathIncludes && onlyIfPathIncludes.length > 0) {
|
|
4259
|
+
if (!onlyIfPathIncludes.some((segment) => path.includes(segment.replaceAll("\\", "/")))) {
|
|
4260
|
+
return false;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
return true;
|
|
4264
|
+
};
|
|
4265
|
+
var classificationById = (classifications) => {
|
|
4266
|
+
const found2 = /* @__PURE__ */ new Map();
|
|
4267
|
+
for (const item of classifications) found2.set(item.functionId, item);
|
|
4268
|
+
return found2;
|
|
4269
|
+
};
|
|
4270
|
+
var toManifestFunctions = (delta, classifications, identities) => {
|
|
4271
|
+
const classified = classificationById(classifications);
|
|
4272
|
+
const indexed = new Map(identities.map((item) => [item.functionId, item]));
|
|
4273
|
+
return delta.functions.map((fn) => {
|
|
4274
|
+
const match = classified.get(fn.functionId);
|
|
4275
|
+
const index = indexed.get(fn.functionId);
|
|
4276
|
+
return {
|
|
4277
|
+
functionId: fn.functionId,
|
|
4278
|
+
name: fn.name,
|
|
4279
|
+
packageName: fn.plan[2],
|
|
4280
|
+
packageRelativePath: fn.plan[3],
|
|
4281
|
+
line: fn.plan[4],
|
|
4282
|
+
column: fn.plan[5],
|
|
4283
|
+
endLine: fn.endLine,
|
|
4284
|
+
endColumn: fn.endColumn,
|
|
4285
|
+
params: fn.params,
|
|
4286
|
+
filePath: fn.filePath,
|
|
4287
|
+
captureClass: match?.captureClass ?? "full",
|
|
4288
|
+
captureReason: match?.captureReason ?? "unclassified-default",
|
|
4289
|
+
...index ? { moduleIndex: index.moduleIndex, planIndex: index.planIndex } : {},
|
|
4290
|
+
...index?.siteId === void 0 ? {} : { siteId: index.siteId }
|
|
4291
|
+
};
|
|
4292
|
+
});
|
|
4293
|
+
};
|
|
4294
|
+
var publicDsn = (value) => {
|
|
4295
|
+
return (value ?? process.env.VITE_RASPUTIN_DSN ?? "").trim();
|
|
4296
|
+
};
|
|
4297
|
+
var VIRTUAL_INIT_ID = "virtual:rasputin-init";
|
|
4298
|
+
var RESOLVED_VIRTUAL_INIT_ID = `\0${VIRTUAL_INIT_ID}`;
|
|
4299
|
+
var isVirtualInitId = (id) => id === VIRTUAL_INIT_ID || id === RESOLVED_VIRTUAL_INIT_ID;
|
|
4300
|
+
var isArtifactsPath = (filePath, directory) => {
|
|
4301
|
+
const file = filePath.replaceAll("\\", "/");
|
|
4302
|
+
const root = directory.replaceAll("\\", "/");
|
|
4303
|
+
return file === root || file.startsWith(`${root}/`);
|
|
4304
|
+
};
|
|
4305
|
+
var rasputin = (options) => {
|
|
4306
|
+
if (options.enabled === false) return [];
|
|
4307
|
+
const functions = /* @__PURE__ */ new Map();
|
|
4308
|
+
const callSites = /* @__PURE__ */ new Map();
|
|
4309
|
+
const destructures = /* @__PURE__ */ new Map();
|
|
4310
|
+
const BUILD_IDENTITIES_MARKER = "@@RASPUTIN_IDENTITIES@@";
|
|
4311
|
+
const BUILD_STATS_MARKER = "@@RASPUTIN_STATS@@";
|
|
4312
|
+
const runtimeIdentities = [];
|
|
4313
|
+
const expressionSites = /* @__PURE__ */ new Map();
|
|
4314
|
+
const verificationFailed = /* @__PURE__ */ new Set();
|
|
4315
|
+
const emitIds = { value: 1 };
|
|
4316
|
+
const reactiveIds = { value: 1 };
|
|
4317
|
+
let nextModuleIndex = 0;
|
|
4318
|
+
let artifactsDir = options.artifactsDir;
|
|
4319
|
+
const identity = {
|
|
4320
|
+
buildId: normalizeExplicitCompileId(options.buildId) || createBrowserCompileId(),
|
|
4321
|
+
release: options.release.trim()
|
|
4322
|
+
};
|
|
4323
|
+
const environment = options.environment.trim();
|
|
4324
|
+
let projectRoot = "";
|
|
4325
|
+
let keepPublicMaps = false;
|
|
4326
|
+
let includeRuntimeNames = options.includeRuntimeNames ?? true;
|
|
4327
|
+
let command = "unknown";
|
|
4328
|
+
const dependencyCoverage = options.dependencyCoverage ?? "provenance";
|
|
4329
|
+
const provenanceStats = {
|
|
4330
|
+
modules: 0,
|
|
4331
|
+
functionWraps: 0,
|
|
4332
|
+
awaitWraps: 0,
|
|
4333
|
+
callWraps: 0,
|
|
4334
|
+
skippedComplexCall: 0,
|
|
4335
|
+
n: 0,
|
|
4336
|
+
p: 0,
|
|
4337
|
+
a: 0,
|
|
4338
|
+
m: 0
|
|
4339
|
+
};
|
|
4340
|
+
const snapshotArtifacts = (debugImages = []) => {
|
|
4341
|
+
const manifestFunctions = [...functions.values()];
|
|
4342
|
+
const sites = [...expressionSites.values()];
|
|
4343
|
+
return {
|
|
4344
|
+
schema_version: 1,
|
|
4345
|
+
buildId: identity.buildId,
|
|
4346
|
+
functions: manifestFunctions,
|
|
4347
|
+
identities: runtimeIdentities.map((item) => {
|
|
4348
|
+
const match = manifestFunctions.find(
|
|
4349
|
+
(fn) => fn.moduleIndex === item.moduleIndex && fn.planIndex === item.planIndex
|
|
4350
|
+
);
|
|
4351
|
+
return {
|
|
4352
|
+
...item,
|
|
4353
|
+
functionId: match?.functionId ?? item.functionId
|
|
4354
|
+
};
|
|
4355
|
+
}),
|
|
4356
|
+
callSites: [...callSites.values()],
|
|
4357
|
+
destructures: [...destructures.values()],
|
|
4358
|
+
expressionSites: sites,
|
|
4359
|
+
classification: summarizeClassification(manifestFunctions, sites),
|
|
4360
|
+
debugImages,
|
|
4361
|
+
verificationFailed: [...verificationFailed],
|
|
4362
|
+
provenance: { ...provenanceStats }
|
|
4363
|
+
};
|
|
4364
|
+
};
|
|
4365
|
+
const persistArtifacts = (input) => {
|
|
4366
|
+
if (!artifactsDir) return;
|
|
4367
|
+
const artifacts = snapshotArtifacts(input.debugImages ?? []);
|
|
4368
|
+
writeLocalArtifacts(artifactsDir, artifacts);
|
|
4369
|
+
if (!input.upload || options.uploadArtifacts === false) return;
|
|
4370
|
+
void uploadBrowserArtifacts({
|
|
4371
|
+
artifacts,
|
|
4372
|
+
release: identity.release,
|
|
4373
|
+
projectApiKey: options.projectApiKey,
|
|
4374
|
+
apiUrl: options.apiUrl,
|
|
4375
|
+
replace: input.replace === true
|
|
4376
|
+
});
|
|
4377
|
+
};
|
|
4378
|
+
const recordInstrumented = (code, filePath, original, incomingMap) => {
|
|
4379
|
+
const instrumented = instrumentBrowserSource(
|
|
4380
|
+
code,
|
|
4381
|
+
filePath,
|
|
4382
|
+
emitIds,
|
|
4383
|
+
reactiveIds,
|
|
4384
|
+
nextModuleIndex++,
|
|
4385
|
+
{
|
|
4386
|
+
includePlans: includeRuntimeNames,
|
|
4387
|
+
mapLocation: createSourceMapLocationMapper(filePath, incomingMap)
|
|
4388
|
+
}
|
|
4389
|
+
);
|
|
4390
|
+
if (instrumented.verificationFailed) {
|
|
4391
|
+
verificationFailed.add(filePath);
|
|
4392
|
+
return code === original ? void 0 : { code: original, map: null };
|
|
4393
|
+
}
|
|
4394
|
+
if (instrumented.delta) {
|
|
4395
|
+
const nextFunctions = toManifestFunctions(
|
|
4396
|
+
instrumented.delta,
|
|
4397
|
+
instrumented.classifications,
|
|
4398
|
+
instrumented.identities
|
|
4399
|
+
);
|
|
4400
|
+
for (const fn of nextFunctions) functions.set(fn.functionId, fn);
|
|
4401
|
+
const packageNameOf = (functionId) => functions.get(functionId)?.packageName ?? null;
|
|
4402
|
+
for (const site of instrumented.delta.callSites) {
|
|
4403
|
+
const artifact = toArtifactCallSite(
|
|
4404
|
+
site,
|
|
4405
|
+
projectRoot,
|
|
4406
|
+
packageNameOf(site.callerFunctionId)
|
|
4407
|
+
);
|
|
4408
|
+
callSites.set(
|
|
4409
|
+
`${site.callerFunctionId}:${site.line}:${site.column}:${site.calleeName}`,
|
|
4410
|
+
artifact
|
|
4411
|
+
);
|
|
4412
|
+
}
|
|
4413
|
+
for (const destructure of instrumented.delta.destructures) {
|
|
4414
|
+
destructures.set(
|
|
4415
|
+
`${destructure.callerFunctionId}:${destructure.line}:${destructure.column}:${destructure.sourceParam}`,
|
|
4416
|
+
toArtifactDestructure(
|
|
4417
|
+
destructure,
|
|
4418
|
+
projectRoot,
|
|
4419
|
+
packageNameOf(destructure.callerFunctionId)
|
|
4420
|
+
)
|
|
4421
|
+
);
|
|
4422
|
+
}
|
|
4423
|
+
}
|
|
4424
|
+
const moduleIdentities = instrumented.identities.map((identity2) => ({
|
|
4425
|
+
compactId: identity2.compactId,
|
|
4426
|
+
functionId: identity2.compactId,
|
|
4427
|
+
name: identity2.name,
|
|
4428
|
+
captureClass: identity2.captureClass,
|
|
4429
|
+
packageRelativePath: projectRoot ? artifactSourcePath(identity2.filePath, projectRoot) : null,
|
|
4430
|
+
line: identity2.line,
|
|
4431
|
+
column: identity2.column,
|
|
4432
|
+
...identity2.siteId === void 0 ? {} : { siteId: identity2.siteId },
|
|
4433
|
+
moduleIndex: identity2.moduleIndex,
|
|
4434
|
+
planIndex: identity2.planIndex
|
|
4435
|
+
}));
|
|
4436
|
+
for (const identity2 of moduleIdentities) runtimeIdentities.push(identity2);
|
|
4437
|
+
for (const site of instrumented.sites) {
|
|
4438
|
+
expressionSites.set(site.siteId, site);
|
|
4439
|
+
}
|
|
4440
|
+
if (!instrumented.delta && instrumented.sites.length === 0 && instrumented.code === code) {
|
|
4441
|
+
return code === original ? void 0 : { code, map: null };
|
|
4442
|
+
}
|
|
4443
|
+
const source = projectRoot ? relative2(projectRoot, filePath).replaceAll("\\", "/") : filePath.replaceAll("\\", "/");
|
|
4444
|
+
const map = instrumented.map ? {
|
|
4445
|
+
...instrumented.map,
|
|
4446
|
+
file: source,
|
|
4447
|
+
sources: [source],
|
|
4448
|
+
names: instrumented.map.names ?? []
|
|
4449
|
+
} : null;
|
|
4450
|
+
let nextCode = instrumented.code;
|
|
4451
|
+
if (includeRuntimeNames && moduleIdentities.length > 0) {
|
|
4452
|
+
nextCode = `${nextCode}
|
|
4453
|
+
;globalThis.__rasputinRegisterIdentities?.(${JSON.stringify(moduleIdentities)});`;
|
|
4454
|
+
}
|
|
4455
|
+
return { code: nextCode, map };
|
|
4456
|
+
};
|
|
4457
|
+
const recordProvenance = (code, filePath, original) => {
|
|
4458
|
+
if (code.length > MAX_PROVENANCE_SOURCE_CHARS) {
|
|
4459
|
+
return code === original ? void 0 : { code: original, map: null };
|
|
4460
|
+
}
|
|
4461
|
+
const instrumented = instrumentProvenanceSource(code, filePath);
|
|
4462
|
+
if (instrumented.verificationFailed) {
|
|
4463
|
+
verificationFailed.add(filePath);
|
|
4464
|
+
return code === original ? void 0 : { code: original, map: null };
|
|
4465
|
+
}
|
|
4466
|
+
if (instrumented.code === code) {
|
|
4467
|
+
return code === original ? void 0 : { code, map: null };
|
|
4468
|
+
}
|
|
4469
|
+
provenanceStats.modules += 1;
|
|
4470
|
+
provenanceStats.functionWraps += instrumented.functionWraps;
|
|
4471
|
+
provenanceStats.awaitWraps += instrumented.awaitWraps;
|
|
4472
|
+
provenanceStats.callWraps += instrumented.callWraps;
|
|
4473
|
+
provenanceStats.skippedComplexCall += instrumented.provenanceSkippedComplexCall;
|
|
4474
|
+
provenanceStats.n += countToken(instrumented.code, "__rasputinN(");
|
|
4475
|
+
provenanceStats.p += countToken(instrumented.code, "__rasputinP(");
|
|
4476
|
+
provenanceStats.a += countToken(instrumented.code, "__rasputinA(");
|
|
4477
|
+
provenanceStats.m += countToken(instrumented.code, "__rasputinM(");
|
|
4478
|
+
const source = projectRoot ? relative2(projectRoot, filePath).replaceAll("\\", "/") : filePath.replaceAll("\\", "/");
|
|
4479
|
+
const map = instrumented.map ? {
|
|
4480
|
+
...instrumented.map,
|
|
4481
|
+
file: source,
|
|
4482
|
+
sources: [source],
|
|
4483
|
+
names: instrumented.map.names ?? []
|
|
4484
|
+
} : null;
|
|
4485
|
+
return { code: instrumented.code, map };
|
|
4486
|
+
};
|
|
4487
|
+
const plugin = {
|
|
4488
|
+
name: "rasputin-browser",
|
|
4489
|
+
enforce: "pre",
|
|
4490
|
+
config(config) {
|
|
4491
|
+
const requested = config.build?.sourcemap;
|
|
4492
|
+
keepPublicMaps = requested === true || requested === "inline";
|
|
4493
|
+
if (requested === false || keepPublicMaps) return void 0;
|
|
4494
|
+
return {
|
|
4495
|
+
build: {
|
|
4496
|
+
sourcemap: "hidden"
|
|
4497
|
+
}
|
|
4498
|
+
};
|
|
4499
|
+
},
|
|
4500
|
+
configResolved(config) {
|
|
4501
|
+
artifactsDir = options.artifactsDir ?? resolve5(config.root, ".rasputin");
|
|
4502
|
+
projectRoot = config.root;
|
|
4503
|
+
command = config.command === "serve" || config.command === "build" ? config.command : "unknown";
|
|
4504
|
+
includeRuntimeNames = options.includeRuntimeNames ?? (config.command !== "build" || config.mode !== "production");
|
|
4505
|
+
},
|
|
4506
|
+
configureServer(server) {
|
|
4507
|
+
if (artifactsDir) server.watcher?.unwatch?.(artifactsDir);
|
|
4508
|
+
},
|
|
4509
|
+
resolveId(id) {
|
|
4510
|
+
if (isVirtualInitId(id)) return RESOLVED_VIRTUAL_INIT_ID;
|
|
4511
|
+
return void 0;
|
|
4512
|
+
},
|
|
4513
|
+
load(id) {
|
|
4514
|
+
if (!isVirtualInitId(id)) return void 0;
|
|
4515
|
+
const dsn = publicDsn(options.dsn);
|
|
4516
|
+
const ingest = options.ingest !== false;
|
|
4517
|
+
return `import { RasputinInit } from '@rasputin-ai/browser';
|
|
4518
|
+
globalThis.__RASPUTIN_BUILD_ID__ = ${JSON.stringify(identity.buildId)};
|
|
4519
|
+
globalThis.__RASPUTIN_RELEASE__ = ${JSON.stringify(identity.release)};
|
|
4520
|
+
globalThis.__RASPUTIN_ENVIRONMENT__ = ${JSON.stringify(environment)};
|
|
4521
|
+
globalThis.__RASPUTIN_DSN__ = ${JSON.stringify(dsn)};
|
|
4522
|
+
globalThis.__RASPUTIN_BUILD_IDENTITIES__ = globalThis.__RASPUTIN_BUILD_IDENTITIES__ ?? "${BUILD_IDENTITIES_MARKER}";
|
|
4523
|
+
globalThis.__RASPUTIN_BUILD_STATS__ = globalThis.__RASPUTIN_BUILD_STATS__ ?? "${BUILD_STATS_MARKER}";
|
|
4524
|
+
RasputinInit({
|
|
4525
|
+
dsn: ${JSON.stringify(dsn)},
|
|
4526
|
+
environment: ${JSON.stringify(environment)},
|
|
4527
|
+
release: ${JSON.stringify(identity.release)},
|
|
4528
|
+
buildId: ${JSON.stringify(identity.buildId)},
|
|
4529
|
+
ingest: ${ingest ? "true" : "false"},
|
|
4530
|
+
identities: globalThis.__RASPUTIN_BUILD_IDENTITIES__,
|
|
4531
|
+
});
|
|
4532
|
+
`;
|
|
4533
|
+
},
|
|
4534
|
+
transform(code, id, transformOptions) {
|
|
4535
|
+
if (transformOptions?.ssr) return void 0;
|
|
4536
|
+
const filePath = id.split("?")[0];
|
|
4537
|
+
if (!filePath) return void 0;
|
|
4538
|
+
const normalized = filePath.replaceAll("\\", "/");
|
|
4539
|
+
let next = code;
|
|
4540
|
+
if (normalized.endsWith("/src/main.ts") || normalized.endsWith("/hooks.client.ts")) {
|
|
4541
|
+
const extras = (options.bootstrapImports ?? []).map((moduleId) => `import '${moduleId}';`).join("\n");
|
|
4542
|
+
next = `import 'virtual:rasputin-init';
|
|
4543
|
+
${extras}${extras ? "\n" : ""}${code}`;
|
|
4544
|
+
}
|
|
4545
|
+
if (isRasputinBrowserRuntimeSource(next)) {
|
|
4546
|
+
return next === code ? void 0 : { code: next, map: null };
|
|
4547
|
+
}
|
|
4548
|
+
if (isServerModule(normalized)) {
|
|
4549
|
+
return next === code ? void 0 : { code: next, map: null };
|
|
4550
|
+
}
|
|
4551
|
+
const coverage = coverageForModule(normalized, { dependencyCoverage });
|
|
4552
|
+
if (coverage === "none") {
|
|
4553
|
+
return next === code ? void 0 : { code: next, map: null };
|
|
4554
|
+
}
|
|
4555
|
+
if (coverage === "provenance") {
|
|
4556
|
+
if (!isJsModulePath(normalized)) {
|
|
4557
|
+
return next === code ? void 0 : { code: next, map: null };
|
|
4558
|
+
}
|
|
4559
|
+
return recordProvenance(next, filePath, code);
|
|
4560
|
+
}
|
|
4561
|
+
if (!isApplicationModule(id, options.onlyIfPathIncludes)) {
|
|
4562
|
+
if (dependencyCoverage === "full" && isJsModulePath(normalized)) {
|
|
4563
|
+
return recordInstrumented(next, filePath, code);
|
|
4564
|
+
}
|
|
4565
|
+
return next === code ? void 0 : { code: next, map: null };
|
|
4566
|
+
}
|
|
4567
|
+
return recordInstrumented(next, filePath, code);
|
|
4568
|
+
},
|
|
4569
|
+
generateBundle(_output, bundle) {
|
|
4570
|
+
const environmentName = this && typeof this === "object" ? Reflect.get(this, "environment") : void 0;
|
|
4571
|
+
const name = environmentName && typeof environmentName === "object" ? Reflect.get(environmentName, "name") : void 0;
|
|
4572
|
+
if (name === "ssr") return;
|
|
4573
|
+
const debugImages = [];
|
|
4574
|
+
const identitiesJson = includeRuntimeNames ? JSON.stringify(runtimeIdentities) : "[]";
|
|
4575
|
+
const classification = summarizeClassification(
|
|
4576
|
+
[...functions.values()],
|
|
4577
|
+
[...expressionSites.values()]
|
|
4578
|
+
);
|
|
4579
|
+
const statsJson = JSON.stringify({
|
|
4580
|
+
functions: functions.size,
|
|
4581
|
+
full: classification.full,
|
|
4582
|
+
structure: classification.structure,
|
|
4583
|
+
skip: classification.skip,
|
|
4584
|
+
reactiveSparse: classification.reactiveSparse,
|
|
4585
|
+
verificationFailed: verificationFailed.size,
|
|
4586
|
+
provenanceModules: provenanceStats.modules,
|
|
4587
|
+
provenanceN: provenanceStats.n,
|
|
4588
|
+
provenanceP: provenanceStats.p,
|
|
4589
|
+
provenanceA: provenanceStats.a,
|
|
4590
|
+
provenanceM: provenanceStats.m,
|
|
4591
|
+
dependencyCoverage
|
|
4592
|
+
});
|
|
4593
|
+
for (const [fileName, item] of Object.entries(bundle)) {
|
|
4594
|
+
if (!keepPublicMaps && fileName.endsWith(".map")) {
|
|
4595
|
+
Reflect.deleteProperty(bundle, fileName);
|
|
4596
|
+
continue;
|
|
4597
|
+
}
|
|
4598
|
+
if (item.type !== "chunk") continue;
|
|
4599
|
+
const debugId = contentDebugId(item.code);
|
|
4600
|
+
item.code = item.code.replaceAll(
|
|
4601
|
+
new RegExp(`[\`"']${BUILD_IDENTITIES_MARKER}[\`"']`, "g"),
|
|
4602
|
+
identitiesJson
|
|
4603
|
+
);
|
|
4604
|
+
item.code = item.code.replaceAll(
|
|
4605
|
+
new RegExp(`[\`"']${BUILD_STATS_MARKER}[\`"']`, "g"),
|
|
4606
|
+
statsJson
|
|
4607
|
+
);
|
|
4608
|
+
item.code = `${item.code.replace(/\n?$/, "\n")}//# debugId=${debugId}
|
|
4609
|
+
`;
|
|
4610
|
+
if (!keepPublicMaps) {
|
|
4611
|
+
item.code = item.code.replace(/\n\/\/# sourceMappingURL=[^\n]+/g, "\n");
|
|
4612
|
+
}
|
|
4613
|
+
debugImages.push({
|
|
4614
|
+
debugId,
|
|
4615
|
+
fileName: item.fileName,
|
|
4616
|
+
map: item.map ?? null
|
|
4617
|
+
});
|
|
4618
|
+
if (!keepPublicMaps) item.map = null;
|
|
4619
|
+
}
|
|
4620
|
+
if (command !== "serve") {
|
|
4621
|
+
persistArtifacts({
|
|
4622
|
+
debugImages,
|
|
4623
|
+
upload: command === "build"
|
|
4624
|
+
});
|
|
4625
|
+
}
|
|
4626
|
+
},
|
|
4627
|
+
handleHotUpdate(ctx) {
|
|
4628
|
+
if (artifactsDir && isArtifactsPath(ctx.file, artifactsDir)) return [];
|
|
4629
|
+
return void 0;
|
|
4630
|
+
}
|
|
4631
|
+
};
|
|
4632
|
+
Reflect.set(plugin, "applyToEnvironment", (environmentRef) => {
|
|
4633
|
+
return environmentRef.name !== "ssr";
|
|
4634
|
+
});
|
|
4635
|
+
const sveltePlugin = {
|
|
4636
|
+
name: "rasputin-browser-svelte",
|
|
4637
|
+
enforce: "post",
|
|
4638
|
+
configResolved(config) {
|
|
4639
|
+
artifactsDir = options.artifactsDir ?? resolve5(config.root, ".rasputin");
|
|
4640
|
+
projectRoot = config.root;
|
|
4641
|
+
},
|
|
4642
|
+
transform: {
|
|
4643
|
+
order: "post",
|
|
4644
|
+
handler(code, id, transformOptions) {
|
|
4645
|
+
if (transformOptions?.ssr) return void 0;
|
|
4646
|
+
if (!isCompiledSvelteModule(id, options.onlyIfPathIncludes)) return void 0;
|
|
4647
|
+
const filePath = id.split("?")[0];
|
|
4648
|
+
if (!filePath) return void 0;
|
|
4649
|
+
let incomingMap;
|
|
4650
|
+
try {
|
|
4651
|
+
incomingMap = typeof this.getCombinedSourcemap === "function" ? this.getCombinedSourcemap() : void 0;
|
|
4652
|
+
} catch {
|
|
4653
|
+
incomingMap = void 0;
|
|
4654
|
+
}
|
|
4655
|
+
return recordInstrumented(code, filePath, code, incomingMap);
|
|
4656
|
+
}
|
|
4657
|
+
}
|
|
4658
|
+
};
|
|
4659
|
+
Reflect.set(sveltePlugin, "applyToEnvironment", (environmentRef) => {
|
|
4660
|
+
return environmentRef.name !== "ssr";
|
|
4661
|
+
});
|
|
4662
|
+
return [plugin, sveltePlugin];
|
|
4663
|
+
};
|
|
4664
|
+
export {
|
|
4665
|
+
rasputin
|
|
4666
|
+
};
|