@rasputin-ai/sveltekit 0.15.1 → 1.0.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/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +1 -2
- package/dist/sdk-meta.d.ts +1 -1
- package/dist/sdk-meta.d.ts.map +1 -1
- package/dist/vite/build-identity.d.ts +0 -1
- package/dist/vite/build-identity.d.ts.map +1 -1
- package/dist/vite/identify-environment.d.ts +1 -2
- package/dist/vite/identify-environment.d.ts.map +1 -1
- package/dist/vite/index.js +404 -3055
- package/dist/vite/module-kind.d.ts +0 -2
- package/dist/vite/module-kind.d.ts.map +1 -1
- package/dist/vite/plugin.d.ts +5 -3
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/rasputin-sdk-path.d.ts.map +1 -1
- package/dist/vite/upload-build-artifacts.d.ts +0 -42
- package/dist/vite/upload-build-artifacts.d.ts.map +1 -1
- package/package.json +4 -10
- package/dist/client/hooks.d.ts +0 -12
- package/dist/client/hooks.d.ts.map +0 -1
- package/dist/client/hooks.js +0 -39
- package/dist/client/options.d.ts +0 -17
- package/dist/client/options.d.ts.map +0 -1
- package/dist/vite/virtual-identity.d.ts +0 -12
- package/dist/vite/virtual-identity.d.ts.map +0 -1
package/dist/vite/index.js
CHANGED
|
@@ -1,49 +1,3 @@
|
|
|
1
|
-
// src/vite/plugin.ts
|
|
2
|
-
import { createHash as createHash3 } from "node:crypto";
|
|
3
|
-
|
|
4
|
-
// ../instrumentation/src/classify-function.ts
|
|
5
|
-
import { resolve } from "node:path";
|
|
6
|
-
|
|
7
|
-
// ../recorder/src/encoded-function-plan.ts
|
|
8
|
-
var withPreBodyParameterEvaluation = (plan) => [
|
|
9
|
-
plan[0],
|
|
10
|
-
plan[1],
|
|
11
|
-
plan[2],
|
|
12
|
-
plan[3],
|
|
13
|
-
plan[4],
|
|
14
|
-
plan[5],
|
|
15
|
-
plan[6],
|
|
16
|
-
1
|
|
17
|
-
];
|
|
18
|
-
var compactRuntimeFunctionId = (moduleIndex, planIndex) => `${moduleIndex}.${planIndex}`;
|
|
19
|
-
|
|
20
|
-
// ../recorder/src/function-plan.ts
|
|
21
|
-
import {
|
|
22
|
-
runtimeFunctionId,
|
|
23
|
-
sourceLocatorFromFile
|
|
24
|
-
} from "@rasputin-ai/core";
|
|
25
|
-
var encodeFunctionPlan = (source) => {
|
|
26
|
-
const locator = sourceLocatorFromFile(source.filePath);
|
|
27
|
-
const definition = {
|
|
28
|
-
name: source.name,
|
|
29
|
-
...locator ? { source: { ...locator, line: source.line, column: source.column } } : {}
|
|
30
|
-
};
|
|
31
|
-
return [
|
|
32
|
-
runtimeFunctionId(definition),
|
|
33
|
-
source.name,
|
|
34
|
-
locator?.packageName ?? null,
|
|
35
|
-
locator?.packageRelativePath ?? null,
|
|
36
|
-
source.line,
|
|
37
|
-
source.column
|
|
38
|
-
];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// ../recorder/src/runtime-symbol.ts
|
|
42
|
-
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
43
|
-
|
|
44
|
-
// ../instrumentation/src/classify-function.ts
|
|
45
|
-
import ts3 from "typescript";
|
|
46
|
-
|
|
47
1
|
// ../instrumentation/src/collect-instrumentation-delta.ts
|
|
48
2
|
import ts from "typescript";
|
|
49
3
|
var paramBindingFromName = (name, sourceFile) => {
|
|
@@ -112,91 +66,6 @@ var mappedLocation = (sourceFile, position, absolutePath, mapLocation) => {
|
|
|
112
66
|
};
|
|
113
67
|
return mapLocation ? mapLocation(raw) : raw;
|
|
114
68
|
};
|
|
115
|
-
var unwrapExpression = (expression) => {
|
|
116
|
-
let current = expression;
|
|
117
|
-
while (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current)) {
|
|
118
|
-
current = current.expression;
|
|
119
|
-
}
|
|
120
|
-
if (ts.isAwaitExpression(current)) return unwrapExpression(current.expression);
|
|
121
|
-
return current;
|
|
122
|
-
};
|
|
123
|
-
var calleeFromExpression = (expression, sourceFile) => {
|
|
124
|
-
const current = unwrapExpression(expression);
|
|
125
|
-
if (ts.isIdentifier(current)) {
|
|
126
|
-
return { calleeName: current.text, calleeText: current.text };
|
|
127
|
-
}
|
|
128
|
-
if (ts.isPropertyAccessExpression(current) && ts.isIdentifier(current.name)) {
|
|
129
|
-
return {
|
|
130
|
-
calleeName: current.name.text,
|
|
131
|
-
calleeText: current.getText(sourceFile).replace(/\s+/g, "")
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
return null;
|
|
135
|
-
};
|
|
136
|
-
var resultBindingForCall = (call) => {
|
|
137
|
-
let node = call.parent;
|
|
138
|
-
if (ts.isAwaitExpression(node)) node = node.parent;
|
|
139
|
-
if (!ts.isVariableDeclaration(node)) return null;
|
|
140
|
-
if (!ts.isIdentifier(node.name)) return null;
|
|
141
|
-
const initializer = node.initializer;
|
|
142
|
-
if (!initializer) return null;
|
|
143
|
-
const inner = unwrapExpression(initializer);
|
|
144
|
-
if (inner !== call) return null;
|
|
145
|
-
return node.name.text;
|
|
146
|
-
};
|
|
147
|
-
var argIdentifiersForCall = (call) => {
|
|
148
|
-
const identifiers = [];
|
|
149
|
-
call.arguments?.forEach((argument, index) => {
|
|
150
|
-
if (ts.isIdentifier(argument)) {
|
|
151
|
-
identifiers.push({ index, kind: "identifier", name: argument.text });
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (!ts.isObjectLiteralExpression(argument)) return;
|
|
155
|
-
const properties = [];
|
|
156
|
-
for (const property of argument.properties) {
|
|
157
|
-
if (ts.isShorthandPropertyAssignment(property)) {
|
|
158
|
-
properties.push({ key: property.name.text, name: property.name.text });
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && ts.isIdentifier(property.initializer)) {
|
|
162
|
-
properties.push({ key: property.name.text, name: property.initializer.text });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (properties.length > 0) {
|
|
166
|
-
identifiers.push({ index, kind: "object", properties });
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
return identifiers;
|
|
170
|
-
};
|
|
171
|
-
var collectCallSite = (call, caller, context) => {
|
|
172
|
-
const callee = calleeFromExpression(call.expression, context.sourceFile);
|
|
173
|
-
if (!callee) return null;
|
|
174
|
-
const start = mappedLocation(
|
|
175
|
-
context.sourceFile,
|
|
176
|
-
call.getStart(context.sourceFile),
|
|
177
|
-
context.absolutePath,
|
|
178
|
-
context.mapLocation
|
|
179
|
-
);
|
|
180
|
-
const end = mappedLocation(
|
|
181
|
-
context.sourceFile,
|
|
182
|
-
call.end,
|
|
183
|
-
context.absolutePath,
|
|
184
|
-
context.mapLocation
|
|
185
|
-
);
|
|
186
|
-
if (!start || !end) return null;
|
|
187
|
-
return {
|
|
188
|
-
callerFunctionId: caller.functionId,
|
|
189
|
-
calleeName: callee.calleeName,
|
|
190
|
-
calleeText: callee.calleeText,
|
|
191
|
-
filePath: start.filePath,
|
|
192
|
-
line: start.line,
|
|
193
|
-
column: start.column,
|
|
194
|
-
endLine: end.line,
|
|
195
|
-
endColumn: end.column,
|
|
196
|
-
resultBinding: resultBindingForCall(call),
|
|
197
|
-
argIdentifiers: argIdentifiersForCall(call)
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
69
|
var collectParamDestructure = (declaration, caller, context) => {
|
|
201
70
|
if (!declaration.initializer || !ts.isIdentifier(declaration.initializer)) return null;
|
|
202
71
|
if (!ts.isObjectBindingPattern(declaration.name) && !ts.isArrayBindingPattern(declaration.name)) {
|
|
@@ -221,271 +90,6 @@ var collectParamDestructure = (declaration, caller, context) => {
|
|
|
221
90
|
};
|
|
222
91
|
};
|
|
223
92
|
|
|
224
|
-
// ../instrumentation/src/parse-source.ts
|
|
225
|
-
import ts2 from "typescript";
|
|
226
|
-
var scriptKindFor = (filePath) => {
|
|
227
|
-
if (/\.tsx$/i.test(filePath)) return ts2.ScriptKind.TSX;
|
|
228
|
-
if (/\.jsx$/i.test(filePath)) return ts2.ScriptKind.JSX;
|
|
229
|
-
if (/\.[cm]?ts$/i.test(filePath)) return ts2.ScriptKind.TS;
|
|
230
|
-
return ts2.ScriptKind.JS;
|
|
231
|
-
};
|
|
232
|
-
var parseSource = (source, filePath) => ts2.createSourceFile(filePath, source, ts2.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
233
|
-
var peel = (expression) => {
|
|
234
|
-
let current = expression;
|
|
235
|
-
while (ts2.isParenthesizedExpression(current) || ts2.isNonNullExpression(current) || ts2.isAsExpression(current) || ts2.isTypeAssertionExpression(current) || ts2.isSatisfiesExpression(current)) {
|
|
236
|
-
current = current.expression;
|
|
237
|
-
}
|
|
238
|
-
return current;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// ../instrumentation/src/classify-function.ts
|
|
242
|
-
var ALLOWED_STATIC_CALLS = /* @__PURE__ */ new Map([
|
|
243
|
-
["Array", /* @__PURE__ */ new Set(["isArray"])],
|
|
244
|
-
["Boolean", /* @__PURE__ */ new Set()],
|
|
245
|
-
["Number", /* @__PURE__ */ new Set(["isNaN", "isFinite"])],
|
|
246
|
-
["Object", /* @__PURE__ */ new Set(["is"])]
|
|
247
|
-
]);
|
|
248
|
-
var functionName = (node, sourceFile) => {
|
|
249
|
-
if (ts3.isConstructorDeclaration(node)) return "constructor";
|
|
250
|
-
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
251
|
-
const parent = node.parent;
|
|
252
|
-
if (ts3.isVariableDeclaration(parent) && ts3.isIdentifier(parent.name)) return parent.name.text;
|
|
253
|
-
if (ts3.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
254
|
-
if (ts3.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
255
|
-
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
256
|
-
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
257
|
-
};
|
|
258
|
-
var functionLocationPosition = (node, sourceFile) => {
|
|
259
|
-
if (node.name) return node.name.getStart(sourceFile);
|
|
260
|
-
const parent = node.parent;
|
|
261
|
-
if ((ts3.isVariableDeclaration(parent) || ts3.isPropertyAssignment(parent)) && parent.name) {
|
|
262
|
-
return parent.name.getStart(sourceFile);
|
|
263
|
-
}
|
|
264
|
-
return node.getStart(sourceFile);
|
|
265
|
-
};
|
|
266
|
-
var isSupportedFunction = (node) => {
|
|
267
|
-
if (!ts3.isFunctionDeclaration(node) && !ts3.isFunctionExpression(node) && !ts3.isArrowFunction(node) && !ts3.isMethodDeclaration(node) && !ts3.isGetAccessorDeclaration(node) && !ts3.isSetAccessorDeclaration(node)) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
271
|
-
return true;
|
|
272
|
-
};
|
|
273
|
-
var singleReturnedExpression = (body) => {
|
|
274
|
-
if (!ts3.isBlock(body)) return body;
|
|
275
|
-
if (body.statements.length === 0) return void 0;
|
|
276
|
-
if (body.statements.length !== 1) return void 0;
|
|
277
|
-
const statement = body.statements[0];
|
|
278
|
-
if (!statement || !ts3.isReturnStatement(statement)) return void 0;
|
|
279
|
-
return statement.expression;
|
|
280
|
-
};
|
|
281
|
-
var isLiteralExpression = (expression) => {
|
|
282
|
-
const node = peel(expression);
|
|
283
|
-
if (ts3.isStringLiteral(node) || ts3.isNoSubstitutionTemplateLiteral(node)) return true;
|
|
284
|
-
if (ts3.isNumericLiteral(node)) return true;
|
|
285
|
-
if (node.kind === ts3.SyntaxKind.TrueKeyword || node.kind === ts3.SyntaxKind.FalseKeyword || node.kind === ts3.SyntaxKind.NullKeyword) {
|
|
286
|
-
return true;
|
|
287
|
-
}
|
|
288
|
-
if (ts3.isIdentifier(node) && (node.text === "undefined" || node.text === "NaN")) return true;
|
|
289
|
-
return false;
|
|
290
|
-
};
|
|
291
|
-
var isLiteralOnlyBody = (body) => {
|
|
292
|
-
if (ts3.isBlock(body)) {
|
|
293
|
-
if (body.statements.length === 0) return true;
|
|
294
|
-
if (body.statements.length !== 1) return false;
|
|
295
|
-
const statement = body.statements[0];
|
|
296
|
-
if (!statement || !ts3.isReturnStatement(statement)) return false;
|
|
297
|
-
return !statement.expression || isLiteralExpression(statement.expression);
|
|
298
|
-
}
|
|
299
|
-
return isLiteralExpression(body);
|
|
300
|
-
};
|
|
301
|
-
var identifierParams = (node) => {
|
|
302
|
-
const names = [];
|
|
303
|
-
for (const parameter of node.parameters) {
|
|
304
|
-
if (ts3.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
305
|
-
if (!ts3.isIdentifier(parameter.name) || parameter.dotDotDotToken) return [];
|
|
306
|
-
names.push(parameter.name.text);
|
|
307
|
-
}
|
|
308
|
-
return names;
|
|
309
|
-
};
|
|
310
|
-
var isIdentityFunction = (node) => {
|
|
311
|
-
const params = identifierParams(node);
|
|
312
|
-
if (params.length !== 1 || !node.body) return false;
|
|
313
|
-
const returned = singleReturnedExpression(node.body);
|
|
314
|
-
if (!returned) return false;
|
|
315
|
-
const value = peel(returned);
|
|
316
|
-
return ts3.isIdentifier(value) && value.text === params[0];
|
|
317
|
-
};
|
|
318
|
-
var isAllowedTypeCall = (expression) => {
|
|
319
|
-
const callee = peel(expression);
|
|
320
|
-
if (ts3.isIdentifier(callee)) {
|
|
321
|
-
return callee.text === "Boolean";
|
|
322
|
-
}
|
|
323
|
-
if (!ts3.isPropertyAccessExpression(callee) || !ts3.isIdentifier(callee.expression)) return false;
|
|
324
|
-
const allowed = ALLOWED_STATIC_CALLS.get(callee.expression.text);
|
|
325
|
-
return !!allowed && ts3.isIdentifier(callee.name) && allowed.has(callee.name.text);
|
|
326
|
-
};
|
|
327
|
-
var isPredicateAtom = (expression) => {
|
|
328
|
-
const node = peel(expression);
|
|
329
|
-
if (isLiteralExpression(node) || ts3.isIdentifier(node)) return true;
|
|
330
|
-
if (node.kind === ts3.SyntaxKind.ThisKeyword) return true;
|
|
331
|
-
if (ts3.isPropertyAccessExpression(node)) return isPredicateAtom(node.expression);
|
|
332
|
-
if (ts3.isElementAccessExpression(node)) {
|
|
333
|
-
return isPredicateAtom(node.expression) && isPredicateAtom(node.argumentExpression);
|
|
334
|
-
}
|
|
335
|
-
return false;
|
|
336
|
-
};
|
|
337
|
-
var isPredicateExpression = (expression) => {
|
|
338
|
-
const node = peel(expression);
|
|
339
|
-
if (ts3.isTypeOfExpression(node)) return isPredicateAtom(node.expression);
|
|
340
|
-
if (ts3.isPrefixUnaryExpression(node) && node.operator === ts3.SyntaxKind.ExclamationToken) {
|
|
341
|
-
return isPredicateExpression(node.operand) || isPredicateAtom(node.operand);
|
|
342
|
-
}
|
|
343
|
-
if (ts3.isBinaryExpression(node)) {
|
|
344
|
-
const kind = node.operatorToken.kind;
|
|
345
|
-
if (kind === ts3.SyntaxKind.EqualsEqualsEqualsToken || kind === ts3.SyntaxKind.ExclamationEqualsEqualsToken || kind === ts3.SyntaxKind.EqualsEqualsToken || kind === ts3.SyntaxKind.ExclamationEqualsToken || kind === ts3.SyntaxKind.LessThanToken || kind === ts3.SyntaxKind.GreaterThanToken || kind === ts3.SyntaxKind.LessThanEqualsToken || kind === ts3.SyntaxKind.GreaterThanEqualsToken || kind === ts3.SyntaxKind.AmpersandAmpersandToken || kind === ts3.SyntaxKind.BarBarToken || kind === ts3.SyntaxKind.QuestionQuestionToken || kind === ts3.SyntaxKind.InstanceOfKeyword) {
|
|
346
|
-
const side = (value) => isPredicateExpression(value) || isPredicateAtom(value);
|
|
347
|
-
return side(node.left) && side(node.right);
|
|
348
|
-
}
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
if (ts3.isCallExpression(node)) {
|
|
352
|
-
return isAllowedTypeCall(node.expression) && node.arguments.every(
|
|
353
|
-
(argument) => isPredicateExpression(argument) || isPredicateAtom(argument)
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
return false;
|
|
357
|
-
};
|
|
358
|
-
var bodyHasDisallowedControl = (body) => {
|
|
359
|
-
let found2 = false;
|
|
360
|
-
const visit = (node) => {
|
|
361
|
-
if (found2) return;
|
|
362
|
-
if (ts3.isAwaitExpression(node) || ts3.isYieldExpression(node) || ts3.isThrowStatement(node) || ts3.isTryStatement(node) || ts3.isNewExpression(node)) {
|
|
363
|
-
found2 = true;
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
if (ts3.isBinaryExpression(node) && node.operatorToken.kind === ts3.SyntaxKind.EqualsToken) {
|
|
367
|
-
found2 = true;
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
ts3.forEachChild(node, visit);
|
|
371
|
-
};
|
|
372
|
-
visit(body);
|
|
373
|
-
return found2;
|
|
374
|
-
};
|
|
375
|
-
var isObjectEntriesWrapper = (body) => {
|
|
376
|
-
const returned = singleReturnedExpression(body);
|
|
377
|
-
if (!returned) return false;
|
|
378
|
-
let current = peel(returned);
|
|
379
|
-
while (ts3.isCallExpression(current) && ts3.isPropertyAccessExpression(current.expression)) {
|
|
380
|
-
const method = current.expression.name.getText();
|
|
381
|
-
if (method === "filter" || method === "map" || method === "flatMap") {
|
|
382
|
-
current = peel(current.expression.expression);
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
if (!ts3.isCallExpression(current) || !ts3.isPropertyAccessExpression(current.expression)) {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
return ts3.isIdentifier(current.expression.expression) && current.expression.expression.text === "Object" && ts3.isIdentifier(current.expression.name) && (current.expression.name.text === "entries" || current.expression.name.text === "keys" || current.expression.name.text === "values");
|
|
391
|
-
};
|
|
392
|
-
var isSimpleReadBody = (body) => {
|
|
393
|
-
const returned = singleReturnedExpression(body);
|
|
394
|
-
if (!returned || bodyHasDisallowedControl(body)) return false;
|
|
395
|
-
const value = peel(returned);
|
|
396
|
-
if (ts3.isIdentifier(value)) return true;
|
|
397
|
-
if (ts3.isPropertyAccessExpression(value) && isPredicateAtom(value)) return true;
|
|
398
|
-
if (!ts3.isCallExpression(value) || value.arguments.length !== 1) return false;
|
|
399
|
-
const argument = value.arguments[0];
|
|
400
|
-
if (!argument) return false;
|
|
401
|
-
if (!ts3.isPropertyAccessExpression(value.expression) || !ts3.isIdentifier(value.expression.expression)) {
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
return value.expression.expression.text === "$" && ts3.isIdentifier(value.expression.name) && value.expression.name.text === "get" && ts3.isIdentifier(peel(argument));
|
|
405
|
-
};
|
|
406
|
-
var classifyBody = (node, name, sourceFile, filePath, policy) => {
|
|
407
|
-
const returned = singleReturnedExpression(node.body);
|
|
408
|
-
const body = {
|
|
409
|
-
isLiteralOnly: isLiteralOnlyBody(node.body),
|
|
410
|
-
isIdentity: isIdentityFunction(node),
|
|
411
|
-
isSimpleRead: isSimpleReadBody(node.body),
|
|
412
|
-
isPredicate: Boolean(
|
|
413
|
-
returned && isPredicateExpression(returned) && !bodyHasDisallowedControl(node.body)
|
|
414
|
-
)
|
|
415
|
-
};
|
|
416
|
-
const decided = policy?.classifyFunction({ node, sourceFile, filePath, name, body });
|
|
417
|
-
if (decided) {
|
|
418
|
-
return {
|
|
419
|
-
captureClass: decided.captureClass,
|
|
420
|
-
captureReason: decided.captureReason,
|
|
421
|
-
inferredName: decided.inferredName,
|
|
422
|
-
reactiveKind: decided.reactiveKind,
|
|
423
|
-
compilerRole: decided.role,
|
|
424
|
-
useSyntheticLocation: decided.useSyntheticLocation
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
if (isIdentityFunction(node)) {
|
|
428
|
-
return { captureClass: "structure", captureReason: "identity wrapper" };
|
|
429
|
-
}
|
|
430
|
-
if (body.isPredicate) {
|
|
431
|
-
return { captureClass: "structure", captureReason: "tiny predicate" };
|
|
432
|
-
}
|
|
433
|
-
if (isObjectEntriesWrapper(node.body) && !bodyHasDisallowedControl(node.body)) {
|
|
434
|
-
return { captureClass: "structure", captureReason: "object-entries wrapper" };
|
|
435
|
-
}
|
|
436
|
-
if (name === "anonymous" && node.body.getText(sourceFile).length < 80 && !bodyHasDisallowedControl(node.body)) {
|
|
437
|
-
return { captureClass: "structure", captureReason: "tiny anonymous helper" };
|
|
438
|
-
}
|
|
439
|
-
return { captureClass: "full", captureReason: "application function" };
|
|
440
|
-
};
|
|
441
|
-
var classifyFunctions = (source, filePath, mapLocation, policy) => {
|
|
442
|
-
const sourceFile = parseSource(source, filePath);
|
|
443
|
-
const absolutePath = resolve(filePath);
|
|
444
|
-
const classifications = [];
|
|
445
|
-
const visit = (node) => {
|
|
446
|
-
if (isSupportedFunction(node) && node.body) {
|
|
447
|
-
const rawName = functionName(node, sourceFile).replace(/@\d+:\d+$/, "");
|
|
448
|
-
const classified = classifyBody(node, rawName, sourceFile, filePath, policy);
|
|
449
|
-
const location = classified.useSyntheticLocation ? { filePath: absolutePath, line: 1, column: 1 } : mappedLocation(
|
|
450
|
-
sourceFile,
|
|
451
|
-
functionLocationPosition(node, sourceFile),
|
|
452
|
-
absolutePath,
|
|
453
|
-
mapLocation
|
|
454
|
-
);
|
|
455
|
-
if (!location) {
|
|
456
|
-
ts3.forEachChild(node, visit);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
const name = classified.inferredName ?? rawName;
|
|
460
|
-
const plan = encodeFunctionPlan({
|
|
461
|
-
filePath: location.filePath,
|
|
462
|
-
name,
|
|
463
|
-
line: location.line,
|
|
464
|
-
column: location.column
|
|
465
|
-
});
|
|
466
|
-
classifications.push({
|
|
467
|
-
functionId: plan[0],
|
|
468
|
-
name,
|
|
469
|
-
captureClass: classified.captureClass,
|
|
470
|
-
captureReason: classified.captureReason,
|
|
471
|
-
line: location.line,
|
|
472
|
-
column: location.column,
|
|
473
|
-
filePath: location.filePath,
|
|
474
|
-
start: node.getStart(sourceFile),
|
|
475
|
-
end: node.end,
|
|
476
|
-
bodyStart: node.body.getStart(sourceFile),
|
|
477
|
-
bodyEnd: node.body.end,
|
|
478
|
-
...classified.reactiveKind ? { reactiveKind: classified.reactiveKind } : {},
|
|
479
|
-
...classified.compilerRole ? { compilerRole: classified.compilerRole } : {}
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
ts3.forEachChild(node, visit);
|
|
483
|
-
};
|
|
484
|
-
visit(sourceFile);
|
|
485
|
-
policy?.finalizeClassifications?.(classifications);
|
|
486
|
-
return classifications;
|
|
487
|
-
};
|
|
488
|
-
|
|
489
93
|
// ../instrumentation/src/edits.ts
|
|
490
94
|
var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
491
95
|
var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
@@ -819,7 +423,7 @@ function normalizePath(url, type) {
|
|
|
819
423
|
}
|
|
820
424
|
url.path = path;
|
|
821
425
|
}
|
|
822
|
-
function
|
|
426
|
+
function resolve(input, base) {
|
|
823
427
|
if (!input && !base)
|
|
824
428
|
return "";
|
|
825
429
|
const url = parseUrl(input);
|
|
@@ -882,7 +486,7 @@ function stripFilename(path) {
|
|
|
882
486
|
function resolver(mapUrl, sourceRoot) {
|
|
883
487
|
const from = stripFilename(mapUrl);
|
|
884
488
|
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
885
|
-
return (source) =>
|
|
489
|
+
return (source) => resolve(prefix + (source || ""), from);
|
|
886
490
|
}
|
|
887
491
|
var COLUMN = 0;
|
|
888
492
|
var SOURCES_INDEX = 1;
|
|
@@ -995,8 +599,8 @@ var TraceMap = class {
|
|
|
995
599
|
this.sources = sources;
|
|
996
600
|
this.sourcesContent = sourcesContent;
|
|
997
601
|
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
998
|
-
const
|
|
999
|
-
this.resolvedSources = sources.map(
|
|
602
|
+
const resolve3 = resolver(mapUrl, sourceRoot);
|
|
603
|
+
this.resolvedSources = sources.map(resolve3);
|
|
1000
604
|
const { mappings } = parsed;
|
|
1001
605
|
if (typeof mappings === "string") {
|
|
1002
606
|
this._encoded = mappings;
|
|
@@ -1364,69 +968,151 @@ var withFunctionMetricDeclarationRegistration = (code, declarations) => {
|
|
|
1364
968
|
return `${code.slice(0, match.index)}${suffix}${code.slice(match.index)}`;
|
|
1365
969
|
};
|
|
1366
970
|
|
|
1367
|
-
// ../instrumentation/src/
|
|
1368
|
-
import
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
import ts4 from "typescript";
|
|
1376
|
-
var nodeFlags = ts4.NodeFlags;
|
|
1377
|
-
var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
|
|
1378
|
-
var USING_FLAG = nodeFlags.Using ?? 0;
|
|
1379
|
-
var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
1380
|
-
"AwaitExpression",
|
|
1381
|
-
"AwaitKeyword",
|
|
1382
|
-
"YieldExpression",
|
|
1383
|
-
"YieldKeyword",
|
|
1384
|
-
"UsingKeyword"
|
|
1385
|
-
];
|
|
1386
|
-
var isFunctionLike = (node) => ts4.isFunctionLike(node);
|
|
1387
|
-
var isAsyncFunctionLike = (node) => (ts4.getCombinedModifierFlags(node) & ts4.ModifierFlags.Async) !== 0;
|
|
1388
|
-
var isAsyncGeneratorLike = (node) => isFunctionLike(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
|
|
1389
|
-
var isSyncGeneratorLike = (node) => isFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken) && !isAsyncFunctionLike(node);
|
|
1390
|
-
var visitOwnBody = (node, visitNode) => {
|
|
1391
|
-
if (!node.body) return;
|
|
1392
|
-
const visit = (candidate) => {
|
|
1393
|
-
if (candidate !== node && isFunctionLike(candidate)) {
|
|
1394
|
-
visitNode(candidate);
|
|
1395
|
-
return;
|
|
1396
|
-
}
|
|
1397
|
-
if (visitNode(candidate)) return;
|
|
1398
|
-
ts4.forEachChild(candidate, visit);
|
|
1399
|
-
};
|
|
1400
|
-
visit(node.body);
|
|
971
|
+
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
972
|
+
import ts2 from "typescript";
|
|
973
|
+
var unwrap = (expression) => {
|
|
974
|
+
let current = expression;
|
|
975
|
+
while (ts2.isParenthesizedExpression(current) || ts2.isNonNullExpression(current)) {
|
|
976
|
+
current = current.expression;
|
|
977
|
+
}
|
|
978
|
+
return current;
|
|
1401
979
|
};
|
|
1402
|
-
var
|
|
1403
|
-
const
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return
|
|
1409
|
-
}
|
|
1410
|
-
|
|
980
|
+
var isSafeLiteralInitializer = (expression) => {
|
|
981
|
+
const current = unwrap(expression);
|
|
982
|
+
if (ts2.isNumericLiteral(current) || ts2.isStringLiteral(current) || ts2.isNoSubstitutionTemplateLiteral(current) || ts2.isBigIntLiteral(current)) {
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
if (current.kind === ts2.SyntaxKind.TrueKeyword || current.kind === ts2.SyntaxKind.FalseKeyword || current.kind === ts2.SyntaxKind.NullKeyword) {
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
if (ts2.isIdentifier(current) && current.text === "undefined") return true;
|
|
989
|
+
if (ts2.isPrefixUnaryExpression(current) && (current.operator === ts2.SyntaxKind.PlusToken || current.operator === ts2.SyntaxKind.MinusToken)) {
|
|
990
|
+
return ts2.isNumericLiteral(unwrap(current.operand));
|
|
991
|
+
}
|
|
992
|
+
return false;
|
|
1411
993
|
};
|
|
1412
|
-
var
|
|
1413
|
-
const
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
if (
|
|
1417
|
-
if (from >= end) break;
|
|
1418
|
-
if (from > cursor) slices.push([cursor, Math.min(from, end)]);
|
|
1419
|
-
cursor = Math.max(cursor, to);
|
|
994
|
+
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
995
|
+
for (const parameter of node.parameters) {
|
|
996
|
+
if (ts2.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
997
|
+
if (!parameter.initializer) continue;
|
|
998
|
+
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
1420
999
|
}
|
|
1421
|
-
|
|
1422
|
-
return slices;
|
|
1000
|
+
return false;
|
|
1423
1001
|
};
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1002
|
+
|
|
1003
|
+
// ../instrumentation/src/parse-source.ts
|
|
1004
|
+
import ts3 from "typescript";
|
|
1005
|
+
|
|
1006
|
+
// ../instrumentation/src/source-map-location.ts
|
|
1007
|
+
import { dirname, join } from "node:path";
|
|
1008
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1009
|
+
var baseName = (path) => path.replaceAll("\\", "/").split("/").pop()?.split("?")[0] ?? "";
|
|
1010
|
+
var isWindowsAbsolute = (path) => /^[A-Za-z]:[\\/]/.test(path);
|
|
1011
|
+
var sameSourceFile = (source, generatedPath) => {
|
|
1012
|
+
const sourceName = baseName(source);
|
|
1013
|
+
const generatedName = baseName(generatedPath);
|
|
1014
|
+
return sourceName.length > 0 && sourceName === generatedName;
|
|
1015
|
+
};
|
|
1016
|
+
var toFilePath = (source, generatedPath) => {
|
|
1017
|
+
if (sameSourceFile(source, generatedPath)) return generatedPath;
|
|
1018
|
+
if (source.startsWith("file:")) {
|
|
1019
|
+
try {
|
|
1020
|
+
return fileURLToPath(source);
|
|
1021
|
+
} catch {
|
|
1022
|
+
return generatedPath;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
if (isWindowsAbsolute(source) || source.startsWith("/")) return source;
|
|
1026
|
+
return join(dirname(generatedPath), source);
|
|
1027
|
+
};
|
|
1028
|
+
var isSourceMapInput = (value) => {
|
|
1029
|
+
if (typeof value === "string") return true;
|
|
1030
|
+
if (!value || typeof value !== "object") return false;
|
|
1031
|
+
return value instanceof TraceMap || "mappings" in value;
|
|
1032
|
+
};
|
|
1033
|
+
var createSourceMapLocationMapper = (generatedPath, map) => {
|
|
1034
|
+
if (!isSourceMapInput(map)) return void 0;
|
|
1035
|
+
try {
|
|
1036
|
+
const traceMap = new TraceMap(map, pathToFileURL(generatedPath).href);
|
|
1037
|
+
return (generated) => {
|
|
1038
|
+
let original = originalPositionFor(traceMap, {
|
|
1039
|
+
line: generated.line,
|
|
1040
|
+
column: Math.max(0, generated.column - 1)
|
|
1041
|
+
});
|
|
1042
|
+
if (!original.source || original.line == null) {
|
|
1043
|
+
original = originalPositionFor(traceMap, {
|
|
1044
|
+
line: generated.line,
|
|
1045
|
+
column: 0
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
if (!original.source || original.line == null) return void 0;
|
|
1049
|
+
return {
|
|
1050
|
+
filePath: toFilePath(original.source, generatedPath),
|
|
1051
|
+
line: original.line,
|
|
1052
|
+
column: (original.column ?? 0) + 1
|
|
1053
|
+
};
|
|
1054
|
+
};
|
|
1055
|
+
} catch {
|
|
1056
|
+
return void 0;
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
// ../instrumentation/src/suspension-whitelist.ts
|
|
1061
|
+
import ts4 from "typescript";
|
|
1062
|
+
var nodeFlags = ts4.NodeFlags;
|
|
1063
|
+
var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
|
|
1064
|
+
var USING_FLAG = nodeFlags.Using ?? 0;
|
|
1065
|
+
var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
1066
|
+
"AwaitExpression",
|
|
1067
|
+
"AwaitKeyword",
|
|
1068
|
+
"YieldExpression",
|
|
1069
|
+
"YieldKeyword",
|
|
1070
|
+
"UsingKeyword"
|
|
1071
|
+
];
|
|
1072
|
+
var isFunctionLike = (node) => ts4.isFunctionLike(node);
|
|
1073
|
+
var isAsyncFunctionLike = (node) => (ts4.getCombinedModifierFlags(node) & ts4.ModifierFlags.Async) !== 0;
|
|
1074
|
+
var isAsyncGeneratorLike = (node) => isFunctionLike(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
|
|
1075
|
+
var isSyncGeneratorLike = (node) => isFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken) && !isAsyncFunctionLike(node);
|
|
1076
|
+
var visitOwnBody = (node, visitNode) => {
|
|
1077
|
+
if (!node.body) return;
|
|
1078
|
+
const visit = (candidate) => {
|
|
1079
|
+
if (candidate !== node && isFunctionLike(candidate)) {
|
|
1080
|
+
visitNode(candidate);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
if (visitNode(candidate)) return;
|
|
1084
|
+
ts4.forEachChild(candidate, visit);
|
|
1085
|
+
};
|
|
1086
|
+
visit(node.body);
|
|
1087
|
+
};
|
|
1088
|
+
var nestedFunctionSpans = (node, sourceFile) => {
|
|
1089
|
+
const spans = [];
|
|
1090
|
+
visitOwnBody(node, (candidate) => {
|
|
1091
|
+
if (candidate !== node && isFunctionLike(candidate)) {
|
|
1092
|
+
spans.push([candidate.getStart(sourceFile), candidate.end]);
|
|
1093
|
+
}
|
|
1094
|
+
return void 0;
|
|
1095
|
+
});
|
|
1096
|
+
return spans.sort((left, right) => left[0] - right[0]);
|
|
1097
|
+
};
|
|
1098
|
+
var slicesOutside = (start, end, spans) => {
|
|
1099
|
+
const slices = [];
|
|
1100
|
+
let cursor = start;
|
|
1101
|
+
for (const [from, to] of spans) {
|
|
1102
|
+
if (to <= cursor) continue;
|
|
1103
|
+
if (from >= end) break;
|
|
1104
|
+
if (from > cursor) slices.push([cursor, Math.min(from, end)]);
|
|
1105
|
+
cursor = Math.max(cursor, to);
|
|
1106
|
+
}
|
|
1107
|
+
if (cursor < end) slices.push([cursor, end]);
|
|
1108
|
+
return slices;
|
|
1109
|
+
};
|
|
1110
|
+
var sliceHasAwaitKeyword = (source, start, end) => {
|
|
1111
|
+
if (end <= start) return false;
|
|
1112
|
+
const scanner = ts4.createScanner(
|
|
1113
|
+
ts4.ScriptTarget.Latest,
|
|
1114
|
+
true,
|
|
1115
|
+
ts4.LanguageVariant.Standard,
|
|
1430
1116
|
source.slice(start, end)
|
|
1431
1117
|
);
|
|
1432
1118
|
while (true) {
|
|
@@ -1498,9 +1184,53 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
|
1498
1184
|
return { action: "inline" };
|
|
1499
1185
|
};
|
|
1500
1186
|
|
|
1187
|
+
// ../instrumentation/src/svelte-module-path.ts
|
|
1188
|
+
var isSvelteCompiledPath = (idOrPath) => {
|
|
1189
|
+
const path = idOrPath.split("?")[0]?.replaceAll("\\", "/") ?? "";
|
|
1190
|
+
return path.endsWith(".svelte") || path.endsWith(".svelte.ts") || path.endsWith(".svelte.js");
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1501
1193
|
// ../instrumentation/src/transform-source.ts
|
|
1502
|
-
import { basename, resolve as
|
|
1503
|
-
|
|
1194
|
+
import { basename, resolve as resolve2 } from "node:path";
|
|
1195
|
+
|
|
1196
|
+
// ../recorder/src/encoded-function-plan.ts
|
|
1197
|
+
var withPreBodyParameterEvaluation = (plan) => [
|
|
1198
|
+
plan[0],
|
|
1199
|
+
plan[1],
|
|
1200
|
+
plan[2],
|
|
1201
|
+
plan[3],
|
|
1202
|
+
plan[4],
|
|
1203
|
+
plan[5],
|
|
1204
|
+
plan[6],
|
|
1205
|
+
1
|
|
1206
|
+
];
|
|
1207
|
+
|
|
1208
|
+
// ../recorder/src/function-plan.ts
|
|
1209
|
+
import {
|
|
1210
|
+
runtimeFunctionId,
|
|
1211
|
+
sourceLocatorFromFile
|
|
1212
|
+
} from "@rasputin-ai/core";
|
|
1213
|
+
var encodeFunctionPlan = (source) => {
|
|
1214
|
+
const locator = sourceLocatorFromFile(source.filePath);
|
|
1215
|
+
const definition = {
|
|
1216
|
+
name: source.name,
|
|
1217
|
+
...locator ? { source: { ...locator, line: source.line, column: source.column } } : {}
|
|
1218
|
+
};
|
|
1219
|
+
return [
|
|
1220
|
+
runtimeFunctionId(definition),
|
|
1221
|
+
source.name,
|
|
1222
|
+
locator?.packageName ?? null,
|
|
1223
|
+
locator?.packageRelativePath ?? null,
|
|
1224
|
+
source.line,
|
|
1225
|
+
source.column
|
|
1226
|
+
];
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
// ../recorder/src/runtime-symbol.ts
|
|
1230
|
+
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
1231
|
+
|
|
1232
|
+
// ../instrumentation/src/transform-source.ts
|
|
1233
|
+
import ts8 from "typescript";
|
|
1504
1234
|
|
|
1505
1235
|
// ../instrumentation/src/function-metric-declarations.ts
|
|
1506
1236
|
import {
|
|
@@ -1754,57 +1484,25 @@ var collectFunctionMetricDeclarations = (input) => {
|
|
|
1754
1484
|
return declarations;
|
|
1755
1485
|
};
|
|
1756
1486
|
|
|
1757
|
-
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
1758
|
-
import ts6 from "typescript";
|
|
1759
|
-
var unwrap = (expression) => {
|
|
1760
|
-
let current = expression;
|
|
1761
|
-
while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
|
|
1762
|
-
current = current.expression;
|
|
1763
|
-
}
|
|
1764
|
-
return current;
|
|
1765
|
-
};
|
|
1766
|
-
var isSafeLiteralInitializer = (expression) => {
|
|
1767
|
-
const current = unwrap(expression);
|
|
1768
|
-
if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
|
|
1769
|
-
return true;
|
|
1770
|
-
}
|
|
1771
|
-
if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
|
|
1772
|
-
return true;
|
|
1773
|
-
}
|
|
1774
|
-
if (ts6.isIdentifier(current) && current.text === "undefined") return true;
|
|
1775
|
-
if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
|
|
1776
|
-
return ts6.isNumericLiteral(unwrap(current.operand));
|
|
1777
|
-
}
|
|
1778
|
-
return false;
|
|
1779
|
-
};
|
|
1780
|
-
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
1781
|
-
for (const parameter of node.parameters) {
|
|
1782
|
-
if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
1783
|
-
if (!parameter.initializer) continue;
|
|
1784
|
-
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
1785
|
-
}
|
|
1786
|
-
return false;
|
|
1787
|
-
};
|
|
1788
|
-
|
|
1789
1487
|
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
1790
|
-
import
|
|
1488
|
+
import ts6 from "typescript";
|
|
1791
1489
|
var RASPUTIN_IDENT = /^__rasputin/;
|
|
1792
|
-
var
|
|
1793
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1794
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1795
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1796
|
-
return
|
|
1490
|
+
var scriptKindFor = (filePath) => {
|
|
1491
|
+
if (/\.tsx$/i.test(filePath)) return ts6.ScriptKind.TSX;
|
|
1492
|
+
if (/\.jsx$/i.test(filePath)) return ts6.ScriptKind.JSX;
|
|
1493
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts6.ScriptKind.TS;
|
|
1494
|
+
return ts6.ScriptKind.JS;
|
|
1797
1495
|
};
|
|
1798
|
-
var parse2 = (filePath, source) =>
|
|
1496
|
+
var parse2 = (filePath, source) => ts6.createSourceFile(filePath, source, ts6.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
1799
1497
|
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
1800
1498
|
var identText = (node) => {
|
|
1801
|
-
if (
|
|
1802
|
-
if (
|
|
1499
|
+
if (ts6.isIdentifier(node)) return node.text;
|
|
1500
|
+
if (ts6.isPrivateIdentifier(node)) return node.text;
|
|
1803
1501
|
return void 0;
|
|
1804
1502
|
};
|
|
1805
1503
|
var calleeName = (expression) => {
|
|
1806
|
-
if (
|
|
1807
|
-
if (
|
|
1504
|
+
if (ts6.isIdentifier(expression)) return expression.text;
|
|
1505
|
+
if (ts6.isPropertyAccessExpression(expression)) {
|
|
1808
1506
|
const object = identText(expression.expression);
|
|
1809
1507
|
const property = identText(expression.name);
|
|
1810
1508
|
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
@@ -1812,7 +1510,7 @@ var calleeName = (expression) => {
|
|
|
1812
1510
|
return void 0;
|
|
1813
1511
|
};
|
|
1814
1512
|
var isRasputinCall = (node, methods) => {
|
|
1815
|
-
if (!
|
|
1513
|
+
if (!ts6.isCallExpression(node)) return false;
|
|
1816
1514
|
const name = calleeName(node.expression);
|
|
1817
1515
|
if (!name) return false;
|
|
1818
1516
|
if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
|
|
@@ -1822,20 +1520,20 @@ var unwrapCall = (node) => {
|
|
|
1822
1520
|
let current = node;
|
|
1823
1521
|
while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
|
|
1824
1522
|
current = current.arguments[0];
|
|
1825
|
-
if (
|
|
1523
|
+
if (ts6.isParenthesizedExpression(current)) current = current.expression;
|
|
1826
1524
|
}
|
|
1827
|
-
if (
|
|
1525
|
+
if (ts6.isParenthesizedExpression(current)) return current.expression;
|
|
1828
1526
|
return current;
|
|
1829
1527
|
};
|
|
1830
1528
|
var isRasputinStatement = (node) => {
|
|
1831
|
-
if (
|
|
1832
|
-
if (
|
|
1529
|
+
if (ts6.isEmptyStatement(node)) return true;
|
|
1530
|
+
if (ts6.isVariableStatement(node)) {
|
|
1833
1531
|
return node.declarationList.declarations.every((declaration) => {
|
|
1834
1532
|
const name = identText(declaration.name);
|
|
1835
1533
|
return Boolean(name && isRasputinName(name));
|
|
1836
1534
|
});
|
|
1837
1535
|
}
|
|
1838
|
-
if (
|
|
1536
|
+
if (ts6.isExpressionStatement(node)) {
|
|
1839
1537
|
if (!isRasputinCall(node.expression)) return false;
|
|
1840
1538
|
const unwrapped = unwrapCall(node.expression);
|
|
1841
1539
|
return unwrapped === node.expression;
|
|
@@ -1849,7 +1547,7 @@ var isRasputinTryWrapper = (node) => {
|
|
|
1849
1547
|
(statement) => !isRasputinStatement(statement)
|
|
1850
1548
|
);
|
|
1851
1549
|
const leftover = catchCalls[0];
|
|
1852
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
1550
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts6.isThrowStatement(leftover) && ts6.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
|
|
1853
1551
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
1854
1552
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
1855
1553
|
};
|
|
@@ -1857,7 +1555,7 @@ var flattenStatements = (statements) => {
|
|
|
1857
1555
|
const flattened = [];
|
|
1858
1556
|
for (const statement of statements) {
|
|
1859
1557
|
if (isRasputinStatement(statement)) continue;
|
|
1860
|
-
if (
|
|
1558
|
+
if (ts6.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
1861
1559
|
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
1862
1560
|
continue;
|
|
1863
1561
|
}
|
|
@@ -1866,38 +1564,38 @@ var flattenStatements = (statements) => {
|
|
|
1866
1564
|
return flattened;
|
|
1867
1565
|
};
|
|
1868
1566
|
var extra = (node) => {
|
|
1869
|
-
if (
|
|
1567
|
+
if (ts6.isIdentifier(node) || ts6.isPrivateIdentifier(node)) {
|
|
1870
1568
|
return isRasputinName(node.text) ? "" : node.text;
|
|
1871
1569
|
}
|
|
1872
|
-
if (
|
|
1570
|
+
if (ts6.isStringLiteral(node) || ts6.isNumericLiteral(node) || ts6.isNoSubstitutionTemplateLiteral(node)) {
|
|
1873
1571
|
return node.text;
|
|
1874
1572
|
}
|
|
1875
|
-
if (
|
|
1573
|
+
if (ts6.isToken(node) && !ts6.isIdentifier(node)) return ts6.SyntaxKind[node.kind] ?? "";
|
|
1876
1574
|
return "";
|
|
1877
1575
|
};
|
|
1878
1576
|
var signatureOf = (node) => {
|
|
1879
1577
|
const unwrapped = unwrapCall(node);
|
|
1880
1578
|
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
1881
|
-
if (
|
|
1882
|
-
if (
|
|
1579
|
+
if (ts6.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
1580
|
+
if (ts6.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
1883
1581
|
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
1884
1582
|
}
|
|
1885
|
-
if (
|
|
1583
|
+
if (ts6.isBlock(unwrapped)) {
|
|
1886
1584
|
const statements = flattenStatements(unwrapped.statements);
|
|
1887
1585
|
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
1888
1586
|
}
|
|
1889
|
-
if (
|
|
1587
|
+
if (ts6.isCatchClause(unwrapped)) {
|
|
1890
1588
|
const statements = flattenStatements(unwrapped.block.statements);
|
|
1891
1589
|
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
1892
1590
|
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
1893
1591
|
}
|
|
1894
|
-
if (
|
|
1592
|
+
if (ts6.isArrowFunction(unwrapped) && ts6.isBlock(unwrapped.body)) {
|
|
1895
1593
|
const statements = flattenStatements(unwrapped.body.statements);
|
|
1896
1594
|
const only = statements[0];
|
|
1897
|
-
if (statements.length === 1 && only &&
|
|
1595
|
+
if (statements.length === 1 && only && ts6.isReturnStatement(only) && only.expression) {
|
|
1898
1596
|
const expression = only.expression;
|
|
1899
1597
|
const parts2 = [];
|
|
1900
|
-
|
|
1598
|
+
ts6.forEachChild(unwrapped, (child) => {
|
|
1901
1599
|
if (child === unwrapped.body) {
|
|
1902
1600
|
const part2 = signatureOf(expression);
|
|
1903
1601
|
if (part2) parts2.push(part2);
|
|
@@ -1910,11 +1608,11 @@ var signatureOf = (node) => {
|
|
|
1910
1608
|
}
|
|
1911
1609
|
}
|
|
1912
1610
|
const parts = [];
|
|
1913
|
-
|
|
1611
|
+
ts6.forEachChild(unwrapped, (child) => {
|
|
1914
1612
|
const part = signatureOf(child);
|
|
1915
1613
|
if (part) parts.push(part);
|
|
1916
1614
|
});
|
|
1917
|
-
const kind =
|
|
1615
|
+
const kind = ts6.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
1918
1616
|
const label = extra(unwrapped);
|
|
1919
1617
|
return `${kind}${label}[${parts.join(",")}]`;
|
|
1920
1618
|
};
|
|
@@ -1923,14 +1621,14 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
|
|
|
1923
1621
|
};
|
|
1924
1622
|
|
|
1925
1623
|
// ../instrumentation/src/verify-transformed-source.ts
|
|
1926
|
-
import
|
|
1927
|
-
var transpileForVerification = (filePath, code) =>
|
|
1624
|
+
import ts7 from "typescript";
|
|
1625
|
+
var transpileForVerification = (filePath, code) => ts7.transpileModule(code, {
|
|
1928
1626
|
compilerOptions: {
|
|
1929
1627
|
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
1930
|
-
target:
|
|
1931
|
-
module:
|
|
1628
|
+
target: ts7.ScriptTarget.ES2020,
|
|
1629
|
+
module: ts7.ModuleKind.ESNext,
|
|
1932
1630
|
allowJs: true,
|
|
1933
|
-
jsx:
|
|
1631
|
+
jsx: ts7.JsxEmit.React,
|
|
1934
1632
|
experimentalDecorators: true
|
|
1935
1633
|
},
|
|
1936
1634
|
reportDiagnostics: true,
|
|
@@ -1938,7 +1636,7 @@ var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
|
1938
1636
|
});
|
|
1939
1637
|
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
1940
1638
|
diagnostics?.some(
|
|
1941
|
-
(diagnostic) => diagnostic.category ===
|
|
1639
|
+
(diagnostic) => diagnostic.category === ts7.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
1942
1640
|
)
|
|
1943
1641
|
);
|
|
1944
1642
|
var scriptBodyForEngine = (emitted) => (
|
|
@@ -1946,40 +1644,40 @@ var scriptBodyForEngine = (emitted) => (
|
|
|
1946
1644
|
emitted.replace(/^#![^\n]*\n/, "").replaceAll("import.meta", "({})")
|
|
1947
1645
|
);
|
|
1948
1646
|
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
1949
|
-
var
|
|
1950
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1951
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1952
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1953
|
-
return
|
|
1647
|
+
var scriptKindFor2 = (filePath) => {
|
|
1648
|
+
if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
|
|
1649
|
+
if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
|
|
1650
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
|
|
1651
|
+
return ts7.ScriptKind.JS;
|
|
1954
1652
|
};
|
|
1955
|
-
var isIterationStatement = (node) =>
|
|
1653
|
+
var isIterationStatement = (node) => ts7.isForStatement(node) || ts7.isForOfStatement(node) || ts7.isForInStatement(node) || ts7.isWhileStatement(node) || ts7.isDoStatement(node);
|
|
1956
1654
|
var unwrapLabeled = (node) => {
|
|
1957
1655
|
let current = node;
|
|
1958
|
-
while (
|
|
1656
|
+
while (ts7.isLabeledStatement(current)) current = current.statement;
|
|
1959
1657
|
return current;
|
|
1960
1658
|
};
|
|
1961
1659
|
var hasInvalidLabelJump = (sourceFile) => {
|
|
1962
1660
|
const visit = (node, labels) => {
|
|
1963
|
-
if (
|
|
1661
|
+
if (ts7.isFunctionLike(node)) {
|
|
1964
1662
|
let nestedInvalid = false;
|
|
1965
|
-
|
|
1663
|
+
ts7.forEachChild(node, (child) => {
|
|
1966
1664
|
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
1967
1665
|
});
|
|
1968
1666
|
return nestedInvalid;
|
|
1969
1667
|
}
|
|
1970
|
-
if (
|
|
1668
|
+
if (ts7.isLabeledStatement(node)) {
|
|
1971
1669
|
const next = new Map(labels);
|
|
1972
1670
|
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
1973
1671
|
return visit(node.statement, next);
|
|
1974
1672
|
}
|
|
1975
|
-
if (
|
|
1673
|
+
if (ts7.isContinueStatement(node) && node.label) {
|
|
1976
1674
|
if (labels.get(node.label.text) !== true) return true;
|
|
1977
1675
|
}
|
|
1978
|
-
if (
|
|
1676
|
+
if (ts7.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
1979
1677
|
return true;
|
|
1980
1678
|
}
|
|
1981
1679
|
let invalid = false;
|
|
1982
|
-
|
|
1680
|
+
ts7.forEachChild(node, (child) => {
|
|
1983
1681
|
if (visit(child, labels)) invalid = true;
|
|
1984
1682
|
});
|
|
1985
1683
|
return invalid;
|
|
@@ -2022,12 +1720,12 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
|
2022
1720
|
var transformedSourceIsInvalid = (filePath, code) => {
|
|
2023
1721
|
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
2024
1722
|
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
2025
|
-
const sourceFile =
|
|
1723
|
+
const sourceFile = ts7.createSourceFile(
|
|
2026
1724
|
filePath,
|
|
2027
1725
|
code,
|
|
2028
|
-
|
|
1726
|
+
ts7.ScriptTarget.Latest,
|
|
2029
1727
|
true,
|
|
2030
|
-
|
|
1728
|
+
scriptKindFor2(filePath)
|
|
2031
1729
|
);
|
|
2032
1730
|
if (hasInvalidLabelJump(sourceFile)) return true;
|
|
2033
1731
|
const { diagnostics, outputText } = transpileForVerification(filePath, code);
|
|
@@ -2045,26 +1743,26 @@ var alreadyInstrumentedResult = (source) => ({
|
|
|
2045
1743
|
code: source,
|
|
2046
1744
|
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
2047
1745
|
});
|
|
2048
|
-
var
|
|
2049
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
2050
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
2051
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
2052
|
-
return
|
|
1746
|
+
var scriptKindFor3 = (filePath) => {
|
|
1747
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
1748
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
1749
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
1750
|
+
return ts8.ScriptKind.JS;
|
|
2053
1751
|
};
|
|
2054
|
-
var
|
|
2055
|
-
if (
|
|
1752
|
+
var functionName = (node, sourceFile) => {
|
|
1753
|
+
if (ts8.isConstructorDeclaration(node)) return "constructor";
|
|
2056
1754
|
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
2057
1755
|
const parent = node.parent;
|
|
2058
|
-
if (
|
|
2059
|
-
if (
|
|
2060
|
-
if (
|
|
1756
|
+
if (ts8.isVariableDeclaration(parent) && ts8.isIdentifier(parent.name)) return parent.name.text;
|
|
1757
|
+
if (ts8.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
1758
|
+
if (ts8.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
2061
1759
|
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
2062
1760
|
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
2063
1761
|
};
|
|
2064
|
-
var
|
|
1762
|
+
var functionLocationPosition = (node, sourceFile) => {
|
|
2065
1763
|
if (node.name) return node.name.getStart(sourceFile);
|
|
2066
1764
|
const parent = node.parent;
|
|
2067
|
-
if ((
|
|
1765
|
+
if ((ts8.isVariableDeclaration(parent) || ts8.isPropertyAssignment(parent)) && parent.name) {
|
|
2068
1766
|
return parent.name.getStart(sourceFile);
|
|
2069
1767
|
}
|
|
2070
1768
|
return node.getStart(sourceFile);
|
|
@@ -2077,12 +1775,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
|
2077
1775
|
}
|
|
2078
1776
|
return end;
|
|
2079
1777
|
};
|
|
2080
|
-
var isStaticPropertyName = (name) =>
|
|
1778
|
+
var isStaticPropertyName = (name) => ts8.isIdentifier(name) || ts8.isStringLiteral(name) || ts8.isNoSubstitutionTemplateLiteral(name) || ts8.isNumericLiteral(name);
|
|
2081
1779
|
var canReconstructBinding = (name) => {
|
|
2082
|
-
if (
|
|
2083
|
-
if (
|
|
1780
|
+
if (ts8.isIdentifier(name)) return true;
|
|
1781
|
+
if (ts8.isArrayBindingPattern(name)) {
|
|
2084
1782
|
return name.elements.every(
|
|
2085
|
-
(element) =>
|
|
1783
|
+
(element) => ts8.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
2086
1784
|
);
|
|
2087
1785
|
}
|
|
2088
1786
|
return name.elements.every((element) => {
|
|
@@ -2091,10 +1789,10 @@ var canReconstructBinding = (name) => {
|
|
|
2091
1789
|
});
|
|
2092
1790
|
};
|
|
2093
1791
|
var bindingValue = (name, sourceFile) => {
|
|
2094
|
-
if (
|
|
2095
|
-
if (
|
|
1792
|
+
if (ts8.isIdentifier(name)) return name.text;
|
|
1793
|
+
if (ts8.isArrayBindingPattern(name)) {
|
|
2096
1794
|
const values = name.elements.map((element) => {
|
|
2097
|
-
if (
|
|
1795
|
+
if (ts8.isOmittedExpression(element)) return "";
|
|
2098
1796
|
const value = bindingValue(element.name, sourceFile);
|
|
2099
1797
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
2100
1798
|
});
|
|
@@ -2104,7 +1802,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
2104
1802
|
const value = bindingValue(element.name, sourceFile);
|
|
2105
1803
|
if (element.dotDotDotToken) return `...${value}`;
|
|
2106
1804
|
if (!element.propertyName) return value;
|
|
2107
|
-
const key =
|
|
1805
|
+
const key = ts8.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
2108
1806
|
return `${key}:${value}`;
|
|
2109
1807
|
});
|
|
2110
1808
|
return `{${properties.join(",")}}`;
|
|
@@ -2112,7 +1810,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
2112
1810
|
var arrowArgsCapture = (node) => {
|
|
2113
1811
|
const sourceFile = node.getSourceFile();
|
|
2114
1812
|
const params = node.parameters.filter(
|
|
2115
|
-
(parameter) => !(
|
|
1813
|
+
(parameter) => !(ts8.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
2116
1814
|
);
|
|
2117
1815
|
if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
|
|
2118
1816
|
return {
|
|
@@ -2126,14 +1824,14 @@ var arrowArgsCapture = (node) => {
|
|
|
2126
1824
|
});
|
|
2127
1825
|
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
2128
1826
|
};
|
|
2129
|
-
var
|
|
2130
|
-
if (!
|
|
1827
|
+
var isSupportedFunction = (node) => {
|
|
1828
|
+
if (!ts8.isFunctionDeclaration(node) && !ts8.isFunctionExpression(node) && !ts8.isArrowFunction(node) && !ts8.isMethodDeclaration(node) && !ts8.isGetAccessorDeclaration(node) && !ts8.isSetAccessorDeclaration(node)) {
|
|
2131
1829
|
return false;
|
|
2132
1830
|
}
|
|
2133
1831
|
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
2134
1832
|
return true;
|
|
2135
1833
|
};
|
|
2136
|
-
var isDirectivePrologue = (statement) =>
|
|
1834
|
+
var isDirectivePrologue = (statement) => ts8.isExpressionStatement(statement) && ts8.isStringLiteral(statement.expression);
|
|
2137
1835
|
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
2138
1836
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
2139
1837
|
let end = shebangEnd;
|
|
@@ -2152,13 +1850,13 @@ var modulePreamble = (runName, plansName, plansJson) => `${RASPUTIN_INSTRUMENTAT
|
|
|
2152
1850
|
var collectWrappedFunction = (node, sourceFile, absolutePath, mapLocation) => {
|
|
2153
1851
|
const start = mappedLocation(
|
|
2154
1852
|
sourceFile,
|
|
2155
|
-
|
|
1853
|
+
functionLocationPosition(node, sourceFile),
|
|
2156
1854
|
absolutePath,
|
|
2157
1855
|
mapLocation
|
|
2158
1856
|
);
|
|
2159
1857
|
if (!start) return void 0;
|
|
2160
1858
|
const end = mappedLocation(sourceFile, node.end, absolutePath, mapLocation) ?? start;
|
|
2161
|
-
const name =
|
|
1859
|
+
const name = functionName(node, sourceFile).replace(/@\d+:\d+$/, "");
|
|
2162
1860
|
const { params, paramNames } = collectFunctionParams(node, sourceFile);
|
|
2163
1861
|
const plan = encodeFunctionPlan({
|
|
2164
1862
|
filePath: start.filePath,
|
|
@@ -2184,7 +1882,7 @@ var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
|
2184
1882
|
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
2185
1883
|
for (const statement of body.statements) {
|
|
2186
1884
|
if (isDirectivePrologue(statement)) continue;
|
|
2187
|
-
if (
|
|
1885
|
+
if (ts8.isExpressionStatement(statement) && ts8.isCallExpression(statement.expression) && statement.expression.expression.kind === ts8.SyntaxKind.SuperKeyword) {
|
|
2188
1886
|
return statement.end;
|
|
2189
1887
|
}
|
|
2190
1888
|
break;
|
|
@@ -2195,15 +1893,15 @@ var failEpilogue = (handleName, errorName, args, restoreOnCatch) => `}catch(${er
|
|
|
2195
1893
|
var walkOwnBody = (node, visitNode) => {
|
|
2196
1894
|
if (!node.body) return;
|
|
2197
1895
|
const visit = (candidate) => {
|
|
2198
|
-
if (candidate !== node &&
|
|
1896
|
+
if (candidate !== node && ts8.isFunctionLike(candidate)) return;
|
|
2199
1897
|
visitNode(candidate);
|
|
2200
|
-
|
|
1898
|
+
ts8.forEachChild(candidate, visit);
|
|
2201
1899
|
};
|
|
2202
1900
|
visit(node.body);
|
|
2203
1901
|
};
|
|
2204
1902
|
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
2205
1903
|
walkOwnBody(node, (candidate) => {
|
|
2206
|
-
if (!
|
|
1904
|
+
if (!ts8.isAwaitExpression(candidate)) return;
|
|
2207
1905
|
wrap(
|
|
2208
1906
|
edits,
|
|
2209
1907
|
candidate.expression.getStart(sourceFile),
|
|
@@ -2224,7 +1922,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
2224
1922
|
};
|
|
2225
1923
|
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
2226
1924
|
walkOwnBody(node, (candidate) => {
|
|
2227
|
-
if (!
|
|
1925
|
+
if (!ts8.isTryStatement(candidate)) return;
|
|
2228
1926
|
const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
|
|
2229
1927
|
for (const block of blocks) {
|
|
2230
1928
|
if (!block) continue;
|
|
@@ -2240,10 +1938,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
|
|
|
2240
1938
|
});
|
|
2241
1939
|
};
|
|
2242
1940
|
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
2243
|
-
if (!node.body || !
|
|
1941
|
+
if (!node.body || !ts8.isBlock(node.body)) return;
|
|
2244
1942
|
const visit = (candidate, at) => {
|
|
2245
|
-
if (candidate !== node &&
|
|
2246
|
-
if (
|
|
1943
|
+
if (candidate !== node && ts8.isFunctionLike(candidate)) return;
|
|
1944
|
+
if (ts8.isReturnStatement(candidate) && candidate.expression) {
|
|
2247
1945
|
const expression = candidate.expression;
|
|
2248
1946
|
wrap(
|
|
2249
1947
|
edits,
|
|
@@ -2255,25 +1953,25 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
2255
1953
|
);
|
|
2256
1954
|
return;
|
|
2257
1955
|
}
|
|
2258
|
-
|
|
1956
|
+
ts8.forEachChild(candidate, (child) => visit(child, at + 1));
|
|
2259
1957
|
};
|
|
2260
1958
|
visit(node.body, depth + 1);
|
|
2261
1959
|
};
|
|
2262
1960
|
var transformSource = (source, options) => {
|
|
2263
1961
|
if (source.includes("@rasputin-ignore-file")) return void 0;
|
|
2264
1962
|
if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
|
|
2265
|
-
const sourceFile =
|
|
1963
|
+
const sourceFile = ts8.createSourceFile(
|
|
2266
1964
|
options.filePath,
|
|
2267
1965
|
source,
|
|
2268
|
-
|
|
1966
|
+
ts8.ScriptTarget.Latest,
|
|
2269
1967
|
true,
|
|
2270
|
-
|
|
1968
|
+
scriptKindFor3(options.filePath)
|
|
2271
1969
|
);
|
|
2272
1970
|
const runName = uniqueName(source, "__rasputinRun__");
|
|
2273
1971
|
const plansName = uniqueName(source, "__rasputinPlans__");
|
|
2274
1972
|
const handleName = uniqueName(source, "__rasputinH__");
|
|
2275
1973
|
const errorName = uniqueName(source, "__rasputinE__");
|
|
2276
|
-
const absolutePath =
|
|
1974
|
+
const absolutePath = resolve2(options.filePath);
|
|
2277
1975
|
const edits = [];
|
|
2278
1976
|
const delta = {
|
|
2279
1977
|
functions: [],
|
|
@@ -2329,7 +2027,7 @@ var transformSource = (source, options) => {
|
|
|
2329
2027
|
collected.asyncFunction = true;
|
|
2330
2028
|
skipFunction(node, collected, "unsupported_async_generator");
|
|
2331
2029
|
}
|
|
2332
|
-
|
|
2030
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2333
2031
|
return;
|
|
2334
2032
|
}
|
|
2335
2033
|
if (isSyncGeneratorLike(node) && node.body) {
|
|
@@ -2341,10 +2039,10 @@ var transformSource = (source, options) => {
|
|
|
2341
2039
|
);
|
|
2342
2040
|
if (collected)
|
|
2343
2041
|
skipFunction(node, collected, "unsupported_sync_generator");
|
|
2344
|
-
|
|
2042
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2345
2043
|
return;
|
|
2346
2044
|
}
|
|
2347
|
-
if (
|
|
2045
|
+
if (ts8.isConstructorDeclaration(node) && node.body) {
|
|
2348
2046
|
const collected = collectWrappedFunction(
|
|
2349
2047
|
node,
|
|
2350
2048
|
sourceFile,
|
|
@@ -2353,13 +2051,13 @@ var transformSource = (source, options) => {
|
|
|
2353
2051
|
);
|
|
2354
2052
|
if (collected)
|
|
2355
2053
|
skipFunction(node, collected, "unsupported_constructor");
|
|
2356
|
-
|
|
2054
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2357
2055
|
return;
|
|
2358
2056
|
}
|
|
2359
|
-
if (
|
|
2057
|
+
if (isSupportedFunction(node)) {
|
|
2360
2058
|
const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
|
|
2361
2059
|
if (!collected) {
|
|
2362
|
-
|
|
2060
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2363
2061
|
return;
|
|
2364
2062
|
}
|
|
2365
2063
|
if (options.decideFunction?.({
|
|
@@ -2368,7 +2066,7 @@ var transformSource = (source, options) => {
|
|
|
2368
2066
|
filePath: options.filePath,
|
|
2369
2067
|
name: collected.name
|
|
2370
2068
|
}) === "skip") {
|
|
2371
|
-
|
|
2069
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2372
2070
|
return;
|
|
2373
2071
|
}
|
|
2374
2072
|
const asyncFunction = isAsyncFunctionLike(node);
|
|
@@ -2376,7 +2074,7 @@ var transformSource = (source, options) => {
|
|
|
2376
2074
|
const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
2377
2075
|
if (decision.action === "skip") {
|
|
2378
2076
|
skipFunction(node, collected, decision.reason);
|
|
2379
|
-
|
|
2077
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2380
2078
|
return;
|
|
2381
2079
|
}
|
|
2382
2080
|
if (functionHasPreBodyParameterEvaluation(node)) {
|
|
@@ -2390,29 +2088,25 @@ var transformSource = (source, options) => {
|
|
|
2390
2088
|
});
|
|
2391
2089
|
delta.functions.push(collected);
|
|
2392
2090
|
rememberIdentity(node, collected);
|
|
2393
|
-
|
|
2091
|
+
ts8.forEachChild(node, (child) => visit(child, collected, depth + 1));
|
|
2394
2092
|
return;
|
|
2395
2093
|
}
|
|
2396
|
-
if (caller &&
|
|
2397
|
-
const site = collectCallSite(node, caller, collectContext);
|
|
2398
|
-
if (site) delta.callSites.push(site);
|
|
2399
|
-
}
|
|
2400
|
-
if (caller && ts9.isVariableDeclaration(node)) {
|
|
2094
|
+
if (caller && ts8.isVariableDeclaration(node)) {
|
|
2401
2095
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
2402
2096
|
if (destructure) delta.destructures.push(destructure);
|
|
2403
2097
|
}
|
|
2404
|
-
|
|
2098
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2405
2099
|
};
|
|
2406
2100
|
visit(sourceFile, void 0, 0);
|
|
2407
2101
|
if (pending.length === 0) {
|
|
2408
2102
|
return delta.functions.length > 0 ? withDeclarations({ code: source, delta }) : void 0;
|
|
2409
2103
|
}
|
|
2410
2104
|
for (const [planIndex, entry] of pending.entries()) {
|
|
2411
|
-
const captured =
|
|
2105
|
+
const captured = ts8.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
|
|
2412
2106
|
const omitArg = captured.omitValues ? ",true" : "";
|
|
2413
2107
|
const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
|
|
2414
2108
|
const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
|
|
2415
|
-
if (
|
|
2109
|
+
if (ts8.isBlock(entry.node.body)) {
|
|
2416
2110
|
const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
|
|
2417
2111
|
const closeAt = entry.node.body.end - 1;
|
|
2418
2112
|
wrap(
|
|
@@ -2501,1812 +2195,33 @@ var transformSource = (source, options) => {
|
|
|
2501
2195
|
});
|
|
2502
2196
|
};
|
|
2503
2197
|
|
|
2504
|
-
//
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
var
|
|
2510
|
-
var
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
var insertPositionAfterPrologue2 = (source, sourceFile) => {
|
|
2516
|
-
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
2517
|
-
let end = shebangEnd;
|
|
2518
|
-
for (const statement of sourceFile.statements) {
|
|
2519
|
-
if (!isDirectivePrologue2(statement)) break;
|
|
2520
|
-
end = statement.end;
|
|
2198
|
+
// src/compiler/ssr-policy.ts
|
|
2199
|
+
import ts10 from "typescript";
|
|
2200
|
+
|
|
2201
|
+
// src/compiler/svelte-generated.ts
|
|
2202
|
+
import ts9 from "typescript";
|
|
2203
|
+
var isFunctionLike2 = (node) => ts9.isFunctionDeclaration(node) || ts9.isFunctionExpression(node) || ts9.isArrowFunction(node) || ts9.isMethodDeclaration(node) || ts9.isGetAccessorDeclaration(node) || ts9.isSetAccessorDeclaration(node);
|
|
2204
|
+
var isDescendant = (root, node) => {
|
|
2205
|
+
let current = node;
|
|
2206
|
+
while (current) {
|
|
2207
|
+
if (current === root) return true;
|
|
2208
|
+
current = current.parent;
|
|
2521
2209
|
}
|
|
2522
|
-
return
|
|
2523
|
-
};
|
|
2524
|
-
var preambleInsert2 = (source, position, preamble) => {
|
|
2525
|
-
if (position <= 0) return preamble;
|
|
2526
|
-
const previous = source[position - 1];
|
|
2527
|
-
return previous === ";" || previous === "\n" || previous === "\r" ? preamble : `;${preamble}`;
|
|
2210
|
+
return false;
|
|
2528
2211
|
};
|
|
2529
|
-
var
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
end = statement.end;
|
|
2212
|
+
var svelteCallMethod = (call) => {
|
|
2213
|
+
const callee = call.expression;
|
|
2214
|
+
if (!ts9.isPropertyAccessExpression(callee) || !ts9.isIdentifier(callee.expression)) {
|
|
2215
|
+
return void 0;
|
|
2534
2216
|
}
|
|
2535
|
-
return
|
|
2217
|
+
if (callee.expression.text !== "$" || !ts9.isIdentifier(callee.name)) return void 0;
|
|
2218
|
+
return callee.name.text;
|
|
2536
2219
|
};
|
|
2537
|
-
var
|
|
2538
|
-
const
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
return statement.end;
|
|
2543
|
-
}
|
|
2544
|
-
break;
|
|
2545
|
-
}
|
|
2546
|
-
return end;
|
|
2547
|
-
};
|
|
2548
|
-
var functionRef = (node) => {
|
|
2549
|
-
if (node.name && ts10.isIdentifier(node.name)) {
|
|
2550
|
-
if (ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node) || ts10.isMethodDeclaration(node)) {
|
|
2551
|
-
return void 0;
|
|
2552
|
-
}
|
|
2553
|
-
return node.name.text;
|
|
2554
|
-
}
|
|
2555
|
-
const parent = node.parent;
|
|
2556
|
-
if (ts10.isVariableDeclaration(parent) && ts10.isIdentifier(parent.name) && parent.initializer === node) {
|
|
2557
|
-
return parent.name.text;
|
|
2558
|
-
}
|
|
2559
|
-
return void 0;
|
|
2560
|
-
};
|
|
2561
|
-
var matchingFunction = (sourceFile, item) => {
|
|
2562
|
-
let found2;
|
|
2563
|
-
const visit = (node) => {
|
|
2564
|
-
if (found2) return;
|
|
2565
|
-
if (isWrapTarget(node) && node.getStart(sourceFile) === item.start && node.end === item.end) {
|
|
2566
|
-
found2 = node;
|
|
2567
|
-
return;
|
|
2568
|
-
}
|
|
2569
|
-
ts10.forEachChild(node, visit);
|
|
2570
|
-
};
|
|
2571
|
-
visit(sourceFile);
|
|
2572
|
-
return found2;
|
|
2573
|
-
};
|
|
2574
|
-
var isStaticPropertyName2 = (name) => ts10.isIdentifier(name) || ts10.isStringLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name) || ts10.isNumericLiteral(name);
|
|
2575
|
-
var canReconstructBinding2 = (name) => {
|
|
2576
|
-
if (ts10.isIdentifier(name)) return true;
|
|
2577
|
-
if (ts10.isArrayBindingPattern(name)) {
|
|
2578
|
-
return name.elements.every(
|
|
2579
|
-
(element) => ts10.isOmittedExpression(element) || canReconstructBinding2(element.name)
|
|
2580
|
-
);
|
|
2581
|
-
}
|
|
2582
|
-
return name.elements.every((element) => {
|
|
2583
|
-
if (element.propertyName && !isStaticPropertyName2(element.propertyName)) return false;
|
|
2584
|
-
return canReconstructBinding2(element.name);
|
|
2585
|
-
});
|
|
2586
|
-
};
|
|
2587
|
-
var REDACTED_ARG_EXPR = 'Symbol.for("rasputin.redacted.v1")';
|
|
2588
|
-
var staticBindingKey = (name) => {
|
|
2589
|
-
if (ts10.isIdentifier(name)) return name.text;
|
|
2590
|
-
if (ts10.isStringLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name)) return name.text;
|
|
2591
|
-
if (ts10.isNumericLiteral(name)) return name.text;
|
|
2592
|
-
return void 0;
|
|
2593
|
-
};
|
|
2594
|
-
var bindingHasSensitiveName = (name) => {
|
|
2595
|
-
if (ts10.isIdentifier(name)) return propertyNameIsSensitive(name.text);
|
|
2596
|
-
if (ts10.isArrayBindingPattern(name)) {
|
|
2597
|
-
return name.elements.some(
|
|
2598
|
-
(element) => !ts10.isOmittedExpression(element) && bindingHasSensitiveName(element.name)
|
|
2599
|
-
);
|
|
2600
|
-
}
|
|
2601
|
-
return name.elements.some((element) => {
|
|
2602
|
-
const key = element.propertyName ? staticBindingKey(element.propertyName) : void 0;
|
|
2603
|
-
if (key && propertyNameIsSensitive(key)) return true;
|
|
2604
|
-
return bindingHasSensitiveName(element.name);
|
|
2605
|
-
});
|
|
2606
|
-
};
|
|
2607
|
-
var capturedBinding = (name, sourceFile) => {
|
|
2608
|
-
if (ts10.isIdentifier(name)) {
|
|
2609
|
-
return propertyNameIsSensitive(name.text) ? REDACTED_ARG_EXPR : name.text;
|
|
2610
|
-
}
|
|
2611
|
-
if (ts10.isArrayBindingPattern(name)) {
|
|
2612
|
-
const values = name.elements.map((element) => {
|
|
2613
|
-
if (ts10.isOmittedExpression(element)) return "";
|
|
2614
|
-
const value = capturedBinding(element.name, sourceFile);
|
|
2615
|
-
return element.dotDotDotToken ? `...${value}` : value;
|
|
2616
|
-
});
|
|
2617
|
-
return `[${values.join(",")}]`;
|
|
2618
|
-
}
|
|
2619
|
-
const properties = name.elements.map((element) => {
|
|
2620
|
-
const key = element.propertyName ? staticBindingKey(element.propertyName) : void 0;
|
|
2621
|
-
const sensitive = key !== void 0 && propertyNameIsSensitive(key) || ts10.isIdentifier(element.name) && propertyNameIsSensitive(element.name.text);
|
|
2622
|
-
if (element.dotDotDotToken) {
|
|
2623
|
-
return `...${sensitive ? REDACTED_ARG_EXPR : capturedBinding(element.name, sourceFile)}`;
|
|
2624
|
-
}
|
|
2625
|
-
if (!element.propertyName) {
|
|
2626
|
-
return sensitive && ts10.isIdentifier(element.name) ? `${element.name.text}:${REDACTED_ARG_EXPR}` : capturedBinding(element.name, sourceFile);
|
|
2627
|
-
}
|
|
2628
|
-
const printedKey = ts10.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
2629
|
-
return `${printedKey}:${sensitive ? REDACTED_ARG_EXPR : capturedBinding(element.name, sourceFile)}`;
|
|
2630
|
-
});
|
|
2631
|
-
return `{${properties.join(",")}}`;
|
|
2632
|
-
};
|
|
2633
|
-
var captureArgs = (node) => {
|
|
2634
|
-
const sourceFile = node.getSourceFile();
|
|
2635
|
-
const params = node.parameters.filter(
|
|
2636
|
-
(parameter) => !(ts10.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
2637
|
-
);
|
|
2638
|
-
const reconstructable = params.every((parameter) => canReconstructBinding2(parameter.name));
|
|
2639
|
-
const sensitive = params.some((parameter) => bindingHasSensitiveName(parameter.name));
|
|
2640
|
-
if (!reconstructable) {
|
|
2641
|
-
if (ts10.isArrowFunction(node) || sensitive) {
|
|
2642
|
-
return {
|
|
2643
|
-
args: `[${Array.from({ length: params.length }, () => "void 0").join(",")}]`,
|
|
2644
|
-
omitValues: true
|
|
2645
|
-
};
|
|
2646
|
-
}
|
|
2647
|
-
return { args: "arguments", omitValues: false };
|
|
2648
|
-
}
|
|
2649
|
-
if (!ts10.isArrowFunction(node) && !sensitive) {
|
|
2650
|
-
return { args: "arguments", omitValues: false };
|
|
2651
|
-
}
|
|
2652
|
-
const values = params.map((parameter) => {
|
|
2653
|
-
const value = capturedBinding(parameter.name, sourceFile);
|
|
2654
|
-
return parameter.dotDotDotToken ? `...${value}` : value;
|
|
2655
|
-
});
|
|
2656
|
-
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
2657
|
-
};
|
|
2658
|
-
var walkOwnBody2 = (node, visitNode) => {
|
|
2659
|
-
const visit = (candidate) => {
|
|
2660
|
-
if (candidate !== node && ts10.isFunctionLike(candidate)) return;
|
|
2661
|
-
visitNode(candidate);
|
|
2662
|
-
ts10.forEachChild(candidate, visit);
|
|
2663
|
-
};
|
|
2664
|
-
visit(node.body);
|
|
2665
|
-
};
|
|
2666
|
-
var collectReturnWraps2 = (node, sourceFile, handleName, edits, depth) => {
|
|
2667
|
-
if (!ts10.isBlock(node.body)) return;
|
|
2668
|
-
walkOwnBody2(node, (candidate) => {
|
|
2669
|
-
if (!ts10.isReturnStatement(candidate) || !candidate.expression) return;
|
|
2670
|
-
wrap(
|
|
2671
|
-
edits,
|
|
2672
|
-
candidate.expression.getStart(sourceFile),
|
|
2673
|
-
candidate.expression.end,
|
|
2674
|
-
`(${handleName}.leave((`,
|
|
2675
|
-
")))",
|
|
2676
|
-
depth + 1
|
|
2677
|
-
);
|
|
2678
|
-
});
|
|
2679
|
-
};
|
|
2680
|
-
var collectAwaitWraps2 = (node, sourceFile, handleName, edits, depth) => {
|
|
2681
|
-
walkOwnBody2(node, (candidate) => {
|
|
2682
|
-
if (!ts10.isAwaitExpression(candidate)) return;
|
|
2683
|
-
wrap(
|
|
2684
|
-
edits,
|
|
2685
|
-
candidate.expression.getStart(sourceFile),
|
|
2686
|
-
candidate.expression.end,
|
|
2687
|
-
`${handleName}.suspend(`,
|
|
2688
|
-
")",
|
|
2689
|
-
depth + 3
|
|
2690
|
-
);
|
|
2691
|
-
wrap(
|
|
2692
|
-
edits,
|
|
2693
|
-
candidate.getStart(sourceFile),
|
|
2694
|
-
candidate.end,
|
|
2695
|
-
`${handleName}.resume(`,
|
|
2696
|
-
")",
|
|
2697
|
-
depth + 2
|
|
2698
|
-
);
|
|
2699
|
-
});
|
|
2700
|
-
};
|
|
2701
|
-
var collectCatchFinallyResumes2 = (node, sourceFile, handleName, edits, depth) => {
|
|
2702
|
-
walkOwnBody2(node, (candidate) => {
|
|
2703
|
-
if (!ts10.isTryStatement(candidate)) return;
|
|
2704
|
-
for (const block of [candidate.catchClause?.block, candidate.finallyBlock]) {
|
|
2705
|
-
if (!block) continue;
|
|
2706
|
-
edits.push({
|
|
2707
|
-
position: block.getStart(sourceFile) + 1,
|
|
2708
|
-
text: `${handleName}.resume();`,
|
|
2709
|
-
deleteCount: 0,
|
|
2710
|
-
depth,
|
|
2711
|
-
width: 0,
|
|
2712
|
-
kind: "replace"
|
|
2713
|
-
});
|
|
2714
|
-
}
|
|
2715
|
-
});
|
|
2716
|
-
};
|
|
2717
|
-
var collectReactiveReturnWraps = (node, sourceFile, siteId, edits, depth) => {
|
|
2718
|
-
if (!ts10.isBlock(node.body)) return;
|
|
2719
|
-
walkOwnBody2(node, (candidate) => {
|
|
2720
|
-
if (!ts10.isReturnStatement(candidate)) return;
|
|
2721
|
-
if (!candidate.expression) {
|
|
2722
|
-
edits.push({
|
|
2723
|
-
position: candidate.getStart(sourceFile),
|
|
2724
|
-
text: `return void ${REACTIVE_LEAVE}(${siteId});`,
|
|
2725
|
-
deleteCount: candidate.end - candidate.getStart(sourceFile),
|
|
2726
|
-
depth,
|
|
2727
|
-
width: 0,
|
|
2728
|
-
kind: "replace"
|
|
2729
|
-
});
|
|
2730
|
-
return;
|
|
2731
|
-
}
|
|
2732
|
-
wrap(
|
|
2733
|
-
edits,
|
|
2734
|
-
candidate.expression.getStart(sourceFile),
|
|
2735
|
-
candidate.expression.end,
|
|
2736
|
-
`${REACTIVE_LEAVE}(${siteId},`,
|
|
2737
|
-
")",
|
|
2738
|
-
depth + 1
|
|
2739
|
-
);
|
|
2740
|
-
});
|
|
2741
|
-
};
|
|
2742
|
-
var failEpilogue2 = (handleName, errorName, failArgs, restoreOnCatch) => `}catch(${errorName}){${restoreOnCatch ? `${handleName}.resume();` : ""}${handleName}.fail(${errorName}${failArgs});throw ${errorName};}finally{${handleName}.end();}`;
|
|
2743
|
-
var toManifestFunction = (item, node, sourceFile, asyncFunction, instrumented, mapLocation) => {
|
|
2744
|
-
const plan = encodeFunctionPlan({
|
|
2745
|
-
filePath: item.filePath,
|
|
2746
|
-
name: item.name,
|
|
2747
|
-
line: item.line,
|
|
2748
|
-
column: item.column
|
|
2749
|
-
});
|
|
2750
|
-
const { params, paramNames } = node ? collectFunctionParams(node, sourceFile) : { params: [], paramNames: /* @__PURE__ */ new Set() };
|
|
2751
|
-
const end = node ? mappedLocation(sourceFile, node.end, item.filePath, mapLocation) : { line: item.line, column: item.column };
|
|
2752
|
-
return {
|
|
2753
|
-
plan,
|
|
2754
|
-
functionId: item.functionId,
|
|
2755
|
-
filePath: item.filePath,
|
|
2756
|
-
name: item.name,
|
|
2757
|
-
startLine: item.line,
|
|
2758
|
-
startColumn: item.column,
|
|
2759
|
-
endLine: end?.line ?? item.line,
|
|
2760
|
-
endColumn: end?.column ?? item.column,
|
|
2761
|
-
params,
|
|
2762
|
-
paramNames,
|
|
2763
|
-
instrumented,
|
|
2764
|
-
asyncFunction
|
|
2765
|
-
};
|
|
2766
|
-
};
|
|
2767
|
-
var collectCallerSites = (sourceFile, classifications, functions, absolutePath, mapLocation, policy) => {
|
|
2768
|
-
const bySpan = /* @__PURE__ */ new Map();
|
|
2769
|
-
const classified = new Map(
|
|
2770
|
-
classifications.map((item) => [`${item.start}:${item.end}`, item])
|
|
2771
|
-
);
|
|
2772
|
-
const byId = new Map(functions.map((fn) => [fn.functionId, fn]));
|
|
2773
|
-
for (const item of classifications) {
|
|
2774
|
-
const fn = byId.get(item.functionId);
|
|
2775
|
-
if (fn) bySpan.set(`${item.start}:${item.end}`, fn);
|
|
2776
|
-
}
|
|
2777
|
-
const callSites = [];
|
|
2778
|
-
const destructures = [];
|
|
2779
|
-
const collectContext = { sourceFile, absolutePath, mapLocation };
|
|
2780
|
-
const visit = (node, caller) => {
|
|
2781
|
-
if (isWrapTarget(node)) {
|
|
2782
|
-
const item = classified.get(`${node.getStart(sourceFile)}:${node.end}`);
|
|
2783
|
-
if (item) {
|
|
2784
|
-
const fn = bySpan.get(`${item.start}:${item.end}`);
|
|
2785
|
-
const next = fn && fn.instrumented !== false ? fn : caller;
|
|
2786
|
-
ts10.forEachChild(node, (child) => visit(child, next));
|
|
2787
|
-
return;
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
if (caller && (ts10.isCallExpression(node) || ts10.isNewExpression(node))) {
|
|
2791
|
-
if (policy?.isCompilerCall({
|
|
2792
|
-
node,
|
|
2793
|
-
sourceFile,
|
|
2794
|
-
filePath: absolutePath
|
|
2795
|
-
})) {
|
|
2796
|
-
ts10.forEachChild(node, (child) => visit(child, caller));
|
|
2797
|
-
return;
|
|
2798
|
-
}
|
|
2799
|
-
const site = collectCallSite(node, caller, collectContext);
|
|
2800
|
-
if (site) callSites.push(site);
|
|
2801
|
-
}
|
|
2802
|
-
if (caller && ts10.isVariableDeclaration(node)) {
|
|
2803
|
-
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
2804
|
-
if (destructure) destructures.push(destructure);
|
|
2805
|
-
}
|
|
2806
|
-
ts10.forEachChild(node, (child) => visit(child, caller));
|
|
2807
|
-
};
|
|
2808
|
-
visit(sourceFile, void 0);
|
|
2809
|
-
return { callSites, destructures };
|
|
2810
|
-
};
|
|
2811
|
-
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});`;
|
|
2812
|
-
var collectBrowserFunctionEdits = (source, sourceFile, classifications, moduleIndex, reactiveIds, options) => {
|
|
2813
|
-
const edits = [];
|
|
2814
|
-
const functions = [];
|
|
2815
|
-
const identities = [];
|
|
2816
|
-
const runtimePlans = [];
|
|
2817
|
-
const reactiveSiteIds = [];
|
|
2818
|
-
const runName = uniqueName(source, "__rasputinRun__");
|
|
2819
|
-
const handleName = uniqueName(source, "__rasputinH__");
|
|
2820
|
-
const errorName = uniqueName(source, "__rasputinE__");
|
|
2821
|
-
const sampledName = uniqueName(source, "__rasputinS__");
|
|
2822
|
-
const valueName = uniqueName(source, "__rasputinV__");
|
|
2823
|
-
let planIndex = 0;
|
|
2824
|
-
let emittedRuntime = false;
|
|
2825
|
-
for (const item of classifications) {
|
|
2826
|
-
const node = matchingFunction(sourceFile, item);
|
|
2827
|
-
const asyncFunction = node ? isAsyncFunctionLike(node) : false;
|
|
2828
|
-
if (item.captureClass === "skip") {
|
|
2829
|
-
functions.push(
|
|
2830
|
-
toManifestFunction(item, node, sourceFile, asyncFunction, false, options.mapLocation)
|
|
2831
|
-
);
|
|
2832
|
-
continue;
|
|
2833
|
-
}
|
|
2834
|
-
if (!node) {
|
|
2835
|
-
functions.push(
|
|
2836
|
-
toManifestFunction(item, void 0, sourceFile, asyncFunction, false, options.mapLocation)
|
|
2837
|
-
);
|
|
2838
|
-
continue;
|
|
2839
|
-
}
|
|
2840
|
-
const remember = (siteId) => {
|
|
2841
|
-
runtimePlans[planIndex] = encodeFunctionPlan({
|
|
2842
|
-
filePath: item.filePath,
|
|
2843
|
-
name: item.name,
|
|
2844
|
-
line: item.line,
|
|
2845
|
-
column: item.column
|
|
2846
|
-
});
|
|
2847
|
-
identities.push({
|
|
2848
|
-
compactId: compactRuntimeFunctionId(moduleIndex, planIndex),
|
|
2849
|
-
functionId: item.functionId,
|
|
2850
|
-
name: item.name,
|
|
2851
|
-
moduleIndex,
|
|
2852
|
-
planIndex,
|
|
2853
|
-
captureClass: item.captureClass,
|
|
2854
|
-
line: item.line,
|
|
2855
|
-
column: item.column,
|
|
2856
|
-
filePath: item.filePath,
|
|
2857
|
-
...siteId === void 0 ? {} : { siteId }
|
|
2858
|
-
});
|
|
2859
|
-
};
|
|
2860
|
-
if (item.captureClass === "reactive-sparse" && !isAsyncFunctionLike(node)) {
|
|
2861
|
-
const siteId = reactiveIds.value++;
|
|
2862
|
-
remember(siteId);
|
|
2863
|
-
const hit = `${REACTIVE_HIT}(${siteId})`;
|
|
2864
|
-
const leave = `${REACTIVE_LEAVE}(${siteId})`;
|
|
2865
|
-
const fail = `${REACTIVE_THROW}(${siteId},${errorName})`;
|
|
2866
|
-
const epilogue2 = `}catch(${errorName}){${fail};throw ${errorName};}finally{${REACTIVE_DONE}()}`;
|
|
2867
|
-
if (ts10.isBlock(node.body)) {
|
|
2868
|
-
wrap(
|
|
2869
|
-
edits,
|
|
2870
|
-
node.body.getStart(sourceFile) + 1,
|
|
2871
|
-
node.body.end - 1,
|
|
2872
|
-
`;var ${sampledName}=${hit};try{`,
|
|
2873
|
-
`;if(!${sampledName})${leave}${epilogue2}`,
|
|
2874
|
-
0
|
|
2875
|
-
);
|
|
2876
|
-
collectReactiveReturnWraps(node, sourceFile, siteId, edits, 0);
|
|
2877
|
-
} else {
|
|
2878
|
-
wrap(
|
|
2879
|
-
edits,
|
|
2880
|
-
node.body.getStart(sourceFile),
|
|
2881
|
-
node.body.end,
|
|
2882
|
-
`{try{var ${sampledName}=${hit},${valueName}=`,
|
|
2883
|
-
`;return ${sampledName}?${valueName}:${REACTIVE_LEAVE}(${siteId},${valueName})${epilogue2}}`,
|
|
2884
|
-
0
|
|
2885
|
-
);
|
|
2886
|
-
}
|
|
2887
|
-
reactiveSiteIds.push(siteId);
|
|
2888
|
-
functions.push(toManifestFunction(item, node, sourceFile, false, true, options.mapLocation));
|
|
2889
|
-
planIndex += 1;
|
|
2890
|
-
continue;
|
|
2891
|
-
}
|
|
2892
|
-
const decision = isAsyncFunctionLike(node) ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
2893
|
-
if (decision.action === "skip") {
|
|
2894
|
-
functions.push(toManifestFunction(item, node, sourceFile, true, false, options.mapLocation));
|
|
2895
|
-
continue;
|
|
2896
|
-
}
|
|
2897
|
-
remember();
|
|
2898
|
-
emittedRuntime = true;
|
|
2899
|
-
const structure = item.captureClass === "structure";
|
|
2900
|
-
const captured = structure ? { args: "void 0", omitValues: true } : captureArgs(node);
|
|
2901
|
-
const omitFlag = structure || captured.omitValues;
|
|
2902
|
-
const ref = functionRef(node);
|
|
2903
|
-
const enterCall = `${runName}.enter(${planIndex},${captured.args},${omitFlag}${ref ? `,${ref}` : ""})`;
|
|
2904
|
-
const failLive = structure ? captureArgs(node) : captured;
|
|
2905
|
-
const failArgs = `,${failLive.args}`;
|
|
2906
|
-
const epilogue = failEpilogue2(
|
|
2907
|
-
handleName,
|
|
2908
|
-
errorName,
|
|
2909
|
-
failArgs,
|
|
2910
|
-
decision.action === "suspend_resume"
|
|
2911
|
-
);
|
|
2912
|
-
if (ts10.isBlock(node.body)) {
|
|
2913
|
-
const prologueAt = insertAfterSuperOrPrologue2(node.body, sourceFile);
|
|
2914
|
-
const closeAt = node.body.end - 1;
|
|
2915
|
-
wrap(edits, prologueAt, closeAt, `;const ${handleName}=${enterCall};try{`, epilogue, 0);
|
|
2916
|
-
collectReturnWraps2(node, sourceFile, handleName, edits, 0);
|
|
2917
|
-
if (decision.action === "suspend_resume") {
|
|
2918
|
-
collectAwaitWraps2(node, sourceFile, handleName, edits, 0);
|
|
2919
|
-
collectCatchFinallyResumes2(node, sourceFile, handleName, edits, 0);
|
|
2920
|
-
}
|
|
2921
|
-
} else {
|
|
2922
|
-
wrap(
|
|
2923
|
-
edits,
|
|
2924
|
-
node.body.getStart(sourceFile),
|
|
2925
|
-
node.body.end,
|
|
2926
|
-
`{;const ${handleName}=${enterCall};try{return (${handleName}.leave((`,
|
|
2927
|
-
`)));${epilogue}}`,
|
|
2928
|
-
0
|
|
2929
|
-
);
|
|
2930
|
-
if (decision.action === "suspend_resume") {
|
|
2931
|
-
collectAwaitWraps2(node, sourceFile, handleName, edits, 0);
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
functions.push(
|
|
2935
|
-
toManifestFunction(
|
|
2936
|
-
item,
|
|
2937
|
-
node,
|
|
2938
|
-
sourceFile,
|
|
2939
|
-
isAsyncFunctionLike(node),
|
|
2940
|
-
true,
|
|
2941
|
-
options.mapLocation
|
|
2942
|
-
)
|
|
2943
|
-
);
|
|
2944
|
-
planIndex += 1;
|
|
2945
|
-
}
|
|
2946
|
-
if (functions.length === 0 && !options.observe) {
|
|
2947
|
-
return {
|
|
2948
|
-
edits: [],
|
|
2949
|
-
delta: { functions: [], callSites: [], destructures: [] },
|
|
2950
|
-
identities: [],
|
|
2951
|
-
reactiveSiteIds: []
|
|
2952
|
-
};
|
|
2953
|
-
}
|
|
2954
|
-
const insertAt = insertPositionAfterPrologue2(source, sourceFile);
|
|
2955
|
-
const reactivePreamble = reactiveSiteIds.length > 0 ? `${REACTIVE_REG}([${reactiveSiteIds.join(",")}]);` : "";
|
|
2956
|
-
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}`;
|
|
2957
|
-
edits.push({
|
|
2958
|
-
position: insertAt,
|
|
2959
|
-
text: preambleInsert2(source, insertAt, preamble),
|
|
2960
|
-
deleteCount: 0,
|
|
2961
|
-
depth: -1,
|
|
2962
|
-
width: 0,
|
|
2963
|
-
kind: "replace"
|
|
2964
|
-
});
|
|
2965
|
-
const sites = collectCallerSites(
|
|
2966
|
-
sourceFile,
|
|
2967
|
-
classifications,
|
|
2968
|
-
functions,
|
|
2969
|
-
classifications[0]?.filePath ?? "",
|
|
2970
|
-
options.mapLocation,
|
|
2971
|
-
options.policy
|
|
2972
|
-
);
|
|
2973
|
-
return {
|
|
2974
|
-
edits,
|
|
2975
|
-
delta: { functions, callSites: sites.callSites, destructures: sites.destructures },
|
|
2976
|
-
identities,
|
|
2977
|
-
reactiveSiteIds
|
|
2978
|
-
};
|
|
2979
|
-
};
|
|
2980
|
-
|
|
2981
|
-
// ../instrumentation/src/json-producer-sites.ts
|
|
2982
|
-
import ts11 from "typescript";
|
|
2983
|
-
var JSON_METHOD_CALLEE = "globalThis.__rasputinM";
|
|
2984
|
-
var JSON_AWAIT_CALLEE = "globalThis.__rasputinA";
|
|
2985
|
-
var JSON_ADOPT_CALLEE = "globalThis.__rasputinP";
|
|
2986
|
-
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};";
|
|
2987
|
-
var NON_PROVENANCE_ROOTS = /* @__PURE__ */ new Set([
|
|
2988
|
-
"String",
|
|
2989
|
-
"Number",
|
|
2990
|
-
"Boolean",
|
|
2991
|
-
"Object",
|
|
2992
|
-
"Array",
|
|
2993
|
-
"Error",
|
|
2994
|
-
"TypeError",
|
|
2995
|
-
"RangeError",
|
|
2996
|
-
"SyntaxError",
|
|
2997
|
-
"URIError",
|
|
2998
|
-
"EvalError",
|
|
2999
|
-
"ReferenceError",
|
|
3000
|
-
"Symbol",
|
|
3001
|
-
"BigInt",
|
|
3002
|
-
"Math",
|
|
3003
|
-
"JSON",
|
|
3004
|
-
"Date",
|
|
3005
|
-
"Promise",
|
|
3006
|
-
"console",
|
|
3007
|
-
"parseInt",
|
|
3008
|
-
"parseFloat",
|
|
3009
|
-
"isNaN",
|
|
3010
|
-
"isFinite",
|
|
3011
|
-
"encodeURIComponent",
|
|
3012
|
-
"decodeURIComponent",
|
|
3013
|
-
"encodeURI",
|
|
3014
|
-
"decodeURI"
|
|
3015
|
-
]);
|
|
3016
|
-
var isSimpleReceiver = (expression) => {
|
|
3017
|
-
const receiver = peel(expression);
|
|
3018
|
-
return ts11.isIdentifier(receiver) || receiver.kind === ts11.SyntaxKind.ThisKeyword;
|
|
3019
|
-
};
|
|
3020
|
-
var isSimpleIdentifierCall = (node) => !node.questionDotToken && ts11.isIdentifier(node.expression);
|
|
3021
|
-
var isSimpleMethodCall = (node) => {
|
|
3022
|
-
if (node.questionDotToken) return false;
|
|
3023
|
-
const callee = node.expression;
|
|
3024
|
-
return ts11.isPropertyAccessExpression(callee) && !callee.questionDotToken && ts11.isIdentifier(callee.name) && !ts11.isPrivateIdentifier(callee.name) && isSimpleReceiver(callee.expression);
|
|
3025
|
-
};
|
|
3026
|
-
var isSimpleProvenanceCall = (node) => isSimpleIdentifierCall(node) || isSimpleMethodCall(node);
|
|
3027
|
-
var isJsonParseCall = (node) => {
|
|
3028
|
-
if (!isSimpleMethodCall(node)) return false;
|
|
3029
|
-
const callee = node.expression;
|
|
3030
|
-
if (!ts11.isPropertyAccessExpression(callee) || callee.name.text !== "parse") return false;
|
|
3031
|
-
const object = peel(callee.expression);
|
|
3032
|
-
return ts11.isIdentifier(object) && object.text === "JSON";
|
|
3033
|
-
};
|
|
3034
|
-
var methodName = (node) => {
|
|
3035
|
-
if (!isSimpleMethodCall(node)) return void 0;
|
|
3036
|
-
const callee = node.expression;
|
|
3037
|
-
return ts11.isPropertyAccessExpression(callee) ? callee.name.text : void 0;
|
|
3038
|
-
};
|
|
3039
|
-
var containsNestedAwaitOrFunction = (node) => {
|
|
3040
|
-
let found2 = false;
|
|
3041
|
-
const visit = (candidate) => {
|
|
3042
|
-
if (candidate !== node && (ts11.isAwaitExpression(candidate) || ts11.isFunctionLike(candidate))) {
|
|
3043
|
-
found2 = true;
|
|
3044
|
-
return;
|
|
3045
|
-
}
|
|
3046
|
-
if (!found2) ts11.forEachChild(candidate, visit);
|
|
3047
|
-
};
|
|
3048
|
-
visit(node);
|
|
3049
|
-
return found2;
|
|
3050
|
-
};
|
|
3051
|
-
var isSimpleProducerCall = (node) => {
|
|
3052
|
-
if (containsNestedAwaitOrFunction(node)) return false;
|
|
3053
|
-
if (isJsonParseCall(node)) return true;
|
|
3054
|
-
return methodName(node) === "json";
|
|
3055
|
-
};
|
|
3056
|
-
var isAwaitExpressionOf = (node) => {
|
|
3057
|
-
let current = node;
|
|
3058
|
-
while (current.parent) {
|
|
3059
|
-
const parent = current.parent;
|
|
3060
|
-
if (ts11.isParenthesizedExpression(parent) || ts11.isNonNullExpression(parent) || ts11.isAsExpression(parent) || ts11.isTypeAssertionExpression(parent) || ts11.isSatisfiesExpression(parent)) {
|
|
3061
|
-
current = parent;
|
|
3062
|
-
continue;
|
|
3063
|
-
}
|
|
3064
|
-
return ts11.isAwaitExpression(parent) && parent.expression === current;
|
|
3065
|
-
}
|
|
3066
|
-
return false;
|
|
3067
|
-
};
|
|
3068
|
-
var isDirectSuperCall = (node) => node.expression.kind === ts11.SyntaxKind.SuperKeyword;
|
|
3069
|
-
var isPolicyCompilerCall = (node, filePath, sourceFile, policy) => {
|
|
3070
|
-
if (!policy) return false;
|
|
3071
|
-
return policy.isCompilerCall({ node, sourceFile, filePath });
|
|
3072
|
-
};
|
|
3073
|
-
var outerExpression = (node) => {
|
|
3074
|
-
let current = node;
|
|
3075
|
-
while (current.parent) {
|
|
3076
|
-
const parent = current.parent;
|
|
3077
|
-
if ((ts11.isParenthesizedExpression(parent) || ts11.isNonNullExpression(parent) || ts11.isAsExpression(parent) || ts11.isTypeAssertionExpression(parent) || ts11.isSatisfiesExpression(parent)) && parent.expression === current) {
|
|
3078
|
-
current = parent;
|
|
3079
|
-
continue;
|
|
3080
|
-
}
|
|
3081
|
-
break;
|
|
3082
|
-
}
|
|
3083
|
-
return current;
|
|
3084
|
-
};
|
|
3085
|
-
var isReturnedOrBoundCall = (node) => {
|
|
3086
|
-
const expression = outerExpression(node);
|
|
3087
|
-
const parent = expression.parent;
|
|
3088
|
-
if (!parent) return false;
|
|
3089
|
-
if (ts11.isReturnStatement(parent) && parent.expression === expression) return true;
|
|
3090
|
-
if (ts11.isVariableDeclaration(parent) && parent.initializer === expression) return true;
|
|
3091
|
-
if (ts11.isBinaryExpression(parent) && parent.right === expression && parent.operatorToken.kind === ts11.SyntaxKind.EqualsToken) {
|
|
3092
|
-
return true;
|
|
3093
|
-
}
|
|
3094
|
-
return false;
|
|
3095
|
-
};
|
|
3096
|
-
var callCanCarryProvenance = (node) => {
|
|
3097
|
-
const name = methodName(node);
|
|
3098
|
-
if (name === "json" || name === "parse") return true;
|
|
3099
|
-
if (name === "call" || name === "apply") return false;
|
|
3100
|
-
const callee = node.expression;
|
|
3101
|
-
if (ts11.isIdentifier(callee)) return !NON_PROVENANCE_ROOTS.has(callee.text);
|
|
3102
|
-
if (ts11.isPropertyAccessExpression(callee)) {
|
|
3103
|
-
const object = peel(callee.expression);
|
|
3104
|
-
if (ts11.isIdentifier(object) && NON_PROVENANCE_ROOTS.has(object.text)) {
|
|
3105
|
-
return object.text === "JSON" && callee.name.text === "parse";
|
|
3106
|
-
}
|
|
3107
|
-
}
|
|
3108
|
-
return true;
|
|
3109
|
-
};
|
|
3110
|
-
var shouldAdoptCall = (node, filePath, sourceFile, policy) => {
|
|
3111
|
-
if (isAwaitExpressionOf(node) || isDirectSuperCall(node) || isPolicyCompilerCall(node, filePath, sourceFile, policy)) {
|
|
3112
|
-
return false;
|
|
3113
|
-
}
|
|
3114
|
-
if (ts11.isComputedPropertyName(outerExpression(node).parent)) return false;
|
|
3115
|
-
if (!isSimpleProvenanceCall(node)) return false;
|
|
3116
|
-
return isReturnedOrBoundCall(node) && callCanCarryProvenance(node);
|
|
3117
|
-
};
|
|
3118
|
-
var shouldAdoptAwaitCall = (node, filePath, sourceFile, policy) => {
|
|
3119
|
-
if (isPolicyCompilerCall(node, filePath, sourceFile, policy) || !isSimpleProvenanceCall(node)) {
|
|
3120
|
-
return false;
|
|
3121
|
-
}
|
|
3122
|
-
return callCanCarryProvenance(node);
|
|
3123
|
-
};
|
|
3124
|
-
var replaceProducerCall = (node, sourceFile, receiverName) => {
|
|
3125
|
-
const callee = node.expression;
|
|
3126
|
-
if (!ts11.isPropertyAccessExpression(callee)) return node.getText(sourceFile);
|
|
3127
|
-
const args = node.arguments.map((argument) => argument.getText(sourceFile));
|
|
3128
|
-
const extra3 = args.length > 0 ? `,${args.join(",")}` : "";
|
|
3129
|
-
const receiver = callee.expression.getText(sourceFile);
|
|
3130
|
-
const method = `${receiverName}.${callee.name.text}`;
|
|
3131
|
-
return `((${receiverName})=>${JSON_METHOD_CALLEE}(${receiverName},${method}${extra3}))(${receiver})`;
|
|
3132
|
-
};
|
|
3133
|
-
var hasBlockBody = (node) => {
|
|
3134
|
-
if (!ts11.isFunctionDeclaration(node) && !ts11.isFunctionExpression(node) && !ts11.isArrowFunction(node) && !ts11.isMethodDeclaration(node) && !ts11.isConstructorDeclaration(node) && !ts11.isGetAccessorDeclaration(node) && !ts11.isSetAccessorDeclaration(node)) {
|
|
3135
|
-
return false;
|
|
3136
|
-
}
|
|
3137
|
-
return node.body !== void 0 && ts11.isBlock(node.body);
|
|
3138
|
-
};
|
|
3139
|
-
var owningFunctionBody = (node) => {
|
|
3140
|
-
let current = node;
|
|
3141
|
-
while (current) {
|
|
3142
|
-
if (hasBlockBody(current)) return current.body;
|
|
3143
|
-
current = current.parent;
|
|
3144
|
-
}
|
|
3145
|
-
return void 0;
|
|
3146
|
-
};
|
|
3147
|
-
var callOpenParen = (node, sourceFile) => {
|
|
3148
|
-
const text = sourceFile.text;
|
|
3149
|
-
for (let index = node.expression.getEnd(); index < node.end; index += 1) {
|
|
3150
|
-
if (text.charCodeAt(index) === 40) return index;
|
|
3151
|
-
}
|
|
3152
|
-
return node.arguments.pos;
|
|
3153
|
-
};
|
|
3154
|
-
var callCloseParen = (node, sourceFile) => {
|
|
3155
|
-
const text = sourceFile.text;
|
|
3156
|
-
for (let index = node.end - 1; index >= node.arguments.pos; index -= 1) {
|
|
3157
|
-
if (text.charCodeAt(index) === 41) return index;
|
|
3158
|
-
}
|
|
3159
|
-
return node.end - 1;
|
|
3160
|
-
};
|
|
3161
|
-
var adoptCall = (edits, node, sourceFile, receiverName, fnName, slotName, slot = false) => {
|
|
3162
|
-
const start = node.getStart(sourceFile);
|
|
3163
|
-
const end = node.end;
|
|
3164
|
-
const depth = slot ? 17 : 14;
|
|
3165
|
-
const wrapOpen = (inner) => slot ? `(${slotName}={p:${inner}` : inner;
|
|
3166
|
-
const wrapClose = (inner) => slot ? `${inner}},${slotName}.p)` : inner;
|
|
3167
|
-
const callee = node.expression;
|
|
3168
|
-
if (ts11.isIdentifier(callee)) {
|
|
3169
|
-
wrap(
|
|
3170
|
-
edits,
|
|
3171
|
-
start,
|
|
3172
|
-
end,
|
|
3173
|
-
wrapOpen(`((${fnName})=>${JSON_ADOPT_CALLEE}(`),
|
|
3174
|
-
wrapClose(`,${fnName}))(${callee.text})`),
|
|
3175
|
-
depth
|
|
3176
|
-
);
|
|
3177
|
-
edits.push({
|
|
3178
|
-
position: callee.getStart(sourceFile),
|
|
3179
|
-
text: fnName,
|
|
3180
|
-
deleteCount: callee.end - callee.getStart(sourceFile),
|
|
3181
|
-
depth: 18,
|
|
3182
|
-
width: callee.end - callee.getStart(sourceFile),
|
|
3183
|
-
kind: "replace"
|
|
3184
|
-
});
|
|
3185
|
-
return;
|
|
3186
|
-
}
|
|
3187
|
-
if (!isSimpleMethodCall(node) || !ts11.isPropertyAccessExpression(callee)) return;
|
|
3188
|
-
const receiver = callee.expression.getText(sourceFile);
|
|
3189
|
-
const method = callee.name.text;
|
|
3190
|
-
const open = callOpenParen(node, sourceFile);
|
|
3191
|
-
const close = callCloseParen(node, sourceFile);
|
|
3192
|
-
wrap(
|
|
3193
|
-
edits,
|
|
3194
|
-
start,
|
|
3195
|
-
end,
|
|
3196
|
-
wrapOpen(`((${receiverName})=>((${fnName})=>${JSON_ADOPT_CALLEE}(`),
|
|
3197
|
-
wrapClose(`,${fnName}))(${receiverName}.${method}))(${receiver})`),
|
|
3198
|
-
depth
|
|
3199
|
-
);
|
|
3200
|
-
edits.push({
|
|
3201
|
-
position: start,
|
|
3202
|
-
text: `Reflect.apply(${fnName},${receiverName},[`,
|
|
3203
|
-
deleteCount: open + 1 - start,
|
|
3204
|
-
depth: 18,
|
|
3205
|
-
width: open + 1 - start,
|
|
3206
|
-
kind: "replace"
|
|
3207
|
-
});
|
|
3208
|
-
edits.push({
|
|
3209
|
-
position: close,
|
|
3210
|
-
text: "])",
|
|
3211
|
-
deleteCount: 1,
|
|
3212
|
-
depth: 18,
|
|
3213
|
-
width: 1,
|
|
3214
|
-
kind: "replace"
|
|
3215
|
-
});
|
|
3216
|
-
};
|
|
3217
|
-
var skippedComplexCall = (node, filePath, sourceFile, policy) => {
|
|
3218
|
-
if (isPolicyCompilerCall(node, filePath, sourceFile, policy) || isDirectSuperCall(node)) {
|
|
3219
|
-
return false;
|
|
3220
|
-
}
|
|
3221
|
-
if (isSimpleProvenanceCall(node)) return false;
|
|
3222
|
-
if (!callCanCarryProvenance(node)) return false;
|
|
3223
|
-
return true;
|
|
3224
|
-
};
|
|
3225
|
-
var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(source, filePath), options) => {
|
|
3226
|
-
const adoptCalls = options?.adoptCalls === true;
|
|
3227
|
-
const receiverName = uniqueName(source, "__rasputinJ");
|
|
3228
|
-
const adoptFnName = uniqueName(source, "__rasputinC");
|
|
3229
|
-
const slotName = uniqueName(source, "__rasputinS");
|
|
3230
|
-
const edits = [];
|
|
3231
|
-
const bodies = /* @__PURE__ */ new Set();
|
|
3232
|
-
let awaitWraps = 0;
|
|
3233
|
-
let callWraps = 0;
|
|
3234
|
-
let provenanceSkippedComplexCall = 0;
|
|
3235
|
-
const visit = (node) => {
|
|
3236
|
-
if (ts11.isCallExpression(node) && isSimpleProducerCall(node) && !isAwaitExpressionOf(node)) {
|
|
3237
|
-
edits.push({
|
|
3238
|
-
position: node.getStart(sourceFile),
|
|
3239
|
-
text: replaceProducerCall(node, sourceFile, receiverName),
|
|
3240
|
-
deleteCount: node.end - node.getStart(sourceFile),
|
|
3241
|
-
depth: 18,
|
|
3242
|
-
width: node.end - node.getStart(sourceFile),
|
|
3243
|
-
kind: "replace"
|
|
3244
|
-
});
|
|
3245
|
-
callWraps += 1;
|
|
3246
|
-
} else if (adoptCalls && ts11.isCallExpression(node) && shouldAdoptCall(node, filePath, sourceFile, options?.policy)) {
|
|
3247
|
-
adoptCall(edits, node, sourceFile, receiverName, adoptFnName, slotName);
|
|
3248
|
-
callWraps += 1;
|
|
3249
|
-
} else if (ts11.isCallExpression(node) && !isAwaitExpressionOf(node) && isReturnedOrBoundCall(node) && skippedComplexCall(node, filePath, sourceFile, options?.policy)) {
|
|
3250
|
-
provenanceSkippedComplexCall += 1;
|
|
3251
|
-
}
|
|
3252
|
-
if (ts11.isAwaitExpression(node)) {
|
|
3253
|
-
const inner = peel(node.expression);
|
|
3254
|
-
const producer = ts11.isCallExpression(inner) && isSimpleProducerCall(inner);
|
|
3255
|
-
const adoptInner = adoptCalls && ts11.isCallExpression(inner) && shouldAdoptAwaitCall(inner, filePath, sourceFile, options?.policy);
|
|
3256
|
-
const adoptValue = adoptCalls && !ts11.isCallExpression(inner);
|
|
3257
|
-
if (producer || adoptInner || adoptValue) {
|
|
3258
|
-
if (producer && ts11.isCallExpression(inner)) {
|
|
3259
|
-
edits.push({
|
|
3260
|
-
position: node.expression.getStart(sourceFile),
|
|
3261
|
-
text: `(${slotName}={p:${replaceProducerCall(inner, sourceFile, receiverName)}},${slotName}.p)`,
|
|
3262
|
-
deleteCount: node.expression.end - node.expression.getStart(sourceFile),
|
|
3263
|
-
depth: 17,
|
|
3264
|
-
width: node.expression.end - node.expression.getStart(sourceFile),
|
|
3265
|
-
kind: "replace"
|
|
3266
|
-
});
|
|
3267
|
-
callWraps += 1;
|
|
3268
|
-
} else if (adoptInner && ts11.isCallExpression(inner)) {
|
|
3269
|
-
if (node.expression === inner) {
|
|
3270
|
-
adoptCall(edits, inner, sourceFile, receiverName, adoptFnName, slotName, true);
|
|
3271
|
-
} else {
|
|
3272
|
-
wrap(
|
|
3273
|
-
edits,
|
|
3274
|
-
node.expression.getStart(sourceFile),
|
|
3275
|
-
node.expression.end,
|
|
3276
|
-
`(${slotName}={p:`,
|
|
3277
|
-
`},${slotName}.p)`,
|
|
3278
|
-
17
|
|
3279
|
-
);
|
|
3280
|
-
adoptCall(edits, inner, sourceFile, receiverName, adoptFnName, slotName);
|
|
3281
|
-
}
|
|
3282
|
-
callWraps += 1;
|
|
3283
|
-
} else {
|
|
3284
|
-
wrap(
|
|
3285
|
-
edits,
|
|
3286
|
-
node.expression.getStart(sourceFile),
|
|
3287
|
-
node.expression.end,
|
|
3288
|
-
`(${slotName}={p:${JSON_ADOPT_CALLEE}(`,
|
|
3289
|
-
`)},${slotName}.p)`,
|
|
3290
|
-
17
|
|
3291
|
-
);
|
|
3292
|
-
}
|
|
3293
|
-
wrap(
|
|
3294
|
-
edits,
|
|
3295
|
-
node.getStart(sourceFile),
|
|
3296
|
-
node.end,
|
|
3297
|
-
`${JSON_AWAIT_CALLEE}(`,
|
|
3298
|
-
`,${slotName}.p)`,
|
|
3299
|
-
16
|
|
3300
|
-
);
|
|
3301
|
-
awaitWraps += 1;
|
|
3302
|
-
const body = owningFunctionBody(node);
|
|
3303
|
-
if (body) bodies.add(body);
|
|
3304
|
-
} else if (ts11.isCallExpression(inner) && skippedComplexCall(inner, filePath, sourceFile, options?.policy)) {
|
|
3305
|
-
provenanceSkippedComplexCall += 1;
|
|
3306
|
-
}
|
|
3307
|
-
}
|
|
3308
|
-
ts11.forEachChild(node, visit);
|
|
3309
|
-
};
|
|
3310
|
-
visit(sourceFile);
|
|
3311
|
-
if (edits.length > 0) {
|
|
3312
|
-
edits.push({
|
|
3313
|
-
position: 0,
|
|
3314
|
-
text: `${RASPUTIN_INSTRUMENTATION_PREAMBLE}${JSON_PRODUCER_GUARD}`,
|
|
3315
|
-
deleteCount: 0,
|
|
3316
|
-
depth: -1,
|
|
3317
|
-
width: 0,
|
|
3318
|
-
kind: "replace"
|
|
3319
|
-
});
|
|
3320
|
-
}
|
|
3321
|
-
for (const body of bodies) {
|
|
3322
|
-
edits.push({
|
|
3323
|
-
position: body.getStart(sourceFile) + 1,
|
|
3324
|
-
text: `var ${slotName};`,
|
|
3325
|
-
deleteCount: 0,
|
|
3326
|
-
depth: 1,
|
|
3327
|
-
width: 0,
|
|
3328
|
-
kind: "replace"
|
|
3329
|
-
});
|
|
3330
|
-
}
|
|
3331
|
-
return { edits, awaitWraps, callWraps, provenanceSkippedComplexCall };
|
|
3332
|
-
};
|
|
3333
|
-
|
|
3334
|
-
// ../instrumentation/src/literal-sites.ts
|
|
3335
|
-
import ts12 from "typescript";
|
|
3336
|
-
var STRUCT_CALLEE = "globalThis.__rasputinK";
|
|
3337
|
-
var owningFunction = (position, classifications) => {
|
|
3338
|
-
let owner;
|
|
3339
|
-
let span = Number.POSITIVE_INFINITY;
|
|
3340
|
-
for (const item of classifications) {
|
|
3341
|
-
if (position < item.bodyStart || position >= item.bodyEnd) continue;
|
|
3342
|
-
const size = item.bodyEnd - item.bodyStart;
|
|
3343
|
-
if (size < span) {
|
|
3344
|
-
owner = item;
|
|
3345
|
-
span = size;
|
|
3346
|
-
}
|
|
3347
|
-
}
|
|
3348
|
-
return owner;
|
|
3349
|
-
};
|
|
3350
|
-
var allowsLiteralCapture = (owner) => owner.captureClass === "full" || owner.captureClass === "reactive-sparse";
|
|
3351
|
-
var walkPeelParent = (node) => {
|
|
3352
|
-
let current = node;
|
|
3353
|
-
while (current.parent) {
|
|
3354
|
-
const parent = current.parent;
|
|
3355
|
-
if ((ts12.isParenthesizedExpression(parent) || ts12.isNonNullExpression(parent) || ts12.isAsExpression(parent) || ts12.isTypeAssertionExpression(parent) || ts12.isSatisfiesExpression(parent)) && parent.expression === current) {
|
|
3356
|
-
current = parent;
|
|
3357
|
-
continue;
|
|
3358
|
-
}
|
|
3359
|
-
break;
|
|
3360
|
-
}
|
|
3361
|
-
return current;
|
|
3362
|
-
};
|
|
3363
|
-
var isCapturePosition = (node) => {
|
|
3364
|
-
const current = walkPeelParent(node);
|
|
3365
|
-
const parent = current.parent;
|
|
3366
|
-
if (!parent) return false;
|
|
3367
|
-
if (ts12.isReturnStatement(parent) && parent.expression === current) return true;
|
|
3368
|
-
if (ts12.isArrowFunction(parent) && parent.body === current) return true;
|
|
3369
|
-
if (ts12.isVariableDeclaration(parent) && parent.initializer === current) return true;
|
|
3370
|
-
if (ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.EqualsToken && parent.right === current) {
|
|
3371
|
-
return true;
|
|
3372
|
-
}
|
|
3373
|
-
if (ts12.isCallExpression(parent) || ts12.isNewExpression(parent)) {
|
|
3374
|
-
return parent.arguments?.some((argument) => argument === current) === true;
|
|
3375
|
-
}
|
|
3376
|
-
return false;
|
|
3377
|
-
};
|
|
3378
|
-
var isInAssignmentPattern = (node) => {
|
|
3379
|
-
let current = walkPeelParent(node);
|
|
3380
|
-
while (current.parent) {
|
|
3381
|
-
const parent = current.parent;
|
|
3382
|
-
if (ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.EqualsToken && parent.left === current) {
|
|
3383
|
-
return true;
|
|
3384
|
-
}
|
|
3385
|
-
if ((ts12.isForOfStatement(parent) || ts12.isForInStatement(parent)) && parent.initializer === current) {
|
|
3386
|
-
return true;
|
|
3387
|
-
}
|
|
3388
|
-
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)) {
|
|
3389
|
-
current = walkPeelParent(parent);
|
|
3390
|
-
continue;
|
|
3391
|
-
}
|
|
3392
|
-
return false;
|
|
3393
|
-
}
|
|
3394
|
-
return false;
|
|
3395
|
-
};
|
|
3396
|
-
var isLiteralChild = (node) => {
|
|
3397
|
-
const current = walkPeelParent(node);
|
|
3398
|
-
const parent = current.parent;
|
|
3399
|
-
if (!parent) return false;
|
|
3400
|
-
if (ts12.isPropertyAssignment(parent) && parent.initializer === current) return true;
|
|
3401
|
-
if (ts12.isArrayLiteralExpression(parent)) return true;
|
|
3402
|
-
return false;
|
|
3403
|
-
};
|
|
3404
|
-
var shouldRewrite = (node, classifications, sourceFile) => {
|
|
3405
|
-
if (isInAssignmentPattern(node)) return false;
|
|
3406
|
-
const owner = owningFunction(node.getStart(sourceFile), classifications);
|
|
3407
|
-
if (!owner || !allowsLiteralCapture(owner)) return false;
|
|
3408
|
-
return isCapturePosition(node) || isLiteralChild(node);
|
|
3409
|
-
};
|
|
3410
|
-
var collectLiteralSiteEdits = (source, filePath, options, sourceFile = parseSource(source, filePath)) => {
|
|
3411
|
-
const edits = [];
|
|
3412
|
-
const visit = (node) => {
|
|
3413
|
-
if ((ts12.isObjectLiteralExpression(node) || ts12.isArrayLiteralExpression(node)) && shouldRewrite(node, options.classifications, sourceFile)) {
|
|
3414
|
-
wrap(edits, node.getStart(sourceFile), node.end, `${STRUCT_CALLEE}(`, ")", 15);
|
|
3415
|
-
}
|
|
3416
|
-
ts12.forEachChild(node, visit);
|
|
3417
|
-
};
|
|
3418
|
-
visit(sourceFile);
|
|
3419
|
-
return { edits };
|
|
3420
|
-
};
|
|
3421
|
-
|
|
3422
|
-
// ../instrumentation/src/observe-sites.ts
|
|
3423
|
-
import { createHash } from "node:crypto";
|
|
3424
|
-
import { resolve as resolve4 } from "node:path";
|
|
3425
|
-
import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
|
|
3426
|
-
import ts13 from "typescript";
|
|
3427
|
-
var OBSERVE_CALLEE = "globalThis.__rasputinO";
|
|
3428
|
-
var siteIdFor = (filePath, line, column, text) => {
|
|
3429
|
-
const digest = createHash("sha256").update(`${resolve4(filePath)}:${line}:${column}:${text}`).digest("base64url").slice(0, 16);
|
|
3430
|
-
return `rs_${digest}`;
|
|
3431
|
-
};
|
|
3432
|
-
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;
|
|
3433
|
-
var isSafeLiteral = (expression) => {
|
|
3434
|
-
const node = peel(expression);
|
|
3435
|
-
if (ts13.isStringLiteral(node) || ts13.isNoSubstitutionTemplateLiteral(node)) return true;
|
|
3436
|
-
if (ts13.isNumericLiteral(node)) return true;
|
|
3437
|
-
if (node.kind === ts13.SyntaxKind.TrueKeyword || node.kind === ts13.SyntaxKind.FalseKeyword || node.kind === ts13.SyntaxKind.NullKeyword) {
|
|
3438
|
-
return true;
|
|
3439
|
-
}
|
|
3440
|
-
if (ts13.isIdentifier(node) && (node.text === "undefined" || node.text === "NaN")) return true;
|
|
3441
|
-
if (ts13.isPrefixUnaryExpression(node) && node.operator === ts13.SyntaxKind.MinusToken && ts13.isNumericLiteral(node.operand)) {
|
|
3442
|
-
return true;
|
|
3443
|
-
}
|
|
3444
|
-
return ts13.isVoidExpression(node) && ts13.isNumericLiteral(peel(node.expression)) && peel(node.expression).getText() === "0";
|
|
3445
|
-
};
|
|
3446
|
-
var isPropertyRead = (node) => {
|
|
3447
|
-
if (ts13.isPropertyAccessExpression(node)) {
|
|
3448
|
-
return !ts13.isPrivateIdentifier(node.name) && node.expression.kind !== ts13.SyntaxKind.SuperKeyword;
|
|
3449
|
-
}
|
|
3450
|
-
if (ts13.isElementAccessExpression(node)) {
|
|
3451
|
-
return node.expression.kind !== ts13.SyntaxKind.SuperKeyword;
|
|
3452
|
-
}
|
|
3453
|
-
return false;
|
|
3454
|
-
};
|
|
3455
|
-
var isMetaChain = (node) => {
|
|
3456
|
-
if (ts13.isMetaProperty(node)) return true;
|
|
3457
|
-
if (ts13.isPropertyAccessExpression(node)) return isMetaChain(node.expression);
|
|
3458
|
-
if (ts13.isElementAccessExpression(node)) return isMetaChain(node.expression);
|
|
3459
|
-
return false;
|
|
3460
|
-
};
|
|
3461
|
-
var isPatternParent = (parent, child) => {
|
|
3462
|
-
if (ts13.isParenthesizedExpression(parent) && parent.expression === child) return true;
|
|
3463
|
-
if (ts13.isAsExpression(parent) && parent.expression === child) return true;
|
|
3464
|
-
if (ts13.isTypeAssertionExpression(parent) && parent.expression === child) return true;
|
|
3465
|
-
if (ts13.isNonNullExpression(parent) && parent.expression === child) return true;
|
|
3466
|
-
if (ts13.isSatisfiesExpression(parent) && parent.expression === child) return true;
|
|
3467
|
-
if (ts13.isPropertyAssignment(parent) && parent.initializer === child) return true;
|
|
3468
|
-
if (ts13.isShorthandPropertyAssignment(parent)) return true;
|
|
3469
|
-
if (ts13.isSpreadAssignment(parent) && parent.expression === child) return true;
|
|
3470
|
-
if (ts13.isSpreadElement(parent) && parent.expression === child) return true;
|
|
3471
|
-
if (ts13.isArrayLiteralExpression(parent)) return true;
|
|
3472
|
-
if (ts13.isObjectLiteralExpression(parent)) return true;
|
|
3473
|
-
return false;
|
|
3474
|
-
};
|
|
3475
|
-
var isAssignmentTarget = (node) => {
|
|
3476
|
-
let current = node;
|
|
3477
|
-
while (current.parent) {
|
|
3478
|
-
const parent = current.parent;
|
|
3479
|
-
if (ts13.isComputedPropertyName(parent) && parent.expression === current) return false;
|
|
3480
|
-
if (ts13.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3481
|
-
return parent.left === current;
|
|
3482
|
-
}
|
|
3483
|
-
if ((ts13.isForOfStatement(parent) || ts13.isForInStatement(parent)) && parent.initializer === current) {
|
|
3484
|
-
return true;
|
|
3485
|
-
}
|
|
3486
|
-
if (!isPatternParent(parent, current)) return false;
|
|
3487
|
-
current = parent;
|
|
3488
|
-
}
|
|
3489
|
-
return false;
|
|
3490
|
-
};
|
|
3491
|
-
var isValueContext = (node) => {
|
|
3492
|
-
if (isAssignmentTarget(node)) return false;
|
|
3493
|
-
const parent = node.parent;
|
|
3494
|
-
if (!parent) return false;
|
|
3495
|
-
if (ts13.isVariableDeclaration(parent) && parent.initializer === node) return true;
|
|
3496
|
-
if (ts13.isReturnStatement(parent) && parent.expression === node) return true;
|
|
3497
|
-
if (ts13.isPropertyAssignment(parent) && parent.initializer === node) return true;
|
|
3498
|
-
if (ts13.isParenthesizedExpression(parent) || ts13.isNonNullExpression(parent) || ts13.isAsExpression(parent) || ts13.isTypeAssertionExpression(parent) || ts13.isSatisfiesExpression(parent)) {
|
|
3499
|
-
return isValueContext(parent);
|
|
3500
|
-
}
|
|
3501
|
-
return false;
|
|
3502
|
-
};
|
|
3503
|
-
var isCoalesceWithLiteral = (node) => {
|
|
3504
|
-
if (!ts13.isBinaryExpression(node)) return false;
|
|
3505
|
-
const operator = node.operatorToken.kind;
|
|
3506
|
-
if (operator !== ts13.SyntaxKind.QuestionQuestionToken && operator !== ts13.SyntaxKind.BarBarToken) {
|
|
3507
|
-
return false;
|
|
3508
|
-
}
|
|
3509
|
-
return isSafeLiteral(node.right);
|
|
3510
|
-
};
|
|
3511
|
-
var shouldWrapPropertyRead = (node) => {
|
|
3512
|
-
if (isMetaChain(node)) return false;
|
|
3513
|
-
const parent = node.parent;
|
|
3514
|
-
if (!parent) return false;
|
|
3515
|
-
if (ts13.isPropertyAccessExpression(parent) && parent.expression === node) return false;
|
|
3516
|
-
if (ts13.isElementAccessExpression(parent) && parent.expression === node) return false;
|
|
3517
|
-
if (ts13.isCallExpression(parent) && parent.expression === node) return false;
|
|
3518
|
-
if (ts13.isNewExpression(parent) && parent.expression === node) return false;
|
|
3519
|
-
if (ts13.isTaggedTemplateExpression(parent) && parent.tag === node) return false;
|
|
3520
|
-
if (ts13.isDeleteExpression(parent)) return false;
|
|
3521
|
-
if (ts13.isPrefixUnaryExpression(parent) && (parent.operator === ts13.SyntaxKind.PlusPlusToken || parent.operator === ts13.SyntaxKind.MinusMinusToken)) {
|
|
3522
|
-
return false;
|
|
3523
|
-
}
|
|
3524
|
-
if (ts13.isPostfixUnaryExpression(parent) && (parent.operator === ts13.SyntaxKind.PlusPlusToken || parent.operator === ts13.SyntaxKind.MinusMinusToken)) {
|
|
3525
|
-
return false;
|
|
3526
|
-
}
|
|
3527
|
-
if (ts13.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3528
|
-
if (parent.left === node) return false;
|
|
3529
|
-
}
|
|
3530
|
-
if (isValueContext(node)) return true;
|
|
3531
|
-
if (isCoalesceWithLiteral(parent) && parent.left === node) {
|
|
3532
|
-
return isValueContext(parent);
|
|
3533
|
-
}
|
|
3534
|
-
return false;
|
|
3535
|
-
};
|
|
3536
|
-
var shouldWrapRead = (node, classifications, sourceFile) => {
|
|
3537
|
-
if (isAssignmentTarget(node)) return false;
|
|
3538
|
-
return shouldWrapPropertyRead(node) || isReactiveArrowValue(node, classifications, sourceFile);
|
|
3539
|
-
};
|
|
3540
|
-
var hasOptional = (node) => !!node.questionDotToken;
|
|
3541
|
-
var isInternalProperty = (node) => {
|
|
3542
|
-
if (ts13.isPropertyAccessExpression(node)) return node.name.text.startsWith("__");
|
|
3543
|
-
if (!ts13.isStringLiteral(node.argumentExpression) && !ts13.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
|
|
3544
|
-
return false;
|
|
3545
|
-
}
|
|
3546
|
-
return node.argumentExpression.text.startsWith("__");
|
|
3547
|
-
};
|
|
3548
|
-
var staticPropertyName = (node) => {
|
|
3549
|
-
if (ts13.isPropertyAccessExpression(node)) return node.name.text;
|
|
3550
|
-
if (ts13.isStringLiteral(node.argumentExpression) || ts13.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
|
|
3551
|
-
return node.argumentExpression.text;
|
|
3552
|
-
}
|
|
3553
|
-
return void 0;
|
|
3554
|
-
};
|
|
3555
|
-
var BROWSER_SENSITIVE_SURFACES = /* @__PURE__ */ new Set([
|
|
3556
|
-
"value",
|
|
3557
|
-
"textContent",
|
|
3558
|
-
"innerText",
|
|
3559
|
-
"innerHTML",
|
|
3560
|
-
"href",
|
|
3561
|
-
"search",
|
|
3562
|
-
"URL"
|
|
3563
|
-
]);
|
|
3564
|
-
var isSensitiveRead = (node) => {
|
|
3565
|
-
const name = staticPropertyName(node);
|
|
3566
|
-
if (name === void 0) return false;
|
|
3567
|
-
return propertyNameIsSensitive2(name) || BROWSER_SENSITIVE_SURFACES.has(name);
|
|
3568
|
-
};
|
|
3569
|
-
var allowsExpressionCapture = (owner) => owner.captureClass === "full" || owner.captureClass === "reactive-sparse" || owner.compilerRole === "component-wrapper";
|
|
3570
|
-
var isReactiveArrowValue = (node, classifications, sourceFile) => {
|
|
3571
|
-
let current = node;
|
|
3572
|
-
while (current) {
|
|
3573
|
-
const parent = current.parent;
|
|
3574
|
-
if (!parent) return false;
|
|
3575
|
-
if (ts13.isArrowFunction(parent) && parent.body === current) {
|
|
3576
|
-
const owner = owningFunction2(node.getStart(sourceFile), classifications);
|
|
3577
|
-
return owner?.captureClass === "reactive-sparse";
|
|
3578
|
-
}
|
|
3579
|
-
if (ts13.isBinaryExpression(parent) && (parent.left === current || parent.right === current) && !isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3580
|
-
current = parent;
|
|
3581
|
-
continue;
|
|
3582
|
-
}
|
|
3583
|
-
if (ts13.isParenthesizedExpression(parent) || ts13.isNonNullExpression(parent) || ts13.isAsExpression(parent) || ts13.isTypeAssertionExpression(parent) || ts13.isSatisfiesExpression(parent)) {
|
|
3584
|
-
current = parent;
|
|
3585
|
-
continue;
|
|
3586
|
-
}
|
|
3587
|
-
return false;
|
|
3588
|
-
}
|
|
3589
|
-
return false;
|
|
3590
|
-
};
|
|
3591
|
-
var owningFunction2 = (position, classifications) => {
|
|
3592
|
-
if (!classifications || classifications.length === 0) return void 0;
|
|
3593
|
-
let owner;
|
|
3594
|
-
let span = Number.POSITIVE_INFINITY;
|
|
3595
|
-
for (const item of classifications) {
|
|
3596
|
-
if (position < item.bodyStart || position >= item.bodyEnd) continue;
|
|
3597
|
-
const size = item.bodyEnd - item.bodyStart;
|
|
3598
|
-
if (size < span) {
|
|
3599
|
-
owner = item;
|
|
3600
|
-
span = size;
|
|
3601
|
-
}
|
|
3602
|
-
}
|
|
3603
|
-
return owner;
|
|
3604
|
-
};
|
|
3605
|
-
var collectObserveSiteEdits = (source, filePath, options = {}, sourceFile = parseSource(source, filePath)) => {
|
|
3606
|
-
const absolutePath = resolve4(filePath);
|
|
3607
|
-
const emitIds = options.emitIds ?? { value: 1 };
|
|
3608
|
-
const queued = [];
|
|
3609
|
-
const visit = (node) => {
|
|
3610
|
-
if (isPropertyRead(node) && shouldWrapRead(node, options.classifications, sourceFile) && !isInternalProperty(node) && !isSensitiveRead(node)) {
|
|
3611
|
-
if (options.classifications) {
|
|
3612
|
-
const owner = owningFunction2(node.getStart(sourceFile), options.classifications);
|
|
3613
|
-
if (!owner || !allowsExpressionCapture(owner)) {
|
|
3614
|
-
ts13.forEachChild(node, visit);
|
|
3615
|
-
return;
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
const start = node.getStart(sourceFile);
|
|
3619
|
-
const text = node.getText(sourceFile);
|
|
3620
|
-
const location = sourceFile.getLineAndCharacterOfPosition(start);
|
|
3621
|
-
const line = location.line + 1;
|
|
3622
|
-
const column = location.character + 1;
|
|
3623
|
-
queued.push({
|
|
3624
|
-
start,
|
|
3625
|
-
end: node.end,
|
|
3626
|
-
site: {
|
|
3627
|
-
siteId: siteIdFor(absolutePath, line, column, text),
|
|
3628
|
-
emitId: emitIds.value++,
|
|
3629
|
-
filePath: absolutePath,
|
|
3630
|
-
line,
|
|
3631
|
-
column,
|
|
3632
|
-
kind: hasOptional(node) ? "optional-chain" : "property-read",
|
|
3633
|
-
sourceText: text.length > 80 ? `${text.slice(0, 77)}...` : text,
|
|
3634
|
-
start,
|
|
3635
|
-
end: node.end
|
|
3636
|
-
}
|
|
3637
|
-
});
|
|
3638
|
-
}
|
|
3639
|
-
ts13.forEachChild(node, visit);
|
|
3640
|
-
};
|
|
3641
|
-
visit(sourceFile);
|
|
3642
|
-
queued.sort((left, right) => right.start - left.start);
|
|
3643
|
-
const applied = [];
|
|
3644
|
-
const edits = [];
|
|
3645
|
-
let lastStart = Number.POSITIVE_INFINITY;
|
|
3646
|
-
for (const item of queued) {
|
|
3647
|
-
if (item.end > lastStart) continue;
|
|
3648
|
-
edits.push({
|
|
3649
|
-
position: item.start,
|
|
3650
|
-
text: `${OBSERVE_CALLEE}(${item.site.emitId},`,
|
|
3651
|
-
deleteCount: 0,
|
|
3652
|
-
depth: 20,
|
|
3653
|
-
width: item.end - item.start,
|
|
3654
|
-
kind: "open"
|
|
3655
|
-
});
|
|
3656
|
-
edits.push({
|
|
3657
|
-
position: item.end,
|
|
3658
|
-
text: ")",
|
|
3659
|
-
deleteCount: 0,
|
|
3660
|
-
depth: 20,
|
|
3661
|
-
width: item.end - item.start,
|
|
3662
|
-
kind: "close"
|
|
3663
|
-
});
|
|
3664
|
-
applied.push(item.site);
|
|
3665
|
-
lastStart = item.start;
|
|
3666
|
-
}
|
|
3667
|
-
applied.reverse();
|
|
3668
|
-
return { edits, sites: applied };
|
|
3669
|
-
};
|
|
3670
|
-
|
|
3671
|
-
// ../instrumentation/src/svelte-module-path.ts
|
|
3672
|
-
var isSvelteCompiledPath = (idOrPath) => {
|
|
3673
|
-
const path = idOrPath.split("?")[0]?.replaceAll("\\", "/") ?? "";
|
|
3674
|
-
return path.endsWith(".svelte") || path.endsWith(".svelte.ts") || path.endsWith(".svelte.js");
|
|
3675
|
-
};
|
|
3676
|
-
|
|
3677
|
-
// ../instrumentation/src/verify-browser-source.ts
|
|
3678
|
-
import ts14 from "typescript";
|
|
3679
|
-
var RASPUTIN_IDENT2 = /^__rasputin/;
|
|
3680
|
-
var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
3681
|
-
"__rasputinO",
|
|
3682
|
-
"__rasputinK",
|
|
3683
|
-
"__rasputinR",
|
|
3684
|
-
"__rasputinL",
|
|
3685
|
-
"__rasputinT",
|
|
3686
|
-
"__rasputinD",
|
|
3687
|
-
"__rasputinReg",
|
|
3688
|
-
"__rasputinM",
|
|
3689
|
-
"__rasputinA",
|
|
3690
|
-
"__rasputinP",
|
|
3691
|
-
"__rasputinN"
|
|
3692
|
-
]);
|
|
3693
|
-
var isRasputinName2 = (name) => RASPUTIN_IDENT2.test(name);
|
|
3694
|
-
var identText2 = (node) => {
|
|
3695
|
-
if (ts14.isIdentifier(node)) return node.text;
|
|
3696
|
-
if (ts14.isPrivateIdentifier(node)) return node.text;
|
|
3697
|
-
return void 0;
|
|
3698
|
-
};
|
|
3699
|
-
var calleeName2 = (expression) => {
|
|
3700
|
-
if (ts14.isIdentifier(expression)) return expression.text;
|
|
3701
|
-
if (ts14.isPropertyAccessExpression(expression)) {
|
|
3702
|
-
const object = identText2(expression.expression);
|
|
3703
|
-
const property = identText2(expression.name);
|
|
3704
|
-
if (object && isRasputinName2(object) && property) return `${object}.${property}`;
|
|
3705
|
-
if (object === "globalThis" && property && BROWSER_GLOBALS.has(property)) return property;
|
|
3706
|
-
}
|
|
3707
|
-
return void 0;
|
|
3708
|
-
};
|
|
3709
|
-
var isRasputinCall2 = (node) => {
|
|
3710
|
-
if (!ts14.isCallExpression(node)) return false;
|
|
3711
|
-
const name = calleeName2(node.expression);
|
|
3712
|
-
return Boolean(name && (isRasputinName2(name) || BROWSER_GLOBALS.has(name)));
|
|
3713
|
-
};
|
|
3714
|
-
var isRasputinAssignment = (node) => {
|
|
3715
|
-
if (!ts14.isBinaryExpression(node)) return false;
|
|
3716
|
-
const operator = node.operatorToken.kind;
|
|
3717
|
-
if (operator !== ts14.SyntaxKind.EqualsToken && operator !== ts14.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
3718
|
-
return false;
|
|
3719
|
-
}
|
|
3720
|
-
if (ts14.isPropertyAccessExpression(node.left)) {
|
|
3721
|
-
const object = identText2(node.left.expression);
|
|
3722
|
-
const property = identText2(node.left.name);
|
|
3723
|
-
return object === "globalThis" && property !== void 0 && BROWSER_GLOBALS.has(property);
|
|
3724
|
-
}
|
|
3725
|
-
const name = identText2(node.left);
|
|
3726
|
-
return Boolean(name && isRasputinName2(name));
|
|
3727
|
-
};
|
|
3728
|
-
var isRasputinOnlyInitializer = (expression) => {
|
|
3729
|
-
if (!expression) return true;
|
|
3730
|
-
const unwrapped = unwrapCall2(expression);
|
|
3731
|
-
if (unwrapped !== expression) {
|
|
3732
|
-
return ts14.isExpression(unwrapped) ? isRasputinOnlyInitializer(unwrapped) : false;
|
|
3733
|
-
}
|
|
3734
|
-
return isRasputinCall2(expression);
|
|
3735
|
-
};
|
|
3736
|
-
var jsonAwaitSlot = (node) => {
|
|
3737
|
-
if (node.operatorToken.kind !== ts14.SyntaxKind.CommaToken) return void 0;
|
|
3738
|
-
const assigned = node.left;
|
|
3739
|
-
if (!ts14.isBinaryExpression(assigned) || assigned.operatorToken.kind !== ts14.SyntaxKind.EqualsToken || !ts14.isIdentifier(assigned.left) || !isRasputinName2(assigned.left.text) || !ts14.isObjectLiteralExpression(assigned.right)) {
|
|
3740
|
-
return void 0;
|
|
3741
|
-
}
|
|
3742
|
-
const property = assigned.right.properties[0];
|
|
3743
|
-
if (!property || !ts14.isPropertyAssignment(property) || !ts14.isIdentifier(property.name) || property.name.text !== "p") {
|
|
3744
|
-
return void 0;
|
|
3745
|
-
}
|
|
3746
|
-
if (!ts14.isPropertyAccessExpression(node.right) || !ts14.isIdentifier(node.right.expression) || !isRasputinName2(node.right.expression.text) || node.right.name.text !== "p") {
|
|
3747
|
-
return void 0;
|
|
3748
|
-
}
|
|
3749
|
-
return property.initializer;
|
|
3750
|
-
};
|
|
3751
|
-
var peelParens = (node) => {
|
|
3752
|
-
let current = node;
|
|
3753
|
-
while (ts14.isParenthesizedExpression(current)) current = current.expression;
|
|
3754
|
-
return current;
|
|
3755
|
-
};
|
|
3756
|
-
var jsonMethodCall = (node) => {
|
|
3757
|
-
const receiver = node.arguments[0];
|
|
3758
|
-
const fn = node.arguments[1];
|
|
3759
|
-
if (!receiver || !fn) return void 0;
|
|
3760
|
-
const args = node.arguments.slice(2);
|
|
3761
|
-
if (!ts14.isPropertyAccessExpression(fn)) return void 0;
|
|
3762
|
-
return ts14.factory.createCallExpression(
|
|
3763
|
-
ts14.factory.createPropertyAccessExpression(receiver, fn.name),
|
|
3764
|
-
void 0,
|
|
3765
|
-
args
|
|
3766
|
-
);
|
|
3767
|
-
};
|
|
3768
|
-
var unwrapAdoptIife = (node) => {
|
|
3769
|
-
if (node.arguments.length !== 1) return void 0;
|
|
3770
|
-
const adopted = node.arguments[0];
|
|
3771
|
-
if (!adopted) return void 0;
|
|
3772
|
-
const callee = peelParens(node.expression);
|
|
3773
|
-
if (!ts14.isArrowFunction(callee) || callee.parameters.length !== 1 || ts14.isBlock(callee.body)) {
|
|
3774
|
-
return void 0;
|
|
3775
|
-
}
|
|
3776
|
-
const param = callee.parameters[0];
|
|
3777
|
-
if (!param || !ts14.isIdentifier(param.name) || param.dotDotDotToken || param.initializer) {
|
|
3778
|
-
return void 0;
|
|
3779
|
-
}
|
|
3780
|
-
const body = peelParens(callee.body);
|
|
3781
|
-
if (ts14.isCallExpression(body) && calleeName2(body.expression) === "__rasputinP") {
|
|
3782
|
-
const invoked = body.arguments[0];
|
|
3783
|
-
if (invoked && ts14.isCallExpression(invoked) && ts14.isIdentifier(invoked.expression) && invoked.expression.text === param.name.text) {
|
|
3784
|
-
return ts14.factory.createCallExpression(adopted, void 0, invoked.arguments);
|
|
3785
|
-
}
|
|
3786
|
-
return void 0;
|
|
3787
|
-
}
|
|
3788
|
-
if (!ts14.isCallExpression(body) || body.arguments.length !== 1) return void 0;
|
|
3789
|
-
const methodLookup = body.arguments[0];
|
|
3790
|
-
if (!methodLookup) return void 0;
|
|
3791
|
-
const inner = peelParens(body.expression);
|
|
3792
|
-
if (!ts14.isArrowFunction(inner) || inner.parameters.length !== 1 || ts14.isBlock(inner.body)) {
|
|
3793
|
-
return void 0;
|
|
3794
|
-
}
|
|
3795
|
-
const fnParam = inner.parameters[0];
|
|
3796
|
-
if (!fnParam || !ts14.isIdentifier(fnParam.name) || fnParam.dotDotDotToken || fnParam.initializer) {
|
|
3797
|
-
return void 0;
|
|
3798
|
-
}
|
|
3799
|
-
const innerBody = peelParens(inner.body);
|
|
3800
|
-
if (!ts14.isCallExpression(innerBody) || calleeName2(innerBody.expression) !== "__rasputinP") {
|
|
3801
|
-
return void 0;
|
|
3802
|
-
}
|
|
3803
|
-
const applied = innerBody.arguments[0];
|
|
3804
|
-
if (!applied || !ts14.isCallExpression(applied)) return void 0;
|
|
3805
|
-
const applyCallee = peelParens(applied.expression);
|
|
3806
|
-
if (!ts14.isPropertyAccessExpression(applyCallee) || applyCallee.name.text !== "apply" || !ts14.isIdentifier(applyCallee.expression) || applyCallee.expression.text !== "Reflect") {
|
|
3807
|
-
return void 0;
|
|
3808
|
-
}
|
|
3809
|
-
const appliedFn = applied.arguments[0];
|
|
3810
|
-
const thisArg = applied.arguments[1];
|
|
3811
|
-
const argsArg = applied.arguments[2];
|
|
3812
|
-
if (!appliedFn || !ts14.isIdentifier(appliedFn) || appliedFn.text !== fnParam.name.text) {
|
|
3813
|
-
return void 0;
|
|
3814
|
-
}
|
|
3815
|
-
if (!thisArg || !ts14.isIdentifier(thisArg) || thisArg.text !== param.name.text) return void 0;
|
|
3816
|
-
if (!argsArg || !ts14.isArrayLiteralExpression(argsArg)) return void 0;
|
|
3817
|
-
if (!ts14.isPropertyAccessExpression(methodLookup) || !ts14.isIdentifier(methodLookup.expression) || methodLookup.expression.text !== param.name.text || ts14.isPrivateIdentifier(methodLookup.name)) {
|
|
3818
|
-
return void 0;
|
|
3819
|
-
}
|
|
3820
|
-
return ts14.factory.createCallExpression(
|
|
3821
|
-
ts14.factory.createPropertyAccessExpression(adopted, methodLookup.name),
|
|
3822
|
-
void 0,
|
|
3823
|
-
[...argsArg.elements]
|
|
3824
|
-
);
|
|
3825
|
-
};
|
|
3826
|
-
var unwrapProducerIife = (node) => {
|
|
3827
|
-
if (node.arguments.length !== 1) return void 0;
|
|
3828
|
-
const receiver = node.arguments[0];
|
|
3829
|
-
if (!receiver) return void 0;
|
|
3830
|
-
const callee = peelParens(node.expression);
|
|
3831
|
-
if (!ts14.isArrowFunction(callee) || callee.parameters.length !== 1 || ts14.isBlock(callee.body)) {
|
|
3832
|
-
return void 0;
|
|
3833
|
-
}
|
|
3834
|
-
const param = callee.parameters[0];
|
|
3835
|
-
if (!param || !ts14.isIdentifier(param.name) || param.dotDotDotToken || param.initializer) {
|
|
3836
|
-
return void 0;
|
|
3837
|
-
}
|
|
3838
|
-
const body = peelParens(callee.body);
|
|
3839
|
-
if (!ts14.isCallExpression(body) || !isRasputinCall2(body)) return void 0;
|
|
3840
|
-
if (calleeName2(body.expression) !== "__rasputinM") return void 0;
|
|
3841
|
-
const bound = body.arguments[0];
|
|
3842
|
-
const fn = body.arguments[1];
|
|
3843
|
-
if (!bound || !fn || !ts14.isIdentifier(bound) || bound.text !== param.name.text) return void 0;
|
|
3844
|
-
if (!ts14.isPropertyAccessExpression(fn)) return void 0;
|
|
3845
|
-
if (!ts14.isIdentifier(fn.expression) || fn.expression.text !== param.name.text) return void 0;
|
|
3846
|
-
return ts14.factory.createCallExpression(
|
|
3847
|
-
ts14.factory.createPropertyAccessExpression(receiver, fn.name),
|
|
3848
|
-
void 0,
|
|
3849
|
-
body.arguments.slice(2)
|
|
3850
|
-
);
|
|
3851
|
-
};
|
|
3852
|
-
var unwrapCall2 = (node) => {
|
|
3853
|
-
let current = node;
|
|
3854
|
-
while (true) {
|
|
3855
|
-
if (ts14.isParenthesizedExpression(current)) {
|
|
3856
|
-
current = current.expression;
|
|
3857
|
-
continue;
|
|
3858
|
-
}
|
|
3859
|
-
if (ts14.isBinaryExpression(current)) {
|
|
3860
|
-
const slot = jsonAwaitSlot(current);
|
|
3861
|
-
if (slot) {
|
|
3862
|
-
current = slot;
|
|
3863
|
-
continue;
|
|
3864
|
-
}
|
|
3865
|
-
}
|
|
3866
|
-
if (ts14.isConditionalExpression(current) && isRasputinName2(identText2(current.condition) ?? "")) {
|
|
3867
|
-
current = current.whenTrue;
|
|
3868
|
-
continue;
|
|
3869
|
-
}
|
|
3870
|
-
if (ts14.isCallExpression(current)) {
|
|
3871
|
-
const adopted = unwrapAdoptIife(current);
|
|
3872
|
-
if (adopted) {
|
|
3873
|
-
current = adopted;
|
|
3874
|
-
continue;
|
|
3875
|
-
}
|
|
3876
|
-
const producer = unwrapProducerIife(current);
|
|
3877
|
-
if (producer) {
|
|
3878
|
-
current = producer;
|
|
3879
|
-
continue;
|
|
3880
|
-
}
|
|
3881
|
-
}
|
|
3882
|
-
if (ts14.isCallExpression(current) && isRasputinCall2(current)) {
|
|
3883
|
-
const name = calleeName2(current.expression);
|
|
3884
|
-
if ((name === "__rasputinO" || name === "__rasputinL") && current.arguments.length >= 2 && current.arguments[1]) {
|
|
3885
|
-
current = current.arguments[1];
|
|
3886
|
-
continue;
|
|
3887
|
-
}
|
|
3888
|
-
if ((name === "__rasputinA" || name === "__rasputinP") && current.arguments[0]) {
|
|
3889
|
-
current = current.arguments[0];
|
|
3890
|
-
continue;
|
|
3891
|
-
}
|
|
3892
|
-
if (name === "__rasputinK" && current.arguments[0]) {
|
|
3893
|
-
current = current.arguments[0];
|
|
3894
|
-
continue;
|
|
3895
|
-
}
|
|
3896
|
-
if (name === "__rasputinM") {
|
|
3897
|
-
const reconstructed = jsonMethodCall(current);
|
|
3898
|
-
if (reconstructed) {
|
|
3899
|
-
current = reconstructed;
|
|
3900
|
-
continue;
|
|
3901
|
-
}
|
|
3902
|
-
}
|
|
3903
|
-
if (current.arguments.length === 1 && current.arguments[0] && name && (name.endsWith(".leave") || name.endsWith(".suspend") || name.endsWith(".resume"))) {
|
|
3904
|
-
current = current.arguments[0];
|
|
3905
|
-
continue;
|
|
3906
|
-
}
|
|
3907
|
-
}
|
|
3908
|
-
break;
|
|
3909
|
-
}
|
|
3910
|
-
return current;
|
|
3911
|
-
};
|
|
3912
|
-
var isRasputinIf = (node) => {
|
|
3913
|
-
if (node.elseStatement) return false;
|
|
3914
|
-
const condition = node.expression;
|
|
3915
|
-
const negated = ts14.isPrefixUnaryExpression(condition) && condition.operator === ts14.SyntaxKind.ExclamationToken && isRasputinName2(identText2(condition.operand) ?? "");
|
|
3916
|
-
if (!negated) return false;
|
|
3917
|
-
const then = node.thenStatement;
|
|
3918
|
-
if (ts14.isExpressionStatement(then) && isRasputinCall2(then.expression)) return true;
|
|
3919
|
-
return ts14.isBlock(then) && then.statements.every((statement) => isRasputinStatement2(statement));
|
|
3920
|
-
};
|
|
3921
|
-
var isRasputinStatement2 = (node) => {
|
|
3922
|
-
if (ts14.isEmptyStatement(node)) return true;
|
|
3923
|
-
if (ts14.isVariableStatement(node)) {
|
|
3924
|
-
return node.declarationList.declarations.every((declaration) => {
|
|
3925
|
-
const name = identText2(declaration.name);
|
|
3926
|
-
return Boolean(name && isRasputinName2(name));
|
|
3927
|
-
});
|
|
3928
|
-
}
|
|
3929
|
-
if (ts14.isExpressionStatement(node)) {
|
|
3930
|
-
if (isRasputinAssignment(node.expression)) return true;
|
|
3931
|
-
if (!isRasputinCall2(node.expression)) return false;
|
|
3932
|
-
return unwrapCall2(node.expression) === node.expression;
|
|
3933
|
-
}
|
|
3934
|
-
if (ts14.isIfStatement(node)) return isRasputinIf(node);
|
|
3935
|
-
return false;
|
|
3936
|
-
};
|
|
3937
|
-
var isRasputinTryWrapper2 = (node) => {
|
|
3938
|
-
const catchClause = node.catchClause;
|
|
3939
|
-
if (!catchClause || !node.finallyBlock) return false;
|
|
3940
|
-
const catchCalls = catchClause.block.statements.filter(
|
|
3941
|
-
(statement) => !isRasputinStatement2(statement)
|
|
3942
|
-
);
|
|
3943
|
-
const leftover = catchCalls[0];
|
|
3944
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts14.isThrowStatement(leftover) && ts14.isIdentifier(leftover.expression);
|
|
3945
|
-
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
3946
|
-
return node.finallyBlock.statements.every((statement) => isRasputinStatement2(statement));
|
|
3947
|
-
};
|
|
3948
|
-
var customerTempInit = (statement) => {
|
|
3949
|
-
if (!ts14.isVariableStatement(statement)) return void 0;
|
|
3950
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
3951
|
-
const name = identText2(declaration.name);
|
|
3952
|
-
if (!name || !isRasputinName2(name) || !declaration.initializer) continue;
|
|
3953
|
-
if (isRasputinOnlyInitializer(declaration.initializer)) continue;
|
|
3954
|
-
return { name, init: declaration.initializer };
|
|
3955
|
-
}
|
|
3956
|
-
return void 0;
|
|
3957
|
-
};
|
|
3958
|
-
var flattenStatements2 = (statements) => {
|
|
3959
|
-
const flattened = [];
|
|
3960
|
-
for (const statement of statements) {
|
|
3961
|
-
if (isRasputinStatement2(statement)) continue;
|
|
3962
|
-
if (ts14.isTryStatement(statement) && isRasputinTryWrapper2(statement)) {
|
|
3963
|
-
flattened.push(...flattenStatements2(statement.tryBlock.statements));
|
|
3964
|
-
continue;
|
|
3965
|
-
}
|
|
3966
|
-
flattened.push(statement);
|
|
3967
|
-
}
|
|
3968
|
-
return flattened;
|
|
3969
|
-
};
|
|
3970
|
-
var isRememberIife = (node) => {
|
|
3971
|
-
if (!ts14.isCallExpression(node) || node.arguments.length > 0) return void 0;
|
|
3972
|
-
let callee = node.expression;
|
|
3973
|
-
if (ts14.isParenthesizedExpression(callee)) callee = callee.expression;
|
|
3974
|
-
if (!ts14.isArrowFunction(callee) || callee.parameters.length > 0 || !ts14.isBlock(callee.body)) {
|
|
3975
|
-
return void 0;
|
|
3976
|
-
}
|
|
3977
|
-
const statements = callee.body.statements;
|
|
3978
|
-
const last = statements.at(-1);
|
|
3979
|
-
if (!last || !ts14.isReturnStatement(last) || !last.expression) return void 0;
|
|
3980
|
-
let returned = last.expression;
|
|
3981
|
-
while (ts14.isParenthesizedExpression(returned)) returned = returned.expression;
|
|
3982
|
-
if (!ts14.isCallExpression(returned)) return void 0;
|
|
3983
|
-
const name = calleeName2(returned.expression);
|
|
3984
|
-
if (name !== "__rasputinK") return void 0;
|
|
3985
|
-
const objectArg = returned.arguments[0];
|
|
3986
|
-
if (!objectArg || !ts14.isIdentifier(objectArg)) return void 0;
|
|
3987
|
-
const temps = /* @__PURE__ */ new Map();
|
|
3988
|
-
for (const statement of statements.slice(0, -1)) {
|
|
3989
|
-
if (!ts14.isVariableStatement(statement)) return void 0;
|
|
3990
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
3991
|
-
if (!ts14.isIdentifier(declaration.name) || !declaration.initializer) return void 0;
|
|
3992
|
-
temps.set(declaration.name.text, declaration.initializer);
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
const object = temps.get(objectArg.text);
|
|
3996
|
-
if (!object) return void 0;
|
|
3997
|
-
return { object, temps };
|
|
3998
|
-
};
|
|
3999
|
-
var resolveRememberTemp = (expression, temps, seen) => {
|
|
4000
|
-
let current = expression;
|
|
4001
|
-
while (ts14.isParenthesizedExpression(current) || ts14.isNonNullExpression(current) || ts14.isAsExpression(current) || ts14.isTypeAssertionExpression(current) || ts14.isSatisfiesExpression(current)) {
|
|
4002
|
-
current = current.expression;
|
|
4003
|
-
}
|
|
4004
|
-
if (ts14.isIdentifier(current) && temps.has(current.text) && !seen.has(current.text)) {
|
|
4005
|
-
const next = temps.get(current.text);
|
|
4006
|
-
if (!next) return current;
|
|
4007
|
-
seen.add(current.text);
|
|
4008
|
-
return resolveRememberTemp(next, temps, seen);
|
|
4009
|
-
}
|
|
4010
|
-
return current;
|
|
4011
|
-
};
|
|
4012
|
-
var extra2 = (node) => {
|
|
4013
|
-
if (ts14.isIdentifier(node) || ts14.isPrivateIdentifier(node)) {
|
|
4014
|
-
return isRasputinName2(node.text) ? "" : node.text;
|
|
4015
|
-
}
|
|
4016
|
-
if (ts14.isStringLiteral(node) || ts14.isNumericLiteral(node) || ts14.isNoSubstitutionTemplateLiteral(node)) {
|
|
4017
|
-
return node.text;
|
|
4018
|
-
}
|
|
4019
|
-
if (ts14.isToken(node) && !ts14.isIdentifier(node)) return ts14.SyntaxKind[node.kind] ?? "";
|
|
4020
|
-
return "";
|
|
4021
|
-
};
|
|
4022
|
-
var signatureOfSubstituted = (node, temps) => {
|
|
4023
|
-
const remembered = isRememberIife(node);
|
|
4024
|
-
if (remembered) return signatureOfSubstituted(remembered.object, remembered.temps);
|
|
4025
|
-
if (ts14.isObjectLiteralExpression(node)) {
|
|
4026
|
-
const parts = node.properties.map((property) => {
|
|
4027
|
-
if (ts14.isShorthandPropertyAssignment(property)) return signatureOf2(property);
|
|
4028
|
-
if (!ts14.isPropertyAssignment(property)) return signatureOf2(property);
|
|
4029
|
-
const init = resolveRememberTemp(property.initializer, temps, /* @__PURE__ */ new Set());
|
|
4030
|
-
if (ts14.isIdentifier(property.name) && ts14.isIdentifier(init) && property.name.text === init.text) {
|
|
4031
|
-
return signatureOf2(ts14.factory.createShorthandPropertyAssignment(property.name));
|
|
4032
|
-
}
|
|
4033
|
-
if (ts14.isComputedPropertyName(property.name)) {
|
|
4034
|
-
const key = resolveRememberTemp(property.name.expression, temps, /* @__PURE__ */ new Set());
|
|
4035
|
-
return `PropertyAssignment[ComputedPropertyName[${signatureOfSubstituted(key, temps)}],${signatureOfSubstituted(init, temps)}]`;
|
|
4036
|
-
}
|
|
4037
|
-
return `PropertyAssignment[${signatureOf2(property.name)},${signatureOfSubstituted(init, temps)}]`;
|
|
4038
|
-
});
|
|
4039
|
-
return `ObjectLiteralExpression[${parts.join(",")}]`;
|
|
4040
|
-
}
|
|
4041
|
-
if (ts14.isArrayLiteralExpression(node)) {
|
|
4042
|
-
const parts = node.elements.map(
|
|
4043
|
-
(element) => signatureOfSubstituted(resolveRememberTemp(element, temps, /* @__PURE__ */ new Set()), temps)
|
|
4044
|
-
);
|
|
4045
|
-
return `ArrayLiteralExpression[${parts.join(",")}]`;
|
|
4046
|
-
}
|
|
4047
|
-
return signatureOf2(node);
|
|
4048
|
-
};
|
|
4049
|
-
var signatureOfRememberedLiteral = (node) => {
|
|
4050
|
-
const parsed = isRememberIife(node);
|
|
4051
|
-
if (!parsed) return void 0;
|
|
4052
|
-
return signatureOfSubstituted(parsed.object, parsed.temps);
|
|
4053
|
-
};
|
|
4054
|
-
var signatureOf2 = (node) => {
|
|
4055
|
-
const unwrapped = unwrapCall2(node);
|
|
4056
|
-
if (unwrapped !== node) return signatureOf2(unwrapped);
|
|
4057
|
-
const remembered = signatureOfRememberedLiteral(unwrapped);
|
|
4058
|
-
if (remembered !== void 0) return remembered;
|
|
4059
|
-
if (ts14.isPropertyAssignment(unwrapped) && ts14.isIdentifier(unwrapped.name) && ts14.isIdentifier(unwrapped.initializer) && unwrapped.name.text === unwrapped.initializer.text) {
|
|
4060
|
-
return signatureOf2(ts14.factory.createShorthandPropertyAssignment(unwrapped.name));
|
|
4061
|
-
}
|
|
4062
|
-
if (ts14.isEmptyStatement(unwrapped) || isRasputinStatement2(unwrapped)) return "";
|
|
4063
|
-
if (ts14.isTryStatement(unwrapped) && isRasputinTryWrapper2(unwrapped)) {
|
|
4064
|
-
return flattenStatements2(unwrapped.tryBlock.statements).map(signatureOf2).filter(Boolean).join("");
|
|
4065
|
-
}
|
|
4066
|
-
if (ts14.isCatchClause(unwrapped)) {
|
|
4067
|
-
const statements = flattenStatements2(unwrapped.block.statements);
|
|
4068
|
-
const variable = unwrapped.variableDeclaration ? signatureOf2(unwrapped.variableDeclaration) : "";
|
|
4069
|
-
return `Catch${variable}[${statements.map(signatureOf2).filter(Boolean).join(",")}]`;
|
|
4070
|
-
}
|
|
4071
|
-
if (ts14.isBlock(unwrapped)) {
|
|
4072
|
-
const statements = flattenStatements2(unwrapped.statements);
|
|
4073
|
-
return `Block[${statements.map(signatureOf2).filter(Boolean).join(",")}]`;
|
|
4074
|
-
}
|
|
4075
|
-
if (ts14.isArrowFunction(unwrapped) && ts14.isBlock(unwrapped.body)) {
|
|
4076
|
-
const raw = unwrapped.body.statements;
|
|
4077
|
-
const tryWrap = raw.length === 1 && raw[0] && ts14.isTryStatement(raw[0]) ? raw[0] : void 0;
|
|
4078
|
-
const inner = tryWrap && isRasputinTryWrapper2(tryWrap) ? tryWrap.tryBlock.statements : raw;
|
|
4079
|
-
const temp = inner[0] ? customerTempInit(inner[0]) : void 0;
|
|
4080
|
-
const returned = inner[1];
|
|
4081
|
-
if (temp && returned && ts14.isReturnStatement(returned) && returned.expression && inner.length === 2) {
|
|
4082
|
-
const value = unwrapCall2(returned.expression);
|
|
4083
|
-
if (ts14.isIdentifier(value) && value.text === temp.name) {
|
|
4084
|
-
const parts2 = [];
|
|
4085
|
-
ts14.forEachChild(unwrapped, (child) => {
|
|
4086
|
-
if (child === unwrapped.body) {
|
|
4087
|
-
const part2 = signatureOf2(temp.init);
|
|
4088
|
-
if (part2) parts2.push(part2);
|
|
4089
|
-
return;
|
|
4090
|
-
}
|
|
4091
|
-
const part = signatureOf2(child);
|
|
4092
|
-
if (part) parts2.push(part);
|
|
4093
|
-
});
|
|
4094
|
-
return `ArrowFunction[${parts2.join(",")}]`;
|
|
4095
|
-
}
|
|
4096
|
-
}
|
|
4097
|
-
const statements = flattenStatements2(unwrapped.body.statements);
|
|
4098
|
-
const only = statements[0];
|
|
4099
|
-
const onlyExpression = only && ts14.isReturnStatement(only) ? only.expression : void 0;
|
|
4100
|
-
if (statements.length === 1 && onlyExpression) {
|
|
4101
|
-
const parts2 = [];
|
|
4102
|
-
ts14.forEachChild(unwrapped, (child) => {
|
|
4103
|
-
if (child === unwrapped.body) {
|
|
4104
|
-
const part2 = signatureOf2(onlyExpression);
|
|
4105
|
-
if (part2) parts2.push(part2);
|
|
4106
|
-
return;
|
|
4107
|
-
}
|
|
4108
|
-
const part = signatureOf2(child);
|
|
4109
|
-
if (part) parts2.push(part);
|
|
4110
|
-
});
|
|
4111
|
-
return `ArrowFunction[${parts2.join(",")}]`;
|
|
4112
|
-
}
|
|
4113
|
-
}
|
|
4114
|
-
if (ts14.isReturnStatement(unwrapped)) {
|
|
4115
|
-
if (!unwrapped.expression) return "ReturnStatement[]";
|
|
4116
|
-
const expression = unwrapCall2(unwrapped.expression);
|
|
4117
|
-
if (ts14.isVoidExpression(expression) && isRasputinCall2(expression.expression)) {
|
|
4118
|
-
return "ReturnStatement[]";
|
|
4119
|
-
}
|
|
4120
|
-
return `Return[${signatureOf2(unwrapped.expression)}]`;
|
|
4121
|
-
}
|
|
4122
|
-
const parts = [];
|
|
4123
|
-
ts14.forEachChild(unwrapped, (child) => {
|
|
4124
|
-
const part = signatureOf2(child);
|
|
4125
|
-
if (part) parts.push(part);
|
|
4126
|
-
});
|
|
4127
|
-
const kind = ts14.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
4128
|
-
return `${kind}${extra2(unwrapped)}[${parts.join(",")}]`;
|
|
4129
|
-
};
|
|
4130
|
-
var browserInstrumentationIsSafe = (filePath, original, transformed) => {
|
|
4131
|
-
if (transformedSourceIsInvalid(filePath, transformed)) return false;
|
|
4132
|
-
try {
|
|
4133
|
-
parseSource(transformed, filePath);
|
|
4134
|
-
} catch {
|
|
4135
|
-
return false;
|
|
4136
|
-
}
|
|
4137
|
-
return signatureOf2(parseSource(original, filePath)) === signatureOf2(parseSource(transformed, filePath));
|
|
4138
|
-
};
|
|
4139
|
-
|
|
4140
|
-
// ../instrumentation/src/instrument-browser-source.ts
|
|
4141
|
-
var refuse = (source, classifications) => ({
|
|
4142
|
-
code: source,
|
|
4143
|
-
delta: { functions: [], callSites: [], destructures: [] },
|
|
4144
|
-
classifications,
|
|
4145
|
-
sites: [],
|
|
4146
|
-
identities: [],
|
|
4147
|
-
verificationFailed: true
|
|
4148
|
-
});
|
|
4149
|
-
var instrumentBrowserSource = (source, filePath, emitIds, reactiveIds, moduleIndex = 0, options) => {
|
|
4150
|
-
if (isSvelteCompiledPath(filePath) && !options?.policy) {
|
|
4151
|
-
return {
|
|
4152
|
-
code: source,
|
|
4153
|
-
classifications: [],
|
|
4154
|
-
sites: [],
|
|
4155
|
-
identities: [],
|
|
4156
|
-
delta: { functions: [], callSites: [], destructures: [] }
|
|
4157
|
-
};
|
|
4158
|
-
}
|
|
4159
|
-
if (source.includes("@rasputin-ignore-file") || sourceIsRasputinInstrumented(source)) {
|
|
4160
|
-
return {
|
|
4161
|
-
code: source,
|
|
4162
|
-
classifications: [],
|
|
4163
|
-
sites: [],
|
|
4164
|
-
identities: [],
|
|
4165
|
-
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
4166
|
-
};
|
|
4167
|
-
}
|
|
4168
|
-
const sourceFile = parseSource(source, filePath);
|
|
4169
|
-
const classifications = classifyFunctions(
|
|
4170
|
-
source,
|
|
4171
|
-
filePath,
|
|
4172
|
-
options?.mapLocation,
|
|
4173
|
-
options?.policy
|
|
4174
|
-
);
|
|
4175
|
-
const observe = collectObserveSiteEdits(
|
|
4176
|
-
source,
|
|
4177
|
-
filePath,
|
|
4178
|
-
{ classifications, emitIds },
|
|
4179
|
-
sourceFile
|
|
4180
|
-
);
|
|
4181
|
-
const literals = collectLiteralSiteEdits(source, filePath, { classifications }, sourceFile);
|
|
4182
|
-
const json = collectJsonProducerEdits(source, filePath, sourceFile, {
|
|
4183
|
-
adoptCalls: true,
|
|
4184
|
-
policy: options?.policy
|
|
4185
|
-
});
|
|
4186
|
-
const functions = collectBrowserFunctionEdits(
|
|
4187
|
-
source,
|
|
4188
|
-
sourceFile,
|
|
4189
|
-
classifications,
|
|
4190
|
-
moduleIndex,
|
|
4191
|
-
reactiveIds ?? { value: 1 },
|
|
4192
|
-
{
|
|
4193
|
-
observe: observe.sites.length > 0,
|
|
4194
|
-
struct: literals.edits.length > 0,
|
|
4195
|
-
includePlans: options?.includePlans === true,
|
|
4196
|
-
mapLocation: options?.mapLocation,
|
|
4197
|
-
policy: options?.policy
|
|
4198
|
-
}
|
|
4199
|
-
);
|
|
4200
|
-
const edits = [...observe.edits, ...literals.edits, ...json.edits, ...functions.edits];
|
|
4201
|
-
if (edits.length === 0) {
|
|
4202
|
-
return {
|
|
4203
|
-
code: source,
|
|
4204
|
-
classifications,
|
|
4205
|
-
sites: [],
|
|
4206
|
-
identities: [],
|
|
4207
|
-
delta: functions.delta
|
|
4208
|
-
};
|
|
4209
|
-
}
|
|
4210
|
-
const code = applyEdits(source, edits);
|
|
4211
|
-
if (!browserInstrumentationIsSafe(filePath, source, code)) {
|
|
4212
|
-
return refuse(source, classifications);
|
|
4213
|
-
}
|
|
4214
|
-
return {
|
|
4215
|
-
code,
|
|
4216
|
-
map: exactTransformMap(source, code, basename2(filePath), edits),
|
|
4217
|
-
delta: functions.delta,
|
|
4218
|
-
classifications,
|
|
4219
|
-
sites: observe.sites,
|
|
4220
|
-
identities: functions.identities
|
|
4221
|
-
};
|
|
4222
|
-
};
|
|
4223
|
-
|
|
4224
|
-
// ../instrumentation/src/provenance-function-edits.ts
|
|
4225
|
-
import ts15 from "typescript";
|
|
4226
|
-
|
|
4227
|
-
// ../instrumentation/src/source-map-location.ts
|
|
4228
|
-
import { dirname, join } from "node:path";
|
|
4229
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4230
|
-
var baseName = (path) => path.replaceAll("\\", "/").split("/").pop()?.split("?")[0] ?? "";
|
|
4231
|
-
var isWindowsAbsolute = (path) => /^[A-Za-z]:[\\/]/.test(path);
|
|
4232
|
-
var sameSourceFile = (source, generatedPath) => {
|
|
4233
|
-
const sourceName = baseName(source);
|
|
4234
|
-
const generatedName = baseName(generatedPath);
|
|
4235
|
-
return sourceName.length > 0 && sourceName === generatedName;
|
|
4236
|
-
};
|
|
4237
|
-
var toFilePath = (source, generatedPath) => {
|
|
4238
|
-
if (sameSourceFile(source, generatedPath)) return generatedPath;
|
|
4239
|
-
if (source.startsWith("file:")) {
|
|
4240
|
-
try {
|
|
4241
|
-
return fileURLToPath(source);
|
|
4242
|
-
} catch {
|
|
4243
|
-
return generatedPath;
|
|
4244
|
-
}
|
|
4245
|
-
}
|
|
4246
|
-
if (isWindowsAbsolute(source) || source.startsWith("/")) return source;
|
|
4247
|
-
return join(dirname(generatedPath), source);
|
|
4248
|
-
};
|
|
4249
|
-
var isSourceMapInput = (value) => {
|
|
4250
|
-
if (typeof value === "string") return true;
|
|
4251
|
-
if (!value || typeof value !== "object") return false;
|
|
4252
|
-
return value instanceof TraceMap || "mappings" in value;
|
|
4253
|
-
};
|
|
4254
|
-
var createSourceMapLocationMapper = (generatedPath, map) => {
|
|
4255
|
-
if (!isSourceMapInput(map)) return void 0;
|
|
4256
|
-
try {
|
|
4257
|
-
const traceMap = new TraceMap(map, pathToFileURL(generatedPath).href);
|
|
4258
|
-
return (generated) => {
|
|
4259
|
-
let original = originalPositionFor(traceMap, {
|
|
4260
|
-
line: generated.line,
|
|
4261
|
-
column: Math.max(0, generated.column - 1)
|
|
4262
|
-
});
|
|
4263
|
-
if (!original.source || original.line == null) {
|
|
4264
|
-
original = originalPositionFor(traceMap, {
|
|
4265
|
-
line: generated.line,
|
|
4266
|
-
column: 0
|
|
4267
|
-
});
|
|
4268
|
-
}
|
|
4269
|
-
if (!original.source || original.line == null) return void 0;
|
|
4270
|
-
return {
|
|
4271
|
-
filePath: toFilePath(original.source, generatedPath),
|
|
4272
|
-
line: original.line,
|
|
4273
|
-
column: (original.column ?? 0) + 1
|
|
4274
|
-
};
|
|
4275
|
-
};
|
|
4276
|
-
} catch {
|
|
4277
|
-
return void 0;
|
|
4278
|
-
}
|
|
4279
|
-
};
|
|
4280
|
-
|
|
4281
|
-
// src/compiler/client-policy.ts
|
|
4282
|
-
import ts17 from "typescript";
|
|
4283
|
-
|
|
4284
|
-
// src/compiler/svelte-generated.ts
|
|
4285
|
-
import ts16 from "typescript";
|
|
4286
|
-
var SVELTE_TEMPLATE_FACTORIES = /* @__PURE__ */ new Set(["from_html", "from_svg", "template"]);
|
|
4287
|
-
var SVELTE_PROP_GETTERS = /* @__PURE__ */ new Set(["prop", "prop_source"]);
|
|
4288
|
-
var isFunctionLike2 = (node) => ts16.isFunctionDeclaration(node) || ts16.isFunctionExpression(node) || ts16.isArrowFunction(node) || ts16.isMethodDeclaration(node) || ts16.isGetAccessorDeclaration(node) || ts16.isSetAccessorDeclaration(node);
|
|
4289
|
-
var isDescendant = (root, node) => {
|
|
4290
|
-
let current = node;
|
|
4291
|
-
while (current) {
|
|
4292
|
-
if (current === root) return true;
|
|
4293
|
-
current = current.parent;
|
|
4294
|
-
}
|
|
4295
|
-
return false;
|
|
4296
|
-
};
|
|
4297
|
-
var svelteCallMethod = (call) => {
|
|
4298
|
-
const callee = call.expression;
|
|
4299
|
-
if (!ts16.isPropertyAccessExpression(callee) || !ts16.isIdentifier(callee.expression)) {
|
|
4300
|
-
return void 0;
|
|
4301
|
-
}
|
|
4302
|
-
if (callee.expression.text !== "$" || !ts16.isIdentifier(callee.name)) return void 0;
|
|
4303
|
-
return callee.name.text;
|
|
4304
|
-
};
|
|
4305
|
-
var svelteRuntimeMethod = (node) => {
|
|
4306
|
-
const parent = node.parent;
|
|
4307
|
-
if (!parent || !ts16.isCallExpression(parent)) return void 0;
|
|
4308
|
-
if (!parent.arguments.some((argument) => argument === node)) return void 0;
|
|
4309
|
-
return svelteCallMethod(parent);
|
|
2220
|
+
var svelteRuntimeMethod = (node) => {
|
|
2221
|
+
const parent = node.parent;
|
|
2222
|
+
if (!parent || !ts9.isCallExpression(parent)) return void 0;
|
|
2223
|
+
if (!parent.arguments.some((argument) => argument === node)) return void 0;
|
|
2224
|
+
return svelteCallMethod(parent);
|
|
4310
2225
|
};
|
|
4311
2226
|
var enclosingSvelteRuntimeMethod = (node) => {
|
|
4312
2227
|
const direct = svelteRuntimeMethod(node);
|
|
@@ -4317,7 +2232,7 @@ var enclosingSvelteRuntimeMethod = (node) => {
|
|
|
4317
2232
|
if (isFunctionLike2(parent) && parent.body) {
|
|
4318
2233
|
if (current === parent.body || isDescendant(parent.body, current)) return void 0;
|
|
4319
2234
|
}
|
|
4320
|
-
if (
|
|
2235
|
+
if (ts9.isCallExpression(parent)) {
|
|
4321
2236
|
const method = svelteCallMethod(parent);
|
|
4322
2237
|
if (method && parent.arguments.some((argument) => argument === current || isDescendant(argument, current))) {
|
|
4323
2238
|
return method;
|
|
@@ -4328,218 +2243,32 @@ var enclosingSvelteRuntimeMethod = (node) => {
|
|
|
4328
2243
|
}
|
|
4329
2244
|
return void 0;
|
|
4330
2245
|
};
|
|
4331
|
-
var svelteGeneratedIdentifierCallees = (sourceFile) => {
|
|
4332
|
-
const names = /* @__PURE__ */ new Set();
|
|
4333
|
-
const visit = (node) => {
|
|
4334
|
-
if (ts16.isVariableDeclaration(node) && ts16.isIdentifier(node.name) && node.initializer && ts16.isCallExpression(node.initializer)) {
|
|
4335
|
-
const method = svelteCallMethod(node.initializer);
|
|
4336
|
-
if (method && (SVELTE_TEMPLATE_FACTORIES.has(method) || SVELTE_PROP_GETTERS.has(method))) {
|
|
4337
|
-
names.add(node.name.text);
|
|
4338
|
-
}
|
|
4339
|
-
}
|
|
4340
|
-
ts16.forEachChild(node, visit);
|
|
4341
|
-
};
|
|
4342
|
-
visit(sourceFile);
|
|
4343
|
-
return names;
|
|
4344
|
-
};
|
|
4345
|
-
var isSvelteCompilerCall = (call, sourceFile, identifierCallees) => {
|
|
4346
|
-
if (svelteCallMethod(call)) return true;
|
|
4347
|
-
if (!ts16.isCallExpression(call) || !ts16.isIdentifier(call.expression)) return false;
|
|
4348
|
-
if (call.expression.text.startsWith("$$")) return true;
|
|
4349
|
-
const names = identifierCallees ?? svelteGeneratedIdentifierCallees(sourceFile);
|
|
4350
|
-
return names.has(call.expression.text);
|
|
4351
|
-
};
|
|
4352
|
-
|
|
4353
|
-
// src/compiler/client-policy.ts
|
|
4354
|
-
var SVELTE_REACTIVE_CALLBACKS = /* @__PURE__ */ new Map([
|
|
4355
|
-
["derived", { name: "$derived", reason: "svelte $derived callback", kind: "derived" }],
|
|
4356
|
-
["user_effect", { name: "$effect", reason: "svelte $effect callback", kind: "effect" }],
|
|
4357
|
-
[
|
|
4358
|
-
"user_pre_effect",
|
|
4359
|
-
{ name: "$effect.pre", reason: "svelte $effect.pre callback", kind: "effect.pre" }
|
|
4360
|
-
]
|
|
4361
|
-
]);
|
|
4362
|
-
var SVELTE_EVENT_CALLBACKS = /* @__PURE__ */ new Set(["delegated", "event"]);
|
|
4363
|
-
var SVELTE_RUNE_ROOTS = /* @__PURE__ */ new Set([
|
|
4364
|
-
"$state",
|
|
4365
|
-
"$derived",
|
|
4366
|
-
"$effect",
|
|
4367
|
-
"$props",
|
|
4368
|
-
"$bindable",
|
|
4369
|
-
"$inspect",
|
|
4370
|
-
"$host"
|
|
4371
|
-
]);
|
|
4372
|
-
var parameterNames = (node) => {
|
|
4373
|
-
const names = [];
|
|
4374
|
-
for (const parameter of node.parameters) {
|
|
4375
|
-
if (ts17.isIdentifier(parameter.name)) names.push(parameter.name.text);
|
|
4376
|
-
}
|
|
4377
|
-
return names;
|
|
4378
|
-
};
|
|
4379
|
-
var isSvelteComponentWrapper = (node) => {
|
|
4380
|
-
const names = parameterNames(node);
|
|
4381
|
-
return names.includes("$$anchor") && names.includes("$$props");
|
|
4382
|
-
};
|
|
4383
|
-
var isSvelteGeneratedBlock = (node) => {
|
|
4384
|
-
const names = parameterNames(node);
|
|
4385
|
-
if (names.includes("$$props")) return false;
|
|
4386
|
-
return names.includes("$$anchor") || names.includes("$$render");
|
|
4387
|
-
};
|
|
4388
|
-
var isSvelteChildPropThunk = (node) => {
|
|
4389
|
-
const parent = node.parent;
|
|
4390
|
-
if (!parent || !ts17.isPropertyAssignment(parent)) return false;
|
|
4391
|
-
const object = parent.parent;
|
|
4392
|
-
if (!object || !ts17.isObjectLiteralExpression(object)) return false;
|
|
4393
|
-
const call = object.parent;
|
|
4394
|
-
if (!call || !ts17.isCallExpression(call)) return false;
|
|
4395
|
-
return call.arguments.some((argument) => argument === object);
|
|
4396
|
-
};
|
|
4397
|
-
var isSvelteRuneCall = (node) => {
|
|
4398
|
-
if (!ts17.isCallExpression(node)) return false;
|
|
4399
|
-
let current = node.expression;
|
|
4400
|
-
while (ts17.isPropertyAccessExpression(current)) current = current.expression;
|
|
4401
|
-
return ts17.isIdentifier(current) && SVELTE_RUNE_ROOTS.has(current.text);
|
|
4402
|
-
};
|
|
4403
|
-
var svelteClientPolicy = {
|
|
4404
|
-
isCompiledModulePath: isSvelteCompiledPath,
|
|
4405
|
-
classifyFunction: ({ node, filePath, name, body }) => {
|
|
4406
|
-
if (!isSvelteCompiledPath(filePath)) return void 0;
|
|
4407
|
-
if (isSvelteComponentWrapper(node)) {
|
|
4408
|
-
return {
|
|
4409
|
-
captureClass: "structure",
|
|
4410
|
-
captureReason: "svelte component wrapper",
|
|
4411
|
-
role: "component-wrapper",
|
|
4412
|
-
useSyntheticLocation: true
|
|
4413
|
-
};
|
|
4414
|
-
}
|
|
4415
|
-
if (/^\$[A-Za-z]/.test(name)) {
|
|
4416
|
-
return {
|
|
4417
|
-
captureClass: "skip",
|
|
4418
|
-
captureReason: "svelte store subscription",
|
|
4419
|
-
role: "store-subscription"
|
|
4420
|
-
};
|
|
4421
|
-
}
|
|
4422
|
-
if (ts17.isGetAccessorDeclaration(node) || ts17.isSetAccessorDeclaration(node)) {
|
|
4423
|
-
return {
|
|
4424
|
-
captureClass: "skip",
|
|
4425
|
-
captureReason: "svelte generated accessor",
|
|
4426
|
-
role: "generated-accessor"
|
|
4427
|
-
};
|
|
4428
|
-
}
|
|
4429
|
-
if (isSvelteGeneratedBlock(node)) {
|
|
4430
|
-
return {
|
|
4431
|
-
captureClass: "skip",
|
|
4432
|
-
captureReason: "svelte generated block",
|
|
4433
|
-
role: "generated-block"
|
|
4434
|
-
};
|
|
4435
|
-
}
|
|
4436
|
-
if (isSvelteChildPropThunk(node)) {
|
|
4437
|
-
if (body.isLiteralOnly || body.isIdentity || body.isSimpleRead || body.isPredicate) {
|
|
4438
|
-
return {
|
|
4439
|
-
captureClass: "skip",
|
|
4440
|
-
captureReason: "svelte prop thunk",
|
|
4441
|
-
role: "generated-prop-thunk"
|
|
4442
|
-
};
|
|
4443
|
-
}
|
|
4444
|
-
return {
|
|
4445
|
-
captureClass: "full",
|
|
4446
|
-
captureReason: "svelte user callback",
|
|
4447
|
-
role: "user-callback"
|
|
4448
|
-
};
|
|
4449
|
-
}
|
|
4450
|
-
const runtimeMethod = svelteRuntimeMethod(node);
|
|
4451
|
-
if (runtimeMethod) {
|
|
4452
|
-
const reactive = SVELTE_REACTIVE_CALLBACKS.get(runtimeMethod);
|
|
4453
|
-
if (reactive) {
|
|
4454
|
-
if (body.isLiteralOnly) {
|
|
4455
|
-
return {
|
|
4456
|
-
captureClass: "skip",
|
|
4457
|
-
captureReason: "literal-only return",
|
|
4458
|
-
role: "reactive"
|
|
4459
|
-
};
|
|
4460
|
-
}
|
|
4461
|
-
return {
|
|
4462
|
-
captureClass: "reactive-sparse",
|
|
4463
|
-
captureReason: reactive.reason,
|
|
4464
|
-
role: "reactive",
|
|
4465
|
-
inferredName: name === "anonymous" ? reactive.name : void 0,
|
|
4466
|
-
reactiveKind: reactive.kind
|
|
4467
|
-
};
|
|
4468
|
-
}
|
|
4469
|
-
if (SVELTE_EVENT_CALLBACKS.has(runtimeMethod)) {
|
|
4470
|
-
if (body.isLiteralOnly) {
|
|
4471
|
-
return {
|
|
4472
|
-
captureClass: "skip",
|
|
4473
|
-
captureReason: "literal-only return",
|
|
4474
|
-
role: "user-callback"
|
|
4475
|
-
};
|
|
4476
|
-
}
|
|
4477
|
-
return {
|
|
4478
|
-
captureClass: "full",
|
|
4479
|
-
captureReason: "svelte user callback",
|
|
4480
|
-
role: "user-callback"
|
|
4481
|
-
};
|
|
4482
|
-
}
|
|
4483
|
-
return {
|
|
4484
|
-
captureClass: "skip",
|
|
4485
|
-
captureReason: "svelte generated callback",
|
|
4486
|
-
role: "generated-callback"
|
|
4487
|
-
};
|
|
4488
|
-
}
|
|
4489
|
-
if (enclosingSvelteRuntimeMethod(node)) {
|
|
4490
|
-
return {
|
|
4491
|
-
captureClass: "skip",
|
|
4492
|
-
captureReason: "svelte generated callback",
|
|
4493
|
-
role: "generated-callback"
|
|
4494
|
-
};
|
|
4495
|
-
}
|
|
4496
|
-
return void 0;
|
|
4497
|
-
},
|
|
4498
|
-
finalizeClassifications: (items) => {
|
|
4499
|
-
const hasUserWork = items.some(
|
|
4500
|
-
(item) => item.captureClass === "full" || item.captureClass === "reactive-sparse"
|
|
4501
|
-
);
|
|
4502
|
-
if (hasUserWork) return;
|
|
4503
|
-
for (const item of items) {
|
|
4504
|
-
if (item.compilerRole !== "component-wrapper") continue;
|
|
4505
|
-
item.captureClass = "skip";
|
|
4506
|
-
item.captureReason = "svelte presentational wrapper";
|
|
4507
|
-
item.compilerRole = "presentational-wrapper";
|
|
4508
|
-
}
|
|
4509
|
-
},
|
|
4510
|
-
isCompilerCall: ({ node, sourceFile, filePath }) => {
|
|
4511
|
-
if (isSvelteRuneCall(node)) return true;
|
|
4512
|
-
if (!isSvelteCompiledPath(filePath)) return false;
|
|
4513
|
-
return isSvelteCompilerCall(node, sourceFile, svelteGeneratedIdentifierCallees(sourceFile));
|
|
4514
|
-
}
|
|
4515
|
-
};
|
|
4516
2246
|
|
|
4517
2247
|
// src/compiler/ssr-policy.ts
|
|
4518
|
-
|
|
4519
|
-
var parameterNames2 = (node) => {
|
|
2248
|
+
var parameterNames = (node) => {
|
|
4520
2249
|
const names = [];
|
|
4521
2250
|
for (const parameter of node.parameters) {
|
|
4522
|
-
if (
|
|
2251
|
+
if (ts10.isIdentifier(parameter.name)) names.push(parameter.name.text);
|
|
4523
2252
|
}
|
|
4524
2253
|
return names;
|
|
4525
2254
|
};
|
|
4526
|
-
var
|
|
4527
|
-
if (
|
|
4528
|
-
if (
|
|
4529
|
-
if (expression.kind ===
|
|
2255
|
+
var isLiteralExpression = (expression) => {
|
|
2256
|
+
if (ts10.isStringLiteral(expression) || ts10.isNoSubstitutionTemplateLiteral(expression)) return true;
|
|
2257
|
+
if (ts10.isNumericLiteral(expression)) return true;
|
|
2258
|
+
if (expression.kind === ts10.SyntaxKind.TrueKeyword || expression.kind === ts10.SyntaxKind.FalseKeyword || expression.kind === ts10.SyntaxKind.NullKeyword) {
|
|
4530
2259
|
return true;
|
|
4531
2260
|
}
|
|
4532
|
-
return
|
|
2261
|
+
return ts10.isIdentifier(expression) && (expression.text === "undefined" || expression.text === "NaN");
|
|
4533
2262
|
};
|
|
4534
|
-
var
|
|
4535
|
-
if (
|
|
2263
|
+
var isLiteralOnlyBody = (body) => {
|
|
2264
|
+
if (ts10.isBlock(body)) {
|
|
4536
2265
|
if (body.statements.length === 0) return true;
|
|
4537
2266
|
if (body.statements.length !== 1) return false;
|
|
4538
2267
|
const statement = body.statements[0];
|
|
4539
|
-
if (!statement || !
|
|
4540
|
-
return !statement.expression ||
|
|
2268
|
+
if (!statement || !ts10.isReturnStatement(statement)) return false;
|
|
2269
|
+
return !statement.expression || isLiteralExpression(statement.expression);
|
|
4541
2270
|
}
|
|
4542
|
-
return
|
|
2271
|
+
return isLiteralExpression(body);
|
|
4543
2272
|
};
|
|
4544
2273
|
var hasServerRuntimeImport = (source) => /\bfrom\s+['"]svelte\/internal\/server['"]/.test(source);
|
|
4545
2274
|
var hasClientRuntimeImport = (source) => /\bfrom\s+['"]svelte\/internal\/client['"]/.test(source);
|
|
@@ -4559,15 +2288,15 @@ var recognizeSvelteSsrModule = (source, filePath) => {
|
|
|
4559
2288
|
};
|
|
4560
2289
|
var decideSvelteSsrFunction = (input) => {
|
|
4561
2290
|
if (!isSvelteCompiledPath(input.filePath)) return "instrument";
|
|
4562
|
-
const names =
|
|
2291
|
+
const names = parameterNames(input.node);
|
|
4563
2292
|
if (names[0] === "$$renderer") return "skip";
|
|
4564
2293
|
if (/^\$[A-Za-z]/.test(input.name)) return "skip";
|
|
4565
|
-
if (
|
|
2294
|
+
if (ts10.isGetAccessorDeclaration(input.node) || ts10.isSetAccessorDeclaration(input.node)) {
|
|
4566
2295
|
return "skip";
|
|
4567
2296
|
}
|
|
4568
2297
|
const runtimeMethod = svelteRuntimeMethod(input.node);
|
|
4569
2298
|
if (runtimeMethod === "derived") {
|
|
4570
|
-
return
|
|
2299
|
+
return isLiteralOnlyBody(input.node.body) ? "skip" : "instrument";
|
|
4571
2300
|
}
|
|
4572
2301
|
if (runtimeMethod || enclosingSvelteRuntimeMethod(input.node)) return "skip";
|
|
4573
2302
|
return "instrument";
|
|
@@ -4576,7 +2305,6 @@ var decideSvelteSsrFunction = (input) => {
|
|
|
4576
2305
|
// src/vite/build-identity.ts
|
|
4577
2306
|
import { randomUUID } from "node:crypto";
|
|
4578
2307
|
var isGitSha = (value) => /^[0-9a-f]{7,40}$/i.test(value.trim());
|
|
4579
|
-
var createClientCompileId = () => `b_${randomUUID()}`;
|
|
4580
2308
|
var createServerCompileId = () => `s_${randomUUID()}`;
|
|
4581
2309
|
var normalizeExplicitCompileId = (value) => {
|
|
4582
2310
|
if (typeof value !== "string") return "";
|
|
@@ -4588,27 +2316,25 @@ var normalizeExplicitCompileId = (value) => {
|
|
|
4588
2316
|
// src/vite/identify-environment.ts
|
|
4589
2317
|
var identifyBuildTarget = (input) => {
|
|
4590
2318
|
const name = input.environmentName?.trim();
|
|
4591
|
-
if (name === "client") return "client";
|
|
4592
2319
|
if (name === "ssr") return "ssr";
|
|
4593
2320
|
if (name) return "unknown";
|
|
4594
|
-
if (input.ssr === true) return "ssr";
|
|
4595
|
-
if (input.ssr === false) return "client";
|
|
4596
|
-
if (input.configSsr === true) return "ssr";
|
|
4597
|
-
if (input.configSsr === false) return "client";
|
|
2321
|
+
if (input.ssr === true || input.configSsr === true) return "ssr";
|
|
4598
2322
|
return "unknown";
|
|
4599
2323
|
};
|
|
4600
2324
|
|
|
4601
2325
|
// src/vite/rasputin-sdk-path.ts
|
|
4602
2326
|
import { existsSync, readFileSync } from "node:fs";
|
|
4603
|
-
import { basename as
|
|
2327
|
+
import { basename as basename2, dirname as dirname2, join as join2 } from "node:path";
|
|
4604
2328
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
4605
2329
|
var RASPUTIN_PACKAGES = [
|
|
4606
|
-
"browser",
|
|
4607
2330
|
"core",
|
|
4608
2331
|
"node",
|
|
4609
2332
|
"recorder",
|
|
4610
2333
|
"instrumentation",
|
|
4611
2334
|
"elysia",
|
|
2335
|
+
"express",
|
|
2336
|
+
"fastify",
|
|
2337
|
+
"hono",
|
|
4612
2338
|
"sveltekit"
|
|
4613
2339
|
];
|
|
4614
2340
|
var packageGroup = RASPUTIN_PACKAGES.join("|");
|
|
@@ -4677,7 +2403,7 @@ var workspaceSdkRoots = () => {
|
|
|
4677
2403
|
const packageRoot = sveltekitPackageRoot();
|
|
4678
2404
|
if (!packageRoot) return [];
|
|
4679
2405
|
const packagesDir = dirname2(packageRoot);
|
|
4680
|
-
if (
|
|
2406
|
+
if (basename2(packagesDir) !== "packages") return [];
|
|
4681
2407
|
return RASPUTIN_PACKAGES.flatMap((name) => {
|
|
4682
2408
|
const root = join2(packagesDir, name);
|
|
4683
2409
|
if (!existsSync(root)) return [];
|
|
@@ -4698,14 +2424,12 @@ var isRasputinSdkPath = (idOrPath) => {
|
|
|
4698
2424
|
|
|
4699
2425
|
// src/vite/module-kind.ts
|
|
4700
2426
|
var isSvelteFilePath = (path) => path.endsWith(".svelte") || path.endsWith(".svelte.ts") || path.endsWith(".svelte.js");
|
|
4701
|
-
var isServerOnlyPath = (path) => path.includes(".server.") || path.endsWith("+server.ts") || path.endsWith("+server.js") || path.includes("/hooks.server.");
|
|
4702
2427
|
var isFrameworkGeneratedPath = (path) => path.includes("/.svelte-kit/") || path.includes("/node_modules/");
|
|
4703
2428
|
var isJsModulePath = (path) => /\.[cm]?[jt]sx?$/.test(path) && !isSvelteFilePath(path);
|
|
4704
2429
|
var isApplicationJsPath = (id, onlyIfPathIncludes) => {
|
|
4705
2430
|
const path = normalizeModulePath(id);
|
|
4706
2431
|
if (!path || path.includes("\0")) return false;
|
|
4707
2432
|
if (isFrameworkGeneratedPath(path) || isRasputinSdkPath(path)) return false;
|
|
4708
|
-
if (path.includes("virtual:rasputin")) return false;
|
|
4709
2433
|
if (isSvelteFilePath(path)) return false;
|
|
4710
2434
|
if (onlyIfPathIncludes && onlyIfPathIncludes.length > 0) {
|
|
4711
2435
|
if (!onlyIfPathIncludes.some((segment) => path.includes(segment.replaceAll("\\", "/")))) {
|
|
@@ -4728,115 +2452,26 @@ var isCompiledSveltePath = (id, onlyIfPathIncludes) => {
|
|
|
4728
2452
|
}
|
|
4729
2453
|
return true;
|
|
4730
2454
|
};
|
|
4731
|
-
var isBrowserClientEntry = (path) => {
|
|
4732
|
-
const normalized = normalizeModulePath(path);
|
|
4733
|
-
if (normalized.includes("/vite/") || normalized.includes("virtual:rasputin")) return false;
|
|
4734
|
-
if (!isRasputinSdkPath(normalized)) return false;
|
|
4735
|
-
if (/\/rasputin-init\.[cm]?[jt]sx?$/.test(normalized)) return true;
|
|
4736
|
-
if (/(?:^|\/)@rasputin-ai\/browser(?:\/(?:dist\/)?index\.[cm]?[jt]sx?)?$/.test(normalized)) {
|
|
4737
|
-
return true;
|
|
4738
|
-
}
|
|
4739
|
-
if (/\/packages\/browser\/(?:src|dist)\/index\.[cm]?[jt]sx?$/.test(normalized)) return true;
|
|
4740
|
-
if (/(?:^|\/)@rasputin-ai\/sveltekit\/client(?:\/hooks\.[cm]?[jt]sx?)?$/.test(normalized)) {
|
|
4741
|
-
return true;
|
|
4742
|
-
}
|
|
4743
|
-
if (/\/packages\/sveltekit\/(?:src|dist)\/client\/hooks\.[cm]?[jt]sx?$/.test(normalized)) {
|
|
4744
|
-
return true;
|
|
4745
|
-
}
|
|
4746
|
-
return false;
|
|
4747
|
-
};
|
|
4748
2455
|
|
|
4749
2456
|
// src/vite/target-state.ts
|
|
4750
|
-
var createTargetState = (
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
functions: /* @__PURE__ */ new Map(),
|
|
4754
|
-
identities: [],
|
|
4755
|
-
files: /* @__PURE__ */ new Map(),
|
|
2457
|
+
var createTargetState = (explicitBuildId) => ({
|
|
2458
|
+
buildId: explicitBuildId || createServerCompileId(),
|
|
2459
|
+
files: /* @__PURE__ */ new Set(),
|
|
4756
2460
|
verificationFailed: /* @__PURE__ */ new Set(),
|
|
4757
|
-
deltas: /* @__PURE__ */ new Map()
|
|
4758
|
-
expressionSites: /* @__PURE__ */ new Map(),
|
|
4759
|
-
nextModuleIndex: 0,
|
|
4760
|
-
emitIds: { value: 1 },
|
|
4761
|
-
reactiveIds: { value: 1 }
|
|
2461
|
+
deltas: /* @__PURE__ */ new Map()
|
|
4762
2462
|
});
|
|
4763
2463
|
var forgetModule = (state, filePath) => {
|
|
4764
|
-
|
|
4765
|
-
if (previous) {
|
|
4766
|
-
for (const functionId of previous.functionIds) state.functions.delete(functionId);
|
|
4767
|
-
state.identities = state.identities.filter((item) => item.filePath !== filePath);
|
|
4768
|
-
state.files.delete(filePath);
|
|
4769
|
-
}
|
|
2464
|
+
state.files.delete(filePath);
|
|
4770
2465
|
state.deltas.delete(filePath);
|
|
4771
2466
|
state.verificationFailed.delete(filePath);
|
|
4772
|
-
for (const [siteId, site] of state.expressionSites) {
|
|
4773
|
-
if (site.filePath === filePath) state.expressionSites.delete(siteId);
|
|
4774
|
-
}
|
|
4775
2467
|
};
|
|
4776
|
-
var recordModule = (state, filePath,
|
|
2468
|
+
var recordModule = (state, filePath, delta) => {
|
|
4777
2469
|
forgetModule(state, filePath);
|
|
4778
|
-
|
|
4779
|
-
state.
|
|
4780
|
-
state.files.set(filePath, { functionIds: functions.map((fn) => fn.functionId) });
|
|
4781
|
-
if (delta) state.deltas.set(filePath, delta);
|
|
4782
|
-
for (const site of sites) state.expressionSites.set(site.siteId, site);
|
|
2470
|
+
state.files.add(filePath);
|
|
2471
|
+
state.deltas.set(filePath, delta);
|
|
4783
2472
|
};
|
|
4784
2473
|
|
|
4785
2474
|
// src/vite/transform-module.ts
|
|
4786
|
-
var instrumentClientModule = (state, code, filePath, incomingMap, includeRuntimeNames, policy) => {
|
|
4787
|
-
if (sourceIsRasputinInstrumented(code)) return void 0;
|
|
4788
|
-
const instrumented = instrumentBrowserSource(
|
|
4789
|
-
code,
|
|
4790
|
-
filePath,
|
|
4791
|
-
state.emitIds,
|
|
4792
|
-
state.reactiveIds,
|
|
4793
|
-
state.nextModuleIndex++,
|
|
4794
|
-
{
|
|
4795
|
-
includePlans: includeRuntimeNames,
|
|
4796
|
-
mapLocation: createSourceMapLocationMapper(filePath, incomingMap),
|
|
4797
|
-
policy
|
|
4798
|
-
}
|
|
4799
|
-
);
|
|
4800
|
-
if (instrumented.verificationFailed) {
|
|
4801
|
-
forgetModule(state, filePath);
|
|
4802
|
-
state.verificationFailed.add(filePath);
|
|
4803
|
-
return code === instrumented.code ? void 0 : { code };
|
|
4804
|
-
}
|
|
4805
|
-
if (!instrumented.delta && instrumented.sites.length === 0 && instrumented.identities.length === 0) {
|
|
4806
|
-
return void 0;
|
|
4807
|
-
}
|
|
4808
|
-
recordModule(
|
|
4809
|
-
state,
|
|
4810
|
-
filePath,
|
|
4811
|
-
instrumented.classifications.map((item) => ({
|
|
4812
|
-
functionId: item.functionId,
|
|
4813
|
-
name: item.name,
|
|
4814
|
-
filePath: item.filePath,
|
|
4815
|
-
line: item.line,
|
|
4816
|
-
column: item.column,
|
|
4817
|
-
captureClass: item.captureClass,
|
|
4818
|
-
captureReason: item.captureReason
|
|
4819
|
-
})),
|
|
4820
|
-
instrumented.identities.map((identity) => ({
|
|
4821
|
-
compactId: identity.compactId,
|
|
4822
|
-
functionId: identity.functionId,
|
|
4823
|
-
name: identity.name,
|
|
4824
|
-
filePath: identity.filePath,
|
|
4825
|
-
moduleIndex: identity.moduleIndex,
|
|
4826
|
-
planIndex: identity.planIndex
|
|
4827
|
-
})),
|
|
4828
|
-
instrumented.delta,
|
|
4829
|
-
instrumented.sites
|
|
4830
|
-
);
|
|
4831
|
-
let nextCode = instrumented.code;
|
|
4832
|
-
if (includeRuntimeNames && instrumented.identities.length > 0) {
|
|
4833
|
-
nextCode = `${nextCode}
|
|
4834
|
-
;globalThis.__rasputinRegisterIdentities?.(${JSON.stringify(
|
|
4835
|
-
instrumented.identities
|
|
4836
|
-
)});`;
|
|
4837
|
-
}
|
|
4838
|
-
return instrumented.map ? { code: nextCode, map: { ...instrumented.map, names: instrumented.map.names ?? [] } } : { code: nextCode };
|
|
4839
|
-
};
|
|
4840
2475
|
var instrumentServerModule = (state, code, filePath, incomingMap, decideFunction) => {
|
|
4841
2476
|
if (sourceIsRasputinInstrumented(code)) return void 0;
|
|
4842
2477
|
const transformed = transformSource(code, {
|
|
@@ -4847,28 +2482,7 @@ var instrumentServerModule = (state, code, filePath, incomingMap, decideFunction
|
|
|
4847
2482
|
});
|
|
4848
2483
|
if (!transformed) return void 0;
|
|
4849
2484
|
if (transformed.delta.alreadyInstrumented) return void 0;
|
|
4850
|
-
|
|
4851
|
-
functionId: fn.functionId,
|
|
4852
|
-
name: fn.name,
|
|
4853
|
-
filePath: fn.filePath,
|
|
4854
|
-
line: fn.startLine,
|
|
4855
|
-
column: fn.startColumn
|
|
4856
|
-
}));
|
|
4857
|
-
recordModule(
|
|
4858
|
-
state,
|
|
4859
|
-
filePath,
|
|
4860
|
-
functions,
|
|
4861
|
-
functions.map((fn, planIndex) => ({
|
|
4862
|
-
compactId: `${state.nextModuleIndex}.${planIndex}`,
|
|
4863
|
-
functionId: fn.functionId,
|
|
4864
|
-
name: fn.name,
|
|
4865
|
-
filePath: fn.filePath,
|
|
4866
|
-
moduleIndex: state.nextModuleIndex,
|
|
4867
|
-
planIndex
|
|
4868
|
-
})),
|
|
4869
|
-
transformed.delta
|
|
4870
|
-
);
|
|
4871
|
-
state.nextModuleIndex += 1;
|
|
2485
|
+
recordModule(state, filePath, transformed.delta);
|
|
4872
2486
|
if (transformed.delta.functions.some((fn) => fn.skipReason === "verification_failed")) {
|
|
4873
2487
|
state.verificationFailed.add(filePath);
|
|
4874
2488
|
forgetModule(state, filePath);
|
|
@@ -4882,193 +2496,44 @@ var instrumentServerModule = (state, code, filePath, incomingMap, decideFunction
|
|
|
4882
2496
|
};
|
|
4883
2497
|
|
|
4884
2498
|
// src/vite/upload-build-artifacts.ts
|
|
4885
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
4886
2499
|
import {
|
|
4887
|
-
encodeJsonRequestBody,
|
|
4888
2500
|
INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
4889
2501
|
resolveEndpointUrls,
|
|
2502
|
+
sourceLocatorKey,
|
|
4890
2503
|
uploadInstrumentationManifest
|
|
4891
2504
|
} from "@rasputin-ai/core";
|
|
4892
2505
|
var DEFAULT_API_URL = "https://api.rasputinai.dev";
|
|
4893
|
-
var contentHash = (value) => createHash2("sha256").update(JSON.stringify(value)).digest("hex");
|
|
4894
2506
|
var projectApiKeyForUpload = (projectApiKey) => (projectApiKey ?? process.env.RASPUTIN_PROJECT_API_KEY ?? "").trim();
|
|
4895
2507
|
var shouldSkipUpload = (key) => key.length === 0 || key.startsWith("rdn_") || key.includes("@");
|
|
4896
|
-
var isCaptureClass = (value) => value === "full" || value === "structure" || value === "skip" || value === "reactive-sparse";
|
|
4897
|
-
var captureClassOf = (value) => isCaptureClass(value) ? value : "full";
|
|
4898
|
-
var nullableCount = (value) => typeof value === "number" && value > 0 ? value : null;
|
|
4899
|
-
var omitSourceMapSourcesContent = (map) => {
|
|
4900
|
-
if (!map || typeof map !== "object" || Array.isArray(map)) return map;
|
|
4901
|
-
if (!("sourcesContent" in map)) return map;
|
|
4902
|
-
const next = { ...map };
|
|
4903
|
-
Reflect.deleteProperty(next, "sourcesContent");
|
|
4904
|
-
return next;
|
|
4905
|
-
};
|
|
4906
2508
|
var packageNameOf = (plan) => {
|
|
4907
2509
|
const value = plan[2];
|
|
4908
|
-
return typeof value === "string" && value ? value :
|
|
2510
|
+
return typeof value === "string" && value ? value : void 0;
|
|
4909
2511
|
};
|
|
4910
2512
|
var packagePathOf = (plan) => {
|
|
4911
2513
|
const value = plan[3];
|
|
4912
|
-
return typeof value === "string" && value ? value :
|
|
2514
|
+
return typeof value === "string" && value ? value : void 0;
|
|
4913
2515
|
};
|
|
4914
|
-
var snapshotClientBuildArtifact = (state, debugImages) => {
|
|
4915
|
-
const classified = new Map(
|
|
4916
|
-
[...state.functions.values()].map((fn) => [
|
|
4917
|
-
fn.functionId,
|
|
4918
|
-
{ captureClass: captureClassOf(fn.captureClass), captureReason: fn.captureReason ?? "" }
|
|
4919
|
-
])
|
|
4920
|
-
);
|
|
4921
|
-
const indexed = new Map(state.identities.map((item) => [item.functionId, item]));
|
|
4922
|
-
const functions = [];
|
|
4923
|
-
const callSites = [];
|
|
4924
|
-
for (const delta of state.deltas.values()) {
|
|
4925
|
-
for (const fn of delta.functions) {
|
|
4926
|
-
const match = classified.get(fn.functionId);
|
|
4927
|
-
const index = indexed.get(fn.functionId);
|
|
4928
|
-
functions.push({
|
|
4929
|
-
functionId: fn.functionId,
|
|
4930
|
-
name: fn.name,
|
|
4931
|
-
packageName: packageNameOf(fn.plan),
|
|
4932
|
-
packageRelativePath: packagePathOf(fn.plan),
|
|
4933
|
-
line: nullableCount(fn.startLine),
|
|
4934
|
-
column: fn.startColumn >= 0 ? fn.startColumn : null,
|
|
4935
|
-
endLine: nullableCount(fn.endLine),
|
|
4936
|
-
endColumn: fn.endColumn >= 0 ? fn.endColumn : null,
|
|
4937
|
-
params: fn.params,
|
|
4938
|
-
captureClass: match?.captureClass ?? "full",
|
|
4939
|
-
captureReason: match?.captureReason || "unclassified-default",
|
|
4940
|
-
...index ? { moduleIndex: index.moduleIndex, planIndex: index.planIndex } : {}
|
|
4941
|
-
});
|
|
4942
|
-
}
|
|
4943
|
-
for (const site of delta.callSites) {
|
|
4944
|
-
callSites.push({
|
|
4945
|
-
callerFunctionId: site.callerFunctionId,
|
|
4946
|
-
calleeName: site.calleeName,
|
|
4947
|
-
calleeText: site.calleeText,
|
|
4948
|
-
line: site.line,
|
|
4949
|
-
column: site.column,
|
|
4950
|
-
endLine: site.endLine,
|
|
4951
|
-
endColumn: site.endColumn,
|
|
4952
|
-
resultBinding: site.resultBinding
|
|
4953
|
-
});
|
|
4954
|
-
}
|
|
4955
|
-
}
|
|
4956
|
-
return {
|
|
4957
|
-
schema_version: 1,
|
|
4958
|
-
buildId: state.buildId,
|
|
4959
|
-
functions,
|
|
4960
|
-
identities: state.identities.map((item) => ({
|
|
4961
|
-
compactId: item.compactId,
|
|
4962
|
-
functionId: item.functionId,
|
|
4963
|
-
moduleIndex: item.moduleIndex,
|
|
4964
|
-
planIndex: item.planIndex
|
|
4965
|
-
})),
|
|
4966
|
-
callSites,
|
|
4967
|
-
debugImages: debugImages.map((image) => ({
|
|
4968
|
-
...image,
|
|
4969
|
-
map: omitSourceMapSourcesContent(image.map)
|
|
4970
|
-
}))
|
|
4971
|
-
};
|
|
4972
|
-
};
|
|
4973
|
-
var stableCallSiteId = (callerFunctionId, packageName, packageRelativePath, line, column) => `cs_${createHash2("sha256").update(["cs", callerFunctionId, packageName, packageRelativePath, line, column].join("\0")).digest("base64url").slice(0, 24)}`;
|
|
4974
2516
|
var snapshotServerInstrumentationManifest = (state) => {
|
|
4975
|
-
const
|
|
4976
|
-
const callSites = [];
|
|
4977
|
-
const sourceByFunctionId = /* @__PURE__ */ new Map();
|
|
2517
|
+
const sources = /* @__PURE__ */ new Map();
|
|
4978
2518
|
for (const delta of state.deltas.values()) {
|
|
4979
2519
|
for (const fn of delta.functions) {
|
|
4980
2520
|
const packageRelativePath = packagePathOf(fn.plan);
|
|
4981
2521
|
if (!packageRelativePath) continue;
|
|
4982
|
-
if (!fn.metricsDeclaration) {
|
|
4983
|
-
throw new Error(`Missing function metrics declaration: ${fn.functionId}`);
|
|
4984
|
-
}
|
|
4985
2522
|
const packageName = packageNameOf(fn.plan);
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
name: fn.name,
|
|
4994
|
-
startLine: fn.startLine,
|
|
4995
|
-
startColumn: fn.startColumn,
|
|
4996
|
-
endLine: fn.endLine,
|
|
4997
|
-
endColumn: fn.endColumn,
|
|
4998
|
-
metricsDeclaration: fn.metricsDeclaration,
|
|
4999
|
-
...fn.instrumented === false ? { instrumented: false, ...fn.skipReason ? { skipReason: fn.skipReason } : {} } : {}
|
|
5000
|
-
});
|
|
5001
|
-
}
|
|
5002
|
-
}
|
|
5003
|
-
for (const delta of state.deltas.values()) {
|
|
5004
|
-
for (const site of delta.callSites) {
|
|
5005
|
-
const source = sourceByFunctionId.get(site.callerFunctionId);
|
|
5006
|
-
if (!source) continue;
|
|
5007
|
-
callSites.push({
|
|
5008
|
-
id: stableCallSiteId(
|
|
5009
|
-
site.callerFunctionId,
|
|
5010
|
-
source.packageName ?? "",
|
|
5011
|
-
source.packageRelativePath,
|
|
5012
|
-
site.line,
|
|
5013
|
-
site.column
|
|
5014
|
-
),
|
|
5015
|
-
callerFunctionId: site.callerFunctionId,
|
|
5016
|
-
calleeName: site.calleeName,
|
|
5017
|
-
calleeText: site.calleeText,
|
|
5018
|
-
line: site.line,
|
|
5019
|
-
column: site.column,
|
|
5020
|
-
endLine: site.endLine,
|
|
5021
|
-
endColumn: site.endColumn,
|
|
5022
|
-
resultBinding: site.resultBinding
|
|
5023
|
-
});
|
|
2523
|
+
const source = {
|
|
2524
|
+
packageRelativePath,
|
|
2525
|
+
...packageName ? { packageName } : {}
|
|
2526
|
+
};
|
|
2527
|
+
const key = sourceLocatorKey(source);
|
|
2528
|
+
if (sources.has(key)) continue;
|
|
2529
|
+
sources.set(key, source);
|
|
5024
2530
|
}
|
|
5025
2531
|
}
|
|
5026
2532
|
return {
|
|
5027
2533
|
schema_version: INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
5028
|
-
|
|
5029
|
-
callSites
|
|
2534
|
+
sources: [...sources.values()]
|
|
5030
2535
|
};
|
|
5031
2536
|
};
|
|
5032
|
-
var uploadClientBuildArtifact = async (input) => {
|
|
5033
|
-
const key = projectApiKeyForUpload(input.projectApiKey);
|
|
5034
|
-
if (shouldSkipUpload(key)) return "skipped";
|
|
5035
|
-
const apiUrl = (input.apiUrl ?? process.env.RASPUTIN_API_URL ?? DEFAULT_API_URL).replace(
|
|
5036
|
-
/\/+$/,
|
|
5037
|
-
""
|
|
5038
|
-
);
|
|
5039
|
-
try {
|
|
5040
|
-
const { body, gzip } = encodeJsonRequestBody({
|
|
5041
|
-
buildId: input.artifacts.buildId,
|
|
5042
|
-
release: input.release,
|
|
5043
|
-
contentHash: contentHash(input.artifacts),
|
|
5044
|
-
artifact: input.artifacts
|
|
5045
|
-
});
|
|
5046
|
-
const response = await fetch(`${apiUrl}/browserArtifacts`, {
|
|
5047
|
-
method: "POST",
|
|
5048
|
-
headers: {
|
|
5049
|
-
authorization: `Bearer ${key}`,
|
|
5050
|
-
"content-type": "application/json",
|
|
5051
|
-
...gzip ? { "content-encoding": "gzip" } : {}
|
|
5052
|
-
},
|
|
5053
|
-
body
|
|
5054
|
-
});
|
|
5055
|
-
if (response.status === 409) return "conflict";
|
|
5056
|
-
if (response.status === 200 || response.status === 201) {
|
|
5057
|
-
const body2 = await response.json().catch(() => ({}));
|
|
5058
|
-
if (body2 && typeof body2 === "object" && "duplicate" in body2 && body2.duplicate === true) {
|
|
5059
|
-
return "duplicate";
|
|
5060
|
-
}
|
|
5061
|
-
return "uploaded";
|
|
5062
|
-
}
|
|
5063
|
-
console.warn(
|
|
5064
|
-
`[rasputin] artifact upload failed (${response.status}); the build still succeeded`
|
|
5065
|
-
);
|
|
5066
|
-
return "failed";
|
|
5067
|
-
} catch {
|
|
5068
|
-
console.warn("[rasputin] artifact upload failed; the build still succeeded");
|
|
5069
|
-
return "failed";
|
|
5070
|
-
}
|
|
5071
|
-
};
|
|
5072
2537
|
var uploadServerBuildManifest = async (input) => {
|
|
5073
2538
|
const key = projectApiKeyForUpload(input.projectApiKey);
|
|
5074
2539
|
if (shouldSkipUpload(key)) return "skipped";
|
|
@@ -5087,35 +2552,7 @@ var uploadServerBuildManifest = async (input) => {
|
|
|
5087
2552
|
return "failed";
|
|
5088
2553
|
};
|
|
5089
2554
|
|
|
5090
|
-
// src/vite/virtual-identity.ts
|
|
5091
|
-
var VIRTUAL_IDENTITY_ID = "virtual:rasputin-identity";
|
|
5092
|
-
var RESOLVED_VIRTUAL_IDENTITY_ID = `\0${VIRTUAL_IDENTITY_ID}`;
|
|
5093
|
-
var BUILD_IDENTITIES_MARKER = "@@RASPUTIN_IDENTITIES@@";
|
|
5094
|
-
var BUILD_STATS_MARKER = "@@RASPUTIN_STATS@@";
|
|
5095
|
-
var isVirtualIdentityId = (id) => id === VIRTUAL_IDENTITY_ID || id === RESOLVED_VIRTUAL_IDENTITY_ID;
|
|
5096
|
-
var clientIdentitySource = (input) => {
|
|
5097
|
-
const lines = [
|
|
5098
|
-
`globalThis.__RASPUTIN_BUILD_ID__ = ${JSON.stringify(input.buildId)};`,
|
|
5099
|
-
`globalThis.__RASPUTIN_RELEASE__ = ${JSON.stringify(input.release)};`,
|
|
5100
|
-
`globalThis.__RASPUTIN_BUILD_IDENTITIES__ = globalThis.__RASPUTIN_BUILD_IDENTITIES__ ?? "${BUILD_IDENTITIES_MARKER}";`,
|
|
5101
|
-
`globalThis.__RASPUTIN_BUILD_STATS__ = globalThis.__RASPUTIN_BUILD_STATS__ ?? "${BUILD_STATS_MARKER}";`
|
|
5102
|
-
];
|
|
5103
|
-
if (input.environment) {
|
|
5104
|
-
lines.splice(
|
|
5105
|
-
2,
|
|
5106
|
-
0,
|
|
5107
|
-
`globalThis.__RASPUTIN_ENVIRONMENT__ = ${JSON.stringify(input.environment)};`
|
|
5108
|
-
);
|
|
5109
|
-
}
|
|
5110
|
-
return `${lines.join("\n")}
|
|
5111
|
-
`;
|
|
5112
|
-
};
|
|
5113
|
-
|
|
5114
2555
|
// src/vite/plugin.ts
|
|
5115
|
-
var contentDebugId = (source) => {
|
|
5116
|
-
const hex = createHash3("sha256").update(source).digest("hex");
|
|
5117
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
|
|
5118
|
-
};
|
|
5119
2556
|
var environmentNameOf = (pluginThis) => {
|
|
5120
2557
|
if (!pluginThis || typeof pluginThis !== "object") return void 0;
|
|
5121
2558
|
const environment = Reflect.get(pluginThis, "environment");
|
|
@@ -5136,22 +2573,9 @@ var incomingMapOf = (pluginThis) => {
|
|
|
5136
2573
|
var rasputin = (options) => {
|
|
5137
2574
|
if (options.enabled === false) return [];
|
|
5138
2575
|
const release = options.release.trim();
|
|
5139
|
-
const
|
|
5140
|
-
"client",
|
|
5141
|
-
normalizeExplicitCompileId(options.buildId) || void 0
|
|
5142
|
-
);
|
|
5143
|
-
const server = createTargetState(
|
|
5144
|
-
"ssr",
|
|
5145
|
-
normalizeExplicitCompileId(options.serverBuildId) || void 0
|
|
5146
|
-
);
|
|
5147
|
-
const stateFor = (target) => {
|
|
5148
|
-
if (target === "client") return client;
|
|
5149
|
-
if (target === "ssr") return server;
|
|
5150
|
-
return void 0;
|
|
5151
|
-
};
|
|
2576
|
+
const server = createTargetState(normalizeExplicitCompileId(options.buildId) || void 0);
|
|
5152
2577
|
let command = "unknown";
|
|
5153
2578
|
let configSsr;
|
|
5154
|
-
let includeRuntimeNames = options.includeRuntimeNames ?? true;
|
|
5155
2579
|
let keepPublicMaps = false;
|
|
5156
2580
|
const identify = (pluginThis, ssr) => identifyBuildTarget({
|
|
5157
2581
|
environmentName: environmentNameOf(pluginThis),
|
|
@@ -5170,123 +2594,42 @@ var rasputin = (options) => {
|
|
|
5170
2594
|
configResolved(config) {
|
|
5171
2595
|
command = config.command === "serve" || config.command === "build" ? config.command : "unknown";
|
|
5172
2596
|
configSsr = typeof config.build?.ssr === "boolean" ? config.build.ssr : void 0;
|
|
5173
|
-
includeRuntimeNames = options.includeRuntimeNames ?? (config.command !== "build" || config.mode !== "production");
|
|
5174
|
-
},
|
|
5175
|
-
resolveId(id) {
|
|
5176
|
-
if (isVirtualIdentityId(id)) return RESOLVED_VIRTUAL_IDENTITY_ID;
|
|
5177
|
-
return void 0;
|
|
5178
|
-
},
|
|
5179
|
-
load(id) {
|
|
5180
|
-
if (!isVirtualIdentityId(id)) return void 0;
|
|
5181
|
-
if (identify(this) !== "client") return "export {};";
|
|
5182
|
-
return clientIdentitySource({
|
|
5183
|
-
buildId: client.buildId,
|
|
5184
|
-
release,
|
|
5185
|
-
environment: options.environment
|
|
5186
|
-
});
|
|
5187
2597
|
},
|
|
5188
2598
|
transform(code, id, transformOptions) {
|
|
5189
|
-
|
|
5190
|
-
if (target === "unknown") return void 0;
|
|
2599
|
+
if (identify(this, transformOptions?.ssr) !== "ssr") return void 0;
|
|
5191
2600
|
const filePath = normalizeModulePath(id);
|
|
5192
|
-
if (!filePath) return void 0;
|
|
5193
|
-
|
|
2601
|
+
if (!filePath || isRasputinSdkPath(filePath)) return void 0;
|
|
2602
|
+
if (!isApplicationJsPath(id, options.onlyIfPathIncludes)) return void 0;
|
|
5194
2603
|
try {
|
|
5195
|
-
|
|
5196
|
-
if (target === "client" && isBrowserClientEntry(filePath)) {
|
|
5197
|
-
next = `import '${VIRTUAL_IDENTITY_ID}';
|
|
5198
|
-
${code}`;
|
|
5199
|
-
}
|
|
5200
|
-
if (isRasputinSdkPath(filePath)) {
|
|
5201
|
-
return next === code ? void 0 : { code: next };
|
|
5202
|
-
}
|
|
5203
|
-
if (target === "client" && isServerOnlyPath(filePath)) {
|
|
5204
|
-
return next === code ? void 0 : { code: next };
|
|
5205
|
-
}
|
|
5206
|
-
if (!isApplicationJsPath(id, options.onlyIfPathIncludes)) {
|
|
5207
|
-
return next === code ? void 0 : { code: next };
|
|
5208
|
-
}
|
|
5209
|
-
if (!state) return next === code ? void 0 : { code: next };
|
|
5210
|
-
const incomingMap = incomingMapOf(this);
|
|
5211
|
-
const transformed = target === "client" ? instrumentClientModule(state, next, filePath, incomingMap, includeRuntimeNames) : instrumentServerModule(state, next, filePath, incomingMap);
|
|
5212
|
-
if (!transformed) return next === code ? void 0 : { code: next };
|
|
5213
|
-
return transformed;
|
|
2604
|
+
return instrumentServerModule(server, code, filePath, incomingMapOf(this));
|
|
5214
2605
|
} catch {
|
|
5215
|
-
|
|
2606
|
+
forgetModule(server, filePath);
|
|
5216
2607
|
return void 0;
|
|
5217
2608
|
}
|
|
5218
2609
|
},
|
|
5219
|
-
async generateBundle(
|
|
5220
|
-
|
|
5221
|
-
if (target === "unknown") return;
|
|
5222
|
-
if (target === "ssr") {
|
|
5223
|
-
if (command !== "build") return;
|
|
5224
|
-
try {
|
|
5225
|
-
await uploadServerBuildManifest({
|
|
5226
|
-
manifest: snapshotServerInstrumentationManifest(server),
|
|
5227
|
-
release,
|
|
5228
|
-
projectApiKey: options.projectApiKey,
|
|
5229
|
-
apiUrl: options.apiUrl
|
|
5230
|
-
});
|
|
5231
|
-
} catch {
|
|
5232
|
-
console.warn(
|
|
5233
|
-
"[rasputin] instrumentation manifest upload failed; the build still succeeded"
|
|
5234
|
-
);
|
|
5235
|
-
}
|
|
5236
|
-
return;
|
|
5237
|
-
}
|
|
5238
|
-
const identitiesJson = includeRuntimeNames ? JSON.stringify(client.identities) : "[]";
|
|
5239
|
-
const statsJson = JSON.stringify({
|
|
5240
|
-
functions: client.functions.size,
|
|
5241
|
-
verificationFailed: client.verificationFailed.size
|
|
5242
|
-
});
|
|
5243
|
-
const debugImages = [];
|
|
5244
|
-
for (const [fileName, item] of Object.entries(bundle)) {
|
|
5245
|
-
if (!keepPublicMaps && fileName.endsWith(".map")) {
|
|
5246
|
-
Reflect.deleteProperty(bundle, fileName);
|
|
5247
|
-
continue;
|
|
5248
|
-
}
|
|
5249
|
-
if (item.type !== "chunk") continue;
|
|
5250
|
-
const debugId = contentDebugId(item.code);
|
|
5251
|
-
item.code = item.code.replaceAll(
|
|
5252
|
-
new RegExp(`[\`"']${BUILD_IDENTITIES_MARKER}[\`"']`, "g"),
|
|
5253
|
-
identitiesJson
|
|
5254
|
-
);
|
|
5255
|
-
item.code = item.code.replaceAll(
|
|
5256
|
-
new RegExp(`[\`"']${BUILD_STATS_MARKER}[\`"']`, "g"),
|
|
5257
|
-
statsJson
|
|
5258
|
-
);
|
|
5259
|
-
item.code = `${item.code.replace(/\n?$/, "\n")}//# debugId=${debugId}
|
|
5260
|
-
`;
|
|
5261
|
-
if (!keepPublicMaps) {
|
|
5262
|
-
item.code = item.code.replace(/\n\/\/# sourceMappingURL=[^\n]+/g, "\n");
|
|
5263
|
-
}
|
|
5264
|
-
debugImages.push({ debugId, fileName: item.fileName, map: item.map ?? null });
|
|
5265
|
-
if (!keepPublicMaps) item.map = null;
|
|
5266
|
-
}
|
|
5267
|
-
if (command !== "build") return;
|
|
2610
|
+
async generateBundle() {
|
|
2611
|
+
if (identify(this) !== "ssr" || command !== "build") return;
|
|
5268
2612
|
try {
|
|
5269
|
-
await
|
|
5270
|
-
|
|
2613
|
+
await uploadServerBuildManifest({
|
|
2614
|
+
manifest: snapshotServerInstrumentationManifest(server),
|
|
5271
2615
|
release,
|
|
5272
2616
|
projectApiKey: options.projectApiKey,
|
|
5273
2617
|
apiUrl: options.apiUrl
|
|
5274
2618
|
});
|
|
5275
2619
|
} catch {
|
|
5276
|
-
console.warn(
|
|
2620
|
+
console.warn(
|
|
2621
|
+
"[rasputin] instrumentation manifest upload failed; the build still succeeded"
|
|
2622
|
+
);
|
|
5277
2623
|
}
|
|
5278
2624
|
},
|
|
5279
2625
|
handleHotUpdate(ctx) {
|
|
5280
2626
|
const filePath = normalizeModulePath(ctx.file);
|
|
5281
|
-
if (filePath)
|
|
5282
|
-
forgetModule(client, filePath);
|
|
5283
|
-
forgetModule(server, filePath);
|
|
5284
|
-
}
|
|
2627
|
+
if (filePath) forgetModule(server, filePath);
|
|
5285
2628
|
return void 0;
|
|
5286
2629
|
}
|
|
5287
2630
|
};
|
|
5288
2631
|
Reflect.set(plugin, "applyToEnvironment", (environmentRef) => {
|
|
5289
|
-
return environmentRef.name === "
|
|
2632
|
+
return environmentRef.name === "ssr";
|
|
5290
2633
|
});
|
|
5291
2634
|
const sveltePlugin = {
|
|
5292
2635
|
name: "rasputin-sveltekit-svelte",
|
|
@@ -5294,44 +2637,50 @@ ${code}`;
|
|
|
5294
2637
|
transform: {
|
|
5295
2638
|
order: "post",
|
|
5296
2639
|
handler(code, id, transformOptions) {
|
|
5297
|
-
|
|
5298
|
-
if (target === "unknown") return void 0;
|
|
2640
|
+
if (identify(this, transformOptions?.ssr) !== "ssr") return void 0;
|
|
5299
2641
|
if (!isCompiledSveltePath(id, options.onlyIfPathIncludes)) return void 0;
|
|
5300
2642
|
const filePath = normalizeModulePath(id);
|
|
5301
2643
|
if (!filePath || isRasputinSdkPath(filePath)) return void 0;
|
|
5302
|
-
|
|
5303
|
-
if (!state) return void 0;
|
|
2644
|
+
if (!recognizeSvelteSsrModule(code, filePath)) return void 0;
|
|
5304
2645
|
try {
|
|
5305
|
-
const incomingMap = incomingMapOf(this);
|
|
5306
|
-
if (target === "client") {
|
|
5307
|
-
return instrumentClientModule(
|
|
5308
|
-
state,
|
|
5309
|
-
code,
|
|
5310
|
-
filePath,
|
|
5311
|
-
incomingMap,
|
|
5312
|
-
includeRuntimeNames,
|
|
5313
|
-
svelteClientPolicy
|
|
5314
|
-
);
|
|
5315
|
-
}
|
|
5316
|
-
if (!recognizeSvelteSsrModule(code, filePath)) return void 0;
|
|
5317
2646
|
return instrumentServerModule(
|
|
5318
|
-
|
|
2647
|
+
server,
|
|
5319
2648
|
code,
|
|
5320
2649
|
filePath,
|
|
5321
|
-
|
|
2650
|
+
incomingMapOf(this),
|
|
5322
2651
|
decideSvelteSsrFunction
|
|
5323
2652
|
);
|
|
5324
2653
|
} catch {
|
|
5325
|
-
forgetModule(
|
|
2654
|
+
forgetModule(server, filePath);
|
|
5326
2655
|
return void 0;
|
|
5327
2656
|
}
|
|
5328
2657
|
}
|
|
5329
2658
|
}
|
|
5330
2659
|
};
|
|
5331
2660
|
Reflect.set(sveltePlugin, "applyToEnvironment", (environmentRef) => {
|
|
5332
|
-
return environmentRef.name === "
|
|
2661
|
+
return environmentRef.name === "ssr";
|
|
2662
|
+
});
|
|
2663
|
+
const stripClientMaps = {
|
|
2664
|
+
name: "rasputin-sveltekit-client-maps",
|
|
2665
|
+
apply: "build",
|
|
2666
|
+
enforce: "post",
|
|
2667
|
+
generateBundle(_output, bundle) {
|
|
2668
|
+
if (keepPublicMaps || identify(this) === "ssr") return;
|
|
2669
|
+
for (const [fileName, item] of Object.entries(bundle)) {
|
|
2670
|
+
if (fileName.endsWith(".map")) {
|
|
2671
|
+
Reflect.deleteProperty(bundle, fileName);
|
|
2672
|
+
continue;
|
|
2673
|
+
}
|
|
2674
|
+
if (item.type !== "chunk") continue;
|
|
2675
|
+
item.code = item.code.replace(/\n\/\/# sourceMappingURL=[^\n]+/g, "\n");
|
|
2676
|
+
item.map = null;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
};
|
|
2680
|
+
Reflect.set(stripClientMaps, "applyToEnvironment", (environmentRef) => {
|
|
2681
|
+
return environmentRef.name !== "ssr";
|
|
5333
2682
|
});
|
|
5334
|
-
return [plugin, sveltePlugin];
|
|
2683
|
+
return [plugin, sveltePlugin, stripClientMaps];
|
|
5335
2684
|
};
|
|
5336
2685
|
export {
|
|
5337
2686
|
rasputin
|