@rasputin-ai/node 0.5.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -216
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts +1 -3
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
- package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts.map +1 -1
- package/dist/auto-instrumentation/source-map-locations.d.ts +1 -1
- package/dist/auto-instrumentation/source-map-locations.d.ts.map +1 -1
- package/dist/auto-instrumentation/transform-disk-cache.d.ts +1 -1
- package/dist/auto-instrumentation/transform-disk-cache.d.ts.map +1 -1
- package/dist/execution-recorder/automatic-runtime.d.ts +2 -33
- package/dist/execution-recorder/automatic-runtime.d.ts.map +1 -1
- package/dist/execution-recorder/encode-frozen.d.ts +0 -8
- package/dist/execution-recorder/encode-frozen.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-types.d.ts +3 -4
- package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/function-plan.d.ts +7 -22
- package/dist/execution-recorder/function-plan.d.ts.map +1 -1
- package/dist/execution-recorder/redact-keys.d.ts +0 -1
- package/dist/execution-recorder/redact-keys.d.ts.map +1 -1
- package/dist/execution-recorder/runtime-state-size-budget.d.ts +0 -2
- package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
- package/dist/execution-recorder/safe-serialize.d.ts +0 -2
- package/dist/execution-recorder/safe-serialize.d.ts.map +1 -1
- package/dist/execution-recorder/value-freeze.d.ts +0 -1
- package/dist/execution-recorder/value-freeze.d.ts.map +1 -1
- package/dist/index.js +146 -125
- package/dist/instrument/build.js +852 -588
- package/dist/instrument/bun.js +639 -373
- package/dist/instrument/node.js +605 -339
- package/dist/internal.js +143 -122
- package/dist/rasputin-init.d.ts +1 -0
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +4 -2
- package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts +0 -29
- package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts.map +0 -1
- package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts +0 -49
- package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts.map +0 -1
- package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts +0 -3
- package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts.map +0 -1
- package/dist/auto-instrumentation/suspension-whitelist.d.ts +0 -33
- package/dist/auto-instrumentation/suspension-whitelist.d.ts.map +0 -1
- package/dist/auto-instrumentation/transform-source.d.ts +0 -27
- package/dist/auto-instrumentation/transform-source.d.ts.map +0 -1
- package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts +0 -2
- package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts.map +0 -1
- package/dist/auto-instrumentation/verify-transformed-source.d.ts +0 -2
- package/dist/auto-instrumentation/verify-transformed-source.d.ts.map +0 -1
- package/dist/execution-recorder/run-exactly-once.d.ts +0 -7
- package/dist/execution-recorder/run-exactly-once.d.ts.map +0 -1
package/dist/instrument/build.js
CHANGED
|
@@ -5,19 +5,7 @@ import {
|
|
|
5
5
|
hashInstrumentationManifest
|
|
6
6
|
} from "@rasputin-ai/core";
|
|
7
7
|
|
|
8
|
-
// src/
|
|
9
|
-
import { createHash } from "node:crypto";
|
|
10
|
-
import { resolve } from "node:path";
|
|
11
|
-
import {
|
|
12
|
-
INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
13
|
-
sourceLocatorFromFile as sourceLocatorFromFile2
|
|
14
|
-
} from "@rasputin-ai/core";
|
|
15
|
-
|
|
16
|
-
// src/execution-recorder/function-plan.ts
|
|
17
|
-
import {
|
|
18
|
-
runtimeFunctionId,
|
|
19
|
-
sourceLocatorFromFile
|
|
20
|
-
} from "@rasputin-ai/core";
|
|
8
|
+
// ../recorder/src/encoded-function-plan.ts
|
|
21
9
|
var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
|
|
22
10
|
var withPreBodyParameterEvaluation = (plan) => [
|
|
23
11
|
plan[0],
|
|
@@ -29,6 +17,12 @@ var withPreBodyParameterEvaluation = (plan) => [
|
|
|
29
17
|
plan[6],
|
|
30
18
|
1
|
|
31
19
|
];
|
|
20
|
+
|
|
21
|
+
// ../recorder/src/function-plan.ts
|
|
22
|
+
import {
|
|
23
|
+
runtimeFunctionId,
|
|
24
|
+
sourceLocatorFromFile
|
|
25
|
+
} from "@rasputin-ai/core";
|
|
32
26
|
var encodeFunctionPlan = (source) => {
|
|
33
27
|
const locator = sourceLocatorFromFile(source.filePath);
|
|
34
28
|
const definition = {
|
|
@@ -60,244 +54,13 @@ var definitionFromEncodedPlan = (plan) => {
|
|
|
60
54
|
};
|
|
61
55
|
};
|
|
62
56
|
|
|
63
|
-
// src/
|
|
64
|
-
var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
|
|
65
|
-
var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
|
|
66
|
-
var getRegistry = () => {
|
|
67
|
-
const existing = Reflect.get(globalThis, registrySymbol);
|
|
68
|
-
if (existing?.__rasputinManifestRegistry && existing.files instanceof Map && typeof existing.generation === "number" && typeof existing.uploadedGeneration === "number") {
|
|
69
|
-
const registry2 = existing;
|
|
70
|
-
if (typeof registry2.alreadyInstrumented !== "number") registry2.alreadyInstrumented = 0;
|
|
71
|
-
return registry2;
|
|
72
|
-
}
|
|
73
|
-
const registry = {
|
|
74
|
-
__rasputinManifestRegistry: true,
|
|
75
|
-
files: /* @__PURE__ */ new Map(),
|
|
76
|
-
generation: 0,
|
|
77
|
-
uploadedGeneration: 0,
|
|
78
|
-
alreadyInstrumented: 0
|
|
79
|
-
};
|
|
80
|
-
Reflect.set(globalThis, registrySymbol, registry);
|
|
81
|
-
return registry;
|
|
82
|
-
};
|
|
83
|
-
var sourceAt = (filePath, line, column) => {
|
|
84
|
-
const source = sourceLocatorFromFile2(filePath);
|
|
85
|
-
return source ? { ...source, line, column } : void 0;
|
|
86
|
-
};
|
|
87
|
-
var stableId = (kind, ...parts) => `${kind}_${createHash("sha256").update(parts.join("\0")).digest("base64url").slice(0, 24)}`;
|
|
88
|
-
var recordInstrumentationManifestDelta = (filePath, delta) => {
|
|
89
|
-
const registry = getRegistry();
|
|
90
|
-
if (delta.alreadyInstrumented) {
|
|
91
|
-
registry.alreadyInstrumented += 1;
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
registry.files.set(resolve(filePath), delta);
|
|
95
|
-
registry.generation += 1;
|
|
96
|
-
registry.onDirty?.();
|
|
97
|
-
};
|
|
98
|
-
var snapshotOptionsKey = (options) => JSON.stringify({
|
|
99
|
-
sourceRoot: options.sourceRoot ?? "",
|
|
100
|
-
sourceRoots: options.sourceRoots ?? {}
|
|
101
|
-
});
|
|
102
|
-
var snapshotInstrumentationManifest = (options = {}) => {
|
|
103
|
-
const registry = getRegistry();
|
|
104
|
-
const optionsKey = snapshotOptionsKey(options);
|
|
105
|
-
if (registry.snapshotCache && registry.snapshotCache.generation === registry.generation && registry.snapshotCache.optionsKey === optionsKey) {
|
|
106
|
-
return registry.snapshotCache.manifest;
|
|
107
|
-
}
|
|
108
|
-
const functions = [];
|
|
109
|
-
const callSites = [];
|
|
110
|
-
const destructures = [];
|
|
111
|
-
const remember = (manifest) => {
|
|
112
|
-
registry.snapshotCache = {
|
|
113
|
-
generation: registry.generation,
|
|
114
|
-
optionsKey,
|
|
115
|
-
manifest
|
|
116
|
-
};
|
|
117
|
-
return manifest;
|
|
118
|
-
};
|
|
119
|
-
for (const delta of registry.files.values()) {
|
|
120
|
-
for (const fn of delta.functions) {
|
|
121
|
-
const definition = definitionFromEncodedPlan(fn.plan);
|
|
122
|
-
if (!definition.source) continue;
|
|
123
|
-
functions.push({
|
|
124
|
-
functionId: definition.functionId,
|
|
125
|
-
source: definition.source,
|
|
126
|
-
name: fn.name,
|
|
127
|
-
startLine: fn.startLine,
|
|
128
|
-
startColumn: fn.startColumn,
|
|
129
|
-
endLine: fn.endLine,
|
|
130
|
-
endColumn: fn.endColumn,
|
|
131
|
-
params: fn.params,
|
|
132
|
-
...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
for (const site of delta.callSites) {
|
|
136
|
-
const source = sourceAt(site.filePath, site.line, site.column);
|
|
137
|
-
if (!source) continue;
|
|
138
|
-
callSites.push({
|
|
139
|
-
id: stableId(
|
|
140
|
-
"cs",
|
|
141
|
-
site.callerFunctionId,
|
|
142
|
-
source.packageName ?? "",
|
|
143
|
-
source.packageRelativePath,
|
|
144
|
-
site.line,
|
|
145
|
-
site.column
|
|
146
|
-
),
|
|
147
|
-
callerFunctionId: site.callerFunctionId,
|
|
148
|
-
calleeName: site.calleeName,
|
|
149
|
-
calleeText: site.calleeText,
|
|
150
|
-
source,
|
|
151
|
-
line: site.line,
|
|
152
|
-
column: site.column,
|
|
153
|
-
endLine: site.endLine,
|
|
154
|
-
endColumn: site.endColumn,
|
|
155
|
-
resultBinding: site.resultBinding,
|
|
156
|
-
argIdentifiers: site.argIdentifiers
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
for (const destructure of delta.destructures) {
|
|
160
|
-
const source = sourceAt(destructure.filePath, destructure.line, destructure.column);
|
|
161
|
-
if (!source) continue;
|
|
162
|
-
destructures.push({
|
|
163
|
-
callerFunctionId: destructure.callerFunctionId,
|
|
164
|
-
sourceParam: destructure.sourceParam,
|
|
165
|
-
source,
|
|
166
|
-
line: destructure.line,
|
|
167
|
-
column: destructure.column,
|
|
168
|
-
binding: destructure.binding
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (registry.prebuilt && registry.files.size === 0) {
|
|
173
|
-
const prebuilt = registry.prebuilt;
|
|
174
|
-
if (!options.sourceRoot && !options.sourceRoots) return remember(prebuilt);
|
|
175
|
-
return remember({
|
|
176
|
-
...prebuilt,
|
|
177
|
-
sourceRoots: {
|
|
178
|
-
...options.sourceRoot ? { default: options.sourceRoot } : {},
|
|
179
|
-
packages: { ...options.sourceRoots ?? {} }
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (functions.length === 0 && callSites.length === 0 && destructures.length === 0) {
|
|
184
|
-
return remember(void 0);
|
|
185
|
-
}
|
|
186
|
-
const packages = { ...options.sourceRoots ?? {} };
|
|
187
|
-
return remember({
|
|
188
|
-
schema_version: INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
189
|
-
...options.sourceRoot || Object.keys(packages).length > 0 ? {
|
|
190
|
-
sourceRoots: {
|
|
191
|
-
...options.sourceRoot ? { default: options.sourceRoot } : {},
|
|
192
|
-
packages
|
|
193
|
-
}
|
|
194
|
-
} : {},
|
|
195
|
-
functions,
|
|
196
|
-
callSites,
|
|
197
|
-
destructures
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
var resetInstrumentationManifestRegistry = () => {
|
|
201
|
-
Reflect.deleteProperty(globalThis, registrySymbol);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// src/auto-instrumentation/source-classification.ts
|
|
205
|
-
import { isAbsolute, relative, resolve as resolve2, sep } from "node:path";
|
|
206
|
-
var sourceExtension = /\.[cm]?[jt]sx?$/i;
|
|
207
|
-
var alwaysExcludedDirectory = /(^|[\\/])(node_modules|coverage|generated|\.git|\.next|\.svelte-kit|\.output|\.vercel|\.rasputin|\.turbo|\.yarn|\.pnpm|\.bun)([\\/]|$)/;
|
|
208
|
-
var buildOutputDirectory = /(^|[\\/])(dist|build|out)([\\/]|$)/;
|
|
209
|
-
var matches = (pattern, value) => {
|
|
210
|
-
pattern.lastIndex = 0;
|
|
211
|
-
const result2 = pattern.test(value);
|
|
212
|
-
pattern.lastIndex = 0;
|
|
213
|
-
return result2;
|
|
214
|
-
};
|
|
215
|
-
var isWithinRoot = (filePath, root) => {
|
|
216
|
-
const fromRoot = relative(resolve2(root), filePath);
|
|
217
|
-
return fromRoot === "" || !fromRoot.startsWith(`..${sep}`) && fromRoot !== ".." && !isAbsolute(fromRoot);
|
|
218
|
-
};
|
|
219
|
-
var isApplicationSource = (filePath, options = {}) => {
|
|
220
|
-
const absolutePath = resolve2(filePath);
|
|
221
|
-
if (!sourceExtension.test(absolutePath) || alwaysExcludedDirectory.test(absolutePath))
|
|
222
|
-
return false;
|
|
223
|
-
if (options.includeBuildOutput !== true && buildOutputDirectory.test(absolutePath)) return false;
|
|
224
|
-
if (options.excludedRoots?.some((root) => isWithinRoot(absolutePath, root))) return false;
|
|
225
|
-
if (options.exclude && matches(options.exclude, absolutePath)) return false;
|
|
226
|
-
if (options.include && !matches(options.include, absolutePath)) return false;
|
|
227
|
-
if (options.rootDir) {
|
|
228
|
-
if (!isWithinRoot(absolutePath, options.rootDir)) return false;
|
|
229
|
-
}
|
|
230
|
-
return true;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// src/auto-instrumentation/source-map-locations.ts
|
|
234
|
-
import { readFileSync } from "node:fs";
|
|
235
|
-
import { dirname, isAbsolute as isAbsolute2, join, resolve as resolve3 } from "node:path";
|
|
236
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
237
|
-
import { LEAST_UPPER_BOUND, originalPositionFor, TraceMap } from "@jridgewell/trace-mapping";
|
|
238
|
-
var sourceMapComment = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
239
|
-
var decodeDataUrl = (url) => {
|
|
240
|
-
const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
|
|
241
|
-
if (base64?.[1]) return Buffer.from(base64[1], "base64").toString("utf8");
|
|
242
|
-
const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
|
|
243
|
-
return raw?.[1] ? decodeURIComponent(raw[1]) : void 0;
|
|
244
|
-
};
|
|
245
|
-
var sourceMapFor = (generatedPath, source) => {
|
|
246
|
-
const match = sourceMapComment.exec(source);
|
|
247
|
-
const reference = match?.[1] ?? match?.[2];
|
|
248
|
-
if (reference?.startsWith("data:")) {
|
|
249
|
-
const payload = decodeDataUrl(reference);
|
|
250
|
-
return payload ? { payload, mapUrl: pathToFileURL(generatedPath).href } : void 0;
|
|
251
|
-
}
|
|
252
|
-
const mapPath = reference ? resolve3(dirname(generatedPath), reference) : `${generatedPath}.map`;
|
|
253
|
-
return {
|
|
254
|
-
payload: readFileSync(mapPath, "utf8"),
|
|
255
|
-
mapUrl: pathToFileURL(mapPath).href
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
var toFilePath = (source, generatedPath) => {
|
|
259
|
-
if (source.startsWith("file:")) return fileURLToPath(source);
|
|
260
|
-
return isAbsolute2(source) ? source : join(dirname(generatedPath), source);
|
|
261
|
-
};
|
|
262
|
-
var createSourceMapLocationMapper = (generatedPath, source) => {
|
|
263
|
-
try {
|
|
264
|
-
const sourceMap = sourceMapFor(generatedPath, source);
|
|
265
|
-
if (!sourceMap) return void 0;
|
|
266
|
-
const traceMap = new TraceMap(sourceMap.payload, sourceMap.mapUrl);
|
|
267
|
-
return (generated) => {
|
|
268
|
-
let original = originalPositionFor(traceMap, {
|
|
269
|
-
line: generated.line,
|
|
270
|
-
column: Math.max(0, generated.column - 1)
|
|
271
|
-
});
|
|
272
|
-
if (!original.source || original.line == null) {
|
|
273
|
-
original = originalPositionFor(traceMap, {
|
|
274
|
-
line: generated.line,
|
|
275
|
-
column: 0,
|
|
276
|
-
bias: LEAST_UPPER_BOUND
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
if (!original.source || original.line == null) return void 0;
|
|
280
|
-
return {
|
|
281
|
-
filePath: toFilePath(original.source, generatedPath),
|
|
282
|
-
line: original.line,
|
|
283
|
-
column: (original.column ?? 0) + 1
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
} catch {
|
|
287
|
-
return void 0;
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// src/auto-instrumentation/transform-source.ts
|
|
292
|
-
import { basename, resolve as resolve4 } from "node:path";
|
|
293
|
-
import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap2 } from "@jridgewell/trace-mapping";
|
|
294
|
-
import ts6 from "typescript";
|
|
295
|
-
|
|
296
|
-
// src/execution-recorder/automatic-runtime.ts
|
|
57
|
+
// ../recorder/src/runtime-symbol.ts
|
|
297
58
|
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
298
|
-
var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
|
|
299
59
|
|
|
300
|
-
// src/
|
|
60
|
+
// ../instrumentation/src/classify-function.ts
|
|
61
|
+
import ts4 from "typescript";
|
|
62
|
+
|
|
63
|
+
// ../instrumentation/src/collect-instrumentation-delta.ts
|
|
301
64
|
import ts from "typescript";
|
|
302
65
|
var paramBindingFromName = (name, sourceFile) => {
|
|
303
66
|
if (ts.isIdentifier(name)) return { kind: "identifier", name: name.text };
|
|
@@ -474,41 +237,436 @@ var collectParamDestructure = (declaration, caller, context) => {
|
|
|
474
237
|
};
|
|
475
238
|
};
|
|
476
239
|
|
|
477
|
-
// src/
|
|
240
|
+
// ../instrumentation/src/parse-source.ts
|
|
478
241
|
import ts2 from "typescript";
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
242
|
+
|
|
243
|
+
// ../instrumentation/src/svelte-generated.ts
|
|
244
|
+
import ts3 from "typescript";
|
|
245
|
+
|
|
246
|
+
// ../instrumentation/src/edits.ts
|
|
247
|
+
var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
248
|
+
var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
249
|
+
var separateFromPreviousToken = (source, position, text) => {
|
|
250
|
+
if (position <= 0 || text.length === 0) return text;
|
|
251
|
+
if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
|
|
252
|
+
return ` ${text}`;
|
|
253
|
+
}
|
|
254
|
+
return text;
|
|
255
|
+
};
|
|
256
|
+
var uniqueName = (source, base) => {
|
|
257
|
+
let name = base;
|
|
258
|
+
while (source.includes(name)) name += "_";
|
|
259
|
+
return name;
|
|
260
|
+
};
|
|
261
|
+
var wrap = (edits, start, end, open, close, depth) => {
|
|
262
|
+
const width = Math.max(0, end - start);
|
|
263
|
+
edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
|
|
264
|
+
edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
|
|
265
|
+
};
|
|
266
|
+
var compareEdits = (left, right) => {
|
|
267
|
+
if (left.position !== right.position) return right.position - left.position;
|
|
268
|
+
if (left.kind !== right.kind) {
|
|
269
|
+
const rank = { replace: 0, close: 1, open: 2 };
|
|
270
|
+
return rank[left.kind] - rank[right.kind];
|
|
271
|
+
}
|
|
272
|
+
if (left.kind === "close") {
|
|
273
|
+
if (left.width !== right.width) return right.width - left.width;
|
|
274
|
+
return left.depth - right.depth;
|
|
275
|
+
}
|
|
276
|
+
if (left.kind === "open") {
|
|
277
|
+
if (left.width !== right.width) return left.width - right.width;
|
|
278
|
+
return right.depth - left.depth;
|
|
279
|
+
}
|
|
280
|
+
return 0;
|
|
281
|
+
};
|
|
282
|
+
var applyEdits = (source, edits) => {
|
|
283
|
+
const ordered = [...edits].sort(compareEdits);
|
|
284
|
+
let transformed = source;
|
|
285
|
+
for (const edit of ordered) {
|
|
286
|
+
const text = separateFromPreviousToken(transformed, edit.position, textOf(edit));
|
|
287
|
+
transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
|
|
288
|
+
}
|
|
289
|
+
return transformed;
|
|
290
|
+
};
|
|
291
|
+
var textOf = (edit) => edit.text;
|
|
292
|
+
|
|
293
|
+
// ../node_modules/.bun/@jridgewell+sourcemap-codec@1.6.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
294
|
+
var comma = ",".charCodeAt(0);
|
|
295
|
+
var semicolon = ";".charCodeAt(0);
|
|
296
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
297
|
+
var intToChar = new Uint8Array(64);
|
|
298
|
+
var charToInt = new Uint8Array(128);
|
|
299
|
+
for (let i = 0; i < chars.length; i++) {
|
|
300
|
+
const c = chars.charCodeAt(i);
|
|
301
|
+
intToChar[i] = c;
|
|
302
|
+
charToInt[c] = i;
|
|
303
|
+
}
|
|
304
|
+
function encodeInteger(builder, num) {
|
|
305
|
+
do {
|
|
306
|
+
let clamped = num & 31;
|
|
307
|
+
num >>>= 5;
|
|
308
|
+
if (num > 0) clamped |= 32;
|
|
309
|
+
builder.write(intToChar[clamped]);
|
|
310
|
+
} while (num > 0);
|
|
311
|
+
}
|
|
312
|
+
function encodeSign(num) {
|
|
313
|
+
return num < 0 ? -num << 1 | 1 : num << 1;
|
|
314
|
+
}
|
|
315
|
+
var bufLength = 1024 * 16;
|
|
316
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
|
|
317
|
+
decode(buf) {
|
|
318
|
+
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
319
|
+
return out.toString();
|
|
320
|
+
}
|
|
321
|
+
} : {
|
|
322
|
+
decode(buf) {
|
|
323
|
+
let out = "";
|
|
324
|
+
for (let i = 0; i < buf.length; i++) {
|
|
325
|
+
out += String.fromCharCode(buf[i]);
|
|
326
|
+
}
|
|
327
|
+
return out;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var StringWriter = class {
|
|
331
|
+
constructor() {
|
|
332
|
+
this.pos = 0;
|
|
333
|
+
this.out = "";
|
|
334
|
+
this.buffer = new Uint8Array(bufLength);
|
|
335
|
+
}
|
|
336
|
+
write(v) {
|
|
337
|
+
const { buffer } = this;
|
|
338
|
+
buffer[this.pos++] = v;
|
|
339
|
+
if (this.pos === bufLength) {
|
|
340
|
+
this.out += td.decode(buffer);
|
|
341
|
+
this.pos = 0;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
flush() {
|
|
345
|
+
const { buffer, out, pos } = this;
|
|
346
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
function encode(decoded) {
|
|
350
|
+
const writer = new StringWriter();
|
|
351
|
+
let sourcesIndex = 0;
|
|
352
|
+
let sourceLine = 0;
|
|
353
|
+
let sourceColumn = 0;
|
|
354
|
+
let namesIndex = 0;
|
|
355
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
356
|
+
const line = decoded[i];
|
|
357
|
+
if (i > 0) writer.write(semicolon);
|
|
358
|
+
if (line.length === 0) continue;
|
|
359
|
+
let genColumn = 0;
|
|
360
|
+
for (let j = 0; j < line.length; j++) {
|
|
361
|
+
const segment = line[j];
|
|
362
|
+
if (j > 0) writer.write(comma);
|
|
363
|
+
encodeInteger(writer, encodeSign(segment[0] - genColumn));
|
|
364
|
+
genColumn = segment[0];
|
|
365
|
+
if (segment.length === 1) continue;
|
|
366
|
+
encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
|
|
367
|
+
encodeInteger(writer, encodeSign(segment[2] - sourceLine));
|
|
368
|
+
encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
|
|
369
|
+
sourcesIndex = segment[1];
|
|
370
|
+
sourceLine = segment[2];
|
|
371
|
+
sourceColumn = segment[3];
|
|
372
|
+
if (segment.length === 4) continue;
|
|
373
|
+
encodeInteger(writer, encodeSign(segment[4] - namesIndex));
|
|
374
|
+
namesIndex = segment[4];
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return writer.flush();
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ../node_modules/.bun/@jridgewell+gen-mapping@0.3.13/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
|
|
381
|
+
import { TraceMap, decodedMappings } from "@jridgewell/trace-mapping";
|
|
382
|
+
var SetArray = class {
|
|
383
|
+
constructor() {
|
|
384
|
+
this._indexes = { __proto__: null };
|
|
385
|
+
this.array = [];
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
function cast(set) {
|
|
389
|
+
return set;
|
|
390
|
+
}
|
|
391
|
+
function get(setarr, key) {
|
|
392
|
+
return cast(setarr)._indexes[key];
|
|
393
|
+
}
|
|
394
|
+
function put(setarr, key) {
|
|
395
|
+
const index = get(setarr, key);
|
|
396
|
+
if (index !== void 0) return index;
|
|
397
|
+
const { array, _indexes: indexes } = cast(setarr);
|
|
398
|
+
const length = array.push(key);
|
|
399
|
+
return indexes[key] = length - 1;
|
|
400
|
+
}
|
|
401
|
+
var COLUMN = 0;
|
|
402
|
+
var SOURCES_INDEX = 1;
|
|
403
|
+
var SOURCE_LINE = 2;
|
|
404
|
+
var SOURCE_COLUMN = 3;
|
|
405
|
+
var NAMES_INDEX = 4;
|
|
406
|
+
var NO_NAME = -1;
|
|
407
|
+
var GenMapping = class {
|
|
408
|
+
constructor({ file, sourceRoot } = {}) {
|
|
409
|
+
this._names = new SetArray();
|
|
410
|
+
this._sources = new SetArray();
|
|
411
|
+
this._sourcesContent = [];
|
|
412
|
+
this._mappings = [];
|
|
413
|
+
this.file = file;
|
|
414
|
+
this.sourceRoot = sourceRoot;
|
|
415
|
+
this._ignoreList = new SetArray();
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
function cast2(map) {
|
|
419
|
+
return map;
|
|
420
|
+
}
|
|
421
|
+
function addSegment(map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|
422
|
+
return addSegmentInternal(
|
|
423
|
+
false,
|
|
424
|
+
map,
|
|
425
|
+
genLine,
|
|
426
|
+
genColumn,
|
|
427
|
+
source,
|
|
428
|
+
sourceLine,
|
|
429
|
+
sourceColumn,
|
|
430
|
+
name,
|
|
431
|
+
content
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
function toDecodedMap(map) {
|
|
435
|
+
const {
|
|
436
|
+
_mappings: mappings,
|
|
437
|
+
_sources: sources,
|
|
438
|
+
_sourcesContent: sourcesContent,
|
|
439
|
+
_names: names,
|
|
440
|
+
_ignoreList: ignoreList
|
|
441
|
+
// _originalScopes: originalScopes,
|
|
442
|
+
// _generatedRanges: generatedRanges,
|
|
443
|
+
} = cast2(map);
|
|
444
|
+
removeEmptyFinalLines(mappings);
|
|
445
|
+
return {
|
|
446
|
+
version: 3,
|
|
447
|
+
file: map.file || void 0,
|
|
448
|
+
names: names.array,
|
|
449
|
+
sourceRoot: map.sourceRoot || void 0,
|
|
450
|
+
sources: sources.array,
|
|
451
|
+
sourcesContent,
|
|
452
|
+
mappings,
|
|
453
|
+
// originalScopes,
|
|
454
|
+
// generatedRanges,
|
|
455
|
+
ignoreList: ignoreList.array
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function toEncodedMap(map) {
|
|
459
|
+
const decoded = toDecodedMap(map);
|
|
460
|
+
return Object.assign({}, decoded, {
|
|
461
|
+
// originalScopes: decoded.originalScopes.map((os) => encodeOriginalScopes(os)),
|
|
462
|
+
// generatedRanges: encodeGeneratedRanges(decoded.generatedRanges as GeneratedRange[]),
|
|
463
|
+
mappings: encode(decoded.mappings)
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|
467
|
+
const {
|
|
468
|
+
_mappings: mappings,
|
|
469
|
+
_sources: sources,
|
|
470
|
+
_sourcesContent: sourcesContent,
|
|
471
|
+
_names: names
|
|
472
|
+
// _originalScopes: originalScopes,
|
|
473
|
+
} = cast2(map);
|
|
474
|
+
const line = getIndex(mappings, genLine);
|
|
475
|
+
const index = getColumnIndex(line, genColumn);
|
|
476
|
+
if (!source) {
|
|
477
|
+
if (skipable && skipSourceless(line, index)) return;
|
|
478
|
+
return insert(line, index, [genColumn]);
|
|
479
|
+
}
|
|
480
|
+
assert(sourceLine);
|
|
481
|
+
assert(sourceColumn);
|
|
482
|
+
const sourcesIndex = put(sources, source);
|
|
483
|
+
const namesIndex = name ? put(names, name) : NO_NAME;
|
|
484
|
+
if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
|
|
485
|
+
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
return insert(
|
|
489
|
+
line,
|
|
490
|
+
index,
|
|
491
|
+
name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
function assert(_val) {
|
|
495
|
+
}
|
|
496
|
+
function getIndex(arr, index) {
|
|
497
|
+
for (let i = arr.length; i <= index; i++) {
|
|
498
|
+
arr[i] = [];
|
|
499
|
+
}
|
|
500
|
+
return arr[index];
|
|
501
|
+
}
|
|
502
|
+
function getColumnIndex(line, genColumn) {
|
|
503
|
+
let index = line.length;
|
|
504
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
505
|
+
const current = line[i];
|
|
506
|
+
if (genColumn >= current[COLUMN]) break;
|
|
507
|
+
}
|
|
508
|
+
return index;
|
|
509
|
+
}
|
|
510
|
+
function insert(array, index, value) {
|
|
511
|
+
for (let i = array.length; i > index; i--) {
|
|
512
|
+
array[i] = array[i - 1];
|
|
513
|
+
}
|
|
514
|
+
array[index] = value;
|
|
515
|
+
}
|
|
516
|
+
function removeEmptyFinalLines(mappings) {
|
|
517
|
+
const { length } = mappings;
|
|
518
|
+
let len = length;
|
|
519
|
+
for (let i = len - 1; i >= 0; len = i, i--) {
|
|
520
|
+
if (mappings[i].length > 0) break;
|
|
521
|
+
}
|
|
522
|
+
if (len < length) mappings.length = len;
|
|
523
|
+
}
|
|
524
|
+
function skipSourceless(line, index) {
|
|
525
|
+
if (index === 0) return true;
|
|
526
|
+
const prev = line[index - 1];
|
|
527
|
+
return prev.length === 1;
|
|
528
|
+
}
|
|
529
|
+
function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
|
|
530
|
+
if (index === 0) return false;
|
|
531
|
+
const prev = line[index - 1];
|
|
532
|
+
if (prev.length === 1) return false;
|
|
533
|
+
return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// ../instrumentation/src/exact-transform-map.ts
|
|
537
|
+
import { originalPositionFor, TraceMap as TraceMap2 } from "@jridgewell/trace-mapping";
|
|
538
|
+
var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
539
|
+
var decodeInlineSourceMap = (url) => {
|
|
540
|
+
const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
|
|
541
|
+
if (base64?.[1]) {
|
|
542
|
+
try {
|
|
543
|
+
return Buffer.from(base64[1], "base64").toString("utf8");
|
|
544
|
+
} catch {
|
|
545
|
+
return void 0;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
|
|
549
|
+
if (!raw?.[1]) return void 0;
|
|
550
|
+
try {
|
|
551
|
+
return decodeURIComponent(raw[1]);
|
|
552
|
+
} catch {
|
|
553
|
+
return void 0;
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
var upstreamTraceMap = (original) => {
|
|
557
|
+
const match = SOURCEMAP_COMMENT.exec(original);
|
|
558
|
+
const url = match?.[1] ?? match?.[2];
|
|
559
|
+
if (!url) return void 0;
|
|
560
|
+
const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
|
|
561
|
+
if (!payload) return void 0;
|
|
562
|
+
try {
|
|
563
|
+
return new TraceMap2(payload);
|
|
564
|
+
} catch {
|
|
565
|
+
return void 0;
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
var lineStartsOf = (text) => {
|
|
569
|
+
const starts = [0];
|
|
570
|
+
for (let index = 0; index < text.length; index++) {
|
|
571
|
+
if (text[index] === "\n") starts.push(index + 1);
|
|
572
|
+
}
|
|
573
|
+
return starts;
|
|
574
|
+
};
|
|
575
|
+
var positionAt = (starts, offset) => {
|
|
576
|
+
let low = 0;
|
|
577
|
+
let high = starts.length - 1;
|
|
578
|
+
while (low < high) {
|
|
579
|
+
const mid = low + high + 1 >> 1;
|
|
580
|
+
if ((starts[mid] ?? 0) <= offset) low = mid;
|
|
581
|
+
else high = mid - 1;
|
|
483
582
|
}
|
|
484
|
-
return
|
|
583
|
+
return { line: low, column: offset - (starts[low] ?? 0) };
|
|
485
584
|
};
|
|
486
|
-
var
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
585
|
+
var sortedEdits = (edits) => [...edits].sort(compareEdits);
|
|
586
|
+
var originalOffsetToGenerated = (originalOffset, edits) => {
|
|
587
|
+
let generated = originalOffset;
|
|
588
|
+
for (const edit of edits) {
|
|
589
|
+
const delta = edit.text.length - edit.deleteCount;
|
|
590
|
+
if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
|
|
591
|
+
else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
|
|
493
592
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
593
|
+
return generated;
|
|
594
|
+
};
|
|
595
|
+
var mappingOffsets = (original, edits) => {
|
|
596
|
+
const offsets = /* @__PURE__ */ new Set([0, original.length]);
|
|
597
|
+
for (const start of lineStartsOf(original)) offsets.add(start);
|
|
598
|
+
for (const edit of edits) {
|
|
599
|
+
offsets.add(edit.position);
|
|
600
|
+
offsets.add(edit.position + edit.deleteCount);
|
|
497
601
|
}
|
|
498
|
-
return
|
|
602
|
+
return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
|
|
499
603
|
};
|
|
500
|
-
var
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
604
|
+
var encodeColumnMappings = (original, generated, file, edits) => {
|
|
605
|
+
const upstream = upstreamTraceMap(original);
|
|
606
|
+
const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
|
|
607
|
+
if (sources.length === 0) sources.push(file);
|
|
608
|
+
const applied = sortedEdits(edits);
|
|
609
|
+
const originalStarts = lineStartsOf(original);
|
|
610
|
+
const generatedStarts = lineStartsOf(generated);
|
|
611
|
+
const map = new GenMapping({ file });
|
|
612
|
+
const seen = /* @__PURE__ */ new Set();
|
|
613
|
+
for (const originalOffset of mappingOffsets(original, edits)) {
|
|
614
|
+
const generatedOffset = Math.min(
|
|
615
|
+
originalOffsetToGenerated(originalOffset, applied),
|
|
616
|
+
generated.length
|
|
617
|
+
);
|
|
618
|
+
const originalPosition = positionAt(originalStarts, originalOffset);
|
|
619
|
+
const generatedPosition = positionAt(generatedStarts, generatedOffset);
|
|
620
|
+
let source = sources[0] ?? file;
|
|
621
|
+
let mappedLine = originalPosition.line;
|
|
622
|
+
let mappedColumn = originalPosition.column;
|
|
623
|
+
if (upstream) {
|
|
624
|
+
const mapped = originalPositionFor(upstream, {
|
|
625
|
+
line: originalPosition.line + 1,
|
|
626
|
+
column: originalPosition.column
|
|
627
|
+
});
|
|
628
|
+
if (mapped.source && mapped.line != null && mapped.column != null) {
|
|
629
|
+
source = mapped.source;
|
|
630
|
+
mappedLine = mapped.line - 1;
|
|
631
|
+
mappedColumn = mapped.column;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const key = `${generatedPosition.line}:${generatedPosition.column}`;
|
|
635
|
+
if (seen.has(key)) continue;
|
|
636
|
+
seen.add(key);
|
|
637
|
+
addSegment(
|
|
638
|
+
map,
|
|
639
|
+
generatedPosition.line,
|
|
640
|
+
generatedPosition.column,
|
|
641
|
+
source,
|
|
642
|
+
mappedLine,
|
|
643
|
+
mappedColumn
|
|
644
|
+
);
|
|
505
645
|
}
|
|
506
|
-
|
|
646
|
+
const encoded = toEncodedMap(map);
|
|
647
|
+
return {
|
|
648
|
+
sources: encoded.sources.filter((source) => Boolean(source)),
|
|
649
|
+
mappings: encoded.mappings
|
|
650
|
+
};
|
|
651
|
+
};
|
|
652
|
+
var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) => {
|
|
653
|
+
const file = basenameOf(filePath);
|
|
654
|
+
const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
|
|
655
|
+
const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
|
|
656
|
+
const comment = `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
|
|
657
|
+
JSON.stringify({ version: 3, file, sources, mappings })
|
|
658
|
+
).toString("base64")} */`;
|
|
659
|
+
return withoutUpstream.endsWith("\n") ? `${withoutUpstream.slice(0, -1)}${comment}
|
|
660
|
+
` : `${withoutUpstream}${comment}`;
|
|
507
661
|
};
|
|
508
662
|
|
|
509
|
-
// src/
|
|
510
|
-
import
|
|
511
|
-
|
|
663
|
+
// ../instrumentation/src/browser-function-edits.ts
|
|
664
|
+
import { propertyNameIsSensitive } from "@rasputin-ai/core";
|
|
665
|
+
import ts10 from "typescript";
|
|
666
|
+
|
|
667
|
+
// ../instrumentation/src/suspension-whitelist.ts
|
|
668
|
+
import ts5 from "typescript";
|
|
669
|
+
var nodeFlags = ts5.NodeFlags;
|
|
512
670
|
var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
|
|
513
671
|
var USING_FLAG = nodeFlags.Using ?? 0;
|
|
514
672
|
var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
@@ -518,8 +676,8 @@ var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
|
518
676
|
"YieldKeyword",
|
|
519
677
|
"UsingKeyword"
|
|
520
678
|
];
|
|
521
|
-
var isFunctionLike = (node) =>
|
|
522
|
-
var isAsyncFunctionLike = (node) => (
|
|
679
|
+
var isFunctionLike = (node) => ts5.isFunctionLike(node);
|
|
680
|
+
var isAsyncFunctionLike = (node) => (ts5.getCombinedModifierFlags(node) & ts5.ModifierFlags.Async) !== 0;
|
|
523
681
|
var isAsyncGeneratorLike = (node) => isFunctionLike(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
|
|
524
682
|
var isSyncGeneratorLike = (node) => isFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken) && !isAsyncFunctionLike(node);
|
|
525
683
|
var visitOwnBody = (node, visitNode) => {
|
|
@@ -530,7 +688,7 @@ var visitOwnBody = (node, visitNode) => {
|
|
|
530
688
|
return;
|
|
531
689
|
}
|
|
532
690
|
if (visitNode(candidate)) return;
|
|
533
|
-
|
|
691
|
+
ts5.forEachChild(candidate, visit);
|
|
534
692
|
};
|
|
535
693
|
visit(node.body);
|
|
536
694
|
};
|
|
@@ -558,16 +716,16 @@ var slicesOutside = (start, end, spans) => {
|
|
|
558
716
|
};
|
|
559
717
|
var sliceHasAwaitKeyword = (source, start, end) => {
|
|
560
718
|
if (end <= start) return false;
|
|
561
|
-
const scanner =
|
|
562
|
-
|
|
719
|
+
const scanner = ts5.createScanner(
|
|
720
|
+
ts5.ScriptTarget.Latest,
|
|
563
721
|
true,
|
|
564
|
-
|
|
722
|
+
ts5.LanguageVariant.Standard,
|
|
565
723
|
source.slice(start, end)
|
|
566
724
|
);
|
|
567
725
|
while (true) {
|
|
568
726
|
const token = scanner.scan();
|
|
569
|
-
if (token ===
|
|
570
|
-
if (token ===
|
|
727
|
+
if (token === ts5.SyntaxKind.EndOfFileToken) return false;
|
|
728
|
+
if (token === ts5.SyntaxKind.AwaitKeyword) return true;
|
|
571
729
|
}
|
|
572
730
|
};
|
|
573
731
|
var ownBodyHasAwaitKeyword = (node, sourceFile) => {
|
|
@@ -585,7 +743,7 @@ var isAwaitUsingList = (node) => {
|
|
|
585
743
|
return (node.flags & AWAIT_USING_FLAG) === AWAIT_USING_FLAG && (node.flags & USING_FLAG) !== 0;
|
|
586
744
|
};
|
|
587
745
|
var unknownSuspensionKind = (node) => {
|
|
588
|
-
const name =
|
|
746
|
+
const name = ts5.SyntaxKind[node.kind];
|
|
589
747
|
if (typeof name !== "string" || !/Await|Yield|Using/.test(name)) return false;
|
|
590
748
|
return !KNOWN_SUSPENSION_KIND_NAMES.includes(name);
|
|
591
749
|
};
|
|
@@ -598,9 +756,9 @@ var ownSuspensionFacts = (node, sourceFile) => {
|
|
|
598
756
|
awaitKeyword: ownBodyHasAwaitKeyword(node, sourceFile)
|
|
599
757
|
};
|
|
600
758
|
visitOwnBody(node, (candidate) => {
|
|
601
|
-
if (
|
|
602
|
-
if (
|
|
603
|
-
if (
|
|
759
|
+
if (ts5.isAwaitExpression(candidate)) facts.awaitExpressions = true;
|
|
760
|
+
if (ts5.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
|
|
761
|
+
if (ts5.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
|
|
604
762
|
facts.awaitUsing = true;
|
|
605
763
|
}
|
|
606
764
|
if (unknownSuspensionKind(candidate)) facts.unknown = true;
|
|
@@ -611,7 +769,7 @@ var ownSuspensionFacts = (node, sourceFile) => {
|
|
|
611
769
|
var bodyHasDirectEval = (node) => {
|
|
612
770
|
let found = false;
|
|
613
771
|
visitOwnBody(node, (candidate) => {
|
|
614
|
-
if (
|
|
772
|
+
if (ts5.isCallExpression(candidate) && ts5.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
|
|
615
773
|
found = true;
|
|
616
774
|
}
|
|
617
775
|
return found;
|
|
@@ -633,25 +791,61 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
|
633
791
|
return { action: "inline" };
|
|
634
792
|
};
|
|
635
793
|
|
|
636
|
-
// src/
|
|
637
|
-
import
|
|
794
|
+
// ../instrumentation/src/transform-source.ts
|
|
795
|
+
import { basename, resolve } from "node:path";
|
|
796
|
+
import ts9 from "typescript";
|
|
797
|
+
|
|
798
|
+
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
799
|
+
import ts6 from "typescript";
|
|
800
|
+
var unwrap = (expression) => {
|
|
801
|
+
let current = expression;
|
|
802
|
+
while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
|
|
803
|
+
current = current.expression;
|
|
804
|
+
}
|
|
805
|
+
return current;
|
|
806
|
+
};
|
|
807
|
+
var isSafeLiteralInitializer = (expression) => {
|
|
808
|
+
const current = unwrap(expression);
|
|
809
|
+
if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
if (ts6.isIdentifier(current) && current.text === "undefined") return true;
|
|
816
|
+
if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
|
|
817
|
+
return ts6.isNumericLiteral(unwrap(current.operand));
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
};
|
|
821
|
+
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
822
|
+
for (const parameter of node.parameters) {
|
|
823
|
+
if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
824
|
+
if (!parameter.initializer) continue;
|
|
825
|
+
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
826
|
+
}
|
|
827
|
+
return false;
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
831
|
+
import ts7 from "typescript";
|
|
638
832
|
var RASPUTIN_IDENT = /^__rasputin/;
|
|
639
833
|
var scriptKindFor = (filePath) => {
|
|
640
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
641
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
642
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
643
|
-
return
|
|
834
|
+
if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
|
|
835
|
+
if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
|
|
836
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
|
|
837
|
+
return ts7.ScriptKind.JS;
|
|
644
838
|
};
|
|
645
|
-
var parse = (filePath, source) =>
|
|
839
|
+
var parse = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
646
840
|
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
647
841
|
var identText = (node) => {
|
|
648
|
-
if (
|
|
649
|
-
if (
|
|
842
|
+
if (ts7.isIdentifier(node)) return node.text;
|
|
843
|
+
if (ts7.isPrivateIdentifier(node)) return node.text;
|
|
650
844
|
return void 0;
|
|
651
845
|
};
|
|
652
846
|
var calleeName = (expression) => {
|
|
653
|
-
if (
|
|
654
|
-
if (
|
|
847
|
+
if (ts7.isIdentifier(expression)) return expression.text;
|
|
848
|
+
if (ts7.isPropertyAccessExpression(expression)) {
|
|
655
849
|
const object = identText(expression.expression);
|
|
656
850
|
const property = identText(expression.name);
|
|
657
851
|
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
@@ -659,7 +853,7 @@ var calleeName = (expression) => {
|
|
|
659
853
|
return void 0;
|
|
660
854
|
};
|
|
661
855
|
var isRasputinCall = (node, methods) => {
|
|
662
|
-
if (!
|
|
856
|
+
if (!ts7.isCallExpression(node)) return false;
|
|
663
857
|
const name = calleeName(node.expression);
|
|
664
858
|
if (!name) return false;
|
|
665
859
|
if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
|
|
@@ -669,20 +863,20 @@ var unwrapCall = (node) => {
|
|
|
669
863
|
let current = node;
|
|
670
864
|
while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
|
|
671
865
|
current = current.arguments[0];
|
|
672
|
-
if (
|
|
866
|
+
if (ts7.isParenthesizedExpression(current)) current = current.expression;
|
|
673
867
|
}
|
|
674
|
-
if (
|
|
868
|
+
if (ts7.isParenthesizedExpression(current)) return current.expression;
|
|
675
869
|
return current;
|
|
676
870
|
};
|
|
677
871
|
var isRasputinStatement = (node) => {
|
|
678
|
-
if (
|
|
679
|
-
if (
|
|
872
|
+
if (ts7.isEmptyStatement(node)) return true;
|
|
873
|
+
if (ts7.isVariableStatement(node)) {
|
|
680
874
|
return node.declarationList.declarations.every((declaration) => {
|
|
681
875
|
const name = identText(declaration.name);
|
|
682
876
|
return Boolean(name && isRasputinName(name));
|
|
683
877
|
});
|
|
684
878
|
}
|
|
685
|
-
if (
|
|
879
|
+
if (ts7.isExpressionStatement(node)) {
|
|
686
880
|
if (!isRasputinCall(node.expression)) return false;
|
|
687
881
|
const unwrapped = unwrapCall(node.expression);
|
|
688
882
|
return unwrapped === node.expression;
|
|
@@ -696,7 +890,7 @@ var isRasputinTryWrapper = (node) => {
|
|
|
696
890
|
(statement) => !isRasputinStatement(statement)
|
|
697
891
|
);
|
|
698
892
|
const leftover = catchCalls[0];
|
|
699
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
893
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
|
|
700
894
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
701
895
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
702
896
|
};
|
|
@@ -704,7 +898,7 @@ var flattenStatements = (statements) => {
|
|
|
704
898
|
const flattened = [];
|
|
705
899
|
for (const statement of statements) {
|
|
706
900
|
if (isRasputinStatement(statement)) continue;
|
|
707
|
-
if (
|
|
901
|
+
if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
708
902
|
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
709
903
|
continue;
|
|
710
904
|
}
|
|
@@ -713,38 +907,38 @@ var flattenStatements = (statements) => {
|
|
|
713
907
|
return flattened;
|
|
714
908
|
};
|
|
715
909
|
var extra = (node) => {
|
|
716
|
-
if (
|
|
910
|
+
if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
|
|
717
911
|
return isRasputinName(node.text) ? "" : node.text;
|
|
718
912
|
}
|
|
719
|
-
if (
|
|
913
|
+
if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
|
|
720
914
|
return node.text;
|
|
721
915
|
}
|
|
722
|
-
if (
|
|
916
|
+
if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
|
|
723
917
|
return "";
|
|
724
918
|
};
|
|
725
919
|
var signatureOf = (node) => {
|
|
726
920
|
const unwrapped = unwrapCall(node);
|
|
727
921
|
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
728
|
-
if (
|
|
729
|
-
if (
|
|
922
|
+
if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
923
|
+
if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
730
924
|
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
731
925
|
}
|
|
732
|
-
if (
|
|
926
|
+
if (ts7.isBlock(unwrapped)) {
|
|
733
927
|
const statements = flattenStatements(unwrapped.statements);
|
|
734
928
|
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
735
929
|
}
|
|
736
|
-
if (
|
|
930
|
+
if (ts7.isCatchClause(unwrapped)) {
|
|
737
931
|
const statements = flattenStatements(unwrapped.block.statements);
|
|
738
932
|
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
739
933
|
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
740
934
|
}
|
|
741
|
-
if (
|
|
935
|
+
if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
|
|
742
936
|
const statements = flattenStatements(unwrapped.body.statements);
|
|
743
937
|
const only = statements[0];
|
|
744
|
-
if (statements.length === 1 && only &&
|
|
938
|
+
if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
|
|
745
939
|
const expression = only.expression;
|
|
746
940
|
const parts2 = [];
|
|
747
|
-
|
|
941
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
748
942
|
if (child === unwrapped.body) {
|
|
749
943
|
const part2 = signatureOf(expression);
|
|
750
944
|
if (part2) parts2.push(part2);
|
|
@@ -757,11 +951,11 @@ var signatureOf = (node) => {
|
|
|
757
951
|
}
|
|
758
952
|
}
|
|
759
953
|
const parts = [];
|
|
760
|
-
|
|
954
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
761
955
|
const part = signatureOf(child);
|
|
762
956
|
if (part) parts.push(part);
|
|
763
957
|
});
|
|
764
|
-
const kind =
|
|
958
|
+
const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
765
959
|
const label = extra(unwrapped);
|
|
766
960
|
return `${kind}${label}[${parts.join(",")}]`;
|
|
767
961
|
};
|
|
@@ -769,15 +963,15 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
|
|
|
769
963
|
return signatureOf(parse(filePath, original)) === signatureOf(parse(filePath, transformed));
|
|
770
964
|
};
|
|
771
965
|
|
|
772
|
-
// src/
|
|
773
|
-
import
|
|
774
|
-
var transpileForVerification = (filePath, code) =>
|
|
966
|
+
// ../instrumentation/src/verify-transformed-source.ts
|
|
967
|
+
import ts8 from "typescript";
|
|
968
|
+
var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
775
969
|
compilerOptions: {
|
|
776
970
|
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
777
|
-
target:
|
|
778
|
-
module:
|
|
971
|
+
target: ts8.ScriptTarget.ES2020,
|
|
972
|
+
module: ts8.ModuleKind.ESNext,
|
|
779
973
|
allowJs: true,
|
|
780
|
-
jsx:
|
|
974
|
+
jsx: ts8.JsxEmit.React,
|
|
781
975
|
experimentalDecorators: true
|
|
782
976
|
},
|
|
783
977
|
reportDiagnostics: true,
|
|
@@ -785,7 +979,7 @@ var transpileForVerification = (filePath, code) => ts5.transpileModule(code, {
|
|
|
785
979
|
});
|
|
786
980
|
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
787
981
|
diagnostics?.some(
|
|
788
|
-
(diagnostic) => diagnostic.category ===
|
|
982
|
+
(diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
789
983
|
)
|
|
790
984
|
);
|
|
791
985
|
var scriptBodyForEngine = (emitted) => (
|
|
@@ -794,39 +988,39 @@ var scriptBodyForEngine = (emitted) => (
|
|
|
794
988
|
);
|
|
795
989
|
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
796
990
|
var scriptKindFor2 = (filePath) => {
|
|
797
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
798
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
799
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
800
|
-
return
|
|
991
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
992
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
993
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
994
|
+
return ts8.ScriptKind.JS;
|
|
801
995
|
};
|
|
802
|
-
var isIterationStatement = (node) =>
|
|
996
|
+
var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
|
|
803
997
|
var unwrapLabeled = (node) => {
|
|
804
998
|
let current = node;
|
|
805
|
-
while (
|
|
999
|
+
while (ts8.isLabeledStatement(current)) current = current.statement;
|
|
806
1000
|
return current;
|
|
807
1001
|
};
|
|
808
1002
|
var hasInvalidLabelJump = (sourceFile) => {
|
|
809
1003
|
const visit = (node, labels) => {
|
|
810
|
-
if (
|
|
1004
|
+
if (ts8.isFunctionLike(node)) {
|
|
811
1005
|
let nestedInvalid = false;
|
|
812
|
-
|
|
1006
|
+
ts8.forEachChild(node, (child) => {
|
|
813
1007
|
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
814
1008
|
});
|
|
815
1009
|
return nestedInvalid;
|
|
816
1010
|
}
|
|
817
|
-
if (
|
|
1011
|
+
if (ts8.isLabeledStatement(node)) {
|
|
818
1012
|
const next = new Map(labels);
|
|
819
1013
|
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
820
1014
|
return visit(node.statement, next);
|
|
821
1015
|
}
|
|
822
|
-
if (
|
|
1016
|
+
if (ts8.isContinueStatement(node) && node.label) {
|
|
823
1017
|
if (labels.get(node.label.text) !== true) return true;
|
|
824
1018
|
}
|
|
825
|
-
if (
|
|
1019
|
+
if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
826
1020
|
return true;
|
|
827
1021
|
}
|
|
828
1022
|
let invalid = false;
|
|
829
|
-
|
|
1023
|
+
ts8.forEachChild(node, (child) => {
|
|
830
1024
|
if (visit(child, labels)) invalid = true;
|
|
831
1025
|
});
|
|
832
1026
|
return invalid;
|
|
@@ -869,10 +1063,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
|
869
1063
|
var transformedSourceIsInvalid = (filePath, code) => {
|
|
870
1064
|
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
871
1065
|
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
872
|
-
const sourceFile =
|
|
1066
|
+
const sourceFile = ts8.createSourceFile(
|
|
873
1067
|
filePath,
|
|
874
1068
|
code,
|
|
875
|
-
|
|
1069
|
+
ts8.ScriptTarget.Latest,
|
|
876
1070
|
true,
|
|
877
1071
|
scriptKindFor2(filePath)
|
|
878
1072
|
);
|
|
@@ -884,16 +1078,7 @@ var transformedSourceIsInvalid = (filePath, code) => {
|
|
|
884
1078
|
return !engineAccepts(scriptBodyForEngine(outputText));
|
|
885
1079
|
};
|
|
886
1080
|
|
|
887
|
-
// src/
|
|
888
|
-
var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
889
|
-
var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
890
|
-
var separateFromPreviousToken = (source, position, text) => {
|
|
891
|
-
if (position <= 0 || text.length === 0) return text;
|
|
892
|
-
if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
|
|
893
|
-
return ` ${text}`;
|
|
894
|
-
}
|
|
895
|
-
return text;
|
|
896
|
-
};
|
|
1081
|
+
// ../instrumentation/src/transform-source.ts
|
|
897
1082
|
var RASPUTIN_INSTRUMENTATION_MARKER = "rasputin.instrumented.v3";
|
|
898
1083
|
var RASPUTIN_INSTRUMENTATION_PREAMBLE = `/*${RASPUTIN_INSTRUMENTATION_MARKER}*/`;
|
|
899
1084
|
var sourceIsRasputinInstrumented = (source) => source.includes(RASPUTIN_INSTRUMENTATION_PREAMBLE);
|
|
@@ -902,25 +1087,25 @@ var alreadyInstrumentedResult = (source) => ({
|
|
|
902
1087
|
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
903
1088
|
});
|
|
904
1089
|
var scriptKindFor3 = (filePath) => {
|
|
905
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
906
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
907
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
908
|
-
return
|
|
1090
|
+
if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
|
|
1091
|
+
if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
|
|
1092
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
|
|
1093
|
+
return ts9.ScriptKind.JS;
|
|
909
1094
|
};
|
|
910
1095
|
var functionName = (node, sourceFile) => {
|
|
911
|
-
if (
|
|
1096
|
+
if (ts9.isConstructorDeclaration(node)) return "constructor";
|
|
912
1097
|
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
913
1098
|
const parent = node.parent;
|
|
914
|
-
if (
|
|
915
|
-
if (
|
|
916
|
-
if (
|
|
1099
|
+
if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
|
|
1100
|
+
if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
1101
|
+
if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
917
1102
|
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
918
1103
|
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
919
1104
|
};
|
|
920
1105
|
var functionLocationPosition = (node, sourceFile) => {
|
|
921
1106
|
if (node.name) return node.name.getStart(sourceFile);
|
|
922
1107
|
const parent = node.parent;
|
|
923
|
-
if ((
|
|
1108
|
+
if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
|
|
924
1109
|
return parent.name.getStart(sourceFile);
|
|
925
1110
|
}
|
|
926
1111
|
return node.getStart(sourceFile);
|
|
@@ -933,12 +1118,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
|
933
1118
|
}
|
|
934
1119
|
return end;
|
|
935
1120
|
};
|
|
936
|
-
var isStaticPropertyName = (name) =>
|
|
1121
|
+
var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
|
|
937
1122
|
var canReconstructBinding = (name) => {
|
|
938
|
-
if (
|
|
939
|
-
if (
|
|
1123
|
+
if (ts9.isIdentifier(name)) return true;
|
|
1124
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
940
1125
|
return name.elements.every(
|
|
941
|
-
(element) =>
|
|
1126
|
+
(element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
942
1127
|
);
|
|
943
1128
|
}
|
|
944
1129
|
return name.elements.every((element) => {
|
|
@@ -947,10 +1132,10 @@ var canReconstructBinding = (name) => {
|
|
|
947
1132
|
});
|
|
948
1133
|
};
|
|
949
1134
|
var bindingValue = (name, sourceFile) => {
|
|
950
|
-
if (
|
|
951
|
-
if (
|
|
1135
|
+
if (ts9.isIdentifier(name)) return name.text;
|
|
1136
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
952
1137
|
const values = name.elements.map((element) => {
|
|
953
|
-
if (
|
|
1138
|
+
if (ts9.isOmittedExpression(element)) return "";
|
|
954
1139
|
const value = bindingValue(element.name, sourceFile);
|
|
955
1140
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
956
1141
|
});
|
|
@@ -960,7 +1145,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
960
1145
|
const value = bindingValue(element.name, sourceFile);
|
|
961
1146
|
if (element.dotDotDotToken) return `...${value}`;
|
|
962
1147
|
if (!element.propertyName) return value;
|
|
963
|
-
const key =
|
|
1148
|
+
const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
964
1149
|
return `${key}:${value}`;
|
|
965
1150
|
});
|
|
966
1151
|
return `{${properties.join(",")}}`;
|
|
@@ -968,7 +1153,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
968
1153
|
var arrowArgsCapture = (node) => {
|
|
969
1154
|
const sourceFile = node.getSourceFile();
|
|
970
1155
|
const params = node.parameters.filter(
|
|
971
|
-
(parameter) => !(
|
|
1156
|
+
(parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
972
1157
|
);
|
|
973
1158
|
if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
|
|
974
1159
|
return {
|
|
@@ -983,18 +1168,13 @@ var arrowArgsCapture = (node) => {
|
|
|
983
1168
|
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
984
1169
|
};
|
|
985
1170
|
var isSupportedFunction = (node) => {
|
|
986
|
-
if (!
|
|
1171
|
+
if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
|
|
987
1172
|
return false;
|
|
988
1173
|
}
|
|
989
1174
|
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
990
1175
|
return true;
|
|
991
1176
|
};
|
|
992
|
-
var
|
|
993
|
-
let name = base;
|
|
994
|
-
while (source.includes(name)) name += "_";
|
|
995
|
-
return name;
|
|
996
|
-
};
|
|
997
|
-
var isDirectivePrologue = (statement) => ts6.isExpressionStatement(statement) && ts6.isStringLiteral(statement.expression);
|
|
1177
|
+
var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
|
|
998
1178
|
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
999
1179
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
1000
1180
|
let end = shebangEnd;
|
|
@@ -1025,194 +1205,27 @@ var collectWrappedFunction = (node, sourceFile, absolutePath, mapLocation) => {
|
|
|
1025
1205
|
filePath: start.filePath,
|
|
1026
1206
|
name,
|
|
1027
1207
|
line: start.line,
|
|
1028
|
-
column: start.column
|
|
1029
|
-
});
|
|
1030
|
-
return {
|
|
1031
|
-
plan,
|
|
1032
|
-
functionId: plan[0],
|
|
1033
|
-
filePath: start.filePath,
|
|
1034
|
-
name,
|
|
1035
|
-
startLine: start.line,
|
|
1036
|
-
startColumn: start.column,
|
|
1037
|
-
endLine: end.line,
|
|
1038
|
-
endColumn: end.column,
|
|
1039
|
-
params,
|
|
1040
|
-
paramNames,
|
|
1041
|
-
instrumented: true
|
|
1042
|
-
};
|
|
1043
|
-
};
|
|
1044
|
-
var wrap = (edits, start, end, open, close, depth) => {
|
|
1045
|
-
const width = Math.max(0, end - start);
|
|
1046
|
-
edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
|
|
1047
|
-
edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
|
|
1048
|
-
};
|
|
1049
|
-
var compareEdits = (left, right) => {
|
|
1050
|
-
if (left.position !== right.position) return right.position - left.position;
|
|
1051
|
-
if (left.kind !== right.kind) {
|
|
1052
|
-
const rank = { replace: 0, close: 1, open: 2 };
|
|
1053
|
-
return rank[left.kind] - rank[right.kind];
|
|
1054
|
-
}
|
|
1055
|
-
if (left.kind === "close") {
|
|
1056
|
-
if (left.width !== right.width) return right.width - left.width;
|
|
1057
|
-
return left.depth - right.depth;
|
|
1058
|
-
}
|
|
1059
|
-
if (left.kind === "open") {
|
|
1060
|
-
if (left.width !== right.width) return left.width - right.width;
|
|
1061
|
-
return right.depth - left.depth;
|
|
1062
|
-
}
|
|
1063
|
-
return 0;
|
|
1064
|
-
};
|
|
1065
|
-
var VLQ_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1066
|
-
var encodeVlq = (value) => {
|
|
1067
|
-
let vlq = value < 0 ? -value << 1 | 1 : value << 1;
|
|
1068
|
-
let encoded = "";
|
|
1069
|
-
do {
|
|
1070
|
-
let digit = vlq & 31;
|
|
1071
|
-
vlq >>>= 5;
|
|
1072
|
-
if (vlq > 0) digit |= 32;
|
|
1073
|
-
encoded += VLQ_ALPHABET[digit];
|
|
1074
|
-
} while (vlq > 0);
|
|
1075
|
-
return encoded;
|
|
1076
|
-
};
|
|
1077
|
-
var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
1078
|
-
var decodeInlineSourceMap = (url) => {
|
|
1079
|
-
const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
|
|
1080
|
-
if (base64?.[1]) {
|
|
1081
|
-
try {
|
|
1082
|
-
return Buffer.from(base64[1], "base64").toString("utf8");
|
|
1083
|
-
} catch {
|
|
1084
|
-
return void 0;
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
|
|
1088
|
-
if (!raw?.[1]) return void 0;
|
|
1089
|
-
try {
|
|
1090
|
-
return decodeURIComponent(raw[1]);
|
|
1091
|
-
} catch {
|
|
1092
|
-
return void 0;
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
|
-
var upstreamTraceMap = (original) => {
|
|
1096
|
-
const match = SOURCEMAP_COMMENT.exec(original);
|
|
1097
|
-
const url = match?.[1] ?? match?.[2];
|
|
1098
|
-
if (!url) return void 0;
|
|
1099
|
-
const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
|
|
1100
|
-
if (!payload) return void 0;
|
|
1101
|
-
try {
|
|
1102
|
-
return new TraceMap2(payload);
|
|
1103
|
-
} catch {
|
|
1104
|
-
return void 0;
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
var lineStartsOf = (text) => {
|
|
1108
|
-
const starts = [0];
|
|
1109
|
-
for (let index = 0; index < text.length; index++) {
|
|
1110
|
-
if (text[index] === "\n") starts.push(index + 1);
|
|
1111
|
-
}
|
|
1112
|
-
return starts;
|
|
1113
|
-
};
|
|
1114
|
-
var positionAt = (starts, offset) => {
|
|
1115
|
-
let low = 0;
|
|
1116
|
-
let high = starts.length - 1;
|
|
1117
|
-
while (low < high) {
|
|
1118
|
-
const mid = low + high + 1 >> 1;
|
|
1119
|
-
if ((starts[mid] ?? 0) <= offset) low = mid;
|
|
1120
|
-
else high = mid - 1;
|
|
1121
|
-
}
|
|
1122
|
-
return { line: low, column: offset - (starts[low] ?? 0) };
|
|
1123
|
-
};
|
|
1124
|
-
var sortedEdits = (edits) => [...edits].sort(compareEdits);
|
|
1125
|
-
var originalOffsetToGenerated = (originalOffset, edits) => {
|
|
1126
|
-
let generated = originalOffset;
|
|
1127
|
-
for (const edit of edits) {
|
|
1128
|
-
const delta = edit.text.length - edit.deleteCount;
|
|
1129
|
-
if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
|
|
1130
|
-
else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
|
|
1131
|
-
}
|
|
1132
|
-
return generated;
|
|
1133
|
-
};
|
|
1134
|
-
var mappingOffsets = (original, edits) => {
|
|
1135
|
-
const offsets = /* @__PURE__ */ new Set([0, original.length]);
|
|
1136
|
-
for (const start of lineStartsOf(original)) offsets.add(start);
|
|
1137
|
-
for (const edit of edits) {
|
|
1138
|
-
offsets.add(edit.position);
|
|
1139
|
-
offsets.add(edit.position + edit.deleteCount);
|
|
1140
|
-
}
|
|
1141
|
-
return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
|
|
1142
|
-
};
|
|
1143
|
-
var encodeColumnMappings = (original, generated, file, edits) => {
|
|
1144
|
-
const upstream = upstreamTraceMap(original);
|
|
1145
|
-
const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
|
|
1146
|
-
if (sources.length === 0) sources.push(file);
|
|
1147
|
-
const applied = sortedEdits(edits);
|
|
1148
|
-
const originalStarts = lineStartsOf(original);
|
|
1149
|
-
const generatedStarts = lineStartsOf(generated);
|
|
1150
|
-
const pointsByLine = Array.from({ length: generatedStarts.length }, () => []);
|
|
1151
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1152
|
-
for (const originalOffset of mappingOffsets(original, edits)) {
|
|
1153
|
-
const generatedOffset = Math.min(
|
|
1154
|
-
originalOffsetToGenerated(originalOffset, applied),
|
|
1155
|
-
generated.length
|
|
1156
|
-
);
|
|
1157
|
-
const originalPosition = positionAt(originalStarts, originalOffset);
|
|
1158
|
-
const generatedPosition = positionAt(generatedStarts, generatedOffset);
|
|
1159
|
-
let sourceIndex = 0;
|
|
1160
|
-
let mappedLine = originalPosition.line;
|
|
1161
|
-
let mappedColumn = originalPosition.column;
|
|
1162
|
-
if (upstream) {
|
|
1163
|
-
const mapped = originalPositionFor2(upstream, {
|
|
1164
|
-
line: originalPosition.line + 1,
|
|
1165
|
-
column: originalPosition.column
|
|
1166
|
-
});
|
|
1167
|
-
if (mapped.source && mapped.line != null && mapped.column != null) {
|
|
1168
|
-
const index = sources.indexOf(mapped.source);
|
|
1169
|
-
sourceIndex = index >= 0 ? index : 0;
|
|
1170
|
-
mappedLine = mapped.line - 1;
|
|
1171
|
-
mappedColumn = mapped.column;
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
const key = `${generatedPosition.line}:${generatedPosition.column}`;
|
|
1175
|
-
if (seen.has(key)) continue;
|
|
1176
|
-
seen.add(key);
|
|
1177
|
-
pointsByLine[generatedPosition.line]?.push({
|
|
1178
|
-
generatedColumn: generatedPosition.column,
|
|
1179
|
-
sourceIndex,
|
|
1180
|
-
originalLine: mappedLine,
|
|
1181
|
-
originalColumn: mappedColumn
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
const lines = pointsByLine.map((segments) => {
|
|
1185
|
-
segments.sort((left, right) => left.generatedColumn - right.generatedColumn);
|
|
1186
|
-
let lastGeneratedColumn = 0;
|
|
1187
|
-
let lastSourceIndex = 0;
|
|
1188
|
-
let lastOriginalLine = 0;
|
|
1189
|
-
let lastOriginalColumn = 0;
|
|
1190
|
-
return segments.map((point) => {
|
|
1191
|
-
const encoded = `${encodeVlq(point.generatedColumn - lastGeneratedColumn)}${encodeVlq(point.sourceIndex - lastSourceIndex)}${encodeVlq(point.originalLine - lastOriginalLine)}${encodeVlq(point.originalColumn - lastOriginalColumn)}`;
|
|
1192
|
-
lastGeneratedColumn = point.generatedColumn;
|
|
1193
|
-
lastSourceIndex = point.sourceIndex;
|
|
1194
|
-
lastOriginalLine = point.originalLine;
|
|
1195
|
-
lastOriginalColumn = point.originalColumn;
|
|
1196
|
-
return encoded;
|
|
1197
|
-
}).join(",");
|
|
1208
|
+
column: start.column
|
|
1198
1209
|
});
|
|
1199
|
-
return {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
+
return {
|
|
1211
|
+
plan,
|
|
1212
|
+
functionId: plan[0],
|
|
1213
|
+
filePath: start.filePath,
|
|
1214
|
+
name,
|
|
1215
|
+
startLine: start.line,
|
|
1216
|
+
startColumn: start.column,
|
|
1217
|
+
endLine: end.line,
|
|
1218
|
+
endColumn: end.column,
|
|
1219
|
+
params,
|
|
1220
|
+
paramNames,
|
|
1221
|
+
instrumented: true
|
|
1222
|
+
};
|
|
1210
1223
|
};
|
|
1211
1224
|
var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
1212
1225
|
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
1213
1226
|
for (const statement of body.statements) {
|
|
1214
1227
|
if (isDirectivePrologue(statement)) continue;
|
|
1215
|
-
if (
|
|
1228
|
+
if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
|
|
1216
1229
|
return statement.end;
|
|
1217
1230
|
}
|
|
1218
1231
|
break;
|
|
@@ -1223,15 +1236,15 @@ var failEpilogue = (handleName, errorName, args2, restoreOnCatch) => `}catch(${e
|
|
|
1223
1236
|
var walkOwnBody = (node, visitNode) => {
|
|
1224
1237
|
if (!node.body) return;
|
|
1225
1238
|
const visit = (candidate) => {
|
|
1226
|
-
if (candidate !== node &&
|
|
1239
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1227
1240
|
visitNode(candidate);
|
|
1228
|
-
|
|
1241
|
+
ts9.forEachChild(candidate, visit);
|
|
1229
1242
|
};
|
|
1230
1243
|
visit(node.body);
|
|
1231
1244
|
};
|
|
1232
1245
|
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1233
1246
|
walkOwnBody(node, (candidate) => {
|
|
1234
|
-
if (!
|
|
1247
|
+
if (!ts9.isAwaitExpression(candidate)) return;
|
|
1235
1248
|
wrap(
|
|
1236
1249
|
edits,
|
|
1237
1250
|
candidate.expression.getStart(sourceFile),
|
|
@@ -1252,7 +1265,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1252
1265
|
};
|
|
1253
1266
|
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
1254
1267
|
walkOwnBody(node, (candidate) => {
|
|
1255
|
-
if (!
|
|
1268
|
+
if (!ts9.isTryStatement(candidate)) return;
|
|
1256
1269
|
const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
|
|
1257
1270
|
for (const block of blocks) {
|
|
1258
1271
|
if (!block) continue;
|
|
@@ -1268,10 +1281,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
|
|
|
1268
1281
|
});
|
|
1269
1282
|
};
|
|
1270
1283
|
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1271
|
-
if (!node.body || !
|
|
1284
|
+
if (!node.body || !ts9.isBlock(node.body)) return;
|
|
1272
1285
|
const visit = (candidate, at) => {
|
|
1273
|
-
if (candidate !== node &&
|
|
1274
|
-
if (
|
|
1286
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1287
|
+
if (ts9.isReturnStatement(candidate) && candidate.expression) {
|
|
1275
1288
|
const expression = candidate.expression;
|
|
1276
1289
|
wrap(
|
|
1277
1290
|
edits,
|
|
@@ -1283,17 +1296,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1283
1296
|
);
|
|
1284
1297
|
return;
|
|
1285
1298
|
}
|
|
1286
|
-
|
|
1299
|
+
ts9.forEachChild(candidate, (child) => visit(child, at + 1));
|
|
1287
1300
|
};
|
|
1288
1301
|
visit(node.body, depth + 1);
|
|
1289
1302
|
};
|
|
1290
1303
|
var transformSource = (source, options) => {
|
|
1291
1304
|
if (source.includes("@rasputin-ignore-file")) return void 0;
|
|
1292
1305
|
if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
|
|
1293
|
-
const sourceFile =
|
|
1306
|
+
const sourceFile = ts9.createSourceFile(
|
|
1294
1307
|
options.filePath,
|
|
1295
1308
|
source,
|
|
1296
|
-
|
|
1309
|
+
ts9.ScriptTarget.Latest,
|
|
1297
1310
|
true,
|
|
1298
1311
|
scriptKindFor3(options.filePath)
|
|
1299
1312
|
);
|
|
@@ -1301,7 +1314,7 @@ var transformSource = (source, options) => {
|
|
|
1301
1314
|
const plansName = uniqueName(source, "__rasputinPlans__");
|
|
1302
1315
|
const handleName = uniqueName(source, "__rasputinH__");
|
|
1303
1316
|
const errorName = uniqueName(source, "__rasputinE__");
|
|
1304
|
-
const absolutePath =
|
|
1317
|
+
const absolutePath = resolve(options.filePath);
|
|
1305
1318
|
const edits = [];
|
|
1306
1319
|
const delta = {
|
|
1307
1320
|
functions: [],
|
|
@@ -1336,7 +1349,7 @@ var transformSource = (source, options) => {
|
|
|
1336
1349
|
collected.asyncFunction = true;
|
|
1337
1350
|
skipFunction(collected, "unsupported_async_generator");
|
|
1338
1351
|
}
|
|
1339
|
-
|
|
1352
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1340
1353
|
return;
|
|
1341
1354
|
}
|
|
1342
1355
|
if (isSyncGeneratorLike(node) && node.body) {
|
|
@@ -1347,10 +1360,10 @@ var transformSource = (source, options) => {
|
|
|
1347
1360
|
options.mapLocation
|
|
1348
1361
|
);
|
|
1349
1362
|
if (collected) skipFunction(collected, "unsupported_sync_generator");
|
|
1350
|
-
|
|
1363
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1351
1364
|
return;
|
|
1352
1365
|
}
|
|
1353
|
-
if (
|
|
1366
|
+
if (ts9.isConstructorDeclaration(node) && node.body) {
|
|
1354
1367
|
const collected = collectWrappedFunction(
|
|
1355
1368
|
node,
|
|
1356
1369
|
sourceFile,
|
|
@@ -1358,13 +1371,13 @@ var transformSource = (source, options) => {
|
|
|
1358
1371
|
options.mapLocation
|
|
1359
1372
|
);
|
|
1360
1373
|
if (collected) skipFunction(collected, "unsupported_constructor");
|
|
1361
|
-
|
|
1374
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1362
1375
|
return;
|
|
1363
1376
|
}
|
|
1364
1377
|
if (isSupportedFunction(node)) {
|
|
1365
1378
|
const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
|
|
1366
1379
|
if (!collected) {
|
|
1367
|
-
|
|
1380
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1368
1381
|
return;
|
|
1369
1382
|
}
|
|
1370
1383
|
const asyncFunction = isAsyncFunctionLike(node);
|
|
@@ -1372,7 +1385,7 @@ var transformSource = (source, options) => {
|
|
|
1372
1385
|
const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
1373
1386
|
if (decision.action === "skip") {
|
|
1374
1387
|
skipFunction(collected, decision.reason);
|
|
1375
|
-
|
|
1388
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1376
1389
|
return;
|
|
1377
1390
|
}
|
|
1378
1391
|
if (functionHasPreBodyParameterEvaluation(node)) {
|
|
@@ -1385,29 +1398,29 @@ var transformSource = (source, options) => {
|
|
|
1385
1398
|
suspendResume: decision.action === "suspend_resume"
|
|
1386
1399
|
});
|
|
1387
1400
|
delta.functions.push(collected);
|
|
1388
|
-
|
|
1401
|
+
ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
|
|
1389
1402
|
return;
|
|
1390
1403
|
}
|
|
1391
|
-
if (caller && (
|
|
1404
|
+
if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
|
|
1392
1405
|
const site = collectCallSite(node, caller, collectContext);
|
|
1393
1406
|
if (site) delta.callSites.push(site);
|
|
1394
1407
|
}
|
|
1395
|
-
if (caller &&
|
|
1408
|
+
if (caller && ts9.isVariableDeclaration(node)) {
|
|
1396
1409
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
1397
1410
|
if (destructure) delta.destructures.push(destructure);
|
|
1398
1411
|
}
|
|
1399
|
-
|
|
1412
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1400
1413
|
};
|
|
1401
1414
|
visit(sourceFile, void 0, 0);
|
|
1402
1415
|
if (pending.length === 0) {
|
|
1403
1416
|
return delta.functions.length > 0 ? { code: source, delta } : void 0;
|
|
1404
1417
|
}
|
|
1405
1418
|
for (const [planIndex, entry] of pending.entries()) {
|
|
1406
|
-
const captured =
|
|
1419
|
+
const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
|
|
1407
1420
|
const omitArg = captured.omitValues ? ",true" : "";
|
|
1408
1421
|
const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
|
|
1409
1422
|
const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
|
|
1410
|
-
if (
|
|
1423
|
+
if (ts9.isBlock(entry.node.body)) {
|
|
1411
1424
|
const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
|
|
1412
1425
|
const closeAt = entry.node.body.end - 1;
|
|
1413
1426
|
wrap(
|
|
@@ -1461,12 +1474,7 @@ var transformSource = (source, options) => {
|
|
|
1461
1474
|
width: 0,
|
|
1462
1475
|
kind: "replace"
|
|
1463
1476
|
});
|
|
1464
|
-
edits
|
|
1465
|
-
let transformed = source;
|
|
1466
|
-
for (const edit of edits) {
|
|
1467
|
-
const text = separateFromPreviousToken(transformed, edit.position, edit.text);
|
|
1468
|
-
transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
|
|
1469
|
-
}
|
|
1477
|
+
const transformed = applyEdits(source, edits);
|
|
1470
1478
|
const verify = options.verifyTransform ?? true;
|
|
1471
1479
|
const refuseTransformed = () => {
|
|
1472
1480
|
for (const entry of pending) {
|
|
@@ -1494,7 +1502,263 @@ var transformSource = (source, options) => {
|
|
|
1494
1502
|
if (verify && !instrumentationTreesAreIsomorphic(options.filePath, source, transformed)) {
|
|
1495
1503
|
return refuseTransformed();
|
|
1496
1504
|
}
|
|
1497
|
-
return {
|
|
1505
|
+
return {
|
|
1506
|
+
code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
|
|
1507
|
+
delta
|
|
1508
|
+
};
|
|
1509
|
+
};
|
|
1510
|
+
|
|
1511
|
+
// ../instrumentation/src/json-producer-sites.ts
|
|
1512
|
+
import ts11 from "typescript";
|
|
1513
|
+
|
|
1514
|
+
// ../instrumentation/src/literal-sites.ts
|
|
1515
|
+
import ts12 from "typescript";
|
|
1516
|
+
|
|
1517
|
+
// ../instrumentation/src/observe-sites.ts
|
|
1518
|
+
import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
|
|
1519
|
+
import ts13 from "typescript";
|
|
1520
|
+
|
|
1521
|
+
// ../instrumentation/src/verify-browser-source.ts
|
|
1522
|
+
import ts14 from "typescript";
|
|
1523
|
+
|
|
1524
|
+
// ../instrumentation/src/provenance-function-edits.ts
|
|
1525
|
+
import ts15 from "typescript";
|
|
1526
|
+
|
|
1527
|
+
// ../instrumentation/src/source-map-location.ts
|
|
1528
|
+
import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
|
|
1529
|
+
|
|
1530
|
+
// src/auto-instrumentation/instrumentation-manifest-registry.ts
|
|
1531
|
+
import { createHash } from "node:crypto";
|
|
1532
|
+
import { resolve as resolve2 } from "node:path";
|
|
1533
|
+
import {
|
|
1534
|
+
INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
1535
|
+
sourceLocatorFromFile as sourceLocatorFromFile2
|
|
1536
|
+
} from "@rasputin-ai/core";
|
|
1537
|
+
var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
|
|
1538
|
+
var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
|
|
1539
|
+
var getRegistry = () => {
|
|
1540
|
+
const existing = Reflect.get(globalThis, registrySymbol);
|
|
1541
|
+
if (existing?.__rasputinManifestRegistry && existing.files instanceof Map && typeof existing.generation === "number" && typeof existing.uploadedGeneration === "number") {
|
|
1542
|
+
const registry2 = existing;
|
|
1543
|
+
if (typeof registry2.alreadyInstrumented !== "number") registry2.alreadyInstrumented = 0;
|
|
1544
|
+
return registry2;
|
|
1545
|
+
}
|
|
1546
|
+
const registry = {
|
|
1547
|
+
__rasputinManifestRegistry: true,
|
|
1548
|
+
files: /* @__PURE__ */ new Map(),
|
|
1549
|
+
generation: 0,
|
|
1550
|
+
uploadedGeneration: 0,
|
|
1551
|
+
alreadyInstrumented: 0
|
|
1552
|
+
};
|
|
1553
|
+
Reflect.set(globalThis, registrySymbol, registry);
|
|
1554
|
+
return registry;
|
|
1555
|
+
};
|
|
1556
|
+
var sourceAt = (filePath, line, column) => {
|
|
1557
|
+
const source = sourceLocatorFromFile2(filePath);
|
|
1558
|
+
return source ? { ...source, line, column } : void 0;
|
|
1559
|
+
};
|
|
1560
|
+
var stableId = (kind, ...parts) => `${kind}_${createHash("sha256").update(parts.join("\0")).digest("base64url").slice(0, 24)}`;
|
|
1561
|
+
var recordInstrumentationManifestDelta = (filePath, delta) => {
|
|
1562
|
+
const registry = getRegistry();
|
|
1563
|
+
if (delta.alreadyInstrumented) {
|
|
1564
|
+
registry.alreadyInstrumented += 1;
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
registry.files.set(resolve2(filePath), delta);
|
|
1568
|
+
registry.generation += 1;
|
|
1569
|
+
registry.onDirty?.();
|
|
1570
|
+
};
|
|
1571
|
+
var snapshotOptionsKey = (options) => JSON.stringify({
|
|
1572
|
+
sourceRoot: options.sourceRoot ?? "",
|
|
1573
|
+
sourceRoots: options.sourceRoots ?? {}
|
|
1574
|
+
});
|
|
1575
|
+
var snapshotInstrumentationManifest = (options = {}) => {
|
|
1576
|
+
const registry = getRegistry();
|
|
1577
|
+
const optionsKey = snapshotOptionsKey(options);
|
|
1578
|
+
if (registry.snapshotCache && registry.snapshotCache.generation === registry.generation && registry.snapshotCache.optionsKey === optionsKey) {
|
|
1579
|
+
return registry.snapshotCache.manifest;
|
|
1580
|
+
}
|
|
1581
|
+
const functions = [];
|
|
1582
|
+
const callSites = [];
|
|
1583
|
+
const destructures = [];
|
|
1584
|
+
const remember = (manifest) => {
|
|
1585
|
+
registry.snapshotCache = {
|
|
1586
|
+
generation: registry.generation,
|
|
1587
|
+
optionsKey,
|
|
1588
|
+
manifest
|
|
1589
|
+
};
|
|
1590
|
+
return manifest;
|
|
1591
|
+
};
|
|
1592
|
+
for (const delta of registry.files.values()) {
|
|
1593
|
+
for (const fn of delta.functions) {
|
|
1594
|
+
const definition = definitionFromEncodedPlan(fn.plan);
|
|
1595
|
+
if (!definition.source) continue;
|
|
1596
|
+
functions.push({
|
|
1597
|
+
functionId: definition.functionId,
|
|
1598
|
+
source: definition.source,
|
|
1599
|
+
name: fn.name,
|
|
1600
|
+
startLine: fn.startLine,
|
|
1601
|
+
startColumn: fn.startColumn,
|
|
1602
|
+
endLine: fn.endLine,
|
|
1603
|
+
endColumn: fn.endColumn,
|
|
1604
|
+
params: fn.params,
|
|
1605
|
+
...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
for (const site of delta.callSites) {
|
|
1609
|
+
const source = sourceAt(site.filePath, site.line, site.column);
|
|
1610
|
+
if (!source) continue;
|
|
1611
|
+
callSites.push({
|
|
1612
|
+
id: stableId(
|
|
1613
|
+
"cs",
|
|
1614
|
+
site.callerFunctionId,
|
|
1615
|
+
source.packageName ?? "",
|
|
1616
|
+
source.packageRelativePath,
|
|
1617
|
+
site.line,
|
|
1618
|
+
site.column
|
|
1619
|
+
),
|
|
1620
|
+
callerFunctionId: site.callerFunctionId,
|
|
1621
|
+
calleeName: site.calleeName,
|
|
1622
|
+
calleeText: site.calleeText,
|
|
1623
|
+
source,
|
|
1624
|
+
line: site.line,
|
|
1625
|
+
column: site.column,
|
|
1626
|
+
endLine: site.endLine,
|
|
1627
|
+
endColumn: site.endColumn,
|
|
1628
|
+
resultBinding: site.resultBinding,
|
|
1629
|
+
argIdentifiers: site.argIdentifiers
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
for (const destructure of delta.destructures) {
|
|
1633
|
+
const source = sourceAt(destructure.filePath, destructure.line, destructure.column);
|
|
1634
|
+
if (!source) continue;
|
|
1635
|
+
destructures.push({
|
|
1636
|
+
callerFunctionId: destructure.callerFunctionId,
|
|
1637
|
+
sourceParam: destructure.sourceParam,
|
|
1638
|
+
source,
|
|
1639
|
+
line: destructure.line,
|
|
1640
|
+
column: destructure.column,
|
|
1641
|
+
binding: destructure.binding
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
if (registry.prebuilt && registry.files.size === 0) {
|
|
1646
|
+
const prebuilt = registry.prebuilt;
|
|
1647
|
+
if (!options.sourceRoot && !options.sourceRoots) return remember(prebuilt);
|
|
1648
|
+
return remember({
|
|
1649
|
+
...prebuilt,
|
|
1650
|
+
sourceRoots: {
|
|
1651
|
+
...options.sourceRoot ? { default: options.sourceRoot } : {},
|
|
1652
|
+
packages: { ...options.sourceRoots ?? {} }
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
if (functions.length === 0 && callSites.length === 0 && destructures.length === 0) {
|
|
1657
|
+
return remember(void 0);
|
|
1658
|
+
}
|
|
1659
|
+
const packages = { ...options.sourceRoots ?? {} };
|
|
1660
|
+
return remember({
|
|
1661
|
+
schema_version: INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
1662
|
+
...options.sourceRoot || Object.keys(packages).length > 0 ? {
|
|
1663
|
+
sourceRoots: {
|
|
1664
|
+
...options.sourceRoot ? { default: options.sourceRoot } : {},
|
|
1665
|
+
packages
|
|
1666
|
+
}
|
|
1667
|
+
} : {},
|
|
1668
|
+
functions,
|
|
1669
|
+
callSites,
|
|
1670
|
+
destructures
|
|
1671
|
+
});
|
|
1672
|
+
};
|
|
1673
|
+
var resetInstrumentationManifestRegistry = () => {
|
|
1674
|
+
Reflect.deleteProperty(globalThis, registrySymbol);
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
// src/auto-instrumentation/source-classification.ts
|
|
1678
|
+
import { isAbsolute, relative, resolve as resolve3, sep } from "node:path";
|
|
1679
|
+
var sourceExtension = /\.[cm]?[jt]sx?$/i;
|
|
1680
|
+
var alwaysExcludedDirectory = /(^|[\\/])(node_modules|coverage|generated|\.git|\.next|\.svelte-kit|\.output|\.vercel|\.rasputin|\.turbo|\.yarn|\.pnpm|\.bun)([\\/]|$)/;
|
|
1681
|
+
var buildOutputDirectory = /(^|[\\/])(dist|build|out)([\\/]|$)/;
|
|
1682
|
+
var matches = (pattern, value) => {
|
|
1683
|
+
pattern.lastIndex = 0;
|
|
1684
|
+
const result2 = pattern.test(value);
|
|
1685
|
+
pattern.lastIndex = 0;
|
|
1686
|
+
return result2;
|
|
1687
|
+
};
|
|
1688
|
+
var isWithinRoot = (filePath, root) => {
|
|
1689
|
+
const fromRoot = relative(resolve3(root), filePath);
|
|
1690
|
+
return fromRoot === "" || !fromRoot.startsWith(`..${sep}`) && fromRoot !== ".." && !isAbsolute(fromRoot);
|
|
1691
|
+
};
|
|
1692
|
+
var isApplicationSource = (filePath, options = {}) => {
|
|
1693
|
+
const absolutePath = resolve3(filePath);
|
|
1694
|
+
if (!sourceExtension.test(absolutePath) || alwaysExcludedDirectory.test(absolutePath))
|
|
1695
|
+
return false;
|
|
1696
|
+
if (options.includeBuildOutput !== true && buildOutputDirectory.test(absolutePath)) return false;
|
|
1697
|
+
if (options.excludedRoots?.some((root) => isWithinRoot(absolutePath, root))) return false;
|
|
1698
|
+
if (options.exclude && matches(options.exclude, absolutePath)) return false;
|
|
1699
|
+
if (options.include && !matches(options.include, absolutePath)) return false;
|
|
1700
|
+
if (options.rootDir) {
|
|
1701
|
+
if (!isWithinRoot(absolutePath, options.rootDir)) return false;
|
|
1702
|
+
}
|
|
1703
|
+
return true;
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
// src/auto-instrumentation/source-map-locations.ts
|
|
1707
|
+
import { readFileSync } from "node:fs";
|
|
1708
|
+
import { dirname, isAbsolute as isAbsolute2, join, resolve as resolve4 } from "node:path";
|
|
1709
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1710
|
+
import { LEAST_UPPER_BOUND, originalPositionFor as originalPositionFor3, TraceMap as TraceMap4 } from "@jridgewell/trace-mapping";
|
|
1711
|
+
var sourceMapComment = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
1712
|
+
var decodeDataUrl = (url) => {
|
|
1713
|
+
const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
|
|
1714
|
+
if (base64?.[1]) return Buffer.from(base64[1], "base64").toString("utf8");
|
|
1715
|
+
const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
|
|
1716
|
+
return raw?.[1] ? decodeURIComponent(raw[1]) : void 0;
|
|
1717
|
+
};
|
|
1718
|
+
var sourceMapFor = (generatedPath, source) => {
|
|
1719
|
+
const match = sourceMapComment.exec(source);
|
|
1720
|
+
const reference = match?.[1] ?? match?.[2];
|
|
1721
|
+
if (reference?.startsWith("data:")) {
|
|
1722
|
+
const payload = decodeDataUrl(reference);
|
|
1723
|
+
return payload ? { payload, mapUrl: pathToFileURL(generatedPath).href } : void 0;
|
|
1724
|
+
}
|
|
1725
|
+
const mapPath = reference ? resolve4(dirname(generatedPath), reference) : `${generatedPath}.map`;
|
|
1726
|
+
return {
|
|
1727
|
+
payload: readFileSync(mapPath, "utf8"),
|
|
1728
|
+
mapUrl: pathToFileURL(mapPath).href
|
|
1729
|
+
};
|
|
1730
|
+
};
|
|
1731
|
+
var toFilePath = (source, generatedPath) => {
|
|
1732
|
+
if (source.startsWith("file:")) return fileURLToPath(source);
|
|
1733
|
+
return isAbsolute2(source) ? source : join(dirname(generatedPath), source);
|
|
1734
|
+
};
|
|
1735
|
+
var createSourceMapLocationMapper2 = (generatedPath, source) => {
|
|
1736
|
+
try {
|
|
1737
|
+
const sourceMap = sourceMapFor(generatedPath, source);
|
|
1738
|
+
if (!sourceMap) return void 0;
|
|
1739
|
+
const traceMap = new TraceMap4(sourceMap.payload, sourceMap.mapUrl);
|
|
1740
|
+
return (generated) => {
|
|
1741
|
+
let original = originalPositionFor3(traceMap, {
|
|
1742
|
+
line: generated.line,
|
|
1743
|
+
column: Math.max(0, generated.column - 1)
|
|
1744
|
+
});
|
|
1745
|
+
if (!original.source || original.line == null) {
|
|
1746
|
+
original = originalPositionFor3(traceMap, {
|
|
1747
|
+
line: generated.line,
|
|
1748
|
+
column: 0,
|
|
1749
|
+
bias: LEAST_UPPER_BOUND
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
if (!original.source || original.line == null) return void 0;
|
|
1753
|
+
return {
|
|
1754
|
+
filePath: toFilePath(original.source, generatedPath),
|
|
1755
|
+
line: original.line,
|
|
1756
|
+
column: (original.column ?? 0) + 1
|
|
1757
|
+
};
|
|
1758
|
+
};
|
|
1759
|
+
} catch {
|
|
1760
|
+
return void 0;
|
|
1761
|
+
}
|
|
1498
1762
|
};
|
|
1499
1763
|
|
|
1500
1764
|
// src/auto-instrumentation/instrument-compiled-esm.ts
|
|
@@ -1541,7 +1805,7 @@ var instrumentCompiledDirectory = (options) => {
|
|
|
1541
1805
|
}
|
|
1542
1806
|
const transformed = transformSource(source, {
|
|
1543
1807
|
filePath,
|
|
1544
|
-
mapLocation:
|
|
1808
|
+
mapLocation: createSourceMapLocationMapper2(filePath, source)
|
|
1545
1809
|
});
|
|
1546
1810
|
if (!transformed) continue;
|
|
1547
1811
|
const outputPath = join2(outputDir, relative2(inputDir, filePath));
|