@rasputin-ai/node 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-instrumentation/bun-plugin.d.ts.map +1 -1
- package/dist/auto-instrumentation/instrument-compiled-esm.d.ts.map +1 -1
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
- package/dist/auto-instrumentation/node-hooks.d.ts.map +1 -1
- package/dist/auto-instrumentation/transform-disk-cache.d.ts.map +1 -1
- package/dist/execution-recorder/bind-adaptive-recorder.d.ts +4 -2
- package/dist/execution-recorder/bind-adaptive-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-hooks.d.ts +3 -0
- package/dist/execution-recorder/execution-recorder-hooks.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-types.d.ts +1 -2
- 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/execution-recording-sync.d.ts +2 -2
- package/dist/execution-recorder/execution-recording-sync.d.ts.map +1 -1
- package/dist/execution-recorder/function-plan.d.ts +3 -1
- package/dist/execution-recorder/function-plan.d.ts.map +1 -1
- package/dist/function-metrics/bind-function-metrics.d.ts +19 -0
- package/dist/function-metrics/bind-function-metrics.d.ts.map +1 -0
- package/dist/function-metrics/create-metrics-only-runtime.d.ts +4 -0
- package/dist/function-metrics/create-metrics-only-runtime.d.ts.map +1 -0
- package/dist/function-metrics/encode-function-metrics-upload.d.ts +14 -0
- package/dist/function-metrics/encode-function-metrics-upload.d.ts.map +1 -0
- package/dist/function-metrics/function-metric-declaration-registry.d.ts +9 -0
- package/dist/function-metrics/function-metric-declaration-registry.d.ts.map +1 -0
- package/dist/function-metrics/function-metrics-batches.d.ts +35 -0
- package/dist/function-metrics/function-metrics-batches.d.ts.map +1 -0
- package/dist/function-metrics/function-metrics-collector.d.ts +45 -0
- package/dist/function-metrics/function-metrics-collector.d.ts.map +1 -0
- package/dist/function-metrics/function-metrics-exporter.d.ts +23 -0
- package/dist/function-metrics/function-metrics-exporter.d.ts.map +1 -0
- package/dist/function-metrics/install-function-metric-declaration-sink.d.ts +2 -0
- package/dist/function-metrics/install-function-metric-declaration-sink.d.ts.map +1 -0
- package/dist/function-metrics/intern-prepared-metrics.d.ts +4 -0
- package/dist/function-metrics/intern-prepared-metrics.d.ts.map +1 -0
- package/dist/function-metrics/send-function-metrics-batch.d.ts +25 -0
- package/dist/function-metrics/send-function-metrics-batch.d.ts.map +1 -0
- package/dist/function-metrics/settle-function-metrics.d.ts +5 -0
- package/dist/function-metrics/settle-function-metrics.d.ts.map +1 -0
- package/dist/index.js +1592 -121
- package/dist/instrument/build.js +450 -140
- package/dist/instrument/bun.js +454 -132
- package/dist/instrument/node.js +452 -132
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1568 -113
- package/dist/rasputin-init.d.ts +17 -4
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +2 -2
package/dist/instrument/build.js
CHANGED
|
@@ -662,9 +662,28 @@ var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) =
|
|
|
662
662
|
` : `${withoutUpstream}${comment}`;
|
|
663
663
|
};
|
|
664
664
|
|
|
665
|
+
// ../instrumentation/src/function-metric-declaration-registration.ts
|
|
666
|
+
var SOURCEMAP_COMMENT2 = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
667
|
+
var FUNCTION_METRIC_DECLARATION_REGISTER = "__rasputinRegisterFunctionMetricDeclarations";
|
|
668
|
+
var FUNCTION_METRIC_DECLARATION_PENDING = "__rasputinPendingFunctionMetricDeclarations";
|
|
669
|
+
var withFunctionMetricDeclarationRegistration = (code, declarations) => {
|
|
670
|
+
const parts = [];
|
|
671
|
+
if (declarations && declarations.length > 0) {
|
|
672
|
+
parts.push(
|
|
673
|
+
`((d)=>{const g=globalThis;const r=g.${FUNCTION_METRIC_DECLARATION_REGISTER};if(typeof r==="function")r(d);else (g.${FUNCTION_METRIC_DECLARATION_PENDING}??=[]).push(...d);})(${JSON.stringify(declarations)})`
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
if (parts.length === 0) return code;
|
|
677
|
+
const suffix = `;${parts.join(";")};
|
|
678
|
+
`;
|
|
679
|
+
const match = SOURCEMAP_COMMENT2.exec(code);
|
|
680
|
+
if (!match) return `${code}${suffix}`;
|
|
681
|
+
return `${code.slice(0, match.index)}${suffix}${code.slice(match.index)}`;
|
|
682
|
+
};
|
|
683
|
+
|
|
665
684
|
// ../instrumentation/src/browser-function-edits.ts
|
|
666
685
|
import { propertyNameIsSensitive } from "@rasputin-ai/core";
|
|
667
|
-
import
|
|
686
|
+
import ts10 from "typescript";
|
|
668
687
|
|
|
669
688
|
// ../instrumentation/src/suspension-whitelist.ts
|
|
670
689
|
import ts4 from "typescript";
|
|
@@ -795,34 +814,286 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
|
795
814
|
|
|
796
815
|
// ../instrumentation/src/transform-source.ts
|
|
797
816
|
import { basename, resolve } from "node:path";
|
|
798
|
-
import
|
|
817
|
+
import ts9 from "typescript";
|
|
799
818
|
|
|
800
|
-
// ../instrumentation/src/
|
|
819
|
+
// ../instrumentation/src/function-metric-declarations.ts
|
|
820
|
+
import {
|
|
821
|
+
canonicalizeFunctionIdentityPath,
|
|
822
|
+
FUNCTION_IDENTITY_VERSION,
|
|
823
|
+
functionIdentityKey,
|
|
824
|
+
sha256Hex,
|
|
825
|
+
sourceLocatorFromFile as sourceLocatorFromFile2
|
|
826
|
+
} from "@rasputin-ai/core";
|
|
801
827
|
import ts5 from "typescript";
|
|
828
|
+
var printer = ts5.createPrinter({ removeComments: true, newLine: ts5.NewLineKind.LineFeed });
|
|
829
|
+
var propertyText = (name) => {
|
|
830
|
+
if (!name) return void 0;
|
|
831
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
832
|
+
return name.text;
|
|
833
|
+
}
|
|
834
|
+
if (ts5.isNoSubstitutionTemplateLiteral(name)) return name.text;
|
|
835
|
+
return void 0;
|
|
836
|
+
};
|
|
837
|
+
var hasStaticModifier = (node) => {
|
|
838
|
+
if (!ts5.canHaveModifiers(node)) return false;
|
|
839
|
+
const modifiers = ts5.getModifiers(node);
|
|
840
|
+
if (!modifiers) return false;
|
|
841
|
+
return modifiers.some((modifier) => modifier.kind === ts5.SyntaxKind.StaticKeyword);
|
|
842
|
+
};
|
|
843
|
+
var memberIsStatic = (node) => {
|
|
844
|
+
if (hasStaticModifier(node)) return true;
|
|
845
|
+
const parent = node.parent;
|
|
846
|
+
const isPropertyValue = ts5.isArrowFunction(node) || ts5.isFunctionExpression(node);
|
|
847
|
+
if (!isPropertyValue || !ts5.isPropertyDeclaration(parent)) return false;
|
|
848
|
+
return hasStaticModifier(parent);
|
|
849
|
+
};
|
|
850
|
+
var kindOf = (node) => {
|
|
851
|
+
if (ts5.isConstructorDeclaration(node)) return "constructor";
|
|
852
|
+
if (ts5.isGetAccessor(node)) return "getter";
|
|
853
|
+
if (ts5.isSetAccessor(node)) return "setter";
|
|
854
|
+
if (ts5.isMethodDeclaration(node)) return "method";
|
|
855
|
+
if (ts5.isArrowFunction(node)) return "arrow";
|
|
856
|
+
return "function";
|
|
857
|
+
};
|
|
858
|
+
var bindingOf = (node) => {
|
|
859
|
+
if (ts5.isConstructorDeclaration(node)) return "constructor";
|
|
860
|
+
const ownName = propertyText(node.name);
|
|
861
|
+
if (ownName) return ownName;
|
|
862
|
+
const parent = node.parent;
|
|
863
|
+
if (ts5.isVariableDeclaration(parent) && ts5.isIdentifier(parent.name)) {
|
|
864
|
+
return parent.name.text;
|
|
865
|
+
}
|
|
866
|
+
if (ts5.isPropertyAssignment(parent) || ts5.isPropertyDeclaration(parent)) {
|
|
867
|
+
return propertyText(parent.name);
|
|
868
|
+
}
|
|
869
|
+
return void 0;
|
|
870
|
+
};
|
|
871
|
+
var calleeText = (expression) => {
|
|
872
|
+
if (ts5.isIdentifier(expression)) return expression.text;
|
|
873
|
+
if (!ts5.isPropertyAccessExpression(expression) || !ts5.isIdentifier(expression.name)) {
|
|
874
|
+
return void 0;
|
|
875
|
+
}
|
|
876
|
+
const object = calleeText(expression.expression);
|
|
877
|
+
if (!object) return void 0;
|
|
878
|
+
return `${object}.${expression.name.text}`;
|
|
879
|
+
};
|
|
880
|
+
var soleCallbackCallee = (node) => {
|
|
881
|
+
const parent = node.parent;
|
|
882
|
+
if (ts5.isCallExpression(parent)) {
|
|
883
|
+
if (parent.arguments.length !== 1 || parent.arguments[0] !== node) return void 0;
|
|
884
|
+
return parent.expression;
|
|
885
|
+
}
|
|
886
|
+
if (!ts5.isNewExpression(parent) || !parent.arguments) return void 0;
|
|
887
|
+
if (parent.arguments.length !== 1 || parent.arguments[0] !== node) return void 0;
|
|
888
|
+
return parent.expression;
|
|
889
|
+
};
|
|
890
|
+
var withScope = (scopes, kind, name) => {
|
|
891
|
+
if (!name) return scopes;
|
|
892
|
+
return [...scopes, { kind, name }];
|
|
893
|
+
};
|
|
894
|
+
var fingerprintOf = (node, sourceFile) => {
|
|
895
|
+
const printed = printer.printNode(ts5.EmitHint.Unspecified, node, sourceFile);
|
|
896
|
+
const normalized = printed.replace(/\s+/g, "");
|
|
897
|
+
return `fp1_${sha256Hex(normalized)}`;
|
|
898
|
+
};
|
|
899
|
+
var sourceRange = (node, sourceFile, filePath, mapLocation) => {
|
|
900
|
+
const start = mappedLocation(sourceFile, node.getStart(sourceFile), filePath, mapLocation);
|
|
901
|
+
const end = mappedLocation(sourceFile, node.end, filePath, mapLocation);
|
|
902
|
+
if (!start || !end) return null;
|
|
903
|
+
return {
|
|
904
|
+
start_line: start.line,
|
|
905
|
+
start_column: start.column,
|
|
906
|
+
end_line: end.line,
|
|
907
|
+
end_column: end.column
|
|
908
|
+
};
|
|
909
|
+
};
|
|
910
|
+
var isFunctionNode = (node) => {
|
|
911
|
+
const isFunction = ts5.isFunctionDeclaration(node) || ts5.isFunctionExpression(node) || ts5.isArrowFunction(node) || ts5.isMethodDeclaration(node) || ts5.isGetAccessor(node) || ts5.isSetAccessor(node) || ts5.isConstructorDeclaration(node);
|
|
912
|
+
return isFunction && Boolean(node.body);
|
|
913
|
+
};
|
|
914
|
+
var anchoredName = (candidate, anchorCount) => {
|
|
915
|
+
if (candidate.binding || !candidate.anchor) return void 0;
|
|
916
|
+
if (anchorCount.get(candidate.anchor) !== 1) return void 0;
|
|
917
|
+
const binding = candidate.anchor.split(".").at(-1) ?? candidate.anchor;
|
|
918
|
+
return {
|
|
919
|
+
binding,
|
|
920
|
+
scopes: withScope(candidate.scopes, "property", candidate.anchor)
|
|
921
|
+
};
|
|
922
|
+
};
|
|
923
|
+
var stableDescriptor = (candidate, packagePath, packageName, anchorCount) => {
|
|
924
|
+
const anchored = anchoredName(candidate, anchorCount);
|
|
925
|
+
const binding = candidate.binding ?? anchored?.binding;
|
|
926
|
+
const scopes = anchored?.scopes ?? candidate.scopes;
|
|
927
|
+
if (candidate.ancestorAmbiguous || !binding || !packagePath || !packageName) return void 0;
|
|
928
|
+
return {
|
|
929
|
+
identity_version: FUNCTION_IDENTITY_VERSION,
|
|
930
|
+
identity_kind: "stable",
|
|
931
|
+
source_basis: "package",
|
|
932
|
+
package_name: packageName,
|
|
933
|
+
path: packagePath,
|
|
934
|
+
scopes,
|
|
935
|
+
declaration_kind: candidate.kind,
|
|
936
|
+
binding_name: binding,
|
|
937
|
+
is_static: candidate.isStatic
|
|
938
|
+
};
|
|
939
|
+
};
|
|
940
|
+
var walkCandidates = (sourceFile, runtimeIdByNode) => {
|
|
941
|
+
const candidates = [];
|
|
942
|
+
const visit = (node, scopes, ancestorAmbiguous, parent) => {
|
|
943
|
+
if (isFunctionNode(node)) {
|
|
944
|
+
const binding = bindingOf(node);
|
|
945
|
+
const index = candidates.length;
|
|
946
|
+
const callee = binding ? void 0 : soleCallbackCallee(node);
|
|
947
|
+
candidates.push({
|
|
948
|
+
node,
|
|
949
|
+
scopes,
|
|
950
|
+
ancestorAmbiguous,
|
|
951
|
+
binding,
|
|
952
|
+
kind: kindOf(node),
|
|
953
|
+
isStatic: memberIsStatic(node),
|
|
954
|
+
anchor: callee ? calleeText(callee) : void 0,
|
|
955
|
+
parent,
|
|
956
|
+
runtimeId: runtimeIdByNode.get(node)
|
|
957
|
+
});
|
|
958
|
+
const nextScopes = binding && !ancestorAmbiguous ? withScope(scopes, "function", binding) : scopes;
|
|
959
|
+
const childAmbiguous = ancestorAmbiguous || !binding;
|
|
960
|
+
ts5.forEachChild(node, (child) => visit(child, nextScopes, childAmbiguous, index));
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
if ((ts5.isClassDeclaration(node) || ts5.isClassExpression(node)) && node.name) {
|
|
964
|
+
const next = withScope(scopes, "class", node.name.text);
|
|
965
|
+
ts5.forEachChild(node, (child) => visit(child, next, ancestorAmbiguous, parent));
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
if (ts5.isModuleDeclaration(node) && ts5.isIdentifier(node.name)) {
|
|
969
|
+
const next = withScope(scopes, "namespace", node.name.text);
|
|
970
|
+
ts5.forEachChild(node, (child) => visit(child, next, ancestorAmbiguous, parent));
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
if (ts5.isVariableDeclaration(node) && ts5.isIdentifier(node.name) && node.initializer && ts5.isObjectLiteralExpression(node.initializer)) {
|
|
974
|
+
visit(
|
|
975
|
+
node.initializer,
|
|
976
|
+
withScope(scopes, "object", node.name.text),
|
|
977
|
+
ancestorAmbiguous,
|
|
978
|
+
parent
|
|
979
|
+
);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
if (ts5.isPropertyAssignment(node) && node.initializer && ts5.isObjectLiteralExpression(node.initializer)) {
|
|
983
|
+
const name = propertyText(node.name);
|
|
984
|
+
visit(node.initializer, withScope(scopes, "property", name), ancestorAmbiguous, parent);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
ts5.forEachChild(node, (child) => visit(child, scopes, ancestorAmbiguous, parent));
|
|
988
|
+
};
|
|
989
|
+
visit(sourceFile, [], false, void 0);
|
|
990
|
+
return candidates;
|
|
991
|
+
};
|
|
992
|
+
var blockDescendants = (candidates, blocked, index) => {
|
|
993
|
+
if (blocked.has(index)) return;
|
|
994
|
+
blocked.add(index);
|
|
995
|
+
for (let child = 0; child < candidates.length; child += 1) {
|
|
996
|
+
const candidate = candidates[child];
|
|
997
|
+
if (candidate?.parent === index) blockDescendants(candidates, blocked, child);
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
var releaseScopedDescriptor = (runtimeId) => ({
|
|
1001
|
+
identity_version: FUNCTION_IDENTITY_VERSION,
|
|
1002
|
+
identity_kind: "release_scoped",
|
|
1003
|
+
declaration_id: runtimeId
|
|
1004
|
+
});
|
|
1005
|
+
var collectFunctionMetricDeclarations = (input) => {
|
|
1006
|
+
const runtimeIdByNode = new Map(input.functions.map((item) => [item.node, item.runtimeId]));
|
|
1007
|
+
const candidates = walkCandidates(input.sourceFile, runtimeIdByNode);
|
|
1008
|
+
const anchorCount = /* @__PURE__ */ new Map();
|
|
1009
|
+
for (const candidate of candidates) {
|
|
1010
|
+
if (!candidate.anchor) continue;
|
|
1011
|
+
anchorCount.set(candidate.anchor, (anchorCount.get(candidate.anchor) ?? 0) + 1);
|
|
1012
|
+
}
|
|
1013
|
+
const locator = input.originalAst ? sourceLocatorFromFile2(input.filePath) : void 0;
|
|
1014
|
+
const packageName = locator?.packageName;
|
|
1015
|
+
const packagePath = locator && packageName ? canonicalizeFunctionIdentityPath(locator.packageRelativePath) : void 0;
|
|
1016
|
+
const rows = candidates.map((candidate) => ({
|
|
1017
|
+
candidate,
|
|
1018
|
+
descriptor: stableDescriptor(candidate, packagePath, packageName, anchorCount)
|
|
1019
|
+
}));
|
|
1020
|
+
const keyCount = /* @__PURE__ */ new Map();
|
|
1021
|
+
for (const row of rows) {
|
|
1022
|
+
if (!row.descriptor) continue;
|
|
1023
|
+
const key = functionIdentityKey(row.descriptor);
|
|
1024
|
+
keyCount.set(key, (keyCount.get(key) ?? 0) + 1);
|
|
1025
|
+
}
|
|
1026
|
+
const blocked = /* @__PURE__ */ new Set();
|
|
1027
|
+
for (const [index, row] of rows.entries()) {
|
|
1028
|
+
if (!row.descriptor) {
|
|
1029
|
+
blockDescendants(candidates, blocked, index);
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
const key = functionIdentityKey(row.descriptor);
|
|
1033
|
+
if ((keyCount.get(key) ?? 0) > 1) blockDescendants(candidates, blocked, index);
|
|
1034
|
+
}
|
|
1035
|
+
const declarations = [];
|
|
1036
|
+
for (const [index, row] of rows.entries()) {
|
|
1037
|
+
const runtimeId = row.candidate.runtimeId;
|
|
1038
|
+
if (!runtimeId) continue;
|
|
1039
|
+
const range = sourceRange(
|
|
1040
|
+
row.candidate.node,
|
|
1041
|
+
input.sourceFile,
|
|
1042
|
+
input.filePath,
|
|
1043
|
+
input.mapLocation
|
|
1044
|
+
);
|
|
1045
|
+
const fingerprint = input.originalAst ? fingerprintOf(row.candidate.node, input.sourceFile) : null;
|
|
1046
|
+
const stable = blocked.has(index) ? void 0 : row.descriptor;
|
|
1047
|
+
if (stable) {
|
|
1048
|
+
declarations.push({
|
|
1049
|
+
runtime_id: runtimeId,
|
|
1050
|
+
logical_key: functionIdentityKey(stable),
|
|
1051
|
+
identity_kind: "stable",
|
|
1052
|
+
descriptor: stable,
|
|
1053
|
+
source_range: range,
|
|
1054
|
+
implementation_fingerprint: fingerprint
|
|
1055
|
+
});
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
const descriptor = releaseScopedDescriptor(runtimeId);
|
|
1059
|
+
declarations.push({
|
|
1060
|
+
runtime_id: runtimeId,
|
|
1061
|
+
logical_key: functionIdentityKey(descriptor),
|
|
1062
|
+
identity_kind: "release_scoped",
|
|
1063
|
+
descriptor,
|
|
1064
|
+
source_range: range,
|
|
1065
|
+
implementation_fingerprint: fingerprint
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
return declarations;
|
|
1069
|
+
};
|
|
1070
|
+
|
|
1071
|
+
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
1072
|
+
import ts6 from "typescript";
|
|
802
1073
|
var unwrap = (expression) => {
|
|
803
1074
|
let current = expression;
|
|
804
|
-
while (
|
|
1075
|
+
while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
|
|
805
1076
|
current = current.expression;
|
|
806
1077
|
}
|
|
807
1078
|
return current;
|
|
808
1079
|
};
|
|
809
1080
|
var isSafeLiteralInitializer = (expression) => {
|
|
810
1081
|
const current = unwrap(expression);
|
|
811
|
-
if (
|
|
1082
|
+
if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
|
|
812
1083
|
return true;
|
|
813
1084
|
}
|
|
814
|
-
if (current.kind ===
|
|
1085
|
+
if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
|
|
815
1086
|
return true;
|
|
816
1087
|
}
|
|
817
|
-
if (
|
|
818
|
-
if (
|
|
819
|
-
return
|
|
1088
|
+
if (ts6.isIdentifier(current) && current.text === "undefined") return true;
|
|
1089
|
+
if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
|
|
1090
|
+
return ts6.isNumericLiteral(unwrap(current.operand));
|
|
820
1091
|
}
|
|
821
1092
|
return false;
|
|
822
1093
|
};
|
|
823
1094
|
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
824
1095
|
for (const parameter of node.parameters) {
|
|
825
|
-
if (
|
|
1096
|
+
if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
826
1097
|
if (!parameter.initializer) continue;
|
|
827
1098
|
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
828
1099
|
}
|
|
@@ -830,24 +1101,24 @@ var functionHasPreBodyParameterEvaluation = (node) => {
|
|
|
830
1101
|
};
|
|
831
1102
|
|
|
832
1103
|
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
833
|
-
import
|
|
1104
|
+
import ts7 from "typescript";
|
|
834
1105
|
var RASPUTIN_IDENT = /^__rasputin/;
|
|
835
1106
|
var scriptKindFor = (filePath) => {
|
|
836
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
837
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
838
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
839
|
-
return
|
|
1107
|
+
if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
|
|
1108
|
+
if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
|
|
1109
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
|
|
1110
|
+
return ts7.ScriptKind.JS;
|
|
840
1111
|
};
|
|
841
|
-
var parse = (filePath, source) =>
|
|
1112
|
+
var parse = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
842
1113
|
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
843
1114
|
var identText = (node) => {
|
|
844
|
-
if (
|
|
845
|
-
if (
|
|
1115
|
+
if (ts7.isIdentifier(node)) return node.text;
|
|
1116
|
+
if (ts7.isPrivateIdentifier(node)) return node.text;
|
|
846
1117
|
return void 0;
|
|
847
1118
|
};
|
|
848
1119
|
var calleeName = (expression) => {
|
|
849
|
-
if (
|
|
850
|
-
if (
|
|
1120
|
+
if (ts7.isIdentifier(expression)) return expression.text;
|
|
1121
|
+
if (ts7.isPropertyAccessExpression(expression)) {
|
|
851
1122
|
const object = identText(expression.expression);
|
|
852
1123
|
const property = identText(expression.name);
|
|
853
1124
|
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
@@ -855,7 +1126,7 @@ var calleeName = (expression) => {
|
|
|
855
1126
|
return void 0;
|
|
856
1127
|
};
|
|
857
1128
|
var isRasputinCall = (node, methods) => {
|
|
858
|
-
if (!
|
|
1129
|
+
if (!ts7.isCallExpression(node)) return false;
|
|
859
1130
|
const name = calleeName(node.expression);
|
|
860
1131
|
if (!name) return false;
|
|
861
1132
|
if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
|
|
@@ -865,20 +1136,20 @@ var unwrapCall = (node) => {
|
|
|
865
1136
|
let current = node;
|
|
866
1137
|
while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
|
|
867
1138
|
current = current.arguments[0];
|
|
868
|
-
if (
|
|
1139
|
+
if (ts7.isParenthesizedExpression(current)) current = current.expression;
|
|
869
1140
|
}
|
|
870
|
-
if (
|
|
1141
|
+
if (ts7.isParenthesizedExpression(current)) return current.expression;
|
|
871
1142
|
return current;
|
|
872
1143
|
};
|
|
873
1144
|
var isRasputinStatement = (node) => {
|
|
874
|
-
if (
|
|
875
|
-
if (
|
|
1145
|
+
if (ts7.isEmptyStatement(node)) return true;
|
|
1146
|
+
if (ts7.isVariableStatement(node)) {
|
|
876
1147
|
return node.declarationList.declarations.every((declaration) => {
|
|
877
1148
|
const name = identText(declaration.name);
|
|
878
1149
|
return Boolean(name && isRasputinName(name));
|
|
879
1150
|
});
|
|
880
1151
|
}
|
|
881
|
-
if (
|
|
1152
|
+
if (ts7.isExpressionStatement(node)) {
|
|
882
1153
|
if (!isRasputinCall(node.expression)) return false;
|
|
883
1154
|
const unwrapped = unwrapCall(node.expression);
|
|
884
1155
|
return unwrapped === node.expression;
|
|
@@ -892,7 +1163,7 @@ var isRasputinTryWrapper = (node) => {
|
|
|
892
1163
|
(statement) => !isRasputinStatement(statement)
|
|
893
1164
|
);
|
|
894
1165
|
const leftover = catchCalls[0];
|
|
895
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
1166
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
|
|
896
1167
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
897
1168
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
898
1169
|
};
|
|
@@ -900,7 +1171,7 @@ var flattenStatements = (statements) => {
|
|
|
900
1171
|
const flattened = [];
|
|
901
1172
|
for (const statement of statements) {
|
|
902
1173
|
if (isRasputinStatement(statement)) continue;
|
|
903
|
-
if (
|
|
1174
|
+
if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
904
1175
|
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
905
1176
|
continue;
|
|
906
1177
|
}
|
|
@@ -909,38 +1180,38 @@ var flattenStatements = (statements) => {
|
|
|
909
1180
|
return flattened;
|
|
910
1181
|
};
|
|
911
1182
|
var extra = (node) => {
|
|
912
|
-
if (
|
|
1183
|
+
if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
|
|
913
1184
|
return isRasputinName(node.text) ? "" : node.text;
|
|
914
1185
|
}
|
|
915
|
-
if (
|
|
1186
|
+
if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
|
|
916
1187
|
return node.text;
|
|
917
1188
|
}
|
|
918
|
-
if (
|
|
1189
|
+
if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
|
|
919
1190
|
return "";
|
|
920
1191
|
};
|
|
921
1192
|
var signatureOf = (node) => {
|
|
922
1193
|
const unwrapped = unwrapCall(node);
|
|
923
1194
|
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
924
|
-
if (
|
|
925
|
-
if (
|
|
1195
|
+
if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
1196
|
+
if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
926
1197
|
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
927
1198
|
}
|
|
928
|
-
if (
|
|
1199
|
+
if (ts7.isBlock(unwrapped)) {
|
|
929
1200
|
const statements = flattenStatements(unwrapped.statements);
|
|
930
1201
|
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
931
1202
|
}
|
|
932
|
-
if (
|
|
1203
|
+
if (ts7.isCatchClause(unwrapped)) {
|
|
933
1204
|
const statements = flattenStatements(unwrapped.block.statements);
|
|
934
1205
|
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
935
1206
|
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
936
1207
|
}
|
|
937
|
-
if (
|
|
1208
|
+
if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
|
|
938
1209
|
const statements = flattenStatements(unwrapped.body.statements);
|
|
939
1210
|
const only = statements[0];
|
|
940
|
-
if (statements.length === 1 && only &&
|
|
1211
|
+
if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
|
|
941
1212
|
const expression = only.expression;
|
|
942
1213
|
const parts2 = [];
|
|
943
|
-
|
|
1214
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
944
1215
|
if (child === unwrapped.body) {
|
|
945
1216
|
const part2 = signatureOf(expression);
|
|
946
1217
|
if (part2) parts2.push(part2);
|
|
@@ -953,11 +1224,11 @@ var signatureOf = (node) => {
|
|
|
953
1224
|
}
|
|
954
1225
|
}
|
|
955
1226
|
const parts = [];
|
|
956
|
-
|
|
1227
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
957
1228
|
const part = signatureOf(child);
|
|
958
1229
|
if (part) parts.push(part);
|
|
959
1230
|
});
|
|
960
|
-
const kind =
|
|
1231
|
+
const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
961
1232
|
const label = extra(unwrapped);
|
|
962
1233
|
return `${kind}${label}[${parts.join(",")}]`;
|
|
963
1234
|
};
|
|
@@ -966,14 +1237,14 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
|
|
|
966
1237
|
};
|
|
967
1238
|
|
|
968
1239
|
// ../instrumentation/src/verify-transformed-source.ts
|
|
969
|
-
import
|
|
970
|
-
var transpileForVerification = (filePath, code) =>
|
|
1240
|
+
import ts8 from "typescript";
|
|
1241
|
+
var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
971
1242
|
compilerOptions: {
|
|
972
1243
|
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
973
|
-
target:
|
|
974
|
-
module:
|
|
1244
|
+
target: ts8.ScriptTarget.ES2020,
|
|
1245
|
+
module: ts8.ModuleKind.ESNext,
|
|
975
1246
|
allowJs: true,
|
|
976
|
-
jsx:
|
|
1247
|
+
jsx: ts8.JsxEmit.React,
|
|
977
1248
|
experimentalDecorators: true
|
|
978
1249
|
},
|
|
979
1250
|
reportDiagnostics: true,
|
|
@@ -981,7 +1252,7 @@ var transpileForVerification = (filePath, code) => ts7.transpileModule(code, {
|
|
|
981
1252
|
});
|
|
982
1253
|
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
983
1254
|
diagnostics?.some(
|
|
984
|
-
(diagnostic) => diagnostic.category ===
|
|
1255
|
+
(diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
985
1256
|
)
|
|
986
1257
|
);
|
|
987
1258
|
var scriptBodyForEngine = (emitted) => (
|
|
@@ -990,39 +1261,39 @@ var scriptBodyForEngine = (emitted) => (
|
|
|
990
1261
|
);
|
|
991
1262
|
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
992
1263
|
var scriptKindFor2 = (filePath) => {
|
|
993
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
994
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
995
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
996
|
-
return
|
|
1264
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
1265
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
1266
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
1267
|
+
return ts8.ScriptKind.JS;
|
|
997
1268
|
};
|
|
998
|
-
var isIterationStatement = (node) =>
|
|
1269
|
+
var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
|
|
999
1270
|
var unwrapLabeled = (node) => {
|
|
1000
1271
|
let current = node;
|
|
1001
|
-
while (
|
|
1272
|
+
while (ts8.isLabeledStatement(current)) current = current.statement;
|
|
1002
1273
|
return current;
|
|
1003
1274
|
};
|
|
1004
1275
|
var hasInvalidLabelJump = (sourceFile) => {
|
|
1005
1276
|
const visit = (node, labels) => {
|
|
1006
|
-
if (
|
|
1277
|
+
if (ts8.isFunctionLike(node)) {
|
|
1007
1278
|
let nestedInvalid = false;
|
|
1008
|
-
|
|
1279
|
+
ts8.forEachChild(node, (child) => {
|
|
1009
1280
|
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
1010
1281
|
});
|
|
1011
1282
|
return nestedInvalid;
|
|
1012
1283
|
}
|
|
1013
|
-
if (
|
|
1284
|
+
if (ts8.isLabeledStatement(node)) {
|
|
1014
1285
|
const next = new Map(labels);
|
|
1015
1286
|
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
1016
1287
|
return visit(node.statement, next);
|
|
1017
1288
|
}
|
|
1018
|
-
if (
|
|
1289
|
+
if (ts8.isContinueStatement(node) && node.label) {
|
|
1019
1290
|
if (labels.get(node.label.text) !== true) return true;
|
|
1020
1291
|
}
|
|
1021
|
-
if (
|
|
1292
|
+
if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
1022
1293
|
return true;
|
|
1023
1294
|
}
|
|
1024
1295
|
let invalid = false;
|
|
1025
|
-
|
|
1296
|
+
ts8.forEachChild(node, (child) => {
|
|
1026
1297
|
if (visit(child, labels)) invalid = true;
|
|
1027
1298
|
});
|
|
1028
1299
|
return invalid;
|
|
@@ -1065,10 +1336,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
|
1065
1336
|
var transformedSourceIsInvalid = (filePath, code) => {
|
|
1066
1337
|
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
1067
1338
|
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
1068
|
-
const sourceFile =
|
|
1339
|
+
const sourceFile = ts8.createSourceFile(
|
|
1069
1340
|
filePath,
|
|
1070
1341
|
code,
|
|
1071
|
-
|
|
1342
|
+
ts8.ScriptTarget.Latest,
|
|
1072
1343
|
true,
|
|
1073
1344
|
scriptKindFor2(filePath)
|
|
1074
1345
|
);
|
|
@@ -1089,25 +1360,25 @@ var alreadyInstrumentedResult = (source) => ({
|
|
|
1089
1360
|
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
1090
1361
|
});
|
|
1091
1362
|
var scriptKindFor3 = (filePath) => {
|
|
1092
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1093
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1094
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1095
|
-
return
|
|
1363
|
+
if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
|
|
1364
|
+
if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
|
|
1365
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
|
|
1366
|
+
return ts9.ScriptKind.JS;
|
|
1096
1367
|
};
|
|
1097
1368
|
var functionName = (node, sourceFile) => {
|
|
1098
|
-
if (
|
|
1369
|
+
if (ts9.isConstructorDeclaration(node)) return "constructor";
|
|
1099
1370
|
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
1100
1371
|
const parent = node.parent;
|
|
1101
|
-
if (
|
|
1102
|
-
if (
|
|
1103
|
-
if (
|
|
1372
|
+
if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
|
|
1373
|
+
if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
1374
|
+
if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
1104
1375
|
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
1105
1376
|
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
1106
1377
|
};
|
|
1107
1378
|
var functionLocationPosition = (node, sourceFile) => {
|
|
1108
1379
|
if (node.name) return node.name.getStart(sourceFile);
|
|
1109
1380
|
const parent = node.parent;
|
|
1110
|
-
if ((
|
|
1381
|
+
if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
|
|
1111
1382
|
return parent.name.getStart(sourceFile);
|
|
1112
1383
|
}
|
|
1113
1384
|
return node.getStart(sourceFile);
|
|
@@ -1120,12 +1391,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
|
1120
1391
|
}
|
|
1121
1392
|
return end;
|
|
1122
1393
|
};
|
|
1123
|
-
var isStaticPropertyName = (name) =>
|
|
1394
|
+
var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
|
|
1124
1395
|
var canReconstructBinding = (name) => {
|
|
1125
|
-
if (
|
|
1126
|
-
if (
|
|
1396
|
+
if (ts9.isIdentifier(name)) return true;
|
|
1397
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
1127
1398
|
return name.elements.every(
|
|
1128
|
-
(element) =>
|
|
1399
|
+
(element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
1129
1400
|
);
|
|
1130
1401
|
}
|
|
1131
1402
|
return name.elements.every((element) => {
|
|
@@ -1134,10 +1405,10 @@ var canReconstructBinding = (name) => {
|
|
|
1134
1405
|
});
|
|
1135
1406
|
};
|
|
1136
1407
|
var bindingValue = (name, sourceFile) => {
|
|
1137
|
-
if (
|
|
1138
|
-
if (
|
|
1408
|
+
if (ts9.isIdentifier(name)) return name.text;
|
|
1409
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
1139
1410
|
const values = name.elements.map((element) => {
|
|
1140
|
-
if (
|
|
1411
|
+
if (ts9.isOmittedExpression(element)) return "";
|
|
1141
1412
|
const value = bindingValue(element.name, sourceFile);
|
|
1142
1413
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
1143
1414
|
});
|
|
@@ -1147,7 +1418,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1147
1418
|
const value = bindingValue(element.name, sourceFile);
|
|
1148
1419
|
if (element.dotDotDotToken) return `...${value}`;
|
|
1149
1420
|
if (!element.propertyName) return value;
|
|
1150
|
-
const key =
|
|
1421
|
+
const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
1151
1422
|
return `${key}:${value}`;
|
|
1152
1423
|
});
|
|
1153
1424
|
return `{${properties.join(",")}}`;
|
|
@@ -1155,7 +1426,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1155
1426
|
var arrowArgsCapture = (node) => {
|
|
1156
1427
|
const sourceFile = node.getSourceFile();
|
|
1157
1428
|
const params = node.parameters.filter(
|
|
1158
|
-
(parameter) => !(
|
|
1429
|
+
(parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
1159
1430
|
);
|
|
1160
1431
|
if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
|
|
1161
1432
|
return {
|
|
@@ -1170,13 +1441,13 @@ var arrowArgsCapture = (node) => {
|
|
|
1170
1441
|
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
1171
1442
|
};
|
|
1172
1443
|
var isSupportedFunction = (node) => {
|
|
1173
|
-
if (!
|
|
1444
|
+
if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
|
|
1174
1445
|
return false;
|
|
1175
1446
|
}
|
|
1176
1447
|
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
1177
1448
|
return true;
|
|
1178
1449
|
};
|
|
1179
|
-
var isDirectivePrologue = (statement) =>
|
|
1450
|
+
var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
|
|
1180
1451
|
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
1181
1452
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
1182
1453
|
let end = shebangEnd;
|
|
@@ -1227,7 +1498,7 @@ var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
|
1227
1498
|
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
1228
1499
|
for (const statement of body.statements) {
|
|
1229
1500
|
if (isDirectivePrologue(statement)) continue;
|
|
1230
|
-
if (
|
|
1501
|
+
if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
|
|
1231
1502
|
return statement.end;
|
|
1232
1503
|
}
|
|
1233
1504
|
break;
|
|
@@ -1238,15 +1509,15 @@ var failEpilogue = (handleName, errorName, args2, restoreOnCatch) => `}catch(${e
|
|
|
1238
1509
|
var walkOwnBody = (node, visitNode) => {
|
|
1239
1510
|
if (!node.body) return;
|
|
1240
1511
|
const visit = (candidate) => {
|
|
1241
|
-
if (candidate !== node &&
|
|
1512
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1242
1513
|
visitNode(candidate);
|
|
1243
|
-
|
|
1514
|
+
ts9.forEachChild(candidate, visit);
|
|
1244
1515
|
};
|
|
1245
1516
|
visit(node.body);
|
|
1246
1517
|
};
|
|
1247
1518
|
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1248
1519
|
walkOwnBody(node, (candidate) => {
|
|
1249
|
-
if (!
|
|
1520
|
+
if (!ts9.isAwaitExpression(candidate)) return;
|
|
1250
1521
|
wrap(
|
|
1251
1522
|
edits,
|
|
1252
1523
|
candidate.expression.getStart(sourceFile),
|
|
@@ -1267,7 +1538,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1267
1538
|
};
|
|
1268
1539
|
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
1269
1540
|
walkOwnBody(node, (candidate) => {
|
|
1270
|
-
if (!
|
|
1541
|
+
if (!ts9.isTryStatement(candidate)) return;
|
|
1271
1542
|
const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
|
|
1272
1543
|
for (const block of blocks) {
|
|
1273
1544
|
if (!block) continue;
|
|
@@ -1283,10 +1554,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
|
|
|
1283
1554
|
});
|
|
1284
1555
|
};
|
|
1285
1556
|
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1286
|
-
if (!node.body || !
|
|
1557
|
+
if (!node.body || !ts9.isBlock(node.body)) return;
|
|
1287
1558
|
const visit = (candidate, at) => {
|
|
1288
|
-
if (candidate !== node &&
|
|
1289
|
-
if (
|
|
1559
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1560
|
+
if (ts9.isReturnStatement(candidate) && candidate.expression) {
|
|
1290
1561
|
const expression = candidate.expression;
|
|
1291
1562
|
wrap(
|
|
1292
1563
|
edits,
|
|
@@ -1298,17 +1569,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1298
1569
|
);
|
|
1299
1570
|
return;
|
|
1300
1571
|
}
|
|
1301
|
-
|
|
1572
|
+
ts9.forEachChild(candidate, (child) => visit(child, at + 1));
|
|
1302
1573
|
};
|
|
1303
1574
|
visit(node.body, depth + 1);
|
|
1304
1575
|
};
|
|
1305
1576
|
var transformSource = (source, options) => {
|
|
1306
1577
|
if (source.includes("@rasputin-ignore-file")) return void 0;
|
|
1307
1578
|
if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
|
|
1308
|
-
const sourceFile =
|
|
1579
|
+
const sourceFile = ts9.createSourceFile(
|
|
1309
1580
|
options.filePath,
|
|
1310
1581
|
source,
|
|
1311
|
-
|
|
1582
|
+
ts9.ScriptTarget.Latest,
|
|
1312
1583
|
true,
|
|
1313
1584
|
scriptKindFor3(options.filePath)
|
|
1314
1585
|
);
|
|
@@ -1329,10 +1600,31 @@ var transformSource = (source, options) => {
|
|
|
1329
1600
|
absolutePath
|
|
1330
1601
|
};
|
|
1331
1602
|
const pending = [];
|
|
1332
|
-
const
|
|
1603
|
+
const identityNodes = [];
|
|
1604
|
+
const rememberIdentity = (node, collected) => {
|
|
1605
|
+
identityNodes.push({ node, runtimeId: collected.functionId });
|
|
1606
|
+
};
|
|
1607
|
+
const withDeclarations = (result2) => {
|
|
1608
|
+
if (!options.functionMetrics) return result2;
|
|
1609
|
+
if (identityNodes.length === 0) return { ...result2, declarations: [] };
|
|
1610
|
+
const declarations = collectFunctionMetricDeclarations({
|
|
1611
|
+
sourceFile,
|
|
1612
|
+
filePath: options.filePath,
|
|
1613
|
+
functions: identityNodes,
|
|
1614
|
+
originalAst: !options.mapLocation,
|
|
1615
|
+
mapLocation: options.mapLocation
|
|
1616
|
+
});
|
|
1617
|
+
const byId = new Map(declarations.map((declaration) => [declaration.runtime_id, declaration]));
|
|
1618
|
+
for (const fn of result2.delta.functions) {
|
|
1619
|
+
fn.metricsDeclaration = byId.get(fn.functionId);
|
|
1620
|
+
}
|
|
1621
|
+
return { ...result2, declarations };
|
|
1622
|
+
};
|
|
1623
|
+
const skipFunction = (node, collected, reason) => {
|
|
1333
1624
|
collected.instrumented = false;
|
|
1334
1625
|
collected.skipReason = reason;
|
|
1335
1626
|
delta.functions.push(collected);
|
|
1627
|
+
rememberIdentity(node, collected);
|
|
1336
1628
|
if (process.env.RASPUTIN_DEBUG === "1") {
|
|
1337
1629
|
console.info(
|
|
1338
1630
|
`[rasputin] skipped instrumentation for ${collected.name} in ${options.filePath}: ${reason}`
|
|
@@ -1349,9 +1641,9 @@ var transformSource = (source, options) => {
|
|
|
1349
1641
|
);
|
|
1350
1642
|
if (collected) {
|
|
1351
1643
|
collected.asyncFunction = true;
|
|
1352
|
-
skipFunction(collected, "unsupported_async_generator");
|
|
1644
|
+
skipFunction(node, collected, "unsupported_async_generator");
|
|
1353
1645
|
}
|
|
1354
|
-
|
|
1646
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1355
1647
|
return;
|
|
1356
1648
|
}
|
|
1357
1649
|
if (isSyncGeneratorLike(node) && node.body) {
|
|
@@ -1361,25 +1653,27 @@ var transformSource = (source, options) => {
|
|
|
1361
1653
|
absolutePath,
|
|
1362
1654
|
options.mapLocation
|
|
1363
1655
|
);
|
|
1364
|
-
if (collected)
|
|
1365
|
-
|
|
1656
|
+
if (collected)
|
|
1657
|
+
skipFunction(node, collected, "unsupported_sync_generator");
|
|
1658
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1366
1659
|
return;
|
|
1367
1660
|
}
|
|
1368
|
-
if (
|
|
1661
|
+
if (ts9.isConstructorDeclaration(node) && node.body) {
|
|
1369
1662
|
const collected = collectWrappedFunction(
|
|
1370
1663
|
node,
|
|
1371
1664
|
sourceFile,
|
|
1372
1665
|
absolutePath,
|
|
1373
1666
|
options.mapLocation
|
|
1374
1667
|
);
|
|
1375
|
-
if (collected)
|
|
1376
|
-
|
|
1668
|
+
if (collected)
|
|
1669
|
+
skipFunction(node, collected, "unsupported_constructor");
|
|
1670
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1377
1671
|
return;
|
|
1378
1672
|
}
|
|
1379
1673
|
if (isSupportedFunction(node)) {
|
|
1380
1674
|
const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
|
|
1381
1675
|
if (!collected) {
|
|
1382
|
-
|
|
1676
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1383
1677
|
return;
|
|
1384
1678
|
}
|
|
1385
1679
|
if (options.decideFunction?.({
|
|
@@ -1388,15 +1682,15 @@ var transformSource = (source, options) => {
|
|
|
1388
1682
|
filePath: options.filePath,
|
|
1389
1683
|
name: collected.name
|
|
1390
1684
|
}) === "skip") {
|
|
1391
|
-
|
|
1685
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1392
1686
|
return;
|
|
1393
1687
|
}
|
|
1394
1688
|
const asyncFunction = isAsyncFunctionLike(node);
|
|
1395
1689
|
collected.asyncFunction = asyncFunction;
|
|
1396
1690
|
const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
1397
1691
|
if (decision.action === "skip") {
|
|
1398
|
-
skipFunction(collected, decision.reason);
|
|
1399
|
-
|
|
1692
|
+
skipFunction(node, collected, decision.reason);
|
|
1693
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1400
1694
|
return;
|
|
1401
1695
|
}
|
|
1402
1696
|
if (functionHasPreBodyParameterEvaluation(node)) {
|
|
@@ -1409,29 +1703,30 @@ var transformSource = (source, options) => {
|
|
|
1409
1703
|
suspendResume: decision.action === "suspend_resume"
|
|
1410
1704
|
});
|
|
1411
1705
|
delta.functions.push(collected);
|
|
1412
|
-
|
|
1706
|
+
rememberIdentity(node, collected);
|
|
1707
|
+
ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
|
|
1413
1708
|
return;
|
|
1414
1709
|
}
|
|
1415
|
-
if (caller && (
|
|
1710
|
+
if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
|
|
1416
1711
|
const site = collectCallSite(node, caller, collectContext);
|
|
1417
1712
|
if (site) delta.callSites.push(site);
|
|
1418
1713
|
}
|
|
1419
|
-
if (caller &&
|
|
1714
|
+
if (caller && ts9.isVariableDeclaration(node)) {
|
|
1420
1715
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
1421
1716
|
if (destructure) delta.destructures.push(destructure);
|
|
1422
1717
|
}
|
|
1423
|
-
|
|
1718
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1424
1719
|
};
|
|
1425
1720
|
visit(sourceFile, void 0, 0);
|
|
1426
1721
|
if (pending.length === 0) {
|
|
1427
|
-
return delta.functions.length > 0 ? { code: source, delta } : void 0;
|
|
1722
|
+
return delta.functions.length > 0 ? withDeclarations({ code: source, delta }) : void 0;
|
|
1428
1723
|
}
|
|
1429
1724
|
for (const [planIndex, entry] of pending.entries()) {
|
|
1430
|
-
const captured =
|
|
1725
|
+
const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
|
|
1431
1726
|
const omitArg = captured.omitValues ? ",true" : "";
|
|
1432
1727
|
const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
|
|
1433
1728
|
const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
|
|
1434
|
-
if (
|
|
1729
|
+
if (ts9.isBlock(entry.node.body)) {
|
|
1435
1730
|
const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
|
|
1436
1731
|
const closeAt = entry.node.body.end - 1;
|
|
1437
1732
|
wrap(
|
|
@@ -1497,7 +1792,7 @@ var transformSource = (source, options) => {
|
|
|
1497
1792
|
`[rasputin] skipped instrumentation for ${options.filePath}: verification_failed`
|
|
1498
1793
|
);
|
|
1499
1794
|
}
|
|
1500
|
-
return { code: source, delta };
|
|
1795
|
+
return withDeclarations({ code: source, delta });
|
|
1501
1796
|
};
|
|
1502
1797
|
if (verify && transformedSourceIsInvalid(options.filePath, transformed)) {
|
|
1503
1798
|
if (transformedSourceIsInvalid(options.filePath, source)) {
|
|
@@ -1513,28 +1808,28 @@ var transformSource = (source, options) => {
|
|
|
1513
1808
|
if (verify && !instrumentationTreesAreIsomorphic(options.filePath, source, transformed)) {
|
|
1514
1809
|
return refuseTransformed();
|
|
1515
1810
|
}
|
|
1516
|
-
return {
|
|
1811
|
+
return withDeclarations({
|
|
1517
1812
|
code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
|
|
1518
1813
|
delta,
|
|
1519
1814
|
map: exactTransformMap(source, transformed, basename(options.filePath), edits)
|
|
1520
|
-
};
|
|
1815
|
+
});
|
|
1521
1816
|
};
|
|
1522
1817
|
|
|
1523
1818
|
// ../instrumentation/src/json-producer-sites.ts
|
|
1524
|
-
import
|
|
1819
|
+
import ts11 from "typescript";
|
|
1525
1820
|
|
|
1526
1821
|
// ../instrumentation/src/literal-sites.ts
|
|
1527
|
-
import
|
|
1822
|
+
import ts12 from "typescript";
|
|
1528
1823
|
|
|
1529
1824
|
// ../instrumentation/src/observe-sites.ts
|
|
1530
1825
|
import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
|
|
1531
|
-
import
|
|
1826
|
+
import ts13 from "typescript";
|
|
1532
1827
|
|
|
1533
1828
|
// ../instrumentation/src/verify-browser-source.ts
|
|
1534
|
-
import
|
|
1829
|
+
import ts14 from "typescript";
|
|
1535
1830
|
|
|
1536
1831
|
// ../instrumentation/src/provenance-function-edits.ts
|
|
1537
|
-
import
|
|
1832
|
+
import ts15 from "typescript";
|
|
1538
1833
|
|
|
1539
1834
|
// ../instrumentation/src/source-map-location.ts
|
|
1540
1835
|
import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
|
|
@@ -1544,7 +1839,7 @@ import { createHash } from "node:crypto";
|
|
|
1544
1839
|
import { resolve as resolve2 } from "node:path";
|
|
1545
1840
|
import {
|
|
1546
1841
|
INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
1547
|
-
sourceLocatorFromFile as
|
|
1842
|
+
sourceLocatorFromFile as sourceLocatorFromFile3
|
|
1548
1843
|
} from "@rasputin-ai/core";
|
|
1549
1844
|
var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
|
|
1550
1845
|
var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
|
|
@@ -1566,7 +1861,7 @@ var getRegistry = () => {
|
|
|
1566
1861
|
return registry;
|
|
1567
1862
|
};
|
|
1568
1863
|
var sourceAt = (filePath, line, column) => {
|
|
1569
|
-
const source =
|
|
1864
|
+
const source = sourceLocatorFromFile3(filePath);
|
|
1570
1865
|
return source ? { ...source, line, column } : void 0;
|
|
1571
1866
|
};
|
|
1572
1867
|
var stableId = (kind, ...parts) => `${kind}_${createHash("sha256").update(parts.join("\0")).digest("base64url").slice(0, 24)}`;
|
|
@@ -1590,8 +1885,12 @@ var snapshotInstrumentationManifest = (options = {}) => {
|
|
|
1590
1885
|
if (registry.snapshotCache && registry.snapshotCache.generation === registry.generation && registry.snapshotCache.optionsKey === optionsKey) {
|
|
1591
1886
|
return registry.snapshotCache.manifest;
|
|
1592
1887
|
}
|
|
1593
|
-
const functions =
|
|
1594
|
-
|
|
1888
|
+
const functions = new Map(
|
|
1889
|
+
registry.prebuilt?.functions.map((fn) => [fn.functionId, fn])
|
|
1890
|
+
);
|
|
1891
|
+
const callSites = new Map(
|
|
1892
|
+
registry.prebuilt?.callSites.map((site) => [site.id, site])
|
|
1893
|
+
);
|
|
1595
1894
|
const remember = (manifest) => {
|
|
1596
1895
|
registry.snapshotCache = {
|
|
1597
1896
|
generation: registry.generation,
|
|
@@ -1604,7 +1903,11 @@ var snapshotInstrumentationManifest = (options = {}) => {
|
|
|
1604
1903
|
for (const fn of delta.functions) {
|
|
1605
1904
|
const definition = definitionFromEncodedPlan(fn.plan);
|
|
1606
1905
|
if (!definition.source) continue;
|
|
1607
|
-
|
|
1906
|
+
if (!fn.metricsDeclaration) {
|
|
1907
|
+
throw new Error(`Missing function metrics declaration: ${fn.functionId}`);
|
|
1908
|
+
}
|
|
1909
|
+
functions.set(definition.functionId, {
|
|
1910
|
+
...functions.get(definition.functionId),
|
|
1608
1911
|
functionId: definition.functionId,
|
|
1609
1912
|
source: {
|
|
1610
1913
|
packageRelativePath: definition.source.packageRelativePath,
|
|
@@ -1616,21 +1919,23 @@ var snapshotInstrumentationManifest = (options = {}) => {
|
|
|
1616
1919
|
startColumn: fn.startColumn,
|
|
1617
1920
|
endLine: fn.endLine,
|
|
1618
1921
|
endColumn: fn.endColumn,
|
|
1922
|
+
metricsDeclaration: fn.metricsDeclaration,
|
|
1619
1923
|
...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
|
|
1620
1924
|
});
|
|
1621
1925
|
}
|
|
1622
1926
|
for (const site of delta.callSites) {
|
|
1623
1927
|
const source = sourceAt(site.filePath, site.line, site.column);
|
|
1624
1928
|
if (!source) continue;
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1929
|
+
const id = stableId(
|
|
1930
|
+
"cs",
|
|
1931
|
+
site.callerFunctionId,
|
|
1932
|
+
source.packageName ?? "",
|
|
1933
|
+
source.packageRelativePath,
|
|
1934
|
+
site.line,
|
|
1935
|
+
site.column
|
|
1936
|
+
);
|
|
1937
|
+
callSites.set(id, {
|
|
1938
|
+
id,
|
|
1634
1939
|
callerFunctionId: site.callerFunctionId,
|
|
1635
1940
|
calleeName: site.calleeName,
|
|
1636
1941
|
calleeText: site.calleeText,
|
|
@@ -1652,20 +1957,21 @@ var snapshotInstrumentationManifest = (options = {}) => {
|
|
|
1652
1957
|
}
|
|
1653
1958
|
});
|
|
1654
1959
|
}
|
|
1655
|
-
if (functions.
|
|
1960
|
+
if (functions.size === 0 && callSites.size === 0) {
|
|
1656
1961
|
return remember(void 0);
|
|
1657
1962
|
}
|
|
1658
|
-
const packages = { ...options.sourceRoots
|
|
1963
|
+
const packages = { ...registry.prebuilt?.sourceRoots?.packages, ...options.sourceRoots };
|
|
1964
|
+
const sourceRoot = options.sourceRoot ?? registry.prebuilt?.sourceRoots?.default;
|
|
1659
1965
|
return remember({
|
|
1660
1966
|
schema_version: INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
|
|
1661
|
-
...
|
|
1967
|
+
...sourceRoot || Object.keys(packages).length > 0 ? {
|
|
1662
1968
|
sourceRoots: {
|
|
1663
|
-
...
|
|
1969
|
+
...sourceRoot ? { default: sourceRoot } : {},
|
|
1664
1970
|
packages
|
|
1665
1971
|
}
|
|
1666
1972
|
} : {},
|
|
1667
|
-
functions,
|
|
1668
|
-
callSites
|
|
1973
|
+
functions: [...functions.values()],
|
|
1974
|
+
callSites: [...callSites.values()]
|
|
1669
1975
|
});
|
|
1670
1976
|
};
|
|
1671
1977
|
var resetInstrumentationManifestRegistry = () => {
|
|
@@ -1803,11 +2109,15 @@ var instrumentCompiledDirectory = (options) => {
|
|
|
1803
2109
|
}
|
|
1804
2110
|
const transformed = transformSource(source, {
|
|
1805
2111
|
filePath,
|
|
1806
|
-
mapLocation: createSourceMapLocationMapper2(filePath, source)
|
|
2112
|
+
mapLocation: createSourceMapLocationMapper2(filePath, source),
|
|
2113
|
+
functionMetrics: true
|
|
1807
2114
|
});
|
|
1808
2115
|
if (!transformed) continue;
|
|
1809
2116
|
const outputPath = join2(outputDir, relative2(inputDir, filePath));
|
|
1810
|
-
writeText(
|
|
2117
|
+
writeText(
|
|
2118
|
+
outputPath,
|
|
2119
|
+
withFunctionMetricDeclarationRegistration(transformed.code, transformed.declarations)
|
|
2120
|
+
);
|
|
1811
2121
|
recordInstrumentationManifestDelta(filePath, transformed.delta);
|
|
1812
2122
|
transformedFiles.push(outputPath);
|
|
1813
2123
|
}
|