@rasputin-ai/node 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts +2 -0
- package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts.map +1 -1
- package/dist/execution-recorder/error-observation.d.ts +14 -0
- package/dist/execution-recorder/error-observation.d.ts.map +1 -0
- package/dist/execution-recorder/execution-recorder-types.d.ts +10 -7
- 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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +159 -66
- package/dist/instrument/build.js +142 -130
- package/dist/instrument/bun.js +143 -131
- package/dist/instrument/node.js +143 -131
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +157 -60
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +5 -5
package/dist/instrument/build.js
CHANGED
|
@@ -58,7 +58,7 @@ var definitionFromEncodedPlan = (plan) => {
|
|
|
58
58
|
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
59
59
|
|
|
60
60
|
// ../instrumentation/src/classify-function.ts
|
|
61
|
-
import
|
|
61
|
+
import ts3 from "typescript";
|
|
62
62
|
|
|
63
63
|
// ../instrumentation/src/collect-instrumentation-delta.ts
|
|
64
64
|
import ts from "typescript";
|
|
@@ -240,9 +240,6 @@ var collectParamDestructure = (declaration, caller, context) => {
|
|
|
240
240
|
// ../instrumentation/src/parse-source.ts
|
|
241
241
|
import ts2 from "typescript";
|
|
242
242
|
|
|
243
|
-
// ../instrumentation/src/svelte-generated.ts
|
|
244
|
-
import ts3 from "typescript";
|
|
245
|
-
|
|
246
243
|
// ../instrumentation/src/edits.ts
|
|
247
244
|
var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
248
245
|
var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
|
|
@@ -290,7 +287,7 @@ var applyEdits = (source, edits) => {
|
|
|
290
287
|
};
|
|
291
288
|
var textOf = (edit) => edit.text;
|
|
292
289
|
|
|
293
|
-
//
|
|
290
|
+
// ../../node_modules/.bun/@jridgewell+sourcemap-codec@1.6.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
294
291
|
var comma = ",".charCodeAt(0);
|
|
295
292
|
var semicolon = ";".charCodeAt(0);
|
|
296
293
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -377,7 +374,7 @@ function encode(decoded) {
|
|
|
377
374
|
return writer.flush();
|
|
378
375
|
}
|
|
379
376
|
|
|
380
|
-
//
|
|
377
|
+
// ../../node_modules/.bun/@jridgewell+gen-mapping@0.3.13/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
|
|
381
378
|
import { TraceMap, decodedMappings } from "@jridgewell/trace-mapping";
|
|
382
379
|
var SetArray = class {
|
|
383
380
|
constructor() {
|
|
@@ -649,6 +646,11 @@ var encodeColumnMappings = (original, generated, file, edits) => {
|
|
|
649
646
|
mappings: encoded.mappings
|
|
650
647
|
};
|
|
651
648
|
};
|
|
649
|
+
var exactTransformMap = (original, generated, file, edits) => {
|
|
650
|
+
const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
|
|
651
|
+
const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
|
|
652
|
+
return { version: 3, file, sources, mappings };
|
|
653
|
+
};
|
|
652
654
|
var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) => {
|
|
653
655
|
const file = basenameOf(filePath);
|
|
654
656
|
const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
|
|
@@ -662,11 +664,11 @@ var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) =
|
|
|
662
664
|
|
|
663
665
|
// ../instrumentation/src/browser-function-edits.ts
|
|
664
666
|
import { propertyNameIsSensitive } from "@rasputin-ai/core";
|
|
665
|
-
import
|
|
667
|
+
import ts9 from "typescript";
|
|
666
668
|
|
|
667
669
|
// ../instrumentation/src/suspension-whitelist.ts
|
|
668
|
-
import
|
|
669
|
-
var nodeFlags =
|
|
670
|
+
import ts4 from "typescript";
|
|
671
|
+
var nodeFlags = ts4.NodeFlags;
|
|
670
672
|
var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
|
|
671
673
|
var USING_FLAG = nodeFlags.Using ?? 0;
|
|
672
674
|
var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
@@ -676,8 +678,8 @@ var KNOWN_SUSPENSION_KIND_NAMES = [
|
|
|
676
678
|
"YieldKeyword",
|
|
677
679
|
"UsingKeyword"
|
|
678
680
|
];
|
|
679
|
-
var isFunctionLike = (node) =>
|
|
680
|
-
var isAsyncFunctionLike = (node) => (
|
|
681
|
+
var isFunctionLike = (node) => ts4.isFunctionLike(node);
|
|
682
|
+
var isAsyncFunctionLike = (node) => (ts4.getCombinedModifierFlags(node) & ts4.ModifierFlags.Async) !== 0;
|
|
681
683
|
var isAsyncGeneratorLike = (node) => isFunctionLike(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
|
|
682
684
|
var isSyncGeneratorLike = (node) => isFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken) && !isAsyncFunctionLike(node);
|
|
683
685
|
var visitOwnBody = (node, visitNode) => {
|
|
@@ -688,7 +690,7 @@ var visitOwnBody = (node, visitNode) => {
|
|
|
688
690
|
return;
|
|
689
691
|
}
|
|
690
692
|
if (visitNode(candidate)) return;
|
|
691
|
-
|
|
693
|
+
ts4.forEachChild(candidate, visit);
|
|
692
694
|
};
|
|
693
695
|
visit(node.body);
|
|
694
696
|
};
|
|
@@ -716,16 +718,16 @@ var slicesOutside = (start, end, spans) => {
|
|
|
716
718
|
};
|
|
717
719
|
var sliceHasAwaitKeyword = (source, start, end) => {
|
|
718
720
|
if (end <= start) return false;
|
|
719
|
-
const scanner =
|
|
720
|
-
|
|
721
|
+
const scanner = ts4.createScanner(
|
|
722
|
+
ts4.ScriptTarget.Latest,
|
|
721
723
|
true,
|
|
722
|
-
|
|
724
|
+
ts4.LanguageVariant.Standard,
|
|
723
725
|
source.slice(start, end)
|
|
724
726
|
);
|
|
725
727
|
while (true) {
|
|
726
728
|
const token = scanner.scan();
|
|
727
|
-
if (token ===
|
|
728
|
-
if (token ===
|
|
729
|
+
if (token === ts4.SyntaxKind.EndOfFileToken) return false;
|
|
730
|
+
if (token === ts4.SyntaxKind.AwaitKeyword) return true;
|
|
729
731
|
}
|
|
730
732
|
};
|
|
731
733
|
var ownBodyHasAwaitKeyword = (node, sourceFile) => {
|
|
@@ -743,7 +745,7 @@ var isAwaitUsingList = (node) => {
|
|
|
743
745
|
return (node.flags & AWAIT_USING_FLAG) === AWAIT_USING_FLAG && (node.flags & USING_FLAG) !== 0;
|
|
744
746
|
};
|
|
745
747
|
var unknownSuspensionKind = (node) => {
|
|
746
|
-
const name =
|
|
748
|
+
const name = ts4.SyntaxKind[node.kind];
|
|
747
749
|
if (typeof name !== "string" || !/Await|Yield|Using/.test(name)) return false;
|
|
748
750
|
return !KNOWN_SUSPENSION_KIND_NAMES.includes(name);
|
|
749
751
|
};
|
|
@@ -756,9 +758,9 @@ var ownSuspensionFacts = (node, sourceFile) => {
|
|
|
756
758
|
awaitKeyword: ownBodyHasAwaitKeyword(node, sourceFile)
|
|
757
759
|
};
|
|
758
760
|
visitOwnBody(node, (candidate) => {
|
|
759
|
-
if (
|
|
760
|
-
if (
|
|
761
|
-
if (
|
|
761
|
+
if (ts4.isAwaitExpression(candidate)) facts.awaitExpressions = true;
|
|
762
|
+
if (ts4.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
|
|
763
|
+
if (ts4.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
|
|
762
764
|
facts.awaitUsing = true;
|
|
763
765
|
}
|
|
764
766
|
if (unknownSuspensionKind(candidate)) facts.unknown = true;
|
|
@@ -769,7 +771,7 @@ var ownSuspensionFacts = (node, sourceFile) => {
|
|
|
769
771
|
var bodyHasDirectEval = (node) => {
|
|
770
772
|
let found = false;
|
|
771
773
|
visitOwnBody(node, (candidate) => {
|
|
772
|
-
if (
|
|
774
|
+
if (ts4.isCallExpression(candidate) && ts4.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
|
|
773
775
|
found = true;
|
|
774
776
|
}
|
|
775
777
|
return found;
|
|
@@ -793,34 +795,34 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
|
793
795
|
|
|
794
796
|
// ../instrumentation/src/transform-source.ts
|
|
795
797
|
import { basename, resolve } from "node:path";
|
|
796
|
-
import
|
|
798
|
+
import ts8 from "typescript";
|
|
797
799
|
|
|
798
800
|
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
799
|
-
import
|
|
801
|
+
import ts5 from "typescript";
|
|
800
802
|
var unwrap = (expression) => {
|
|
801
803
|
let current = expression;
|
|
802
|
-
while (
|
|
804
|
+
while (ts5.isParenthesizedExpression(current) || ts5.isNonNullExpression(current)) {
|
|
803
805
|
current = current.expression;
|
|
804
806
|
}
|
|
805
807
|
return current;
|
|
806
808
|
};
|
|
807
809
|
var isSafeLiteralInitializer = (expression) => {
|
|
808
810
|
const current = unwrap(expression);
|
|
809
|
-
if (
|
|
811
|
+
if (ts5.isNumericLiteral(current) || ts5.isStringLiteral(current) || ts5.isNoSubstitutionTemplateLiteral(current) || ts5.isBigIntLiteral(current)) {
|
|
810
812
|
return true;
|
|
811
813
|
}
|
|
812
|
-
if (current.kind ===
|
|
814
|
+
if (current.kind === ts5.SyntaxKind.TrueKeyword || current.kind === ts5.SyntaxKind.FalseKeyword || current.kind === ts5.SyntaxKind.NullKeyword) {
|
|
813
815
|
return true;
|
|
814
816
|
}
|
|
815
|
-
if (
|
|
816
|
-
if (
|
|
817
|
-
return
|
|
817
|
+
if (ts5.isIdentifier(current) && current.text === "undefined") return true;
|
|
818
|
+
if (ts5.isPrefixUnaryExpression(current) && (current.operator === ts5.SyntaxKind.PlusToken || current.operator === ts5.SyntaxKind.MinusToken)) {
|
|
819
|
+
return ts5.isNumericLiteral(unwrap(current.operand));
|
|
818
820
|
}
|
|
819
821
|
return false;
|
|
820
822
|
};
|
|
821
823
|
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
822
824
|
for (const parameter of node.parameters) {
|
|
823
|
-
if (
|
|
825
|
+
if (ts5.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
824
826
|
if (!parameter.initializer) continue;
|
|
825
827
|
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
826
828
|
}
|
|
@@ -828,24 +830,24 @@ var functionHasPreBodyParameterEvaluation = (node) => {
|
|
|
828
830
|
};
|
|
829
831
|
|
|
830
832
|
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
831
|
-
import
|
|
833
|
+
import ts6 from "typescript";
|
|
832
834
|
var RASPUTIN_IDENT = /^__rasputin/;
|
|
833
835
|
var scriptKindFor = (filePath) => {
|
|
834
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
835
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
836
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
837
|
-
return
|
|
836
|
+
if (/\.tsx$/i.test(filePath)) return ts6.ScriptKind.TSX;
|
|
837
|
+
if (/\.jsx$/i.test(filePath)) return ts6.ScriptKind.JSX;
|
|
838
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts6.ScriptKind.TS;
|
|
839
|
+
return ts6.ScriptKind.JS;
|
|
838
840
|
};
|
|
839
|
-
var parse = (filePath, source) =>
|
|
841
|
+
var parse = (filePath, source) => ts6.createSourceFile(filePath, source, ts6.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
840
842
|
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
841
843
|
var identText = (node) => {
|
|
842
|
-
if (
|
|
843
|
-
if (
|
|
844
|
+
if (ts6.isIdentifier(node)) return node.text;
|
|
845
|
+
if (ts6.isPrivateIdentifier(node)) return node.text;
|
|
844
846
|
return void 0;
|
|
845
847
|
};
|
|
846
848
|
var calleeName = (expression) => {
|
|
847
|
-
if (
|
|
848
|
-
if (
|
|
849
|
+
if (ts6.isIdentifier(expression)) return expression.text;
|
|
850
|
+
if (ts6.isPropertyAccessExpression(expression)) {
|
|
849
851
|
const object = identText(expression.expression);
|
|
850
852
|
const property = identText(expression.name);
|
|
851
853
|
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
@@ -853,7 +855,7 @@ var calleeName = (expression) => {
|
|
|
853
855
|
return void 0;
|
|
854
856
|
};
|
|
855
857
|
var isRasputinCall = (node, methods) => {
|
|
856
|
-
if (!
|
|
858
|
+
if (!ts6.isCallExpression(node)) return false;
|
|
857
859
|
const name = calleeName(node.expression);
|
|
858
860
|
if (!name) return false;
|
|
859
861
|
if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
|
|
@@ -863,20 +865,20 @@ var unwrapCall = (node) => {
|
|
|
863
865
|
let current = node;
|
|
864
866
|
while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
|
|
865
867
|
current = current.arguments[0];
|
|
866
|
-
if (
|
|
868
|
+
if (ts6.isParenthesizedExpression(current)) current = current.expression;
|
|
867
869
|
}
|
|
868
|
-
if (
|
|
870
|
+
if (ts6.isParenthesizedExpression(current)) return current.expression;
|
|
869
871
|
return current;
|
|
870
872
|
};
|
|
871
873
|
var isRasputinStatement = (node) => {
|
|
872
|
-
if (
|
|
873
|
-
if (
|
|
874
|
+
if (ts6.isEmptyStatement(node)) return true;
|
|
875
|
+
if (ts6.isVariableStatement(node)) {
|
|
874
876
|
return node.declarationList.declarations.every((declaration) => {
|
|
875
877
|
const name = identText(declaration.name);
|
|
876
878
|
return Boolean(name && isRasputinName(name));
|
|
877
879
|
});
|
|
878
880
|
}
|
|
879
|
-
if (
|
|
881
|
+
if (ts6.isExpressionStatement(node)) {
|
|
880
882
|
if (!isRasputinCall(node.expression)) return false;
|
|
881
883
|
const unwrapped = unwrapCall(node.expression);
|
|
882
884
|
return unwrapped === node.expression;
|
|
@@ -890,7 +892,7 @@ var isRasputinTryWrapper = (node) => {
|
|
|
890
892
|
(statement) => !isRasputinStatement(statement)
|
|
891
893
|
);
|
|
892
894
|
const leftover = catchCalls[0];
|
|
893
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
895
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts6.isThrowStatement(leftover) && ts6.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
|
|
894
896
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
895
897
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
896
898
|
};
|
|
@@ -898,7 +900,7 @@ var flattenStatements = (statements) => {
|
|
|
898
900
|
const flattened = [];
|
|
899
901
|
for (const statement of statements) {
|
|
900
902
|
if (isRasputinStatement(statement)) continue;
|
|
901
|
-
if (
|
|
903
|
+
if (ts6.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
902
904
|
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
903
905
|
continue;
|
|
904
906
|
}
|
|
@@ -907,38 +909,38 @@ var flattenStatements = (statements) => {
|
|
|
907
909
|
return flattened;
|
|
908
910
|
};
|
|
909
911
|
var extra = (node) => {
|
|
910
|
-
if (
|
|
912
|
+
if (ts6.isIdentifier(node) || ts6.isPrivateIdentifier(node)) {
|
|
911
913
|
return isRasputinName(node.text) ? "" : node.text;
|
|
912
914
|
}
|
|
913
|
-
if (
|
|
915
|
+
if (ts6.isStringLiteral(node) || ts6.isNumericLiteral(node) || ts6.isNoSubstitutionTemplateLiteral(node)) {
|
|
914
916
|
return node.text;
|
|
915
917
|
}
|
|
916
|
-
if (
|
|
918
|
+
if (ts6.isToken(node) && !ts6.isIdentifier(node)) return ts6.SyntaxKind[node.kind] ?? "";
|
|
917
919
|
return "";
|
|
918
920
|
};
|
|
919
921
|
var signatureOf = (node) => {
|
|
920
922
|
const unwrapped = unwrapCall(node);
|
|
921
923
|
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
922
|
-
if (
|
|
923
|
-
if (
|
|
924
|
+
if (ts6.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
925
|
+
if (ts6.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
924
926
|
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
925
927
|
}
|
|
926
|
-
if (
|
|
928
|
+
if (ts6.isBlock(unwrapped)) {
|
|
927
929
|
const statements = flattenStatements(unwrapped.statements);
|
|
928
930
|
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
929
931
|
}
|
|
930
|
-
if (
|
|
932
|
+
if (ts6.isCatchClause(unwrapped)) {
|
|
931
933
|
const statements = flattenStatements(unwrapped.block.statements);
|
|
932
934
|
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
933
935
|
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
934
936
|
}
|
|
935
|
-
if (
|
|
937
|
+
if (ts6.isArrowFunction(unwrapped) && ts6.isBlock(unwrapped.body)) {
|
|
936
938
|
const statements = flattenStatements(unwrapped.body.statements);
|
|
937
939
|
const only = statements[0];
|
|
938
|
-
if (statements.length === 1 && only &&
|
|
940
|
+
if (statements.length === 1 && only && ts6.isReturnStatement(only) && only.expression) {
|
|
939
941
|
const expression = only.expression;
|
|
940
942
|
const parts2 = [];
|
|
941
|
-
|
|
943
|
+
ts6.forEachChild(unwrapped, (child) => {
|
|
942
944
|
if (child === unwrapped.body) {
|
|
943
945
|
const part2 = signatureOf(expression);
|
|
944
946
|
if (part2) parts2.push(part2);
|
|
@@ -951,11 +953,11 @@ var signatureOf = (node) => {
|
|
|
951
953
|
}
|
|
952
954
|
}
|
|
953
955
|
const parts = [];
|
|
954
|
-
|
|
956
|
+
ts6.forEachChild(unwrapped, (child) => {
|
|
955
957
|
const part = signatureOf(child);
|
|
956
958
|
if (part) parts.push(part);
|
|
957
959
|
});
|
|
958
|
-
const kind =
|
|
960
|
+
const kind = ts6.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
959
961
|
const label = extra(unwrapped);
|
|
960
962
|
return `${kind}${label}[${parts.join(",")}]`;
|
|
961
963
|
};
|
|
@@ -964,14 +966,14 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
|
|
|
964
966
|
};
|
|
965
967
|
|
|
966
968
|
// ../instrumentation/src/verify-transformed-source.ts
|
|
967
|
-
import
|
|
968
|
-
var transpileForVerification = (filePath, code) =>
|
|
969
|
+
import ts7 from "typescript";
|
|
970
|
+
var transpileForVerification = (filePath, code) => ts7.transpileModule(code, {
|
|
969
971
|
compilerOptions: {
|
|
970
972
|
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
971
|
-
target:
|
|
972
|
-
module:
|
|
973
|
+
target: ts7.ScriptTarget.ES2020,
|
|
974
|
+
module: ts7.ModuleKind.ESNext,
|
|
973
975
|
allowJs: true,
|
|
974
|
-
jsx:
|
|
976
|
+
jsx: ts7.JsxEmit.React,
|
|
975
977
|
experimentalDecorators: true
|
|
976
978
|
},
|
|
977
979
|
reportDiagnostics: true,
|
|
@@ -979,7 +981,7 @@ var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
|
979
981
|
});
|
|
980
982
|
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
981
983
|
diagnostics?.some(
|
|
982
|
-
(diagnostic) => diagnostic.category ===
|
|
984
|
+
(diagnostic) => diagnostic.category === ts7.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
983
985
|
)
|
|
984
986
|
);
|
|
985
987
|
var scriptBodyForEngine = (emitted) => (
|
|
@@ -988,39 +990,39 @@ var scriptBodyForEngine = (emitted) => (
|
|
|
988
990
|
);
|
|
989
991
|
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
990
992
|
var scriptKindFor2 = (filePath) => {
|
|
991
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
992
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
993
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
994
|
-
return
|
|
993
|
+
if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
|
|
994
|
+
if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
|
|
995
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
|
|
996
|
+
return ts7.ScriptKind.JS;
|
|
995
997
|
};
|
|
996
|
-
var isIterationStatement = (node) =>
|
|
998
|
+
var isIterationStatement = (node) => ts7.isForStatement(node) || ts7.isForOfStatement(node) || ts7.isForInStatement(node) || ts7.isWhileStatement(node) || ts7.isDoStatement(node);
|
|
997
999
|
var unwrapLabeled = (node) => {
|
|
998
1000
|
let current = node;
|
|
999
|
-
while (
|
|
1001
|
+
while (ts7.isLabeledStatement(current)) current = current.statement;
|
|
1000
1002
|
return current;
|
|
1001
1003
|
};
|
|
1002
1004
|
var hasInvalidLabelJump = (sourceFile) => {
|
|
1003
1005
|
const visit = (node, labels) => {
|
|
1004
|
-
if (
|
|
1006
|
+
if (ts7.isFunctionLike(node)) {
|
|
1005
1007
|
let nestedInvalid = false;
|
|
1006
|
-
|
|
1008
|
+
ts7.forEachChild(node, (child) => {
|
|
1007
1009
|
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
1008
1010
|
});
|
|
1009
1011
|
return nestedInvalid;
|
|
1010
1012
|
}
|
|
1011
|
-
if (
|
|
1013
|
+
if (ts7.isLabeledStatement(node)) {
|
|
1012
1014
|
const next = new Map(labels);
|
|
1013
1015
|
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
1014
1016
|
return visit(node.statement, next);
|
|
1015
1017
|
}
|
|
1016
|
-
if (
|
|
1018
|
+
if (ts7.isContinueStatement(node) && node.label) {
|
|
1017
1019
|
if (labels.get(node.label.text) !== true) return true;
|
|
1018
1020
|
}
|
|
1019
|
-
if (
|
|
1021
|
+
if (ts7.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
1020
1022
|
return true;
|
|
1021
1023
|
}
|
|
1022
1024
|
let invalid = false;
|
|
1023
|
-
|
|
1025
|
+
ts7.forEachChild(node, (child) => {
|
|
1024
1026
|
if (visit(child, labels)) invalid = true;
|
|
1025
1027
|
});
|
|
1026
1028
|
return invalid;
|
|
@@ -1063,10 +1065,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
|
1063
1065
|
var transformedSourceIsInvalid = (filePath, code) => {
|
|
1064
1066
|
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
1065
1067
|
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
1066
|
-
const sourceFile =
|
|
1068
|
+
const sourceFile = ts7.createSourceFile(
|
|
1067
1069
|
filePath,
|
|
1068
1070
|
code,
|
|
1069
|
-
|
|
1071
|
+
ts7.ScriptTarget.Latest,
|
|
1070
1072
|
true,
|
|
1071
1073
|
scriptKindFor2(filePath)
|
|
1072
1074
|
);
|
|
@@ -1087,25 +1089,25 @@ var alreadyInstrumentedResult = (source) => ({
|
|
|
1087
1089
|
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
1088
1090
|
});
|
|
1089
1091
|
var scriptKindFor3 = (filePath) => {
|
|
1090
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1091
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1092
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1093
|
-
return
|
|
1092
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
1093
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
1094
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
1095
|
+
return ts8.ScriptKind.JS;
|
|
1094
1096
|
};
|
|
1095
1097
|
var functionName = (node, sourceFile) => {
|
|
1096
|
-
if (
|
|
1098
|
+
if (ts8.isConstructorDeclaration(node)) return "constructor";
|
|
1097
1099
|
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
1098
1100
|
const parent = node.parent;
|
|
1099
|
-
if (
|
|
1100
|
-
if (
|
|
1101
|
-
if (
|
|
1101
|
+
if (ts8.isVariableDeclaration(parent) && ts8.isIdentifier(parent.name)) return parent.name.text;
|
|
1102
|
+
if (ts8.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
1103
|
+
if (ts8.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
1102
1104
|
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
1103
1105
|
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
1104
1106
|
};
|
|
1105
1107
|
var functionLocationPosition = (node, sourceFile) => {
|
|
1106
1108
|
if (node.name) return node.name.getStart(sourceFile);
|
|
1107
1109
|
const parent = node.parent;
|
|
1108
|
-
if ((
|
|
1110
|
+
if ((ts8.isVariableDeclaration(parent) || ts8.isPropertyAssignment(parent)) && parent.name) {
|
|
1109
1111
|
return parent.name.getStart(sourceFile);
|
|
1110
1112
|
}
|
|
1111
1113
|
return node.getStart(sourceFile);
|
|
@@ -1118,12 +1120,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
|
1118
1120
|
}
|
|
1119
1121
|
return end;
|
|
1120
1122
|
};
|
|
1121
|
-
var isStaticPropertyName = (name) =>
|
|
1123
|
+
var isStaticPropertyName = (name) => ts8.isIdentifier(name) || ts8.isStringLiteral(name) || ts8.isNoSubstitutionTemplateLiteral(name) || ts8.isNumericLiteral(name);
|
|
1122
1124
|
var canReconstructBinding = (name) => {
|
|
1123
|
-
if (
|
|
1124
|
-
if (
|
|
1125
|
+
if (ts8.isIdentifier(name)) return true;
|
|
1126
|
+
if (ts8.isArrayBindingPattern(name)) {
|
|
1125
1127
|
return name.elements.every(
|
|
1126
|
-
(element) =>
|
|
1128
|
+
(element) => ts8.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
1127
1129
|
);
|
|
1128
1130
|
}
|
|
1129
1131
|
return name.elements.every((element) => {
|
|
@@ -1132,10 +1134,10 @@ var canReconstructBinding = (name) => {
|
|
|
1132
1134
|
});
|
|
1133
1135
|
};
|
|
1134
1136
|
var bindingValue = (name, sourceFile) => {
|
|
1135
|
-
if (
|
|
1136
|
-
if (
|
|
1137
|
+
if (ts8.isIdentifier(name)) return name.text;
|
|
1138
|
+
if (ts8.isArrayBindingPattern(name)) {
|
|
1137
1139
|
const values = name.elements.map((element) => {
|
|
1138
|
-
if (
|
|
1140
|
+
if (ts8.isOmittedExpression(element)) return "";
|
|
1139
1141
|
const value = bindingValue(element.name, sourceFile);
|
|
1140
1142
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
1141
1143
|
});
|
|
@@ -1145,7 +1147,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1145
1147
|
const value = bindingValue(element.name, sourceFile);
|
|
1146
1148
|
if (element.dotDotDotToken) return `...${value}`;
|
|
1147
1149
|
if (!element.propertyName) return value;
|
|
1148
|
-
const key =
|
|
1150
|
+
const key = ts8.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
1149
1151
|
return `${key}:${value}`;
|
|
1150
1152
|
});
|
|
1151
1153
|
return `{${properties.join(",")}}`;
|
|
@@ -1153,7 +1155,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1153
1155
|
var arrowArgsCapture = (node) => {
|
|
1154
1156
|
const sourceFile = node.getSourceFile();
|
|
1155
1157
|
const params = node.parameters.filter(
|
|
1156
|
-
(parameter) => !(
|
|
1158
|
+
(parameter) => !(ts8.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
1157
1159
|
);
|
|
1158
1160
|
if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
|
|
1159
1161
|
return {
|
|
@@ -1168,13 +1170,13 @@ var arrowArgsCapture = (node) => {
|
|
|
1168
1170
|
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
1169
1171
|
};
|
|
1170
1172
|
var isSupportedFunction = (node) => {
|
|
1171
|
-
if (!
|
|
1173
|
+
if (!ts8.isFunctionDeclaration(node) && !ts8.isFunctionExpression(node) && !ts8.isArrowFunction(node) && !ts8.isMethodDeclaration(node) && !ts8.isGetAccessorDeclaration(node) && !ts8.isSetAccessorDeclaration(node)) {
|
|
1172
1174
|
return false;
|
|
1173
1175
|
}
|
|
1174
1176
|
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
1175
1177
|
return true;
|
|
1176
1178
|
};
|
|
1177
|
-
var isDirectivePrologue = (statement) =>
|
|
1179
|
+
var isDirectivePrologue = (statement) => ts8.isExpressionStatement(statement) && ts8.isStringLiteral(statement.expression);
|
|
1178
1180
|
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
1179
1181
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
1180
1182
|
let end = shebangEnd;
|
|
@@ -1225,7 +1227,7 @@ var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
|
1225
1227
|
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
1226
1228
|
for (const statement of body.statements) {
|
|
1227
1229
|
if (isDirectivePrologue(statement)) continue;
|
|
1228
|
-
if (
|
|
1230
|
+
if (ts8.isExpressionStatement(statement) && ts8.isCallExpression(statement.expression) && statement.expression.expression.kind === ts8.SyntaxKind.SuperKeyword) {
|
|
1229
1231
|
return statement.end;
|
|
1230
1232
|
}
|
|
1231
1233
|
break;
|
|
@@ -1236,15 +1238,15 @@ var failEpilogue = (handleName, errorName, args2, restoreOnCatch) => `}catch(${e
|
|
|
1236
1238
|
var walkOwnBody = (node, visitNode) => {
|
|
1237
1239
|
if (!node.body) return;
|
|
1238
1240
|
const visit = (candidate) => {
|
|
1239
|
-
if (candidate !== node &&
|
|
1241
|
+
if (candidate !== node && ts8.isFunctionLike(candidate)) return;
|
|
1240
1242
|
visitNode(candidate);
|
|
1241
|
-
|
|
1243
|
+
ts8.forEachChild(candidate, visit);
|
|
1242
1244
|
};
|
|
1243
1245
|
visit(node.body);
|
|
1244
1246
|
};
|
|
1245
1247
|
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1246
1248
|
walkOwnBody(node, (candidate) => {
|
|
1247
|
-
if (!
|
|
1249
|
+
if (!ts8.isAwaitExpression(candidate)) return;
|
|
1248
1250
|
wrap(
|
|
1249
1251
|
edits,
|
|
1250
1252
|
candidate.expression.getStart(sourceFile),
|
|
@@ -1265,7 +1267,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1265
1267
|
};
|
|
1266
1268
|
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
1267
1269
|
walkOwnBody(node, (candidate) => {
|
|
1268
|
-
if (!
|
|
1270
|
+
if (!ts8.isTryStatement(candidate)) return;
|
|
1269
1271
|
const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
|
|
1270
1272
|
for (const block of blocks) {
|
|
1271
1273
|
if (!block) continue;
|
|
@@ -1281,10 +1283,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
|
|
|
1281
1283
|
});
|
|
1282
1284
|
};
|
|
1283
1285
|
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1284
|
-
if (!node.body || !
|
|
1286
|
+
if (!node.body || !ts8.isBlock(node.body)) return;
|
|
1285
1287
|
const visit = (candidate, at) => {
|
|
1286
|
-
if (candidate !== node &&
|
|
1287
|
-
if (
|
|
1288
|
+
if (candidate !== node && ts8.isFunctionLike(candidate)) return;
|
|
1289
|
+
if (ts8.isReturnStatement(candidate) && candidate.expression) {
|
|
1288
1290
|
const expression = candidate.expression;
|
|
1289
1291
|
wrap(
|
|
1290
1292
|
edits,
|
|
@@ -1296,17 +1298,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1296
1298
|
);
|
|
1297
1299
|
return;
|
|
1298
1300
|
}
|
|
1299
|
-
|
|
1301
|
+
ts8.forEachChild(candidate, (child) => visit(child, at + 1));
|
|
1300
1302
|
};
|
|
1301
1303
|
visit(node.body, depth + 1);
|
|
1302
1304
|
};
|
|
1303
1305
|
var transformSource = (source, options) => {
|
|
1304
1306
|
if (source.includes("@rasputin-ignore-file")) return void 0;
|
|
1305
1307
|
if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
|
|
1306
|
-
const sourceFile =
|
|
1308
|
+
const sourceFile = ts8.createSourceFile(
|
|
1307
1309
|
options.filePath,
|
|
1308
1310
|
source,
|
|
1309
|
-
|
|
1311
|
+
ts8.ScriptTarget.Latest,
|
|
1310
1312
|
true,
|
|
1311
1313
|
scriptKindFor3(options.filePath)
|
|
1312
1314
|
);
|
|
@@ -1349,7 +1351,7 @@ var transformSource = (source, options) => {
|
|
|
1349
1351
|
collected.asyncFunction = true;
|
|
1350
1352
|
skipFunction(collected, "unsupported_async_generator");
|
|
1351
1353
|
}
|
|
1352
|
-
|
|
1354
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1353
1355
|
return;
|
|
1354
1356
|
}
|
|
1355
1357
|
if (isSyncGeneratorLike(node) && node.body) {
|
|
@@ -1360,10 +1362,10 @@ var transformSource = (source, options) => {
|
|
|
1360
1362
|
options.mapLocation
|
|
1361
1363
|
);
|
|
1362
1364
|
if (collected) skipFunction(collected, "unsupported_sync_generator");
|
|
1363
|
-
|
|
1365
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1364
1366
|
return;
|
|
1365
1367
|
}
|
|
1366
|
-
if (
|
|
1368
|
+
if (ts8.isConstructorDeclaration(node) && node.body) {
|
|
1367
1369
|
const collected = collectWrappedFunction(
|
|
1368
1370
|
node,
|
|
1369
1371
|
sourceFile,
|
|
@@ -1371,13 +1373,22 @@ var transformSource = (source, options) => {
|
|
|
1371
1373
|
options.mapLocation
|
|
1372
1374
|
);
|
|
1373
1375
|
if (collected) skipFunction(collected, "unsupported_constructor");
|
|
1374
|
-
|
|
1376
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1375
1377
|
return;
|
|
1376
1378
|
}
|
|
1377
1379
|
if (isSupportedFunction(node)) {
|
|
1378
1380
|
const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
|
|
1379
1381
|
if (!collected) {
|
|
1380
|
-
|
|
1382
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
if (options.decideFunction?.({
|
|
1386
|
+
node,
|
|
1387
|
+
sourceFile,
|
|
1388
|
+
filePath: options.filePath,
|
|
1389
|
+
name: collected.name
|
|
1390
|
+
}) === "skip") {
|
|
1391
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1381
1392
|
return;
|
|
1382
1393
|
}
|
|
1383
1394
|
const asyncFunction = isAsyncFunctionLike(node);
|
|
@@ -1385,7 +1396,7 @@ var transformSource = (source, options) => {
|
|
|
1385
1396
|
const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
1386
1397
|
if (decision.action === "skip") {
|
|
1387
1398
|
skipFunction(collected, decision.reason);
|
|
1388
|
-
|
|
1399
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1389
1400
|
return;
|
|
1390
1401
|
}
|
|
1391
1402
|
if (functionHasPreBodyParameterEvaluation(node)) {
|
|
@@ -1398,29 +1409,29 @@ var transformSource = (source, options) => {
|
|
|
1398
1409
|
suspendResume: decision.action === "suspend_resume"
|
|
1399
1410
|
});
|
|
1400
1411
|
delta.functions.push(collected);
|
|
1401
|
-
|
|
1412
|
+
ts8.forEachChild(node, (child) => visit(child, collected, depth + 1));
|
|
1402
1413
|
return;
|
|
1403
1414
|
}
|
|
1404
|
-
if (caller && (
|
|
1415
|
+
if (caller && (ts8.isCallExpression(node) || ts8.isNewExpression(node))) {
|
|
1405
1416
|
const site = collectCallSite(node, caller, collectContext);
|
|
1406
1417
|
if (site) delta.callSites.push(site);
|
|
1407
1418
|
}
|
|
1408
|
-
if (caller &&
|
|
1419
|
+
if (caller && ts8.isVariableDeclaration(node)) {
|
|
1409
1420
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
1410
1421
|
if (destructure) delta.destructures.push(destructure);
|
|
1411
1422
|
}
|
|
1412
|
-
|
|
1423
|
+
ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1413
1424
|
};
|
|
1414
1425
|
visit(sourceFile, void 0, 0);
|
|
1415
1426
|
if (pending.length === 0) {
|
|
1416
1427
|
return delta.functions.length > 0 ? { code: source, delta } : void 0;
|
|
1417
1428
|
}
|
|
1418
1429
|
for (const [planIndex, entry] of pending.entries()) {
|
|
1419
|
-
const captured =
|
|
1430
|
+
const captured = ts8.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
|
|
1420
1431
|
const omitArg = captured.omitValues ? ",true" : "";
|
|
1421
1432
|
const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
|
|
1422
1433
|
const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
|
|
1423
|
-
if (
|
|
1434
|
+
if (ts8.isBlock(entry.node.body)) {
|
|
1424
1435
|
const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
|
|
1425
1436
|
const closeAt = entry.node.body.end - 1;
|
|
1426
1437
|
wrap(
|
|
@@ -1504,25 +1515,26 @@ var transformSource = (source, options) => {
|
|
|
1504
1515
|
}
|
|
1505
1516
|
return {
|
|
1506
1517
|
code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
|
|
1507
|
-
delta
|
|
1518
|
+
delta,
|
|
1519
|
+
map: exactTransformMap(source, transformed, basename(options.filePath), edits)
|
|
1508
1520
|
};
|
|
1509
1521
|
};
|
|
1510
1522
|
|
|
1511
1523
|
// ../instrumentation/src/json-producer-sites.ts
|
|
1512
|
-
import
|
|
1524
|
+
import ts10 from "typescript";
|
|
1513
1525
|
|
|
1514
1526
|
// ../instrumentation/src/literal-sites.ts
|
|
1515
|
-
import
|
|
1527
|
+
import ts11 from "typescript";
|
|
1516
1528
|
|
|
1517
1529
|
// ../instrumentation/src/observe-sites.ts
|
|
1518
1530
|
import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
|
|
1519
|
-
import
|
|
1531
|
+
import ts12 from "typescript";
|
|
1520
1532
|
|
|
1521
1533
|
// ../instrumentation/src/verify-browser-source.ts
|
|
1522
|
-
import
|
|
1534
|
+
import ts13 from "typescript";
|
|
1523
1535
|
|
|
1524
1536
|
// ../instrumentation/src/provenance-function-edits.ts
|
|
1525
|
-
import
|
|
1537
|
+
import ts14 from "typescript";
|
|
1526
1538
|
|
|
1527
1539
|
// ../instrumentation/src/source-map-location.ts
|
|
1528
1540
|
import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
|