@rasputin-ai/sveltekit 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/client/options.d.ts +2 -1
- package/dist/client/options.d.ts.map +1 -1
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +31 -6
- package/dist/sdk-meta.d.ts +1 -1
- package/dist/vite/index.js +687 -383
- package/dist/vite/plugin.d.ts +2 -1
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/upload-build-artifacts.d.ts.map +1 -1
- package/dist/vite/virtual-identity.d.ts +2 -1
- package/dist/vite/virtual-identity.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/vite/index.js
CHANGED
|
@@ -1345,12 +1345,31 @@ var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) =
|
|
|
1345
1345
|
` : `${withoutUpstream}${comment}`;
|
|
1346
1346
|
};
|
|
1347
1347
|
|
|
1348
|
+
// ../instrumentation/src/function-metric-declaration-registration.ts
|
|
1349
|
+
var SOURCEMAP_COMMENT2 = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
|
|
1350
|
+
var FUNCTION_METRIC_DECLARATION_REGISTER = "__rasputinRegisterFunctionMetricDeclarations";
|
|
1351
|
+
var FUNCTION_METRIC_DECLARATION_PENDING = "__rasputinPendingFunctionMetricDeclarations";
|
|
1352
|
+
var withFunctionMetricDeclarationRegistration = (code, declarations) => {
|
|
1353
|
+
const parts = [];
|
|
1354
|
+
if (declarations && declarations.length > 0) {
|
|
1355
|
+
parts.push(
|
|
1356
|
+
`((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)})`
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
if (parts.length === 0) return code;
|
|
1360
|
+
const suffix = `;${parts.join(";")};
|
|
1361
|
+
`;
|
|
1362
|
+
const match = SOURCEMAP_COMMENT2.exec(code);
|
|
1363
|
+
if (!match) return `${code}${suffix}`;
|
|
1364
|
+
return `${code.slice(0, match.index)}${suffix}${code.slice(match.index)}`;
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1348
1367
|
// ../instrumentation/src/instrument-browser-source.ts
|
|
1349
1368
|
import { basename as basename2 } from "node:path";
|
|
1350
1369
|
|
|
1351
1370
|
// ../instrumentation/src/browser-function-edits.ts
|
|
1352
1371
|
import { propertyNameIsSensitive } from "@rasputin-ai/core";
|
|
1353
|
-
import
|
|
1372
|
+
import ts10 from "typescript";
|
|
1354
1373
|
|
|
1355
1374
|
// ../instrumentation/src/suspension-whitelist.ts
|
|
1356
1375
|
import ts4 from "typescript";
|
|
@@ -1481,34 +1500,286 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
|
1481
1500
|
|
|
1482
1501
|
// ../instrumentation/src/transform-source.ts
|
|
1483
1502
|
import { basename, resolve as resolve3 } from "node:path";
|
|
1484
|
-
import
|
|
1503
|
+
import ts9 from "typescript";
|
|
1485
1504
|
|
|
1486
|
-
// ../instrumentation/src/
|
|
1505
|
+
// ../instrumentation/src/function-metric-declarations.ts
|
|
1506
|
+
import {
|
|
1507
|
+
canonicalizeFunctionIdentityPath,
|
|
1508
|
+
FUNCTION_IDENTITY_VERSION,
|
|
1509
|
+
functionIdentityKey,
|
|
1510
|
+
sha256Hex,
|
|
1511
|
+
sourceLocatorFromFile as sourceLocatorFromFile2
|
|
1512
|
+
} from "@rasputin-ai/core";
|
|
1487
1513
|
import ts5 from "typescript";
|
|
1514
|
+
var printer = ts5.createPrinter({ removeComments: true, newLine: ts5.NewLineKind.LineFeed });
|
|
1515
|
+
var propertyText = (name) => {
|
|
1516
|
+
if (!name) return void 0;
|
|
1517
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
1518
|
+
return name.text;
|
|
1519
|
+
}
|
|
1520
|
+
if (ts5.isNoSubstitutionTemplateLiteral(name)) return name.text;
|
|
1521
|
+
return void 0;
|
|
1522
|
+
};
|
|
1523
|
+
var hasStaticModifier = (node) => {
|
|
1524
|
+
if (!ts5.canHaveModifiers(node)) return false;
|
|
1525
|
+
const modifiers = ts5.getModifiers(node);
|
|
1526
|
+
if (!modifiers) return false;
|
|
1527
|
+
return modifiers.some((modifier) => modifier.kind === ts5.SyntaxKind.StaticKeyword);
|
|
1528
|
+
};
|
|
1529
|
+
var memberIsStatic = (node) => {
|
|
1530
|
+
if (hasStaticModifier(node)) return true;
|
|
1531
|
+
const parent = node.parent;
|
|
1532
|
+
const isPropertyValue = ts5.isArrowFunction(node) || ts5.isFunctionExpression(node);
|
|
1533
|
+
if (!isPropertyValue || !ts5.isPropertyDeclaration(parent)) return false;
|
|
1534
|
+
return hasStaticModifier(parent);
|
|
1535
|
+
};
|
|
1536
|
+
var kindOf = (node) => {
|
|
1537
|
+
if (ts5.isConstructorDeclaration(node)) return "constructor";
|
|
1538
|
+
if (ts5.isGetAccessor(node)) return "getter";
|
|
1539
|
+
if (ts5.isSetAccessor(node)) return "setter";
|
|
1540
|
+
if (ts5.isMethodDeclaration(node)) return "method";
|
|
1541
|
+
if (ts5.isArrowFunction(node)) return "arrow";
|
|
1542
|
+
return "function";
|
|
1543
|
+
};
|
|
1544
|
+
var bindingOf = (node) => {
|
|
1545
|
+
if (ts5.isConstructorDeclaration(node)) return "constructor";
|
|
1546
|
+
const ownName = propertyText(node.name);
|
|
1547
|
+
if (ownName) return ownName;
|
|
1548
|
+
const parent = node.parent;
|
|
1549
|
+
if (ts5.isVariableDeclaration(parent) && ts5.isIdentifier(parent.name)) {
|
|
1550
|
+
return parent.name.text;
|
|
1551
|
+
}
|
|
1552
|
+
if (ts5.isPropertyAssignment(parent) || ts5.isPropertyDeclaration(parent)) {
|
|
1553
|
+
return propertyText(parent.name);
|
|
1554
|
+
}
|
|
1555
|
+
return void 0;
|
|
1556
|
+
};
|
|
1557
|
+
var calleeText = (expression) => {
|
|
1558
|
+
if (ts5.isIdentifier(expression)) return expression.text;
|
|
1559
|
+
if (!ts5.isPropertyAccessExpression(expression) || !ts5.isIdentifier(expression.name)) {
|
|
1560
|
+
return void 0;
|
|
1561
|
+
}
|
|
1562
|
+
const object = calleeText(expression.expression);
|
|
1563
|
+
if (!object) return void 0;
|
|
1564
|
+
return `${object}.${expression.name.text}`;
|
|
1565
|
+
};
|
|
1566
|
+
var soleCallbackCallee = (node) => {
|
|
1567
|
+
const parent = node.parent;
|
|
1568
|
+
if (ts5.isCallExpression(parent)) {
|
|
1569
|
+
if (parent.arguments.length !== 1 || parent.arguments[0] !== node) return void 0;
|
|
1570
|
+
return parent.expression;
|
|
1571
|
+
}
|
|
1572
|
+
if (!ts5.isNewExpression(parent) || !parent.arguments) return void 0;
|
|
1573
|
+
if (parent.arguments.length !== 1 || parent.arguments[0] !== node) return void 0;
|
|
1574
|
+
return parent.expression;
|
|
1575
|
+
};
|
|
1576
|
+
var withScope = (scopes, kind, name) => {
|
|
1577
|
+
if (!name) return scopes;
|
|
1578
|
+
return [...scopes, { kind, name }];
|
|
1579
|
+
};
|
|
1580
|
+
var fingerprintOf = (node, sourceFile) => {
|
|
1581
|
+
const printed = printer.printNode(ts5.EmitHint.Unspecified, node, sourceFile);
|
|
1582
|
+
const normalized = printed.replace(/\s+/g, "");
|
|
1583
|
+
return `fp1_${sha256Hex(normalized)}`;
|
|
1584
|
+
};
|
|
1585
|
+
var sourceRange = (node, sourceFile, filePath, mapLocation) => {
|
|
1586
|
+
const start = mappedLocation(sourceFile, node.getStart(sourceFile), filePath, mapLocation);
|
|
1587
|
+
const end = mappedLocation(sourceFile, node.end, filePath, mapLocation);
|
|
1588
|
+
if (!start || !end) return null;
|
|
1589
|
+
return {
|
|
1590
|
+
start_line: start.line,
|
|
1591
|
+
start_column: start.column,
|
|
1592
|
+
end_line: end.line,
|
|
1593
|
+
end_column: end.column
|
|
1594
|
+
};
|
|
1595
|
+
};
|
|
1596
|
+
var isFunctionNode = (node) => {
|
|
1597
|
+
const isFunction = ts5.isFunctionDeclaration(node) || ts5.isFunctionExpression(node) || ts5.isArrowFunction(node) || ts5.isMethodDeclaration(node) || ts5.isGetAccessor(node) || ts5.isSetAccessor(node) || ts5.isConstructorDeclaration(node);
|
|
1598
|
+
return isFunction && Boolean(node.body);
|
|
1599
|
+
};
|
|
1600
|
+
var anchoredName = (candidate, anchorCount) => {
|
|
1601
|
+
if (candidate.binding || !candidate.anchor) return void 0;
|
|
1602
|
+
if (anchorCount.get(candidate.anchor) !== 1) return void 0;
|
|
1603
|
+
const binding = candidate.anchor.split(".").at(-1) ?? candidate.anchor;
|
|
1604
|
+
return {
|
|
1605
|
+
binding,
|
|
1606
|
+
scopes: withScope(candidate.scopes, "property", candidate.anchor)
|
|
1607
|
+
};
|
|
1608
|
+
};
|
|
1609
|
+
var stableDescriptor = (candidate, packagePath, packageName, anchorCount) => {
|
|
1610
|
+
const anchored = anchoredName(candidate, anchorCount);
|
|
1611
|
+
const binding = candidate.binding ?? anchored?.binding;
|
|
1612
|
+
const scopes = anchored?.scopes ?? candidate.scopes;
|
|
1613
|
+
if (candidate.ancestorAmbiguous || !binding || !packagePath || !packageName) return void 0;
|
|
1614
|
+
return {
|
|
1615
|
+
identity_version: FUNCTION_IDENTITY_VERSION,
|
|
1616
|
+
identity_kind: "stable",
|
|
1617
|
+
source_basis: "package",
|
|
1618
|
+
package_name: packageName,
|
|
1619
|
+
path: packagePath,
|
|
1620
|
+
scopes,
|
|
1621
|
+
declaration_kind: candidate.kind,
|
|
1622
|
+
binding_name: binding,
|
|
1623
|
+
is_static: candidate.isStatic
|
|
1624
|
+
};
|
|
1625
|
+
};
|
|
1626
|
+
var walkCandidates = (sourceFile, runtimeIdByNode) => {
|
|
1627
|
+
const candidates = [];
|
|
1628
|
+
const visit = (node, scopes, ancestorAmbiguous, parent) => {
|
|
1629
|
+
if (isFunctionNode(node)) {
|
|
1630
|
+
const binding = bindingOf(node);
|
|
1631
|
+
const index = candidates.length;
|
|
1632
|
+
const callee = binding ? void 0 : soleCallbackCallee(node);
|
|
1633
|
+
candidates.push({
|
|
1634
|
+
node,
|
|
1635
|
+
scopes,
|
|
1636
|
+
ancestorAmbiguous,
|
|
1637
|
+
binding,
|
|
1638
|
+
kind: kindOf(node),
|
|
1639
|
+
isStatic: memberIsStatic(node),
|
|
1640
|
+
anchor: callee ? calleeText(callee) : void 0,
|
|
1641
|
+
parent,
|
|
1642
|
+
runtimeId: runtimeIdByNode.get(node)
|
|
1643
|
+
});
|
|
1644
|
+
const nextScopes = binding && !ancestorAmbiguous ? withScope(scopes, "function", binding) : scopes;
|
|
1645
|
+
const childAmbiguous = ancestorAmbiguous || !binding;
|
|
1646
|
+
ts5.forEachChild(node, (child) => visit(child, nextScopes, childAmbiguous, index));
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
if ((ts5.isClassDeclaration(node) || ts5.isClassExpression(node)) && node.name) {
|
|
1650
|
+
const next = withScope(scopes, "class", node.name.text);
|
|
1651
|
+
ts5.forEachChild(node, (child) => visit(child, next, ancestorAmbiguous, parent));
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
if (ts5.isModuleDeclaration(node) && ts5.isIdentifier(node.name)) {
|
|
1655
|
+
const next = withScope(scopes, "namespace", node.name.text);
|
|
1656
|
+
ts5.forEachChild(node, (child) => visit(child, next, ancestorAmbiguous, parent));
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
if (ts5.isVariableDeclaration(node) && ts5.isIdentifier(node.name) && node.initializer && ts5.isObjectLiteralExpression(node.initializer)) {
|
|
1660
|
+
visit(
|
|
1661
|
+
node.initializer,
|
|
1662
|
+
withScope(scopes, "object", node.name.text),
|
|
1663
|
+
ancestorAmbiguous,
|
|
1664
|
+
parent
|
|
1665
|
+
);
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
if (ts5.isPropertyAssignment(node) && node.initializer && ts5.isObjectLiteralExpression(node.initializer)) {
|
|
1669
|
+
const name = propertyText(node.name);
|
|
1670
|
+
visit(node.initializer, withScope(scopes, "property", name), ancestorAmbiguous, parent);
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
ts5.forEachChild(node, (child) => visit(child, scopes, ancestorAmbiguous, parent));
|
|
1674
|
+
};
|
|
1675
|
+
visit(sourceFile, [], false, void 0);
|
|
1676
|
+
return candidates;
|
|
1677
|
+
};
|
|
1678
|
+
var blockDescendants = (candidates, blocked, index) => {
|
|
1679
|
+
if (blocked.has(index)) return;
|
|
1680
|
+
blocked.add(index);
|
|
1681
|
+
for (let child = 0; child < candidates.length; child += 1) {
|
|
1682
|
+
const candidate = candidates[child];
|
|
1683
|
+
if (candidate?.parent === index) blockDescendants(candidates, blocked, child);
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
var releaseScopedDescriptor = (runtimeId) => ({
|
|
1687
|
+
identity_version: FUNCTION_IDENTITY_VERSION,
|
|
1688
|
+
identity_kind: "release_scoped",
|
|
1689
|
+
declaration_id: runtimeId
|
|
1690
|
+
});
|
|
1691
|
+
var collectFunctionMetricDeclarations = (input) => {
|
|
1692
|
+
const runtimeIdByNode = new Map(input.functions.map((item) => [item.node, item.runtimeId]));
|
|
1693
|
+
const candidates = walkCandidates(input.sourceFile, runtimeIdByNode);
|
|
1694
|
+
const anchorCount = /* @__PURE__ */ new Map();
|
|
1695
|
+
for (const candidate of candidates) {
|
|
1696
|
+
if (!candidate.anchor) continue;
|
|
1697
|
+
anchorCount.set(candidate.anchor, (anchorCount.get(candidate.anchor) ?? 0) + 1);
|
|
1698
|
+
}
|
|
1699
|
+
const locator = input.originalAst ? sourceLocatorFromFile2(input.filePath) : void 0;
|
|
1700
|
+
const packageName = locator?.packageName;
|
|
1701
|
+
const packagePath = locator && packageName ? canonicalizeFunctionIdentityPath(locator.packageRelativePath) : void 0;
|
|
1702
|
+
const rows = candidates.map((candidate) => ({
|
|
1703
|
+
candidate,
|
|
1704
|
+
descriptor: stableDescriptor(candidate, packagePath, packageName, anchorCount)
|
|
1705
|
+
}));
|
|
1706
|
+
const keyCount = /* @__PURE__ */ new Map();
|
|
1707
|
+
for (const row of rows) {
|
|
1708
|
+
if (!row.descriptor) continue;
|
|
1709
|
+
const key = functionIdentityKey(row.descriptor);
|
|
1710
|
+
keyCount.set(key, (keyCount.get(key) ?? 0) + 1);
|
|
1711
|
+
}
|
|
1712
|
+
const blocked = /* @__PURE__ */ new Set();
|
|
1713
|
+
for (const [index, row] of rows.entries()) {
|
|
1714
|
+
if (!row.descriptor) {
|
|
1715
|
+
blockDescendants(candidates, blocked, index);
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
const key = functionIdentityKey(row.descriptor);
|
|
1719
|
+
if ((keyCount.get(key) ?? 0) > 1) blockDescendants(candidates, blocked, index);
|
|
1720
|
+
}
|
|
1721
|
+
const declarations = [];
|
|
1722
|
+
for (const [index, row] of rows.entries()) {
|
|
1723
|
+
const runtimeId = row.candidate.runtimeId;
|
|
1724
|
+
if (!runtimeId) continue;
|
|
1725
|
+
const range = sourceRange(
|
|
1726
|
+
row.candidate.node,
|
|
1727
|
+
input.sourceFile,
|
|
1728
|
+
input.filePath,
|
|
1729
|
+
input.mapLocation
|
|
1730
|
+
);
|
|
1731
|
+
const fingerprint = input.originalAst ? fingerprintOf(row.candidate.node, input.sourceFile) : null;
|
|
1732
|
+
const stable = blocked.has(index) ? void 0 : row.descriptor;
|
|
1733
|
+
if (stable) {
|
|
1734
|
+
declarations.push({
|
|
1735
|
+
runtime_id: runtimeId,
|
|
1736
|
+
logical_key: functionIdentityKey(stable),
|
|
1737
|
+
identity_kind: "stable",
|
|
1738
|
+
descriptor: stable,
|
|
1739
|
+
source_range: range,
|
|
1740
|
+
implementation_fingerprint: fingerprint
|
|
1741
|
+
});
|
|
1742
|
+
continue;
|
|
1743
|
+
}
|
|
1744
|
+
const descriptor = releaseScopedDescriptor(runtimeId);
|
|
1745
|
+
declarations.push({
|
|
1746
|
+
runtime_id: runtimeId,
|
|
1747
|
+
logical_key: functionIdentityKey(descriptor),
|
|
1748
|
+
identity_kind: "release_scoped",
|
|
1749
|
+
descriptor,
|
|
1750
|
+
source_range: range,
|
|
1751
|
+
implementation_fingerprint: fingerprint
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
return declarations;
|
|
1755
|
+
};
|
|
1756
|
+
|
|
1757
|
+
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
1758
|
+
import ts6 from "typescript";
|
|
1488
1759
|
var unwrap = (expression) => {
|
|
1489
1760
|
let current = expression;
|
|
1490
|
-
while (
|
|
1761
|
+
while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
|
|
1491
1762
|
current = current.expression;
|
|
1492
1763
|
}
|
|
1493
1764
|
return current;
|
|
1494
1765
|
};
|
|
1495
1766
|
var isSafeLiteralInitializer = (expression) => {
|
|
1496
1767
|
const current = unwrap(expression);
|
|
1497
|
-
if (
|
|
1768
|
+
if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
|
|
1498
1769
|
return true;
|
|
1499
1770
|
}
|
|
1500
|
-
if (current.kind ===
|
|
1771
|
+
if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
|
|
1501
1772
|
return true;
|
|
1502
1773
|
}
|
|
1503
|
-
if (
|
|
1504
|
-
if (
|
|
1505
|
-
return
|
|
1774
|
+
if (ts6.isIdentifier(current) && current.text === "undefined") return true;
|
|
1775
|
+
if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
|
|
1776
|
+
return ts6.isNumericLiteral(unwrap(current.operand));
|
|
1506
1777
|
}
|
|
1507
1778
|
return false;
|
|
1508
1779
|
};
|
|
1509
1780
|
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
1510
1781
|
for (const parameter of node.parameters) {
|
|
1511
|
-
if (
|
|
1782
|
+
if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
1512
1783
|
if (!parameter.initializer) continue;
|
|
1513
1784
|
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
1514
1785
|
}
|
|
@@ -1516,24 +1787,24 @@ var functionHasPreBodyParameterEvaluation = (node) => {
|
|
|
1516
1787
|
};
|
|
1517
1788
|
|
|
1518
1789
|
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
1519
|
-
import
|
|
1790
|
+
import ts7 from "typescript";
|
|
1520
1791
|
var RASPUTIN_IDENT = /^__rasputin/;
|
|
1521
1792
|
var scriptKindFor2 = (filePath) => {
|
|
1522
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1523
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1524
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1525
|
-
return
|
|
1793
|
+
if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
|
|
1794
|
+
if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
|
|
1795
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
|
|
1796
|
+
return ts7.ScriptKind.JS;
|
|
1526
1797
|
};
|
|
1527
|
-
var parse2 = (filePath, source) =>
|
|
1798
|
+
var parse2 = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor2(filePath));
|
|
1528
1799
|
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
1529
1800
|
var identText = (node) => {
|
|
1530
|
-
if (
|
|
1531
|
-
if (
|
|
1801
|
+
if (ts7.isIdentifier(node)) return node.text;
|
|
1802
|
+
if (ts7.isPrivateIdentifier(node)) return node.text;
|
|
1532
1803
|
return void 0;
|
|
1533
1804
|
};
|
|
1534
1805
|
var calleeName = (expression) => {
|
|
1535
|
-
if (
|
|
1536
|
-
if (
|
|
1806
|
+
if (ts7.isIdentifier(expression)) return expression.text;
|
|
1807
|
+
if (ts7.isPropertyAccessExpression(expression)) {
|
|
1537
1808
|
const object = identText(expression.expression);
|
|
1538
1809
|
const property = identText(expression.name);
|
|
1539
1810
|
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
@@ -1541,7 +1812,7 @@ var calleeName = (expression) => {
|
|
|
1541
1812
|
return void 0;
|
|
1542
1813
|
};
|
|
1543
1814
|
var isRasputinCall = (node, methods) => {
|
|
1544
|
-
if (!
|
|
1815
|
+
if (!ts7.isCallExpression(node)) return false;
|
|
1545
1816
|
const name = calleeName(node.expression);
|
|
1546
1817
|
if (!name) return false;
|
|
1547
1818
|
if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
|
|
@@ -1551,20 +1822,20 @@ var unwrapCall = (node) => {
|
|
|
1551
1822
|
let current = node;
|
|
1552
1823
|
while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
|
|
1553
1824
|
current = current.arguments[0];
|
|
1554
|
-
if (
|
|
1825
|
+
if (ts7.isParenthesizedExpression(current)) current = current.expression;
|
|
1555
1826
|
}
|
|
1556
|
-
if (
|
|
1827
|
+
if (ts7.isParenthesizedExpression(current)) return current.expression;
|
|
1557
1828
|
return current;
|
|
1558
1829
|
};
|
|
1559
1830
|
var isRasputinStatement = (node) => {
|
|
1560
|
-
if (
|
|
1561
|
-
if (
|
|
1831
|
+
if (ts7.isEmptyStatement(node)) return true;
|
|
1832
|
+
if (ts7.isVariableStatement(node)) {
|
|
1562
1833
|
return node.declarationList.declarations.every((declaration) => {
|
|
1563
1834
|
const name = identText(declaration.name);
|
|
1564
1835
|
return Boolean(name && isRasputinName(name));
|
|
1565
1836
|
});
|
|
1566
1837
|
}
|
|
1567
|
-
if (
|
|
1838
|
+
if (ts7.isExpressionStatement(node)) {
|
|
1568
1839
|
if (!isRasputinCall(node.expression)) return false;
|
|
1569
1840
|
const unwrapped = unwrapCall(node.expression);
|
|
1570
1841
|
return unwrapped === node.expression;
|
|
@@ -1578,7 +1849,7 @@ var isRasputinTryWrapper = (node) => {
|
|
|
1578
1849
|
(statement) => !isRasputinStatement(statement)
|
|
1579
1850
|
);
|
|
1580
1851
|
const leftover = catchCalls[0];
|
|
1581
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
1852
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
|
|
1582
1853
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
1583
1854
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
1584
1855
|
};
|
|
@@ -1586,7 +1857,7 @@ var flattenStatements = (statements) => {
|
|
|
1586
1857
|
const flattened = [];
|
|
1587
1858
|
for (const statement of statements) {
|
|
1588
1859
|
if (isRasputinStatement(statement)) continue;
|
|
1589
|
-
if (
|
|
1860
|
+
if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
1590
1861
|
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
1591
1862
|
continue;
|
|
1592
1863
|
}
|
|
@@ -1595,38 +1866,38 @@ var flattenStatements = (statements) => {
|
|
|
1595
1866
|
return flattened;
|
|
1596
1867
|
};
|
|
1597
1868
|
var extra = (node) => {
|
|
1598
|
-
if (
|
|
1869
|
+
if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
|
|
1599
1870
|
return isRasputinName(node.text) ? "" : node.text;
|
|
1600
1871
|
}
|
|
1601
|
-
if (
|
|
1872
|
+
if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
|
|
1602
1873
|
return node.text;
|
|
1603
1874
|
}
|
|
1604
|
-
if (
|
|
1875
|
+
if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
|
|
1605
1876
|
return "";
|
|
1606
1877
|
};
|
|
1607
1878
|
var signatureOf = (node) => {
|
|
1608
1879
|
const unwrapped = unwrapCall(node);
|
|
1609
1880
|
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
1610
|
-
if (
|
|
1611
|
-
if (
|
|
1881
|
+
if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
1882
|
+
if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
1612
1883
|
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
1613
1884
|
}
|
|
1614
|
-
if (
|
|
1885
|
+
if (ts7.isBlock(unwrapped)) {
|
|
1615
1886
|
const statements = flattenStatements(unwrapped.statements);
|
|
1616
1887
|
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
1617
1888
|
}
|
|
1618
|
-
if (
|
|
1889
|
+
if (ts7.isCatchClause(unwrapped)) {
|
|
1619
1890
|
const statements = flattenStatements(unwrapped.block.statements);
|
|
1620
1891
|
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
1621
1892
|
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
1622
1893
|
}
|
|
1623
|
-
if (
|
|
1894
|
+
if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
|
|
1624
1895
|
const statements = flattenStatements(unwrapped.body.statements);
|
|
1625
1896
|
const only = statements[0];
|
|
1626
|
-
if (statements.length === 1 && only &&
|
|
1897
|
+
if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
|
|
1627
1898
|
const expression = only.expression;
|
|
1628
1899
|
const parts2 = [];
|
|
1629
|
-
|
|
1900
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
1630
1901
|
if (child === unwrapped.body) {
|
|
1631
1902
|
const part2 = signatureOf(expression);
|
|
1632
1903
|
if (part2) parts2.push(part2);
|
|
@@ -1639,11 +1910,11 @@ var signatureOf = (node) => {
|
|
|
1639
1910
|
}
|
|
1640
1911
|
}
|
|
1641
1912
|
const parts = [];
|
|
1642
|
-
|
|
1913
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
1643
1914
|
const part = signatureOf(child);
|
|
1644
1915
|
if (part) parts.push(part);
|
|
1645
1916
|
});
|
|
1646
|
-
const kind =
|
|
1917
|
+
const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
1647
1918
|
const label = extra(unwrapped);
|
|
1648
1919
|
return `${kind}${label}[${parts.join(",")}]`;
|
|
1649
1920
|
};
|
|
@@ -1652,14 +1923,14 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
|
|
|
1652
1923
|
};
|
|
1653
1924
|
|
|
1654
1925
|
// ../instrumentation/src/verify-transformed-source.ts
|
|
1655
|
-
import
|
|
1656
|
-
var transpileForVerification = (filePath, code) =>
|
|
1926
|
+
import ts8 from "typescript";
|
|
1927
|
+
var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
1657
1928
|
compilerOptions: {
|
|
1658
1929
|
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
1659
|
-
target:
|
|
1660
|
-
module:
|
|
1930
|
+
target: ts8.ScriptTarget.ES2020,
|
|
1931
|
+
module: ts8.ModuleKind.ESNext,
|
|
1661
1932
|
allowJs: true,
|
|
1662
|
-
jsx:
|
|
1933
|
+
jsx: ts8.JsxEmit.React,
|
|
1663
1934
|
experimentalDecorators: true
|
|
1664
1935
|
},
|
|
1665
1936
|
reportDiagnostics: true,
|
|
@@ -1667,7 +1938,7 @@ var transpileForVerification = (filePath, code) => ts7.transpileModule(code, {
|
|
|
1667
1938
|
});
|
|
1668
1939
|
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
1669
1940
|
diagnostics?.some(
|
|
1670
|
-
(diagnostic) => diagnostic.category ===
|
|
1941
|
+
(diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
1671
1942
|
)
|
|
1672
1943
|
);
|
|
1673
1944
|
var scriptBodyForEngine = (emitted) => (
|
|
@@ -1676,39 +1947,39 @@ var scriptBodyForEngine = (emitted) => (
|
|
|
1676
1947
|
);
|
|
1677
1948
|
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
1678
1949
|
var scriptKindFor3 = (filePath) => {
|
|
1679
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1680
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1681
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1682
|
-
return
|
|
1950
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
1951
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
1952
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
1953
|
+
return ts8.ScriptKind.JS;
|
|
1683
1954
|
};
|
|
1684
|
-
var isIterationStatement = (node) =>
|
|
1955
|
+
var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
|
|
1685
1956
|
var unwrapLabeled = (node) => {
|
|
1686
1957
|
let current = node;
|
|
1687
|
-
while (
|
|
1958
|
+
while (ts8.isLabeledStatement(current)) current = current.statement;
|
|
1688
1959
|
return current;
|
|
1689
1960
|
};
|
|
1690
1961
|
var hasInvalidLabelJump = (sourceFile) => {
|
|
1691
1962
|
const visit = (node, labels) => {
|
|
1692
|
-
if (
|
|
1963
|
+
if (ts8.isFunctionLike(node)) {
|
|
1693
1964
|
let nestedInvalid = false;
|
|
1694
|
-
|
|
1965
|
+
ts8.forEachChild(node, (child) => {
|
|
1695
1966
|
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
1696
1967
|
});
|
|
1697
1968
|
return nestedInvalid;
|
|
1698
1969
|
}
|
|
1699
|
-
if (
|
|
1970
|
+
if (ts8.isLabeledStatement(node)) {
|
|
1700
1971
|
const next = new Map(labels);
|
|
1701
1972
|
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
1702
1973
|
return visit(node.statement, next);
|
|
1703
1974
|
}
|
|
1704
|
-
if (
|
|
1975
|
+
if (ts8.isContinueStatement(node) && node.label) {
|
|
1705
1976
|
if (labels.get(node.label.text) !== true) return true;
|
|
1706
1977
|
}
|
|
1707
|
-
if (
|
|
1978
|
+
if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
1708
1979
|
return true;
|
|
1709
1980
|
}
|
|
1710
1981
|
let invalid = false;
|
|
1711
|
-
|
|
1982
|
+
ts8.forEachChild(node, (child) => {
|
|
1712
1983
|
if (visit(child, labels)) invalid = true;
|
|
1713
1984
|
});
|
|
1714
1985
|
return invalid;
|
|
@@ -1751,10 +2022,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
|
1751
2022
|
var transformedSourceIsInvalid = (filePath, code) => {
|
|
1752
2023
|
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
1753
2024
|
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
1754
|
-
const sourceFile =
|
|
2025
|
+
const sourceFile = ts8.createSourceFile(
|
|
1755
2026
|
filePath,
|
|
1756
2027
|
code,
|
|
1757
|
-
|
|
2028
|
+
ts8.ScriptTarget.Latest,
|
|
1758
2029
|
true,
|
|
1759
2030
|
scriptKindFor3(filePath)
|
|
1760
2031
|
);
|
|
@@ -1775,25 +2046,25 @@ var alreadyInstrumentedResult = (source) => ({
|
|
|
1775
2046
|
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
1776
2047
|
});
|
|
1777
2048
|
var scriptKindFor4 = (filePath) => {
|
|
1778
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1779
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1780
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1781
|
-
return
|
|
2049
|
+
if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
|
|
2050
|
+
if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
|
|
2051
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
|
|
2052
|
+
return ts9.ScriptKind.JS;
|
|
1782
2053
|
};
|
|
1783
2054
|
var functionName2 = (node, sourceFile) => {
|
|
1784
|
-
if (
|
|
2055
|
+
if (ts9.isConstructorDeclaration(node)) return "constructor";
|
|
1785
2056
|
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
1786
2057
|
const parent = node.parent;
|
|
1787
|
-
if (
|
|
1788
|
-
if (
|
|
1789
|
-
if (
|
|
2058
|
+
if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
|
|
2059
|
+
if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
2060
|
+
if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
1790
2061
|
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
1791
2062
|
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
1792
2063
|
};
|
|
1793
2064
|
var functionLocationPosition2 = (node, sourceFile) => {
|
|
1794
2065
|
if (node.name) return node.name.getStart(sourceFile);
|
|
1795
2066
|
const parent = node.parent;
|
|
1796
|
-
if ((
|
|
2067
|
+
if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
|
|
1797
2068
|
return parent.name.getStart(sourceFile);
|
|
1798
2069
|
}
|
|
1799
2070
|
return node.getStart(sourceFile);
|
|
@@ -1806,12 +2077,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
|
1806
2077
|
}
|
|
1807
2078
|
return end;
|
|
1808
2079
|
};
|
|
1809
|
-
var isStaticPropertyName = (name) =>
|
|
2080
|
+
var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
|
|
1810
2081
|
var canReconstructBinding = (name) => {
|
|
1811
|
-
if (
|
|
1812
|
-
if (
|
|
2082
|
+
if (ts9.isIdentifier(name)) return true;
|
|
2083
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
1813
2084
|
return name.elements.every(
|
|
1814
|
-
(element) =>
|
|
2085
|
+
(element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
1815
2086
|
);
|
|
1816
2087
|
}
|
|
1817
2088
|
return name.elements.every((element) => {
|
|
@@ -1820,10 +2091,10 @@ var canReconstructBinding = (name) => {
|
|
|
1820
2091
|
});
|
|
1821
2092
|
};
|
|
1822
2093
|
var bindingValue = (name, sourceFile) => {
|
|
1823
|
-
if (
|
|
1824
|
-
if (
|
|
2094
|
+
if (ts9.isIdentifier(name)) return name.text;
|
|
2095
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
1825
2096
|
const values = name.elements.map((element) => {
|
|
1826
|
-
if (
|
|
2097
|
+
if (ts9.isOmittedExpression(element)) return "";
|
|
1827
2098
|
const value = bindingValue(element.name, sourceFile);
|
|
1828
2099
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
1829
2100
|
});
|
|
@@ -1833,7 +2104,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1833
2104
|
const value = bindingValue(element.name, sourceFile);
|
|
1834
2105
|
if (element.dotDotDotToken) return `...${value}`;
|
|
1835
2106
|
if (!element.propertyName) return value;
|
|
1836
|
-
const key =
|
|
2107
|
+
const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
1837
2108
|
return `${key}:${value}`;
|
|
1838
2109
|
});
|
|
1839
2110
|
return `{${properties.join(",")}}`;
|
|
@@ -1841,7 +2112,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1841
2112
|
var arrowArgsCapture = (node) => {
|
|
1842
2113
|
const sourceFile = node.getSourceFile();
|
|
1843
2114
|
const params = node.parameters.filter(
|
|
1844
|
-
(parameter) => !(
|
|
2115
|
+
(parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
1845
2116
|
);
|
|
1846
2117
|
if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
|
|
1847
2118
|
return {
|
|
@@ -1856,13 +2127,13 @@ var arrowArgsCapture = (node) => {
|
|
|
1856
2127
|
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
1857
2128
|
};
|
|
1858
2129
|
var isSupportedFunction2 = (node) => {
|
|
1859
|
-
if (!
|
|
2130
|
+
if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
|
|
1860
2131
|
return false;
|
|
1861
2132
|
}
|
|
1862
2133
|
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
1863
2134
|
return true;
|
|
1864
2135
|
};
|
|
1865
|
-
var isDirectivePrologue = (statement) =>
|
|
2136
|
+
var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
|
|
1866
2137
|
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
1867
2138
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
1868
2139
|
let end = shebangEnd;
|
|
@@ -1913,7 +2184,7 @@ var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
|
1913
2184
|
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
1914
2185
|
for (const statement of body.statements) {
|
|
1915
2186
|
if (isDirectivePrologue(statement)) continue;
|
|
1916
|
-
if (
|
|
2187
|
+
if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
|
|
1917
2188
|
return statement.end;
|
|
1918
2189
|
}
|
|
1919
2190
|
break;
|
|
@@ -1924,15 +2195,15 @@ var failEpilogue = (handleName, errorName, args, restoreOnCatch) => `}catch(${er
|
|
|
1924
2195
|
var walkOwnBody = (node, visitNode) => {
|
|
1925
2196
|
if (!node.body) return;
|
|
1926
2197
|
const visit = (candidate) => {
|
|
1927
|
-
if (candidate !== node &&
|
|
2198
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1928
2199
|
visitNode(candidate);
|
|
1929
|
-
|
|
2200
|
+
ts9.forEachChild(candidate, visit);
|
|
1930
2201
|
};
|
|
1931
2202
|
visit(node.body);
|
|
1932
2203
|
};
|
|
1933
2204
|
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1934
2205
|
walkOwnBody(node, (candidate) => {
|
|
1935
|
-
if (!
|
|
2206
|
+
if (!ts9.isAwaitExpression(candidate)) return;
|
|
1936
2207
|
wrap(
|
|
1937
2208
|
edits,
|
|
1938
2209
|
candidate.expression.getStart(sourceFile),
|
|
@@ -1953,7 +2224,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1953
2224
|
};
|
|
1954
2225
|
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
1955
2226
|
walkOwnBody(node, (candidate) => {
|
|
1956
|
-
if (!
|
|
2227
|
+
if (!ts9.isTryStatement(candidate)) return;
|
|
1957
2228
|
const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
|
|
1958
2229
|
for (const block of blocks) {
|
|
1959
2230
|
if (!block) continue;
|
|
@@ -1969,10 +2240,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
|
|
|
1969
2240
|
});
|
|
1970
2241
|
};
|
|
1971
2242
|
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1972
|
-
if (!node.body || !
|
|
2243
|
+
if (!node.body || !ts9.isBlock(node.body)) return;
|
|
1973
2244
|
const visit = (candidate, at) => {
|
|
1974
|
-
if (candidate !== node &&
|
|
1975
|
-
if (
|
|
2245
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
2246
|
+
if (ts9.isReturnStatement(candidate) && candidate.expression) {
|
|
1976
2247
|
const expression = candidate.expression;
|
|
1977
2248
|
wrap(
|
|
1978
2249
|
edits,
|
|
@@ -1984,17 +2255,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1984
2255
|
);
|
|
1985
2256
|
return;
|
|
1986
2257
|
}
|
|
1987
|
-
|
|
2258
|
+
ts9.forEachChild(candidate, (child) => visit(child, at + 1));
|
|
1988
2259
|
};
|
|
1989
2260
|
visit(node.body, depth + 1);
|
|
1990
2261
|
};
|
|
1991
2262
|
var transformSource = (source, options) => {
|
|
1992
2263
|
if (source.includes("@rasputin-ignore-file")) return void 0;
|
|
1993
2264
|
if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
|
|
1994
|
-
const sourceFile =
|
|
2265
|
+
const sourceFile = ts9.createSourceFile(
|
|
1995
2266
|
options.filePath,
|
|
1996
2267
|
source,
|
|
1997
|
-
|
|
2268
|
+
ts9.ScriptTarget.Latest,
|
|
1998
2269
|
true,
|
|
1999
2270
|
scriptKindFor4(options.filePath)
|
|
2000
2271
|
);
|
|
@@ -2015,10 +2286,31 @@ var transformSource = (source, options) => {
|
|
|
2015
2286
|
absolutePath
|
|
2016
2287
|
};
|
|
2017
2288
|
const pending = [];
|
|
2018
|
-
const
|
|
2289
|
+
const identityNodes = [];
|
|
2290
|
+
const rememberIdentity = (node, collected) => {
|
|
2291
|
+
identityNodes.push({ node, runtimeId: collected.functionId });
|
|
2292
|
+
};
|
|
2293
|
+
const withDeclarations = (result) => {
|
|
2294
|
+
if (!options.functionMetrics) return result;
|
|
2295
|
+
if (identityNodes.length === 0) return { ...result, declarations: [] };
|
|
2296
|
+
const declarations = collectFunctionMetricDeclarations({
|
|
2297
|
+
sourceFile,
|
|
2298
|
+
filePath: options.filePath,
|
|
2299
|
+
functions: identityNodes,
|
|
2300
|
+
originalAst: !options.mapLocation,
|
|
2301
|
+
mapLocation: options.mapLocation
|
|
2302
|
+
});
|
|
2303
|
+
const byId = new Map(declarations.map((declaration) => [declaration.runtime_id, declaration]));
|
|
2304
|
+
for (const fn of result.delta.functions) {
|
|
2305
|
+
fn.metricsDeclaration = byId.get(fn.functionId);
|
|
2306
|
+
}
|
|
2307
|
+
return { ...result, declarations };
|
|
2308
|
+
};
|
|
2309
|
+
const skipFunction = (node, collected, reason) => {
|
|
2019
2310
|
collected.instrumented = false;
|
|
2020
2311
|
collected.skipReason = reason;
|
|
2021
2312
|
delta.functions.push(collected);
|
|
2313
|
+
rememberIdentity(node, collected);
|
|
2022
2314
|
if (process.env.RASPUTIN_DEBUG === "1") {
|
|
2023
2315
|
console.info(
|
|
2024
2316
|
`[rasputin] skipped instrumentation for ${collected.name} in ${options.filePath}: ${reason}`
|
|
@@ -2035,9 +2327,9 @@ var transformSource = (source, options) => {
|
|
|
2035
2327
|
);
|
|
2036
2328
|
if (collected) {
|
|
2037
2329
|
collected.asyncFunction = true;
|
|
2038
|
-
skipFunction(collected, "unsupported_async_generator");
|
|
2330
|
+
skipFunction(node, collected, "unsupported_async_generator");
|
|
2039
2331
|
}
|
|
2040
|
-
|
|
2332
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2041
2333
|
return;
|
|
2042
2334
|
}
|
|
2043
2335
|
if (isSyncGeneratorLike(node) && node.body) {
|
|
@@ -2047,25 +2339,27 @@ var transformSource = (source, options) => {
|
|
|
2047
2339
|
absolutePath,
|
|
2048
2340
|
options.mapLocation
|
|
2049
2341
|
);
|
|
2050
|
-
if (collected)
|
|
2051
|
-
|
|
2342
|
+
if (collected)
|
|
2343
|
+
skipFunction(node, collected, "unsupported_sync_generator");
|
|
2344
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2052
2345
|
return;
|
|
2053
2346
|
}
|
|
2054
|
-
if (
|
|
2347
|
+
if (ts9.isConstructorDeclaration(node) && node.body) {
|
|
2055
2348
|
const collected = collectWrappedFunction(
|
|
2056
2349
|
node,
|
|
2057
2350
|
sourceFile,
|
|
2058
2351
|
absolutePath,
|
|
2059
2352
|
options.mapLocation
|
|
2060
2353
|
);
|
|
2061
|
-
if (collected)
|
|
2062
|
-
|
|
2354
|
+
if (collected)
|
|
2355
|
+
skipFunction(node, collected, "unsupported_constructor");
|
|
2356
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2063
2357
|
return;
|
|
2064
2358
|
}
|
|
2065
2359
|
if (isSupportedFunction2(node)) {
|
|
2066
2360
|
const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
|
|
2067
2361
|
if (!collected) {
|
|
2068
|
-
|
|
2362
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2069
2363
|
return;
|
|
2070
2364
|
}
|
|
2071
2365
|
if (options.decideFunction?.({
|
|
@@ -2074,15 +2368,15 @@ var transformSource = (source, options) => {
|
|
|
2074
2368
|
filePath: options.filePath,
|
|
2075
2369
|
name: collected.name
|
|
2076
2370
|
}) === "skip") {
|
|
2077
|
-
|
|
2371
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2078
2372
|
return;
|
|
2079
2373
|
}
|
|
2080
2374
|
const asyncFunction = isAsyncFunctionLike(node);
|
|
2081
2375
|
collected.asyncFunction = asyncFunction;
|
|
2082
2376
|
const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
2083
2377
|
if (decision.action === "skip") {
|
|
2084
|
-
skipFunction(collected, decision.reason);
|
|
2085
|
-
|
|
2378
|
+
skipFunction(node, collected, decision.reason);
|
|
2379
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2086
2380
|
return;
|
|
2087
2381
|
}
|
|
2088
2382
|
if (functionHasPreBodyParameterEvaluation(node)) {
|
|
@@ -2095,29 +2389,30 @@ var transformSource = (source, options) => {
|
|
|
2095
2389
|
suspendResume: decision.action === "suspend_resume"
|
|
2096
2390
|
});
|
|
2097
2391
|
delta.functions.push(collected);
|
|
2098
|
-
|
|
2392
|
+
rememberIdentity(node, collected);
|
|
2393
|
+
ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
|
|
2099
2394
|
return;
|
|
2100
2395
|
}
|
|
2101
|
-
if (caller && (
|
|
2396
|
+
if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
|
|
2102
2397
|
const site = collectCallSite(node, caller, collectContext);
|
|
2103
2398
|
if (site) delta.callSites.push(site);
|
|
2104
2399
|
}
|
|
2105
|
-
if (caller &&
|
|
2400
|
+
if (caller && ts9.isVariableDeclaration(node)) {
|
|
2106
2401
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
2107
2402
|
if (destructure) delta.destructures.push(destructure);
|
|
2108
2403
|
}
|
|
2109
|
-
|
|
2404
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
2110
2405
|
};
|
|
2111
2406
|
visit(sourceFile, void 0, 0);
|
|
2112
2407
|
if (pending.length === 0) {
|
|
2113
|
-
return delta.functions.length > 0 ? { code: source, delta } : void 0;
|
|
2408
|
+
return delta.functions.length > 0 ? withDeclarations({ code: source, delta }) : void 0;
|
|
2114
2409
|
}
|
|
2115
2410
|
for (const [planIndex, entry] of pending.entries()) {
|
|
2116
|
-
const captured =
|
|
2411
|
+
const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
|
|
2117
2412
|
const omitArg = captured.omitValues ? ",true" : "";
|
|
2118
2413
|
const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
|
|
2119
2414
|
const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
|
|
2120
|
-
if (
|
|
2415
|
+
if (ts9.isBlock(entry.node.body)) {
|
|
2121
2416
|
const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
|
|
2122
2417
|
const closeAt = entry.node.body.end - 1;
|
|
2123
2418
|
wrap(
|
|
@@ -2183,7 +2478,7 @@ var transformSource = (source, options) => {
|
|
|
2183
2478
|
`[rasputin] skipped instrumentation for ${options.filePath}: verification_failed`
|
|
2184
2479
|
);
|
|
2185
2480
|
}
|
|
2186
|
-
return { code: source, delta };
|
|
2481
|
+
return withDeclarations({ code: source, delta });
|
|
2187
2482
|
};
|
|
2188
2483
|
if (verify && transformedSourceIsInvalid(options.filePath, transformed)) {
|
|
2189
2484
|
if (transformedSourceIsInvalid(options.filePath, source)) {
|
|
@@ -2199,11 +2494,11 @@ var transformSource = (source, options) => {
|
|
|
2199
2494
|
if (verify && !instrumentationTreesAreIsomorphic(options.filePath, source, transformed)) {
|
|
2200
2495
|
return refuseTransformed();
|
|
2201
2496
|
}
|
|
2202
|
-
return {
|
|
2497
|
+
return withDeclarations({
|
|
2203
2498
|
code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
|
|
2204
2499
|
delta,
|
|
2205
2500
|
map: exactTransformMap(source, transformed, basename(options.filePath), edits)
|
|
2206
|
-
};
|
|
2501
|
+
});
|
|
2207
2502
|
};
|
|
2208
2503
|
|
|
2209
2504
|
// ../instrumentation/src/browser-function-edits.ts
|
|
@@ -2215,8 +2510,8 @@ var REACTIVE_REG = "__rasputinReg";
|
|
|
2215
2510
|
var OBSERVE_GUARD = "globalThis.__rasputinO??=function(i,v){return v};";
|
|
2216
2511
|
var STRUCT_GUARD = "globalThis.__rasputinK??=function(o){return o};";
|
|
2217
2512
|
var REACTIVE_GUARD = "globalThis.__rasputinR??=function(){return 1};globalThis.__rasputinL??=function(i,v){return v};globalThis.__rasputinT??=function(){};globalThis.__rasputinD??=function(){};globalThis.__rasputinReg??=function(){};";
|
|
2218
|
-
var isWrapTarget = (node) => (
|
|
2219
|
-
var isDirectivePrologue2 = (statement) =>
|
|
2513
|
+
var isWrapTarget = (node) => (ts10.isFunctionDeclaration(node) || ts10.isFunctionExpression(node) || ts10.isArrowFunction(node) || ts10.isMethodDeclaration(node) || ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node)) && node.body !== void 0;
|
|
2514
|
+
var isDirectivePrologue2 = (statement) => ts10.isExpressionStatement(statement) && ts10.isStringLiteral(statement.expression);
|
|
2220
2515
|
var insertPositionAfterPrologue2 = (source, sourceFile) => {
|
|
2221
2516
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
2222
2517
|
let end = shebangEnd;
|
|
@@ -2243,7 +2538,7 @@ var insertAfterSuperOrPrologue2 = (body, sourceFile) => {
|
|
|
2243
2538
|
const end = functionBodyPrologueEnd2(body, sourceFile);
|
|
2244
2539
|
for (const statement of body.statements) {
|
|
2245
2540
|
if (isDirectivePrologue2(statement)) continue;
|
|
2246
|
-
if (
|
|
2541
|
+
if (ts10.isExpressionStatement(statement) && ts10.isCallExpression(statement.expression) && statement.expression.expression.kind === ts10.SyntaxKind.SuperKeyword) {
|
|
2247
2542
|
return statement.end;
|
|
2248
2543
|
}
|
|
2249
2544
|
break;
|
|
@@ -2251,14 +2546,14 @@ var insertAfterSuperOrPrologue2 = (body, sourceFile) => {
|
|
|
2251
2546
|
return end;
|
|
2252
2547
|
};
|
|
2253
2548
|
var functionRef = (node) => {
|
|
2254
|
-
if (node.name &&
|
|
2255
|
-
if (
|
|
2549
|
+
if (node.name && ts10.isIdentifier(node.name)) {
|
|
2550
|
+
if (ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node) || ts10.isMethodDeclaration(node)) {
|
|
2256
2551
|
return void 0;
|
|
2257
2552
|
}
|
|
2258
2553
|
return node.name.text;
|
|
2259
2554
|
}
|
|
2260
2555
|
const parent = node.parent;
|
|
2261
|
-
if (
|
|
2556
|
+
if (ts10.isVariableDeclaration(parent) && ts10.isIdentifier(parent.name) && parent.initializer === node) {
|
|
2262
2557
|
return parent.name.text;
|
|
2263
2558
|
}
|
|
2264
2559
|
return void 0;
|
|
@@ -2271,17 +2566,17 @@ var matchingFunction = (sourceFile, item) => {
|
|
|
2271
2566
|
found2 = node;
|
|
2272
2567
|
return;
|
|
2273
2568
|
}
|
|
2274
|
-
|
|
2569
|
+
ts10.forEachChild(node, visit);
|
|
2275
2570
|
};
|
|
2276
2571
|
visit(sourceFile);
|
|
2277
2572
|
return found2;
|
|
2278
2573
|
};
|
|
2279
|
-
var isStaticPropertyName2 = (name) =>
|
|
2574
|
+
var isStaticPropertyName2 = (name) => ts10.isIdentifier(name) || ts10.isStringLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name) || ts10.isNumericLiteral(name);
|
|
2280
2575
|
var canReconstructBinding2 = (name) => {
|
|
2281
|
-
if (
|
|
2282
|
-
if (
|
|
2576
|
+
if (ts10.isIdentifier(name)) return true;
|
|
2577
|
+
if (ts10.isArrayBindingPattern(name)) {
|
|
2283
2578
|
return name.elements.every(
|
|
2284
|
-
(element) =>
|
|
2579
|
+
(element) => ts10.isOmittedExpression(element) || canReconstructBinding2(element.name)
|
|
2285
2580
|
);
|
|
2286
2581
|
}
|
|
2287
2582
|
return name.elements.every((element) => {
|
|
@@ -2291,16 +2586,16 @@ var canReconstructBinding2 = (name) => {
|
|
|
2291
2586
|
};
|
|
2292
2587
|
var REDACTED_ARG_EXPR = 'Symbol.for("rasputin.redacted.v1")';
|
|
2293
2588
|
var staticBindingKey = (name) => {
|
|
2294
|
-
if (
|
|
2295
|
-
if (
|
|
2296
|
-
if (
|
|
2589
|
+
if (ts10.isIdentifier(name)) return name.text;
|
|
2590
|
+
if (ts10.isStringLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name)) return name.text;
|
|
2591
|
+
if (ts10.isNumericLiteral(name)) return name.text;
|
|
2297
2592
|
return void 0;
|
|
2298
2593
|
};
|
|
2299
2594
|
var bindingHasSensitiveName = (name) => {
|
|
2300
|
-
if (
|
|
2301
|
-
if (
|
|
2595
|
+
if (ts10.isIdentifier(name)) return propertyNameIsSensitive(name.text);
|
|
2596
|
+
if (ts10.isArrayBindingPattern(name)) {
|
|
2302
2597
|
return name.elements.some(
|
|
2303
|
-
(element) => !
|
|
2598
|
+
(element) => !ts10.isOmittedExpression(element) && bindingHasSensitiveName(element.name)
|
|
2304
2599
|
);
|
|
2305
2600
|
}
|
|
2306
2601
|
return name.elements.some((element) => {
|
|
@@ -2310,12 +2605,12 @@ var bindingHasSensitiveName = (name) => {
|
|
|
2310
2605
|
});
|
|
2311
2606
|
};
|
|
2312
2607
|
var capturedBinding = (name, sourceFile) => {
|
|
2313
|
-
if (
|
|
2608
|
+
if (ts10.isIdentifier(name)) {
|
|
2314
2609
|
return propertyNameIsSensitive(name.text) ? REDACTED_ARG_EXPR : name.text;
|
|
2315
2610
|
}
|
|
2316
|
-
if (
|
|
2611
|
+
if (ts10.isArrayBindingPattern(name)) {
|
|
2317
2612
|
const values = name.elements.map((element) => {
|
|
2318
|
-
if (
|
|
2613
|
+
if (ts10.isOmittedExpression(element)) return "";
|
|
2319
2614
|
const value = capturedBinding(element.name, sourceFile);
|
|
2320
2615
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
2321
2616
|
});
|
|
@@ -2323,14 +2618,14 @@ var capturedBinding = (name, sourceFile) => {
|
|
|
2323
2618
|
}
|
|
2324
2619
|
const properties = name.elements.map((element) => {
|
|
2325
2620
|
const key = element.propertyName ? staticBindingKey(element.propertyName) : void 0;
|
|
2326
|
-
const sensitive = key !== void 0 && propertyNameIsSensitive(key) ||
|
|
2621
|
+
const sensitive = key !== void 0 && propertyNameIsSensitive(key) || ts10.isIdentifier(element.name) && propertyNameIsSensitive(element.name.text);
|
|
2327
2622
|
if (element.dotDotDotToken) {
|
|
2328
2623
|
return `...${sensitive ? REDACTED_ARG_EXPR : capturedBinding(element.name, sourceFile)}`;
|
|
2329
2624
|
}
|
|
2330
2625
|
if (!element.propertyName) {
|
|
2331
|
-
return sensitive &&
|
|
2626
|
+
return sensitive && ts10.isIdentifier(element.name) ? `${element.name.text}:${REDACTED_ARG_EXPR}` : capturedBinding(element.name, sourceFile);
|
|
2332
2627
|
}
|
|
2333
|
-
const printedKey =
|
|
2628
|
+
const printedKey = ts10.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
2334
2629
|
return `${printedKey}:${sensitive ? REDACTED_ARG_EXPR : capturedBinding(element.name, sourceFile)}`;
|
|
2335
2630
|
});
|
|
2336
2631
|
return `{${properties.join(",")}}`;
|
|
@@ -2338,12 +2633,12 @@ var capturedBinding = (name, sourceFile) => {
|
|
|
2338
2633
|
var captureArgs = (node) => {
|
|
2339
2634
|
const sourceFile = node.getSourceFile();
|
|
2340
2635
|
const params = node.parameters.filter(
|
|
2341
|
-
(parameter) => !(
|
|
2636
|
+
(parameter) => !(ts10.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
2342
2637
|
);
|
|
2343
2638
|
const reconstructable = params.every((parameter) => canReconstructBinding2(parameter.name));
|
|
2344
2639
|
const sensitive = params.some((parameter) => bindingHasSensitiveName(parameter.name));
|
|
2345
2640
|
if (!reconstructable) {
|
|
2346
|
-
if (
|
|
2641
|
+
if (ts10.isArrowFunction(node) || sensitive) {
|
|
2347
2642
|
return {
|
|
2348
2643
|
args: `[${Array.from({ length: params.length }, () => "void 0").join(",")}]`,
|
|
2349
2644
|
omitValues: true
|
|
@@ -2351,7 +2646,7 @@ var captureArgs = (node) => {
|
|
|
2351
2646
|
}
|
|
2352
2647
|
return { args: "arguments", omitValues: false };
|
|
2353
2648
|
}
|
|
2354
|
-
if (!
|
|
2649
|
+
if (!ts10.isArrowFunction(node) && !sensitive) {
|
|
2355
2650
|
return { args: "arguments", omitValues: false };
|
|
2356
2651
|
}
|
|
2357
2652
|
const values = params.map((parameter) => {
|
|
@@ -2362,16 +2657,16 @@ var captureArgs = (node) => {
|
|
|
2362
2657
|
};
|
|
2363
2658
|
var walkOwnBody2 = (node, visitNode) => {
|
|
2364
2659
|
const visit = (candidate) => {
|
|
2365
|
-
if (candidate !== node &&
|
|
2660
|
+
if (candidate !== node && ts10.isFunctionLike(candidate)) return;
|
|
2366
2661
|
visitNode(candidate);
|
|
2367
|
-
|
|
2662
|
+
ts10.forEachChild(candidate, visit);
|
|
2368
2663
|
};
|
|
2369
2664
|
visit(node.body);
|
|
2370
2665
|
};
|
|
2371
2666
|
var collectReturnWraps2 = (node, sourceFile, handleName, edits, depth) => {
|
|
2372
|
-
if (!
|
|
2667
|
+
if (!ts10.isBlock(node.body)) return;
|
|
2373
2668
|
walkOwnBody2(node, (candidate) => {
|
|
2374
|
-
if (!
|
|
2669
|
+
if (!ts10.isReturnStatement(candidate) || !candidate.expression) return;
|
|
2375
2670
|
wrap(
|
|
2376
2671
|
edits,
|
|
2377
2672
|
candidate.expression.getStart(sourceFile),
|
|
@@ -2384,7 +2679,7 @@ var collectReturnWraps2 = (node, sourceFile, handleName, edits, depth) => {
|
|
|
2384
2679
|
};
|
|
2385
2680
|
var collectAwaitWraps2 = (node, sourceFile, handleName, edits, depth) => {
|
|
2386
2681
|
walkOwnBody2(node, (candidate) => {
|
|
2387
|
-
if (!
|
|
2682
|
+
if (!ts10.isAwaitExpression(candidate)) return;
|
|
2388
2683
|
wrap(
|
|
2389
2684
|
edits,
|
|
2390
2685
|
candidate.expression.getStart(sourceFile),
|
|
@@ -2405,7 +2700,7 @@ var collectAwaitWraps2 = (node, sourceFile, handleName, edits, depth) => {
|
|
|
2405
2700
|
};
|
|
2406
2701
|
var collectCatchFinallyResumes2 = (node, sourceFile, handleName, edits, depth) => {
|
|
2407
2702
|
walkOwnBody2(node, (candidate) => {
|
|
2408
|
-
if (!
|
|
2703
|
+
if (!ts10.isTryStatement(candidate)) return;
|
|
2409
2704
|
for (const block of [candidate.catchClause?.block, candidate.finallyBlock]) {
|
|
2410
2705
|
if (!block) continue;
|
|
2411
2706
|
edits.push({
|
|
@@ -2420,9 +2715,9 @@ var collectCatchFinallyResumes2 = (node, sourceFile, handleName, edits, depth) =
|
|
|
2420
2715
|
});
|
|
2421
2716
|
};
|
|
2422
2717
|
var collectReactiveReturnWraps = (node, sourceFile, siteId, edits, depth) => {
|
|
2423
|
-
if (!
|
|
2718
|
+
if (!ts10.isBlock(node.body)) return;
|
|
2424
2719
|
walkOwnBody2(node, (candidate) => {
|
|
2425
|
-
if (!
|
|
2720
|
+
if (!ts10.isReturnStatement(candidate)) return;
|
|
2426
2721
|
if (!candidate.expression) {
|
|
2427
2722
|
edits.push({
|
|
2428
2723
|
position: candidate.getStart(sourceFile),
|
|
@@ -2488,27 +2783,27 @@ var collectCallerSites = (sourceFile, classifications, functions, absolutePath,
|
|
|
2488
2783
|
if (item) {
|
|
2489
2784
|
const fn = bySpan.get(`${item.start}:${item.end}`);
|
|
2490
2785
|
const next = fn && fn.instrumented !== false ? fn : caller;
|
|
2491
|
-
|
|
2786
|
+
ts10.forEachChild(node, (child) => visit(child, next));
|
|
2492
2787
|
return;
|
|
2493
2788
|
}
|
|
2494
2789
|
}
|
|
2495
|
-
if (caller && (
|
|
2790
|
+
if (caller && (ts10.isCallExpression(node) || ts10.isNewExpression(node))) {
|
|
2496
2791
|
if (policy?.isCompilerCall({
|
|
2497
2792
|
node,
|
|
2498
2793
|
sourceFile,
|
|
2499
2794
|
filePath: absolutePath
|
|
2500
2795
|
})) {
|
|
2501
|
-
|
|
2796
|
+
ts10.forEachChild(node, (child) => visit(child, caller));
|
|
2502
2797
|
return;
|
|
2503
2798
|
}
|
|
2504
2799
|
const site = collectCallSite(node, caller, collectContext);
|
|
2505
2800
|
if (site) callSites.push(site);
|
|
2506
2801
|
}
|
|
2507
|
-
if (caller &&
|
|
2802
|
+
if (caller && ts10.isVariableDeclaration(node)) {
|
|
2508
2803
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
2509
2804
|
if (destructure) destructures.push(destructure);
|
|
2510
2805
|
}
|
|
2511
|
-
|
|
2806
|
+
ts10.forEachChild(node, (child) => visit(child, caller));
|
|
2512
2807
|
};
|
|
2513
2808
|
visit(sourceFile, void 0);
|
|
2514
2809
|
return { callSites, destructures };
|
|
@@ -2569,7 +2864,7 @@ var collectBrowserFunctionEdits = (source, sourceFile, classifications, moduleIn
|
|
|
2569
2864
|
const leave = `${REACTIVE_LEAVE}(${siteId})`;
|
|
2570
2865
|
const fail = `${REACTIVE_THROW}(${siteId},${errorName})`;
|
|
2571
2866
|
const epilogue2 = `}catch(${errorName}){${fail};throw ${errorName};}finally{${REACTIVE_DONE}()}`;
|
|
2572
|
-
if (
|
|
2867
|
+
if (ts10.isBlock(node.body)) {
|
|
2573
2868
|
wrap(
|
|
2574
2869
|
edits,
|
|
2575
2870
|
node.body.getStart(sourceFile) + 1,
|
|
@@ -2614,7 +2909,7 @@ var collectBrowserFunctionEdits = (source, sourceFile, classifications, moduleIn
|
|
|
2614
2909
|
failArgs,
|
|
2615
2910
|
decision.action === "suspend_resume"
|
|
2616
2911
|
);
|
|
2617
|
-
if (
|
|
2912
|
+
if (ts10.isBlock(node.body)) {
|
|
2618
2913
|
const prologueAt = insertAfterSuperOrPrologue2(node.body, sourceFile);
|
|
2619
2914
|
const closeAt = node.body.end - 1;
|
|
2620
2915
|
wrap(edits, prologueAt, closeAt, `;const ${handleName}=${enterCall};try{`, epilogue, 0);
|
|
@@ -2684,7 +2979,7 @@ var collectBrowserFunctionEdits = (source, sourceFile, classifications, moduleIn
|
|
|
2684
2979
|
};
|
|
2685
2980
|
|
|
2686
2981
|
// ../instrumentation/src/json-producer-sites.ts
|
|
2687
|
-
import
|
|
2982
|
+
import ts11 from "typescript";
|
|
2688
2983
|
var JSON_METHOD_CALLEE = "globalThis.__rasputinM";
|
|
2689
2984
|
var JSON_AWAIT_CALLEE = "globalThis.__rasputinA";
|
|
2690
2985
|
var JSON_ADOPT_CALLEE = "globalThis.__rasputinP";
|
|
@@ -2720,35 +3015,35 @@ var NON_PROVENANCE_ROOTS = /* @__PURE__ */ new Set([
|
|
|
2720
3015
|
]);
|
|
2721
3016
|
var isSimpleReceiver = (expression) => {
|
|
2722
3017
|
const receiver = peel(expression);
|
|
2723
|
-
return
|
|
3018
|
+
return ts11.isIdentifier(receiver) || receiver.kind === ts11.SyntaxKind.ThisKeyword;
|
|
2724
3019
|
};
|
|
2725
|
-
var isSimpleIdentifierCall = (node) => !node.questionDotToken &&
|
|
3020
|
+
var isSimpleIdentifierCall = (node) => !node.questionDotToken && ts11.isIdentifier(node.expression);
|
|
2726
3021
|
var isSimpleMethodCall = (node) => {
|
|
2727
3022
|
if (node.questionDotToken) return false;
|
|
2728
3023
|
const callee = node.expression;
|
|
2729
|
-
return
|
|
3024
|
+
return ts11.isPropertyAccessExpression(callee) && !callee.questionDotToken && ts11.isIdentifier(callee.name) && !ts11.isPrivateIdentifier(callee.name) && isSimpleReceiver(callee.expression);
|
|
2730
3025
|
};
|
|
2731
3026
|
var isSimpleProvenanceCall = (node) => isSimpleIdentifierCall(node) || isSimpleMethodCall(node);
|
|
2732
3027
|
var isJsonParseCall = (node) => {
|
|
2733
3028
|
if (!isSimpleMethodCall(node)) return false;
|
|
2734
3029
|
const callee = node.expression;
|
|
2735
|
-
if (!
|
|
3030
|
+
if (!ts11.isPropertyAccessExpression(callee) || callee.name.text !== "parse") return false;
|
|
2736
3031
|
const object = peel(callee.expression);
|
|
2737
|
-
return
|
|
3032
|
+
return ts11.isIdentifier(object) && object.text === "JSON";
|
|
2738
3033
|
};
|
|
2739
3034
|
var methodName = (node) => {
|
|
2740
3035
|
if (!isSimpleMethodCall(node)) return void 0;
|
|
2741
3036
|
const callee = node.expression;
|
|
2742
|
-
return
|
|
3037
|
+
return ts11.isPropertyAccessExpression(callee) ? callee.name.text : void 0;
|
|
2743
3038
|
};
|
|
2744
3039
|
var containsNestedAwaitOrFunction = (node) => {
|
|
2745
3040
|
let found2 = false;
|
|
2746
3041
|
const visit = (candidate) => {
|
|
2747
|
-
if (candidate !== node && (
|
|
3042
|
+
if (candidate !== node && (ts11.isAwaitExpression(candidate) || ts11.isFunctionLike(candidate))) {
|
|
2748
3043
|
found2 = true;
|
|
2749
3044
|
return;
|
|
2750
3045
|
}
|
|
2751
|
-
if (!found2)
|
|
3046
|
+
if (!found2) ts11.forEachChild(candidate, visit);
|
|
2752
3047
|
};
|
|
2753
3048
|
visit(node);
|
|
2754
3049
|
return found2;
|
|
@@ -2762,15 +3057,15 @@ var isAwaitExpressionOf = (node) => {
|
|
|
2762
3057
|
let current = node;
|
|
2763
3058
|
while (current.parent) {
|
|
2764
3059
|
const parent = current.parent;
|
|
2765
|
-
if (
|
|
3060
|
+
if (ts11.isParenthesizedExpression(parent) || ts11.isNonNullExpression(parent) || ts11.isAsExpression(parent) || ts11.isTypeAssertionExpression(parent) || ts11.isSatisfiesExpression(parent)) {
|
|
2766
3061
|
current = parent;
|
|
2767
3062
|
continue;
|
|
2768
3063
|
}
|
|
2769
|
-
return
|
|
3064
|
+
return ts11.isAwaitExpression(parent) && parent.expression === current;
|
|
2770
3065
|
}
|
|
2771
3066
|
return false;
|
|
2772
3067
|
};
|
|
2773
|
-
var isDirectSuperCall = (node) => node.expression.kind ===
|
|
3068
|
+
var isDirectSuperCall = (node) => node.expression.kind === ts11.SyntaxKind.SuperKeyword;
|
|
2774
3069
|
var isPolicyCompilerCall = (node, filePath, sourceFile, policy) => {
|
|
2775
3070
|
if (!policy) return false;
|
|
2776
3071
|
return policy.isCompilerCall({ node, sourceFile, filePath });
|
|
@@ -2779,7 +3074,7 @@ var outerExpression = (node) => {
|
|
|
2779
3074
|
let current = node;
|
|
2780
3075
|
while (current.parent) {
|
|
2781
3076
|
const parent = current.parent;
|
|
2782
|
-
if ((
|
|
3077
|
+
if ((ts11.isParenthesizedExpression(parent) || ts11.isNonNullExpression(parent) || ts11.isAsExpression(parent) || ts11.isTypeAssertionExpression(parent) || ts11.isSatisfiesExpression(parent)) && parent.expression === current) {
|
|
2783
3078
|
current = parent;
|
|
2784
3079
|
continue;
|
|
2785
3080
|
}
|
|
@@ -2791,9 +3086,9 @@ var isReturnedOrBoundCall = (node) => {
|
|
|
2791
3086
|
const expression = outerExpression(node);
|
|
2792
3087
|
const parent = expression.parent;
|
|
2793
3088
|
if (!parent) return false;
|
|
2794
|
-
if (
|
|
2795
|
-
if (
|
|
2796
|
-
if (
|
|
3089
|
+
if (ts11.isReturnStatement(parent) && parent.expression === expression) return true;
|
|
3090
|
+
if (ts11.isVariableDeclaration(parent) && parent.initializer === expression) return true;
|
|
3091
|
+
if (ts11.isBinaryExpression(parent) && parent.right === expression && parent.operatorToken.kind === ts11.SyntaxKind.EqualsToken) {
|
|
2797
3092
|
return true;
|
|
2798
3093
|
}
|
|
2799
3094
|
return false;
|
|
@@ -2803,10 +3098,10 @@ var callCanCarryProvenance = (node) => {
|
|
|
2803
3098
|
if (name === "json" || name === "parse") return true;
|
|
2804
3099
|
if (name === "call" || name === "apply") return false;
|
|
2805
3100
|
const callee = node.expression;
|
|
2806
|
-
if (
|
|
2807
|
-
if (
|
|
3101
|
+
if (ts11.isIdentifier(callee)) return !NON_PROVENANCE_ROOTS.has(callee.text);
|
|
3102
|
+
if (ts11.isPropertyAccessExpression(callee)) {
|
|
2808
3103
|
const object = peel(callee.expression);
|
|
2809
|
-
if (
|
|
3104
|
+
if (ts11.isIdentifier(object) && NON_PROVENANCE_ROOTS.has(object.text)) {
|
|
2810
3105
|
return object.text === "JSON" && callee.name.text === "parse";
|
|
2811
3106
|
}
|
|
2812
3107
|
}
|
|
@@ -2816,7 +3111,7 @@ var shouldAdoptCall = (node, filePath, sourceFile, policy) => {
|
|
|
2816
3111
|
if (isAwaitExpressionOf(node) || isDirectSuperCall(node) || isPolicyCompilerCall(node, filePath, sourceFile, policy)) {
|
|
2817
3112
|
return false;
|
|
2818
3113
|
}
|
|
2819
|
-
if (
|
|
3114
|
+
if (ts11.isComputedPropertyName(outerExpression(node).parent)) return false;
|
|
2820
3115
|
if (!isSimpleProvenanceCall(node)) return false;
|
|
2821
3116
|
return isReturnedOrBoundCall(node) && callCanCarryProvenance(node);
|
|
2822
3117
|
};
|
|
@@ -2828,7 +3123,7 @@ var shouldAdoptAwaitCall = (node, filePath, sourceFile, policy) => {
|
|
|
2828
3123
|
};
|
|
2829
3124
|
var replaceProducerCall = (node, sourceFile, receiverName) => {
|
|
2830
3125
|
const callee = node.expression;
|
|
2831
|
-
if (!
|
|
3126
|
+
if (!ts11.isPropertyAccessExpression(callee)) return node.getText(sourceFile);
|
|
2832
3127
|
const args = node.arguments.map((argument) => argument.getText(sourceFile));
|
|
2833
3128
|
const extra3 = args.length > 0 ? `,${args.join(",")}` : "";
|
|
2834
3129
|
const receiver = callee.expression.getText(sourceFile);
|
|
@@ -2836,10 +3131,10 @@ var replaceProducerCall = (node, sourceFile, receiverName) => {
|
|
|
2836
3131
|
return `((${receiverName})=>${JSON_METHOD_CALLEE}(${receiverName},${method}${extra3}))(${receiver})`;
|
|
2837
3132
|
};
|
|
2838
3133
|
var hasBlockBody = (node) => {
|
|
2839
|
-
if (!
|
|
3134
|
+
if (!ts11.isFunctionDeclaration(node) && !ts11.isFunctionExpression(node) && !ts11.isArrowFunction(node) && !ts11.isMethodDeclaration(node) && !ts11.isConstructorDeclaration(node) && !ts11.isGetAccessorDeclaration(node) && !ts11.isSetAccessorDeclaration(node)) {
|
|
2840
3135
|
return false;
|
|
2841
3136
|
}
|
|
2842
|
-
return node.body !== void 0 &&
|
|
3137
|
+
return node.body !== void 0 && ts11.isBlock(node.body);
|
|
2843
3138
|
};
|
|
2844
3139
|
var owningFunctionBody = (node) => {
|
|
2845
3140
|
let current = node;
|
|
@@ -2870,7 +3165,7 @@ var adoptCall = (edits, node, sourceFile, receiverName, fnName, slotName, slot =
|
|
|
2870
3165
|
const wrapOpen = (inner) => slot ? `(${slotName}={p:${inner}` : inner;
|
|
2871
3166
|
const wrapClose = (inner) => slot ? `${inner}},${slotName}.p)` : inner;
|
|
2872
3167
|
const callee = node.expression;
|
|
2873
|
-
if (
|
|
3168
|
+
if (ts11.isIdentifier(callee)) {
|
|
2874
3169
|
wrap(
|
|
2875
3170
|
edits,
|
|
2876
3171
|
start,
|
|
@@ -2889,7 +3184,7 @@ var adoptCall = (edits, node, sourceFile, receiverName, fnName, slotName, slot =
|
|
|
2889
3184
|
});
|
|
2890
3185
|
return;
|
|
2891
3186
|
}
|
|
2892
|
-
if (!isSimpleMethodCall(node) || !
|
|
3187
|
+
if (!isSimpleMethodCall(node) || !ts11.isPropertyAccessExpression(callee)) return;
|
|
2893
3188
|
const receiver = callee.expression.getText(sourceFile);
|
|
2894
3189
|
const method = callee.name.text;
|
|
2895
3190
|
const open = callOpenParen(node, sourceFile);
|
|
@@ -2938,7 +3233,7 @@ var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(sourc
|
|
|
2938
3233
|
let callWraps = 0;
|
|
2939
3234
|
let provenanceSkippedComplexCall = 0;
|
|
2940
3235
|
const visit = (node) => {
|
|
2941
|
-
if (
|
|
3236
|
+
if (ts11.isCallExpression(node) && isSimpleProducerCall(node) && !isAwaitExpressionOf(node)) {
|
|
2942
3237
|
edits.push({
|
|
2943
3238
|
position: node.getStart(sourceFile),
|
|
2944
3239
|
text: replaceProducerCall(node, sourceFile, receiverName),
|
|
@@ -2948,19 +3243,19 @@ var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(sourc
|
|
|
2948
3243
|
kind: "replace"
|
|
2949
3244
|
});
|
|
2950
3245
|
callWraps += 1;
|
|
2951
|
-
} else if (adoptCalls &&
|
|
3246
|
+
} else if (adoptCalls && ts11.isCallExpression(node) && shouldAdoptCall(node, filePath, sourceFile, options?.policy)) {
|
|
2952
3247
|
adoptCall(edits, node, sourceFile, receiverName, adoptFnName, slotName);
|
|
2953
3248
|
callWraps += 1;
|
|
2954
|
-
} else if (
|
|
3249
|
+
} else if (ts11.isCallExpression(node) && !isAwaitExpressionOf(node) && isReturnedOrBoundCall(node) && skippedComplexCall(node, filePath, sourceFile, options?.policy)) {
|
|
2955
3250
|
provenanceSkippedComplexCall += 1;
|
|
2956
3251
|
}
|
|
2957
|
-
if (
|
|
3252
|
+
if (ts11.isAwaitExpression(node)) {
|
|
2958
3253
|
const inner = peel(node.expression);
|
|
2959
|
-
const producer =
|
|
2960
|
-
const adoptInner = adoptCalls &&
|
|
2961
|
-
const adoptValue = adoptCalls && !
|
|
3254
|
+
const producer = ts11.isCallExpression(inner) && isSimpleProducerCall(inner);
|
|
3255
|
+
const adoptInner = adoptCalls && ts11.isCallExpression(inner) && shouldAdoptAwaitCall(inner, filePath, sourceFile, options?.policy);
|
|
3256
|
+
const adoptValue = adoptCalls && !ts11.isCallExpression(inner);
|
|
2962
3257
|
if (producer || adoptInner || adoptValue) {
|
|
2963
|
-
if (producer &&
|
|
3258
|
+
if (producer && ts11.isCallExpression(inner)) {
|
|
2964
3259
|
edits.push({
|
|
2965
3260
|
position: node.expression.getStart(sourceFile),
|
|
2966
3261
|
text: `(${slotName}={p:${replaceProducerCall(inner, sourceFile, receiverName)}},${slotName}.p)`,
|
|
@@ -2970,7 +3265,7 @@ var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(sourc
|
|
|
2970
3265
|
kind: "replace"
|
|
2971
3266
|
});
|
|
2972
3267
|
callWraps += 1;
|
|
2973
|
-
} else if (adoptInner &&
|
|
3268
|
+
} else if (adoptInner && ts11.isCallExpression(inner)) {
|
|
2974
3269
|
if (node.expression === inner) {
|
|
2975
3270
|
adoptCall(edits, inner, sourceFile, receiverName, adoptFnName, slotName, true);
|
|
2976
3271
|
} else {
|
|
@@ -3006,11 +3301,11 @@ var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(sourc
|
|
|
3006
3301
|
awaitWraps += 1;
|
|
3007
3302
|
const body = owningFunctionBody(node);
|
|
3008
3303
|
if (body) bodies.add(body);
|
|
3009
|
-
} else if (
|
|
3304
|
+
} else if (ts11.isCallExpression(inner) && skippedComplexCall(inner, filePath, sourceFile, options?.policy)) {
|
|
3010
3305
|
provenanceSkippedComplexCall += 1;
|
|
3011
3306
|
}
|
|
3012
3307
|
}
|
|
3013
|
-
|
|
3308
|
+
ts11.forEachChild(node, visit);
|
|
3014
3309
|
};
|
|
3015
3310
|
visit(sourceFile);
|
|
3016
3311
|
if (edits.length > 0) {
|
|
@@ -3037,7 +3332,7 @@ var collectJsonProducerEdits = (source, filePath, sourceFile = parseSource(sourc
|
|
|
3037
3332
|
};
|
|
3038
3333
|
|
|
3039
3334
|
// ../instrumentation/src/literal-sites.ts
|
|
3040
|
-
import
|
|
3335
|
+
import ts12 from "typescript";
|
|
3041
3336
|
var STRUCT_CALLEE = "globalThis.__rasputinK";
|
|
3042
3337
|
var owningFunction = (position, classifications) => {
|
|
3043
3338
|
let owner;
|
|
@@ -3057,7 +3352,7 @@ var walkPeelParent = (node) => {
|
|
|
3057
3352
|
let current = node;
|
|
3058
3353
|
while (current.parent) {
|
|
3059
3354
|
const parent = current.parent;
|
|
3060
|
-
if ((
|
|
3355
|
+
if ((ts12.isParenthesizedExpression(parent) || ts12.isNonNullExpression(parent) || ts12.isAsExpression(parent) || ts12.isTypeAssertionExpression(parent) || ts12.isSatisfiesExpression(parent)) && parent.expression === current) {
|
|
3061
3356
|
current = parent;
|
|
3062
3357
|
continue;
|
|
3063
3358
|
}
|
|
@@ -3069,13 +3364,13 @@ var isCapturePosition = (node) => {
|
|
|
3069
3364
|
const current = walkPeelParent(node);
|
|
3070
3365
|
const parent = current.parent;
|
|
3071
3366
|
if (!parent) return false;
|
|
3072
|
-
if (
|
|
3073
|
-
if (
|
|
3074
|
-
if (
|
|
3075
|
-
if (
|
|
3367
|
+
if (ts12.isReturnStatement(parent) && parent.expression === current) return true;
|
|
3368
|
+
if (ts12.isArrowFunction(parent) && parent.body === current) return true;
|
|
3369
|
+
if (ts12.isVariableDeclaration(parent) && parent.initializer === current) return true;
|
|
3370
|
+
if (ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.EqualsToken && parent.right === current) {
|
|
3076
3371
|
return true;
|
|
3077
3372
|
}
|
|
3078
|
-
if (
|
|
3373
|
+
if (ts12.isCallExpression(parent) || ts12.isNewExpression(parent)) {
|
|
3079
3374
|
return parent.arguments?.some((argument) => argument === current) === true;
|
|
3080
3375
|
}
|
|
3081
3376
|
return false;
|
|
@@ -3084,13 +3379,13 @@ var isInAssignmentPattern = (node) => {
|
|
|
3084
3379
|
let current = walkPeelParent(node);
|
|
3085
3380
|
while (current.parent) {
|
|
3086
3381
|
const parent = current.parent;
|
|
3087
|
-
if (
|
|
3382
|
+
if (ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.EqualsToken && parent.left === current) {
|
|
3088
3383
|
return true;
|
|
3089
3384
|
}
|
|
3090
|
-
if ((
|
|
3385
|
+
if ((ts12.isForOfStatement(parent) || ts12.isForInStatement(parent)) && parent.initializer === current) {
|
|
3091
3386
|
return true;
|
|
3092
3387
|
}
|
|
3093
|
-
if (
|
|
3388
|
+
if (ts12.isPropertyAssignment(parent) || ts12.isShorthandPropertyAssignment(parent) || ts12.isSpreadAssignment(parent) || ts12.isObjectLiteralExpression(parent) || ts12.isArrayLiteralExpression(parent) || ts12.isParenthesizedExpression(parent) || ts12.isAsExpression(parent) || ts12.isTypeAssertionExpression(parent) || ts12.isNonNullExpression(parent) || ts12.isSatisfiesExpression(parent)) {
|
|
3094
3389
|
current = walkPeelParent(parent);
|
|
3095
3390
|
continue;
|
|
3096
3391
|
}
|
|
@@ -3102,8 +3397,8 @@ var isLiteralChild = (node) => {
|
|
|
3102
3397
|
const current = walkPeelParent(node);
|
|
3103
3398
|
const parent = current.parent;
|
|
3104
3399
|
if (!parent) return false;
|
|
3105
|
-
if (
|
|
3106
|
-
if (
|
|
3400
|
+
if (ts12.isPropertyAssignment(parent) && parent.initializer === current) return true;
|
|
3401
|
+
if (ts12.isArrayLiteralExpression(parent)) return true;
|
|
3107
3402
|
return false;
|
|
3108
3403
|
};
|
|
3109
3404
|
var shouldRewrite = (node, classifications, sourceFile) => {
|
|
@@ -3115,10 +3410,10 @@ var shouldRewrite = (node, classifications, sourceFile) => {
|
|
|
3115
3410
|
var collectLiteralSiteEdits = (source, filePath, options, sourceFile = parseSource(source, filePath)) => {
|
|
3116
3411
|
const edits = [];
|
|
3117
3412
|
const visit = (node) => {
|
|
3118
|
-
if ((
|
|
3413
|
+
if ((ts12.isObjectLiteralExpression(node) || ts12.isArrayLiteralExpression(node)) && shouldRewrite(node, options.classifications, sourceFile)) {
|
|
3119
3414
|
wrap(edits, node.getStart(sourceFile), node.end, `${STRUCT_CALLEE}(`, ")", 15);
|
|
3120
3415
|
}
|
|
3121
|
-
|
|
3416
|
+
ts12.forEachChild(node, visit);
|
|
3122
3417
|
};
|
|
3123
3418
|
visit(sourceFile);
|
|
3124
3419
|
return { edits };
|
|
@@ -3128,64 +3423,64 @@ var collectLiteralSiteEdits = (source, filePath, options, sourceFile = parseSour
|
|
|
3128
3423
|
import { createHash } from "node:crypto";
|
|
3129
3424
|
import { resolve as resolve4 } from "node:path";
|
|
3130
3425
|
import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
|
|
3131
|
-
import
|
|
3426
|
+
import ts13 from "typescript";
|
|
3132
3427
|
var OBSERVE_CALLEE = "globalThis.__rasputinO";
|
|
3133
3428
|
var siteIdFor = (filePath, line, column, text) => {
|
|
3134
3429
|
const digest = createHash("sha256").update(`${resolve4(filePath)}:${line}:${column}:${text}`).digest("base64url").slice(0, 16);
|
|
3135
3430
|
return `rs_${digest}`;
|
|
3136
3431
|
};
|
|
3137
|
-
var isAssignmentOperator = (kind) => kind ===
|
|
3432
|
+
var isAssignmentOperator = (kind) => kind === ts13.SyntaxKind.EqualsToken || kind === ts13.SyntaxKind.PlusEqualsToken || kind === ts13.SyntaxKind.MinusEqualsToken || kind === ts13.SyntaxKind.AsteriskEqualsToken || kind === ts13.SyntaxKind.SlashEqualsToken || kind === ts13.SyntaxKind.PercentEqualsToken || kind === ts13.SyntaxKind.AmpersandEqualsToken || kind === ts13.SyntaxKind.BarEqualsToken || kind === ts13.SyntaxKind.CaretEqualsToken || kind === ts13.SyntaxKind.LessThanLessThanEqualsToken || kind === ts13.SyntaxKind.GreaterThanGreaterThanEqualsToken || kind === ts13.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || kind === ts13.SyntaxKind.AsteriskAsteriskEqualsToken || kind === ts13.SyntaxKind.BarBarEqualsToken || kind === ts13.SyntaxKind.AmpersandAmpersandEqualsToken || kind === ts13.SyntaxKind.QuestionQuestionEqualsToken;
|
|
3138
3433
|
var isSafeLiteral = (expression) => {
|
|
3139
3434
|
const node = peel(expression);
|
|
3140
|
-
if (
|
|
3141
|
-
if (
|
|
3142
|
-
if (node.kind ===
|
|
3435
|
+
if (ts13.isStringLiteral(node) || ts13.isNoSubstitutionTemplateLiteral(node)) return true;
|
|
3436
|
+
if (ts13.isNumericLiteral(node)) return true;
|
|
3437
|
+
if (node.kind === ts13.SyntaxKind.TrueKeyword || node.kind === ts13.SyntaxKind.FalseKeyword || node.kind === ts13.SyntaxKind.NullKeyword) {
|
|
3143
3438
|
return true;
|
|
3144
3439
|
}
|
|
3145
|
-
if (
|
|
3146
|
-
if (
|
|
3440
|
+
if (ts13.isIdentifier(node) && (node.text === "undefined" || node.text === "NaN")) return true;
|
|
3441
|
+
if (ts13.isPrefixUnaryExpression(node) && node.operator === ts13.SyntaxKind.MinusToken && ts13.isNumericLiteral(node.operand)) {
|
|
3147
3442
|
return true;
|
|
3148
3443
|
}
|
|
3149
|
-
return
|
|
3444
|
+
return ts13.isVoidExpression(node) && ts13.isNumericLiteral(peel(node.expression)) && peel(node.expression).getText() === "0";
|
|
3150
3445
|
};
|
|
3151
3446
|
var isPropertyRead = (node) => {
|
|
3152
|
-
if (
|
|
3153
|
-
return !
|
|
3447
|
+
if (ts13.isPropertyAccessExpression(node)) {
|
|
3448
|
+
return !ts13.isPrivateIdentifier(node.name) && node.expression.kind !== ts13.SyntaxKind.SuperKeyword;
|
|
3154
3449
|
}
|
|
3155
|
-
if (
|
|
3156
|
-
return node.expression.kind !==
|
|
3450
|
+
if (ts13.isElementAccessExpression(node)) {
|
|
3451
|
+
return node.expression.kind !== ts13.SyntaxKind.SuperKeyword;
|
|
3157
3452
|
}
|
|
3158
3453
|
return false;
|
|
3159
3454
|
};
|
|
3160
3455
|
var isMetaChain = (node) => {
|
|
3161
|
-
if (
|
|
3162
|
-
if (
|
|
3163
|
-
if (
|
|
3456
|
+
if (ts13.isMetaProperty(node)) return true;
|
|
3457
|
+
if (ts13.isPropertyAccessExpression(node)) return isMetaChain(node.expression);
|
|
3458
|
+
if (ts13.isElementAccessExpression(node)) return isMetaChain(node.expression);
|
|
3164
3459
|
return false;
|
|
3165
3460
|
};
|
|
3166
3461
|
var isPatternParent = (parent, child) => {
|
|
3167
|
-
if (
|
|
3168
|
-
if (
|
|
3169
|
-
if (
|
|
3170
|
-
if (
|
|
3171
|
-
if (
|
|
3172
|
-
if (
|
|
3173
|
-
if (
|
|
3174
|
-
if (
|
|
3175
|
-
if (
|
|
3176
|
-
if (
|
|
3177
|
-
if (
|
|
3462
|
+
if (ts13.isParenthesizedExpression(parent) && parent.expression === child) return true;
|
|
3463
|
+
if (ts13.isAsExpression(parent) && parent.expression === child) return true;
|
|
3464
|
+
if (ts13.isTypeAssertionExpression(parent) && parent.expression === child) return true;
|
|
3465
|
+
if (ts13.isNonNullExpression(parent) && parent.expression === child) return true;
|
|
3466
|
+
if (ts13.isSatisfiesExpression(parent) && parent.expression === child) return true;
|
|
3467
|
+
if (ts13.isPropertyAssignment(parent) && parent.initializer === child) return true;
|
|
3468
|
+
if (ts13.isShorthandPropertyAssignment(parent)) return true;
|
|
3469
|
+
if (ts13.isSpreadAssignment(parent) && parent.expression === child) return true;
|
|
3470
|
+
if (ts13.isSpreadElement(parent) && parent.expression === child) return true;
|
|
3471
|
+
if (ts13.isArrayLiteralExpression(parent)) return true;
|
|
3472
|
+
if (ts13.isObjectLiteralExpression(parent)) return true;
|
|
3178
3473
|
return false;
|
|
3179
3474
|
};
|
|
3180
3475
|
var isAssignmentTarget = (node) => {
|
|
3181
3476
|
let current = node;
|
|
3182
3477
|
while (current.parent) {
|
|
3183
3478
|
const parent = current.parent;
|
|
3184
|
-
if (
|
|
3185
|
-
if (
|
|
3479
|
+
if (ts13.isComputedPropertyName(parent) && parent.expression === current) return false;
|
|
3480
|
+
if (ts13.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3186
3481
|
return parent.left === current;
|
|
3187
3482
|
}
|
|
3188
|
-
if ((
|
|
3483
|
+
if ((ts13.isForOfStatement(parent) || ts13.isForInStatement(parent)) && parent.initializer === current) {
|
|
3189
3484
|
return true;
|
|
3190
3485
|
}
|
|
3191
3486
|
if (!isPatternParent(parent, current)) return false;
|
|
@@ -3197,18 +3492,18 @@ var isValueContext = (node) => {
|
|
|
3197
3492
|
if (isAssignmentTarget(node)) return false;
|
|
3198
3493
|
const parent = node.parent;
|
|
3199
3494
|
if (!parent) return false;
|
|
3200
|
-
if (
|
|
3201
|
-
if (
|
|
3202
|
-
if (
|
|
3203
|
-
if (
|
|
3495
|
+
if (ts13.isVariableDeclaration(parent) && parent.initializer === node) return true;
|
|
3496
|
+
if (ts13.isReturnStatement(parent) && parent.expression === node) return true;
|
|
3497
|
+
if (ts13.isPropertyAssignment(parent) && parent.initializer === node) return true;
|
|
3498
|
+
if (ts13.isParenthesizedExpression(parent) || ts13.isNonNullExpression(parent) || ts13.isAsExpression(parent) || ts13.isTypeAssertionExpression(parent) || ts13.isSatisfiesExpression(parent)) {
|
|
3204
3499
|
return isValueContext(parent);
|
|
3205
3500
|
}
|
|
3206
3501
|
return false;
|
|
3207
3502
|
};
|
|
3208
3503
|
var isCoalesceWithLiteral = (node) => {
|
|
3209
|
-
if (!
|
|
3504
|
+
if (!ts13.isBinaryExpression(node)) return false;
|
|
3210
3505
|
const operator = node.operatorToken.kind;
|
|
3211
|
-
if (operator !==
|
|
3506
|
+
if (operator !== ts13.SyntaxKind.QuestionQuestionToken && operator !== ts13.SyntaxKind.BarBarToken) {
|
|
3212
3507
|
return false;
|
|
3213
3508
|
}
|
|
3214
3509
|
return isSafeLiteral(node.right);
|
|
@@ -3217,19 +3512,19 @@ var shouldWrapPropertyRead = (node) => {
|
|
|
3217
3512
|
if (isMetaChain(node)) return false;
|
|
3218
3513
|
const parent = node.parent;
|
|
3219
3514
|
if (!parent) return false;
|
|
3220
|
-
if (
|
|
3221
|
-
if (
|
|
3222
|
-
if (
|
|
3223
|
-
if (
|
|
3224
|
-
if (
|
|
3225
|
-
if (
|
|
3226
|
-
if (
|
|
3515
|
+
if (ts13.isPropertyAccessExpression(parent) && parent.expression === node) return false;
|
|
3516
|
+
if (ts13.isElementAccessExpression(parent) && parent.expression === node) return false;
|
|
3517
|
+
if (ts13.isCallExpression(parent) && parent.expression === node) return false;
|
|
3518
|
+
if (ts13.isNewExpression(parent) && parent.expression === node) return false;
|
|
3519
|
+
if (ts13.isTaggedTemplateExpression(parent) && parent.tag === node) return false;
|
|
3520
|
+
if (ts13.isDeleteExpression(parent)) return false;
|
|
3521
|
+
if (ts13.isPrefixUnaryExpression(parent) && (parent.operator === ts13.SyntaxKind.PlusPlusToken || parent.operator === ts13.SyntaxKind.MinusMinusToken)) {
|
|
3227
3522
|
return false;
|
|
3228
3523
|
}
|
|
3229
|
-
if (
|
|
3524
|
+
if (ts13.isPostfixUnaryExpression(parent) && (parent.operator === ts13.SyntaxKind.PlusPlusToken || parent.operator === ts13.SyntaxKind.MinusMinusToken)) {
|
|
3230
3525
|
return false;
|
|
3231
3526
|
}
|
|
3232
|
-
if (
|
|
3527
|
+
if (ts13.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3233
3528
|
if (parent.left === node) return false;
|
|
3234
3529
|
}
|
|
3235
3530
|
if (isValueContext(node)) return true;
|
|
@@ -3244,15 +3539,15 @@ var shouldWrapRead = (node, classifications, sourceFile) => {
|
|
|
3244
3539
|
};
|
|
3245
3540
|
var hasOptional = (node) => !!node.questionDotToken;
|
|
3246
3541
|
var isInternalProperty = (node) => {
|
|
3247
|
-
if (
|
|
3248
|
-
if (!
|
|
3542
|
+
if (ts13.isPropertyAccessExpression(node)) return node.name.text.startsWith("__");
|
|
3543
|
+
if (!ts13.isStringLiteral(node.argumentExpression) && !ts13.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
|
|
3249
3544
|
return false;
|
|
3250
3545
|
}
|
|
3251
3546
|
return node.argumentExpression.text.startsWith("__");
|
|
3252
3547
|
};
|
|
3253
3548
|
var staticPropertyName = (node) => {
|
|
3254
|
-
if (
|
|
3255
|
-
if (
|
|
3549
|
+
if (ts13.isPropertyAccessExpression(node)) return node.name.text;
|
|
3550
|
+
if (ts13.isStringLiteral(node.argumentExpression) || ts13.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
|
|
3256
3551
|
return node.argumentExpression.text;
|
|
3257
3552
|
}
|
|
3258
3553
|
return void 0;
|
|
@@ -3277,15 +3572,15 @@ var isReactiveArrowValue = (node, classifications, sourceFile) => {
|
|
|
3277
3572
|
while (current) {
|
|
3278
3573
|
const parent = current.parent;
|
|
3279
3574
|
if (!parent) return false;
|
|
3280
|
-
if (
|
|
3575
|
+
if (ts13.isArrowFunction(parent) && parent.body === current) {
|
|
3281
3576
|
const owner = owningFunction2(node.getStart(sourceFile), classifications);
|
|
3282
3577
|
return owner?.captureClass === "reactive-sparse";
|
|
3283
3578
|
}
|
|
3284
|
-
if (
|
|
3579
|
+
if (ts13.isBinaryExpression(parent) && (parent.left === current || parent.right === current) && !isAssignmentOperator(parent.operatorToken.kind)) {
|
|
3285
3580
|
current = parent;
|
|
3286
3581
|
continue;
|
|
3287
3582
|
}
|
|
3288
|
-
if (
|
|
3583
|
+
if (ts13.isParenthesizedExpression(parent) || ts13.isNonNullExpression(parent) || ts13.isAsExpression(parent) || ts13.isTypeAssertionExpression(parent) || ts13.isSatisfiesExpression(parent)) {
|
|
3289
3584
|
current = parent;
|
|
3290
3585
|
continue;
|
|
3291
3586
|
}
|
|
@@ -3316,7 +3611,7 @@ var collectObserveSiteEdits = (source, filePath, options = {}, sourceFile = pars
|
|
|
3316
3611
|
if (options.classifications) {
|
|
3317
3612
|
const owner = owningFunction2(node.getStart(sourceFile), options.classifications);
|
|
3318
3613
|
if (!owner || !allowsExpressionCapture(owner)) {
|
|
3319
|
-
|
|
3614
|
+
ts13.forEachChild(node, visit);
|
|
3320
3615
|
return;
|
|
3321
3616
|
}
|
|
3322
3617
|
}
|
|
@@ -3341,7 +3636,7 @@ var collectObserveSiteEdits = (source, filePath, options = {}, sourceFile = pars
|
|
|
3341
3636
|
}
|
|
3342
3637
|
});
|
|
3343
3638
|
}
|
|
3344
|
-
|
|
3639
|
+
ts13.forEachChild(node, visit);
|
|
3345
3640
|
};
|
|
3346
3641
|
visit(sourceFile);
|
|
3347
3642
|
queued.sort((left, right) => right.start - left.start);
|
|
@@ -3380,7 +3675,7 @@ var isSvelteCompiledPath = (idOrPath) => {
|
|
|
3380
3675
|
};
|
|
3381
3676
|
|
|
3382
3677
|
// ../instrumentation/src/verify-browser-source.ts
|
|
3383
|
-
import
|
|
3678
|
+
import ts14 from "typescript";
|
|
3384
3679
|
var RASPUTIN_IDENT2 = /^__rasputin/;
|
|
3385
3680
|
var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
3386
3681
|
"__rasputinO",
|
|
@@ -3397,13 +3692,13 @@ var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
|
3397
3692
|
]);
|
|
3398
3693
|
var isRasputinName2 = (name) => RASPUTIN_IDENT2.test(name);
|
|
3399
3694
|
var identText2 = (node) => {
|
|
3400
|
-
if (
|
|
3401
|
-
if (
|
|
3695
|
+
if (ts14.isIdentifier(node)) return node.text;
|
|
3696
|
+
if (ts14.isPrivateIdentifier(node)) return node.text;
|
|
3402
3697
|
return void 0;
|
|
3403
3698
|
};
|
|
3404
3699
|
var calleeName2 = (expression) => {
|
|
3405
|
-
if (
|
|
3406
|
-
if (
|
|
3700
|
+
if (ts14.isIdentifier(expression)) return expression.text;
|
|
3701
|
+
if (ts14.isPropertyAccessExpression(expression)) {
|
|
3407
3702
|
const object = identText2(expression.expression);
|
|
3408
3703
|
const property = identText2(expression.name);
|
|
3409
3704
|
if (object && isRasputinName2(object) && property) return `${object}.${property}`;
|
|
@@ -3412,17 +3707,17 @@ var calleeName2 = (expression) => {
|
|
|
3412
3707
|
return void 0;
|
|
3413
3708
|
};
|
|
3414
3709
|
var isRasputinCall2 = (node) => {
|
|
3415
|
-
if (!
|
|
3710
|
+
if (!ts14.isCallExpression(node)) return false;
|
|
3416
3711
|
const name = calleeName2(node.expression);
|
|
3417
3712
|
return Boolean(name && (isRasputinName2(name) || BROWSER_GLOBALS.has(name)));
|
|
3418
3713
|
};
|
|
3419
3714
|
var isRasputinAssignment = (node) => {
|
|
3420
|
-
if (!
|
|
3715
|
+
if (!ts14.isBinaryExpression(node)) return false;
|
|
3421
3716
|
const operator = node.operatorToken.kind;
|
|
3422
|
-
if (operator !==
|
|
3717
|
+
if (operator !== ts14.SyntaxKind.EqualsToken && operator !== ts14.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
3423
3718
|
return false;
|
|
3424
3719
|
}
|
|
3425
|
-
if (
|
|
3720
|
+
if (ts14.isPropertyAccessExpression(node.left)) {
|
|
3426
3721
|
const object = identText2(node.left.expression);
|
|
3427
3722
|
const property = identText2(node.left.name);
|
|
3428
3723
|
return object === "globalThis" && property !== void 0 && BROWSER_GLOBALS.has(property);
|
|
@@ -3434,28 +3729,28 @@ var isRasputinOnlyInitializer = (expression) => {
|
|
|
3434
3729
|
if (!expression) return true;
|
|
3435
3730
|
const unwrapped = unwrapCall2(expression);
|
|
3436
3731
|
if (unwrapped !== expression) {
|
|
3437
|
-
return
|
|
3732
|
+
return ts14.isExpression(unwrapped) ? isRasputinOnlyInitializer(unwrapped) : false;
|
|
3438
3733
|
}
|
|
3439
3734
|
return isRasputinCall2(expression);
|
|
3440
3735
|
};
|
|
3441
3736
|
var jsonAwaitSlot = (node) => {
|
|
3442
|
-
if (node.operatorToken.kind !==
|
|
3737
|
+
if (node.operatorToken.kind !== ts14.SyntaxKind.CommaToken) return void 0;
|
|
3443
3738
|
const assigned = node.left;
|
|
3444
|
-
if (!
|
|
3739
|
+
if (!ts14.isBinaryExpression(assigned) || assigned.operatorToken.kind !== ts14.SyntaxKind.EqualsToken || !ts14.isIdentifier(assigned.left) || !isRasputinName2(assigned.left.text) || !ts14.isObjectLiteralExpression(assigned.right)) {
|
|
3445
3740
|
return void 0;
|
|
3446
3741
|
}
|
|
3447
3742
|
const property = assigned.right.properties[0];
|
|
3448
|
-
if (!property || !
|
|
3743
|
+
if (!property || !ts14.isPropertyAssignment(property) || !ts14.isIdentifier(property.name) || property.name.text !== "p") {
|
|
3449
3744
|
return void 0;
|
|
3450
3745
|
}
|
|
3451
|
-
if (!
|
|
3746
|
+
if (!ts14.isPropertyAccessExpression(node.right) || !ts14.isIdentifier(node.right.expression) || !isRasputinName2(node.right.expression.text) || node.right.name.text !== "p") {
|
|
3452
3747
|
return void 0;
|
|
3453
3748
|
}
|
|
3454
3749
|
return property.initializer;
|
|
3455
3750
|
};
|
|
3456
3751
|
var peelParens = (node) => {
|
|
3457
3752
|
let current = node;
|
|
3458
|
-
while (
|
|
3753
|
+
while (ts14.isParenthesizedExpression(current)) current = current.expression;
|
|
3459
3754
|
return current;
|
|
3460
3755
|
};
|
|
3461
3756
|
var jsonMethodCall = (node) => {
|
|
@@ -3463,9 +3758,9 @@ var jsonMethodCall = (node) => {
|
|
|
3463
3758
|
const fn = node.arguments[1];
|
|
3464
3759
|
if (!receiver || !fn) return void 0;
|
|
3465
3760
|
const args = node.arguments.slice(2);
|
|
3466
|
-
if (!
|
|
3467
|
-
return
|
|
3468
|
-
|
|
3761
|
+
if (!ts14.isPropertyAccessExpression(fn)) return void 0;
|
|
3762
|
+
return ts14.factory.createCallExpression(
|
|
3763
|
+
ts14.factory.createPropertyAccessExpression(receiver, fn.name),
|
|
3469
3764
|
void 0,
|
|
3470
3765
|
args
|
|
3471
3766
|
);
|
|
@@ -3475,55 +3770,55 @@ var unwrapAdoptIife = (node) => {
|
|
|
3475
3770
|
const adopted = node.arguments[0];
|
|
3476
3771
|
if (!adopted) return void 0;
|
|
3477
3772
|
const callee = peelParens(node.expression);
|
|
3478
|
-
if (!
|
|
3773
|
+
if (!ts14.isArrowFunction(callee) || callee.parameters.length !== 1 || ts14.isBlock(callee.body)) {
|
|
3479
3774
|
return void 0;
|
|
3480
3775
|
}
|
|
3481
3776
|
const param = callee.parameters[0];
|
|
3482
|
-
if (!param || !
|
|
3777
|
+
if (!param || !ts14.isIdentifier(param.name) || param.dotDotDotToken || param.initializer) {
|
|
3483
3778
|
return void 0;
|
|
3484
3779
|
}
|
|
3485
3780
|
const body = peelParens(callee.body);
|
|
3486
|
-
if (
|
|
3781
|
+
if (ts14.isCallExpression(body) && calleeName2(body.expression) === "__rasputinP") {
|
|
3487
3782
|
const invoked = body.arguments[0];
|
|
3488
|
-
if (invoked &&
|
|
3489
|
-
return
|
|
3783
|
+
if (invoked && ts14.isCallExpression(invoked) && ts14.isIdentifier(invoked.expression) && invoked.expression.text === param.name.text) {
|
|
3784
|
+
return ts14.factory.createCallExpression(adopted, void 0, invoked.arguments);
|
|
3490
3785
|
}
|
|
3491
3786
|
return void 0;
|
|
3492
3787
|
}
|
|
3493
|
-
if (!
|
|
3788
|
+
if (!ts14.isCallExpression(body) || body.arguments.length !== 1) return void 0;
|
|
3494
3789
|
const methodLookup = body.arguments[0];
|
|
3495
3790
|
if (!methodLookup) return void 0;
|
|
3496
3791
|
const inner = peelParens(body.expression);
|
|
3497
|
-
if (!
|
|
3792
|
+
if (!ts14.isArrowFunction(inner) || inner.parameters.length !== 1 || ts14.isBlock(inner.body)) {
|
|
3498
3793
|
return void 0;
|
|
3499
3794
|
}
|
|
3500
3795
|
const fnParam = inner.parameters[0];
|
|
3501
|
-
if (!fnParam || !
|
|
3796
|
+
if (!fnParam || !ts14.isIdentifier(fnParam.name) || fnParam.dotDotDotToken || fnParam.initializer) {
|
|
3502
3797
|
return void 0;
|
|
3503
3798
|
}
|
|
3504
3799
|
const innerBody = peelParens(inner.body);
|
|
3505
|
-
if (!
|
|
3800
|
+
if (!ts14.isCallExpression(innerBody) || calleeName2(innerBody.expression) !== "__rasputinP") {
|
|
3506
3801
|
return void 0;
|
|
3507
3802
|
}
|
|
3508
3803
|
const applied = innerBody.arguments[0];
|
|
3509
|
-
if (!applied || !
|
|
3804
|
+
if (!applied || !ts14.isCallExpression(applied)) return void 0;
|
|
3510
3805
|
const applyCallee = peelParens(applied.expression);
|
|
3511
|
-
if (!
|
|
3806
|
+
if (!ts14.isPropertyAccessExpression(applyCallee) || applyCallee.name.text !== "apply" || !ts14.isIdentifier(applyCallee.expression) || applyCallee.expression.text !== "Reflect") {
|
|
3512
3807
|
return void 0;
|
|
3513
3808
|
}
|
|
3514
3809
|
const appliedFn = applied.arguments[0];
|
|
3515
3810
|
const thisArg = applied.arguments[1];
|
|
3516
3811
|
const argsArg = applied.arguments[2];
|
|
3517
|
-
if (!appliedFn || !
|
|
3812
|
+
if (!appliedFn || !ts14.isIdentifier(appliedFn) || appliedFn.text !== fnParam.name.text) {
|
|
3518
3813
|
return void 0;
|
|
3519
3814
|
}
|
|
3520
|
-
if (!thisArg || !
|
|
3521
|
-
if (!argsArg || !
|
|
3522
|
-
if (!
|
|
3815
|
+
if (!thisArg || !ts14.isIdentifier(thisArg) || thisArg.text !== param.name.text) return void 0;
|
|
3816
|
+
if (!argsArg || !ts14.isArrayLiteralExpression(argsArg)) return void 0;
|
|
3817
|
+
if (!ts14.isPropertyAccessExpression(methodLookup) || !ts14.isIdentifier(methodLookup.expression) || methodLookup.expression.text !== param.name.text || ts14.isPrivateIdentifier(methodLookup.name)) {
|
|
3523
3818
|
return void 0;
|
|
3524
3819
|
}
|
|
3525
|
-
return
|
|
3526
|
-
|
|
3820
|
+
return ts14.factory.createCallExpression(
|
|
3821
|
+
ts14.factory.createPropertyAccessExpression(adopted, methodLookup.name),
|
|
3527
3822
|
void 0,
|
|
3528
3823
|
[...argsArg.elements]
|
|
3529
3824
|
);
|
|
@@ -3533,23 +3828,23 @@ var unwrapProducerIife = (node) => {
|
|
|
3533
3828
|
const receiver = node.arguments[0];
|
|
3534
3829
|
if (!receiver) return void 0;
|
|
3535
3830
|
const callee = peelParens(node.expression);
|
|
3536
|
-
if (!
|
|
3831
|
+
if (!ts14.isArrowFunction(callee) || callee.parameters.length !== 1 || ts14.isBlock(callee.body)) {
|
|
3537
3832
|
return void 0;
|
|
3538
3833
|
}
|
|
3539
3834
|
const param = callee.parameters[0];
|
|
3540
|
-
if (!param || !
|
|
3835
|
+
if (!param || !ts14.isIdentifier(param.name) || param.dotDotDotToken || param.initializer) {
|
|
3541
3836
|
return void 0;
|
|
3542
3837
|
}
|
|
3543
3838
|
const body = peelParens(callee.body);
|
|
3544
|
-
if (!
|
|
3839
|
+
if (!ts14.isCallExpression(body) || !isRasputinCall2(body)) return void 0;
|
|
3545
3840
|
if (calleeName2(body.expression) !== "__rasputinM") return void 0;
|
|
3546
3841
|
const bound = body.arguments[0];
|
|
3547
3842
|
const fn = body.arguments[1];
|
|
3548
|
-
if (!bound || !fn || !
|
|
3549
|
-
if (!
|
|
3550
|
-
if (!
|
|
3551
|
-
return
|
|
3552
|
-
|
|
3843
|
+
if (!bound || !fn || !ts14.isIdentifier(bound) || bound.text !== param.name.text) return void 0;
|
|
3844
|
+
if (!ts14.isPropertyAccessExpression(fn)) return void 0;
|
|
3845
|
+
if (!ts14.isIdentifier(fn.expression) || fn.expression.text !== param.name.text) return void 0;
|
|
3846
|
+
return ts14.factory.createCallExpression(
|
|
3847
|
+
ts14.factory.createPropertyAccessExpression(receiver, fn.name),
|
|
3553
3848
|
void 0,
|
|
3554
3849
|
body.arguments.slice(2)
|
|
3555
3850
|
);
|
|
@@ -3557,22 +3852,22 @@ var unwrapProducerIife = (node) => {
|
|
|
3557
3852
|
var unwrapCall2 = (node) => {
|
|
3558
3853
|
let current = node;
|
|
3559
3854
|
while (true) {
|
|
3560
|
-
if (
|
|
3855
|
+
if (ts14.isParenthesizedExpression(current)) {
|
|
3561
3856
|
current = current.expression;
|
|
3562
3857
|
continue;
|
|
3563
3858
|
}
|
|
3564
|
-
if (
|
|
3859
|
+
if (ts14.isBinaryExpression(current)) {
|
|
3565
3860
|
const slot = jsonAwaitSlot(current);
|
|
3566
3861
|
if (slot) {
|
|
3567
3862
|
current = slot;
|
|
3568
3863
|
continue;
|
|
3569
3864
|
}
|
|
3570
3865
|
}
|
|
3571
|
-
if (
|
|
3866
|
+
if (ts14.isConditionalExpression(current) && isRasputinName2(identText2(current.condition) ?? "")) {
|
|
3572
3867
|
current = current.whenTrue;
|
|
3573
3868
|
continue;
|
|
3574
3869
|
}
|
|
3575
|
-
if (
|
|
3870
|
+
if (ts14.isCallExpression(current)) {
|
|
3576
3871
|
const adopted = unwrapAdoptIife(current);
|
|
3577
3872
|
if (adopted) {
|
|
3578
3873
|
current = adopted;
|
|
@@ -3584,7 +3879,7 @@ var unwrapCall2 = (node) => {
|
|
|
3584
3879
|
continue;
|
|
3585
3880
|
}
|
|
3586
3881
|
}
|
|
3587
|
-
if (
|
|
3882
|
+
if (ts14.isCallExpression(current) && isRasputinCall2(current)) {
|
|
3588
3883
|
const name = calleeName2(current.expression);
|
|
3589
3884
|
if ((name === "__rasputinO" || name === "__rasputinL") && current.arguments.length >= 2 && current.arguments[1]) {
|
|
3590
3885
|
current = current.arguments[1];
|
|
@@ -3617,26 +3912,26 @@ var unwrapCall2 = (node) => {
|
|
|
3617
3912
|
var isRasputinIf = (node) => {
|
|
3618
3913
|
if (node.elseStatement) return false;
|
|
3619
3914
|
const condition = node.expression;
|
|
3620
|
-
const negated =
|
|
3915
|
+
const negated = ts14.isPrefixUnaryExpression(condition) && condition.operator === ts14.SyntaxKind.ExclamationToken && isRasputinName2(identText2(condition.operand) ?? "");
|
|
3621
3916
|
if (!negated) return false;
|
|
3622
3917
|
const then = node.thenStatement;
|
|
3623
|
-
if (
|
|
3624
|
-
return
|
|
3918
|
+
if (ts14.isExpressionStatement(then) && isRasputinCall2(then.expression)) return true;
|
|
3919
|
+
return ts14.isBlock(then) && then.statements.every((statement) => isRasputinStatement2(statement));
|
|
3625
3920
|
};
|
|
3626
3921
|
var isRasputinStatement2 = (node) => {
|
|
3627
|
-
if (
|
|
3628
|
-
if (
|
|
3922
|
+
if (ts14.isEmptyStatement(node)) return true;
|
|
3923
|
+
if (ts14.isVariableStatement(node)) {
|
|
3629
3924
|
return node.declarationList.declarations.every((declaration) => {
|
|
3630
3925
|
const name = identText2(declaration.name);
|
|
3631
3926
|
return Boolean(name && isRasputinName2(name));
|
|
3632
3927
|
});
|
|
3633
3928
|
}
|
|
3634
|
-
if (
|
|
3929
|
+
if (ts14.isExpressionStatement(node)) {
|
|
3635
3930
|
if (isRasputinAssignment(node.expression)) return true;
|
|
3636
3931
|
if (!isRasputinCall2(node.expression)) return false;
|
|
3637
3932
|
return unwrapCall2(node.expression) === node.expression;
|
|
3638
3933
|
}
|
|
3639
|
-
if (
|
|
3934
|
+
if (ts14.isIfStatement(node)) return isRasputinIf(node);
|
|
3640
3935
|
return false;
|
|
3641
3936
|
};
|
|
3642
3937
|
var isRasputinTryWrapper2 = (node) => {
|
|
@@ -3646,12 +3941,12 @@ var isRasputinTryWrapper2 = (node) => {
|
|
|
3646
3941
|
(statement) => !isRasputinStatement2(statement)
|
|
3647
3942
|
);
|
|
3648
3943
|
const leftover = catchCalls[0];
|
|
3649
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
3944
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts14.isThrowStatement(leftover) && ts14.isIdentifier(leftover.expression);
|
|
3650
3945
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
3651
3946
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement2(statement));
|
|
3652
3947
|
};
|
|
3653
3948
|
var customerTempInit = (statement) => {
|
|
3654
|
-
if (!
|
|
3949
|
+
if (!ts14.isVariableStatement(statement)) return void 0;
|
|
3655
3950
|
for (const declaration of statement.declarationList.declarations) {
|
|
3656
3951
|
const name = identText2(declaration.name);
|
|
3657
3952
|
if (!name || !isRasputinName2(name) || !declaration.initializer) continue;
|
|
@@ -3664,7 +3959,7 @@ var flattenStatements2 = (statements) => {
|
|
|
3664
3959
|
const flattened = [];
|
|
3665
3960
|
for (const statement of statements) {
|
|
3666
3961
|
if (isRasputinStatement2(statement)) continue;
|
|
3667
|
-
if (
|
|
3962
|
+
if (ts14.isTryStatement(statement) && isRasputinTryWrapper2(statement)) {
|
|
3668
3963
|
flattened.push(...flattenStatements2(statement.tryBlock.statements));
|
|
3669
3964
|
continue;
|
|
3670
3965
|
}
|
|
@@ -3673,27 +3968,27 @@ var flattenStatements2 = (statements) => {
|
|
|
3673
3968
|
return flattened;
|
|
3674
3969
|
};
|
|
3675
3970
|
var isRememberIife = (node) => {
|
|
3676
|
-
if (!
|
|
3971
|
+
if (!ts14.isCallExpression(node) || node.arguments.length > 0) return void 0;
|
|
3677
3972
|
let callee = node.expression;
|
|
3678
|
-
if (
|
|
3679
|
-
if (!
|
|
3973
|
+
if (ts14.isParenthesizedExpression(callee)) callee = callee.expression;
|
|
3974
|
+
if (!ts14.isArrowFunction(callee) || callee.parameters.length > 0 || !ts14.isBlock(callee.body)) {
|
|
3680
3975
|
return void 0;
|
|
3681
3976
|
}
|
|
3682
3977
|
const statements = callee.body.statements;
|
|
3683
3978
|
const last = statements.at(-1);
|
|
3684
|
-
if (!last || !
|
|
3979
|
+
if (!last || !ts14.isReturnStatement(last) || !last.expression) return void 0;
|
|
3685
3980
|
let returned = last.expression;
|
|
3686
|
-
while (
|
|
3687
|
-
if (!
|
|
3981
|
+
while (ts14.isParenthesizedExpression(returned)) returned = returned.expression;
|
|
3982
|
+
if (!ts14.isCallExpression(returned)) return void 0;
|
|
3688
3983
|
const name = calleeName2(returned.expression);
|
|
3689
3984
|
if (name !== "__rasputinK") return void 0;
|
|
3690
3985
|
const objectArg = returned.arguments[0];
|
|
3691
|
-
if (!objectArg || !
|
|
3986
|
+
if (!objectArg || !ts14.isIdentifier(objectArg)) return void 0;
|
|
3692
3987
|
const temps = /* @__PURE__ */ new Map();
|
|
3693
3988
|
for (const statement of statements.slice(0, -1)) {
|
|
3694
|
-
if (!
|
|
3989
|
+
if (!ts14.isVariableStatement(statement)) return void 0;
|
|
3695
3990
|
for (const declaration of statement.declarationList.declarations) {
|
|
3696
|
-
if (!
|
|
3991
|
+
if (!ts14.isIdentifier(declaration.name) || !declaration.initializer) return void 0;
|
|
3697
3992
|
temps.set(declaration.name.text, declaration.initializer);
|
|
3698
3993
|
}
|
|
3699
3994
|
}
|
|
@@ -3703,10 +3998,10 @@ var isRememberIife = (node) => {
|
|
|
3703
3998
|
};
|
|
3704
3999
|
var resolveRememberTemp = (expression, temps, seen) => {
|
|
3705
4000
|
let current = expression;
|
|
3706
|
-
while (
|
|
4001
|
+
while (ts14.isParenthesizedExpression(current) || ts14.isNonNullExpression(current) || ts14.isAsExpression(current) || ts14.isTypeAssertionExpression(current) || ts14.isSatisfiesExpression(current)) {
|
|
3707
4002
|
current = current.expression;
|
|
3708
4003
|
}
|
|
3709
|
-
if (
|
|
4004
|
+
if (ts14.isIdentifier(current) && temps.has(current.text) && !seen.has(current.text)) {
|
|
3710
4005
|
const next = temps.get(current.text);
|
|
3711
4006
|
if (!next) return current;
|
|
3712
4007
|
seen.add(current.text);
|
|
@@ -3715,27 +4010,27 @@ var resolveRememberTemp = (expression, temps, seen) => {
|
|
|
3715
4010
|
return current;
|
|
3716
4011
|
};
|
|
3717
4012
|
var extra2 = (node) => {
|
|
3718
|
-
if (
|
|
4013
|
+
if (ts14.isIdentifier(node) || ts14.isPrivateIdentifier(node)) {
|
|
3719
4014
|
return isRasputinName2(node.text) ? "" : node.text;
|
|
3720
4015
|
}
|
|
3721
|
-
if (
|
|
4016
|
+
if (ts14.isStringLiteral(node) || ts14.isNumericLiteral(node) || ts14.isNoSubstitutionTemplateLiteral(node)) {
|
|
3722
4017
|
return node.text;
|
|
3723
4018
|
}
|
|
3724
|
-
if (
|
|
4019
|
+
if (ts14.isToken(node) && !ts14.isIdentifier(node)) return ts14.SyntaxKind[node.kind] ?? "";
|
|
3725
4020
|
return "";
|
|
3726
4021
|
};
|
|
3727
4022
|
var signatureOfSubstituted = (node, temps) => {
|
|
3728
4023
|
const remembered = isRememberIife(node);
|
|
3729
4024
|
if (remembered) return signatureOfSubstituted(remembered.object, remembered.temps);
|
|
3730
|
-
if (
|
|
4025
|
+
if (ts14.isObjectLiteralExpression(node)) {
|
|
3731
4026
|
const parts = node.properties.map((property) => {
|
|
3732
|
-
if (
|
|
3733
|
-
if (!
|
|
4027
|
+
if (ts14.isShorthandPropertyAssignment(property)) return signatureOf2(property);
|
|
4028
|
+
if (!ts14.isPropertyAssignment(property)) return signatureOf2(property);
|
|
3734
4029
|
const init = resolveRememberTemp(property.initializer, temps, /* @__PURE__ */ new Set());
|
|
3735
|
-
if (
|
|
3736
|
-
return signatureOf2(
|
|
4030
|
+
if (ts14.isIdentifier(property.name) && ts14.isIdentifier(init) && property.name.text === init.text) {
|
|
4031
|
+
return signatureOf2(ts14.factory.createShorthandPropertyAssignment(property.name));
|
|
3737
4032
|
}
|
|
3738
|
-
if (
|
|
4033
|
+
if (ts14.isComputedPropertyName(property.name)) {
|
|
3739
4034
|
const key = resolveRememberTemp(property.name.expression, temps, /* @__PURE__ */ new Set());
|
|
3740
4035
|
return `PropertyAssignment[ComputedPropertyName[${signatureOfSubstituted(key, temps)}],${signatureOfSubstituted(init, temps)}]`;
|
|
3741
4036
|
}
|
|
@@ -3743,7 +4038,7 @@ var signatureOfSubstituted = (node, temps) => {
|
|
|
3743
4038
|
});
|
|
3744
4039
|
return `ObjectLiteralExpression[${parts.join(",")}]`;
|
|
3745
4040
|
}
|
|
3746
|
-
if (
|
|
4041
|
+
if (ts14.isArrayLiteralExpression(node)) {
|
|
3747
4042
|
const parts = node.elements.map(
|
|
3748
4043
|
(element) => signatureOfSubstituted(resolveRememberTemp(element, temps, /* @__PURE__ */ new Set()), temps)
|
|
3749
4044
|
);
|
|
@@ -3761,33 +4056,33 @@ var signatureOf2 = (node) => {
|
|
|
3761
4056
|
if (unwrapped !== node) return signatureOf2(unwrapped);
|
|
3762
4057
|
const remembered = signatureOfRememberedLiteral(unwrapped);
|
|
3763
4058
|
if (remembered !== void 0) return remembered;
|
|
3764
|
-
if (
|
|
3765
|
-
return signatureOf2(
|
|
4059
|
+
if (ts14.isPropertyAssignment(unwrapped) && ts14.isIdentifier(unwrapped.name) && ts14.isIdentifier(unwrapped.initializer) && unwrapped.name.text === unwrapped.initializer.text) {
|
|
4060
|
+
return signatureOf2(ts14.factory.createShorthandPropertyAssignment(unwrapped.name));
|
|
3766
4061
|
}
|
|
3767
|
-
if (
|
|
3768
|
-
if (
|
|
4062
|
+
if (ts14.isEmptyStatement(unwrapped) || isRasputinStatement2(unwrapped)) return "";
|
|
4063
|
+
if (ts14.isTryStatement(unwrapped) && isRasputinTryWrapper2(unwrapped)) {
|
|
3769
4064
|
return flattenStatements2(unwrapped.tryBlock.statements).map(signatureOf2).filter(Boolean).join("");
|
|
3770
4065
|
}
|
|
3771
|
-
if (
|
|
4066
|
+
if (ts14.isCatchClause(unwrapped)) {
|
|
3772
4067
|
const statements = flattenStatements2(unwrapped.block.statements);
|
|
3773
4068
|
const variable = unwrapped.variableDeclaration ? signatureOf2(unwrapped.variableDeclaration) : "";
|
|
3774
4069
|
return `Catch${variable}[${statements.map(signatureOf2).filter(Boolean).join(",")}]`;
|
|
3775
4070
|
}
|
|
3776
|
-
if (
|
|
4071
|
+
if (ts14.isBlock(unwrapped)) {
|
|
3777
4072
|
const statements = flattenStatements2(unwrapped.statements);
|
|
3778
4073
|
return `Block[${statements.map(signatureOf2).filter(Boolean).join(",")}]`;
|
|
3779
4074
|
}
|
|
3780
|
-
if (
|
|
4075
|
+
if (ts14.isArrowFunction(unwrapped) && ts14.isBlock(unwrapped.body)) {
|
|
3781
4076
|
const raw = unwrapped.body.statements;
|
|
3782
|
-
const tryWrap = raw.length === 1 && raw[0] &&
|
|
4077
|
+
const tryWrap = raw.length === 1 && raw[0] && ts14.isTryStatement(raw[0]) ? raw[0] : void 0;
|
|
3783
4078
|
const inner = tryWrap && isRasputinTryWrapper2(tryWrap) ? tryWrap.tryBlock.statements : raw;
|
|
3784
4079
|
const temp = inner[0] ? customerTempInit(inner[0]) : void 0;
|
|
3785
4080
|
const returned = inner[1];
|
|
3786
|
-
if (temp && returned &&
|
|
4081
|
+
if (temp && returned && ts14.isReturnStatement(returned) && returned.expression && inner.length === 2) {
|
|
3787
4082
|
const value = unwrapCall2(returned.expression);
|
|
3788
|
-
if (
|
|
4083
|
+
if (ts14.isIdentifier(value) && value.text === temp.name) {
|
|
3789
4084
|
const parts2 = [];
|
|
3790
|
-
|
|
4085
|
+
ts14.forEachChild(unwrapped, (child) => {
|
|
3791
4086
|
if (child === unwrapped.body) {
|
|
3792
4087
|
const part2 = signatureOf2(temp.init);
|
|
3793
4088
|
if (part2) parts2.push(part2);
|
|
@@ -3801,10 +4096,10 @@ var signatureOf2 = (node) => {
|
|
|
3801
4096
|
}
|
|
3802
4097
|
const statements = flattenStatements2(unwrapped.body.statements);
|
|
3803
4098
|
const only = statements[0];
|
|
3804
|
-
const onlyExpression = only &&
|
|
4099
|
+
const onlyExpression = only && ts14.isReturnStatement(only) ? only.expression : void 0;
|
|
3805
4100
|
if (statements.length === 1 && onlyExpression) {
|
|
3806
4101
|
const parts2 = [];
|
|
3807
|
-
|
|
4102
|
+
ts14.forEachChild(unwrapped, (child) => {
|
|
3808
4103
|
if (child === unwrapped.body) {
|
|
3809
4104
|
const part2 = signatureOf2(onlyExpression);
|
|
3810
4105
|
if (part2) parts2.push(part2);
|
|
@@ -3816,20 +4111,20 @@ var signatureOf2 = (node) => {
|
|
|
3816
4111
|
return `ArrowFunction[${parts2.join(",")}]`;
|
|
3817
4112
|
}
|
|
3818
4113
|
}
|
|
3819
|
-
if (
|
|
4114
|
+
if (ts14.isReturnStatement(unwrapped)) {
|
|
3820
4115
|
if (!unwrapped.expression) return "ReturnStatement[]";
|
|
3821
4116
|
const expression = unwrapCall2(unwrapped.expression);
|
|
3822
|
-
if (
|
|
4117
|
+
if (ts14.isVoidExpression(expression) && isRasputinCall2(expression.expression)) {
|
|
3823
4118
|
return "ReturnStatement[]";
|
|
3824
4119
|
}
|
|
3825
4120
|
return `Return[${signatureOf2(unwrapped.expression)}]`;
|
|
3826
4121
|
}
|
|
3827
4122
|
const parts = [];
|
|
3828
|
-
|
|
4123
|
+
ts14.forEachChild(unwrapped, (child) => {
|
|
3829
4124
|
const part = signatureOf2(child);
|
|
3830
4125
|
if (part) parts.push(part);
|
|
3831
4126
|
});
|
|
3832
|
-
const kind =
|
|
4127
|
+
const kind = ts14.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
3833
4128
|
return `${kind}${extra2(unwrapped)}[${parts.join(",")}]`;
|
|
3834
4129
|
};
|
|
3835
4130
|
var browserInstrumentationIsSafe = (filePath, original, transformed) => {
|
|
@@ -3927,7 +4222,7 @@ var instrumentBrowserSource = (source, filePath, emitIds, reactiveIds, moduleInd
|
|
|
3927
4222
|
};
|
|
3928
4223
|
|
|
3929
4224
|
// ../instrumentation/src/provenance-function-edits.ts
|
|
3930
|
-
import
|
|
4225
|
+
import ts15 from "typescript";
|
|
3931
4226
|
|
|
3932
4227
|
// ../instrumentation/src/source-map-location.ts
|
|
3933
4228
|
import { dirname, join } from "node:path";
|
|
@@ -3984,13 +4279,13 @@ var createSourceMapLocationMapper = (generatedPath, map) => {
|
|
|
3984
4279
|
};
|
|
3985
4280
|
|
|
3986
4281
|
// src/compiler/client-policy.ts
|
|
3987
|
-
import
|
|
4282
|
+
import ts17 from "typescript";
|
|
3988
4283
|
|
|
3989
4284
|
// src/compiler/svelte-generated.ts
|
|
3990
|
-
import
|
|
4285
|
+
import ts16 from "typescript";
|
|
3991
4286
|
var SVELTE_TEMPLATE_FACTORIES = /* @__PURE__ */ new Set(["from_html", "from_svg", "template"]);
|
|
3992
4287
|
var SVELTE_PROP_GETTERS = /* @__PURE__ */ new Set(["prop", "prop_source"]);
|
|
3993
|
-
var isFunctionLike2 = (node) =>
|
|
4288
|
+
var isFunctionLike2 = (node) => ts16.isFunctionDeclaration(node) || ts16.isFunctionExpression(node) || ts16.isArrowFunction(node) || ts16.isMethodDeclaration(node) || ts16.isGetAccessorDeclaration(node) || ts16.isSetAccessorDeclaration(node);
|
|
3994
4289
|
var isDescendant = (root, node) => {
|
|
3995
4290
|
let current = node;
|
|
3996
4291
|
while (current) {
|
|
@@ -4001,15 +4296,15 @@ var isDescendant = (root, node) => {
|
|
|
4001
4296
|
};
|
|
4002
4297
|
var svelteCallMethod = (call) => {
|
|
4003
4298
|
const callee = call.expression;
|
|
4004
|
-
if (!
|
|
4299
|
+
if (!ts16.isPropertyAccessExpression(callee) || !ts16.isIdentifier(callee.expression)) {
|
|
4005
4300
|
return void 0;
|
|
4006
4301
|
}
|
|
4007
|
-
if (callee.expression.text !== "$" || !
|
|
4302
|
+
if (callee.expression.text !== "$" || !ts16.isIdentifier(callee.name)) return void 0;
|
|
4008
4303
|
return callee.name.text;
|
|
4009
4304
|
};
|
|
4010
4305
|
var svelteRuntimeMethod = (node) => {
|
|
4011
4306
|
const parent = node.parent;
|
|
4012
|
-
if (!parent || !
|
|
4307
|
+
if (!parent || !ts16.isCallExpression(parent)) return void 0;
|
|
4013
4308
|
if (!parent.arguments.some((argument) => argument === node)) return void 0;
|
|
4014
4309
|
return svelteCallMethod(parent);
|
|
4015
4310
|
};
|
|
@@ -4022,7 +4317,7 @@ var enclosingSvelteRuntimeMethod = (node) => {
|
|
|
4022
4317
|
if (isFunctionLike2(parent) && parent.body) {
|
|
4023
4318
|
if (current === parent.body || isDescendant(parent.body, current)) return void 0;
|
|
4024
4319
|
}
|
|
4025
|
-
if (
|
|
4320
|
+
if (ts16.isCallExpression(parent)) {
|
|
4026
4321
|
const method = svelteCallMethod(parent);
|
|
4027
4322
|
if (method && parent.arguments.some((argument) => argument === current || isDescendant(argument, current))) {
|
|
4028
4323
|
return method;
|
|
@@ -4036,20 +4331,20 @@ var enclosingSvelteRuntimeMethod = (node) => {
|
|
|
4036
4331
|
var svelteGeneratedIdentifierCallees = (sourceFile) => {
|
|
4037
4332
|
const names = /* @__PURE__ */ new Set();
|
|
4038
4333
|
const visit = (node) => {
|
|
4039
|
-
if (
|
|
4334
|
+
if (ts16.isVariableDeclaration(node) && ts16.isIdentifier(node.name) && node.initializer && ts16.isCallExpression(node.initializer)) {
|
|
4040
4335
|
const method = svelteCallMethod(node.initializer);
|
|
4041
4336
|
if (method && (SVELTE_TEMPLATE_FACTORIES.has(method) || SVELTE_PROP_GETTERS.has(method))) {
|
|
4042
4337
|
names.add(node.name.text);
|
|
4043
4338
|
}
|
|
4044
4339
|
}
|
|
4045
|
-
|
|
4340
|
+
ts16.forEachChild(node, visit);
|
|
4046
4341
|
};
|
|
4047
4342
|
visit(sourceFile);
|
|
4048
4343
|
return names;
|
|
4049
4344
|
};
|
|
4050
4345
|
var isSvelteCompilerCall = (call, sourceFile, identifierCallees) => {
|
|
4051
4346
|
if (svelteCallMethod(call)) return true;
|
|
4052
|
-
if (!
|
|
4347
|
+
if (!ts16.isCallExpression(call) || !ts16.isIdentifier(call.expression)) return false;
|
|
4053
4348
|
if (call.expression.text.startsWith("$$")) return true;
|
|
4054
4349
|
const names = identifierCallees ?? svelteGeneratedIdentifierCallees(sourceFile);
|
|
4055
4350
|
return names.has(call.expression.text);
|
|
@@ -4077,7 +4372,7 @@ var SVELTE_RUNE_ROOTS = /* @__PURE__ */ new Set([
|
|
|
4077
4372
|
var parameterNames = (node) => {
|
|
4078
4373
|
const names = [];
|
|
4079
4374
|
for (const parameter of node.parameters) {
|
|
4080
|
-
if (
|
|
4375
|
+
if (ts17.isIdentifier(parameter.name)) names.push(parameter.name.text);
|
|
4081
4376
|
}
|
|
4082
4377
|
return names;
|
|
4083
4378
|
};
|
|
@@ -4092,18 +4387,18 @@ var isSvelteGeneratedBlock = (node) => {
|
|
|
4092
4387
|
};
|
|
4093
4388
|
var isSvelteChildPropThunk = (node) => {
|
|
4094
4389
|
const parent = node.parent;
|
|
4095
|
-
if (!parent || !
|
|
4390
|
+
if (!parent || !ts17.isPropertyAssignment(parent)) return false;
|
|
4096
4391
|
const object = parent.parent;
|
|
4097
|
-
if (!object || !
|
|
4392
|
+
if (!object || !ts17.isObjectLiteralExpression(object)) return false;
|
|
4098
4393
|
const call = object.parent;
|
|
4099
|
-
if (!call || !
|
|
4394
|
+
if (!call || !ts17.isCallExpression(call)) return false;
|
|
4100
4395
|
return call.arguments.some((argument) => argument === object);
|
|
4101
4396
|
};
|
|
4102
4397
|
var isSvelteRuneCall = (node) => {
|
|
4103
|
-
if (!
|
|
4398
|
+
if (!ts17.isCallExpression(node)) return false;
|
|
4104
4399
|
let current = node.expression;
|
|
4105
|
-
while (
|
|
4106
|
-
return
|
|
4400
|
+
while (ts17.isPropertyAccessExpression(current)) current = current.expression;
|
|
4401
|
+
return ts17.isIdentifier(current) && SVELTE_RUNE_ROOTS.has(current.text);
|
|
4107
4402
|
};
|
|
4108
4403
|
var svelteClientPolicy = {
|
|
4109
4404
|
isCompiledModulePath: isSvelteCompiledPath,
|
|
@@ -4124,7 +4419,7 @@ var svelteClientPolicy = {
|
|
|
4124
4419
|
role: "store-subscription"
|
|
4125
4420
|
};
|
|
4126
4421
|
}
|
|
4127
|
-
if (
|
|
4422
|
+
if (ts17.isGetAccessorDeclaration(node) || ts17.isSetAccessorDeclaration(node)) {
|
|
4128
4423
|
return {
|
|
4129
4424
|
captureClass: "skip",
|
|
4130
4425
|
captureReason: "svelte generated accessor",
|
|
@@ -4220,28 +4515,28 @@ var svelteClientPolicy = {
|
|
|
4220
4515
|
};
|
|
4221
4516
|
|
|
4222
4517
|
// src/compiler/ssr-policy.ts
|
|
4223
|
-
import
|
|
4518
|
+
import ts18 from "typescript";
|
|
4224
4519
|
var parameterNames2 = (node) => {
|
|
4225
4520
|
const names = [];
|
|
4226
4521
|
for (const parameter of node.parameters) {
|
|
4227
|
-
if (
|
|
4522
|
+
if (ts18.isIdentifier(parameter.name)) names.push(parameter.name.text);
|
|
4228
4523
|
}
|
|
4229
4524
|
return names;
|
|
4230
4525
|
};
|
|
4231
4526
|
var isLiteralExpression2 = (expression) => {
|
|
4232
|
-
if (
|
|
4233
|
-
if (
|
|
4234
|
-
if (expression.kind ===
|
|
4527
|
+
if (ts18.isStringLiteral(expression) || ts18.isNoSubstitutionTemplateLiteral(expression)) return true;
|
|
4528
|
+
if (ts18.isNumericLiteral(expression)) return true;
|
|
4529
|
+
if (expression.kind === ts18.SyntaxKind.TrueKeyword || expression.kind === ts18.SyntaxKind.FalseKeyword || expression.kind === ts18.SyntaxKind.NullKeyword) {
|
|
4235
4530
|
return true;
|
|
4236
4531
|
}
|
|
4237
|
-
return
|
|
4532
|
+
return ts18.isIdentifier(expression) && (expression.text === "undefined" || expression.text === "NaN");
|
|
4238
4533
|
};
|
|
4239
4534
|
var isLiteralOnlyBody2 = (body) => {
|
|
4240
|
-
if (
|
|
4535
|
+
if (ts18.isBlock(body)) {
|
|
4241
4536
|
if (body.statements.length === 0) return true;
|
|
4242
4537
|
if (body.statements.length !== 1) return false;
|
|
4243
4538
|
const statement = body.statements[0];
|
|
4244
|
-
if (!statement || !
|
|
4539
|
+
if (!statement || !ts18.isReturnStatement(statement)) return false;
|
|
4245
4540
|
return !statement.expression || isLiteralExpression2(statement.expression);
|
|
4246
4541
|
}
|
|
4247
4542
|
return isLiteralExpression2(body);
|
|
@@ -4267,7 +4562,7 @@ var decideSvelteSsrFunction = (input) => {
|
|
|
4267
4562
|
const names = parameterNames2(input.node);
|
|
4268
4563
|
if (names[0] === "$$renderer") return "skip";
|
|
4269
4564
|
if (/^\$[A-Za-z]/.test(input.name)) return "skip";
|
|
4270
|
-
if (
|
|
4565
|
+
if (ts18.isGetAccessorDeclaration(input.node) || ts18.isSetAccessorDeclaration(input.node)) {
|
|
4271
4566
|
return "skip";
|
|
4272
4567
|
}
|
|
4273
4568
|
const runtimeMethod = svelteRuntimeMethod(input.node);
|
|
@@ -4547,7 +4842,8 @@ var instrumentServerModule = (state, code, filePath, incomingMap, decideFunction
|
|
|
4547
4842
|
const transformed = transformSource(code, {
|
|
4548
4843
|
filePath,
|
|
4549
4844
|
mapLocation: createSourceMapLocationMapper(filePath, incomingMap),
|
|
4550
|
-
decideFunction
|
|
4845
|
+
decideFunction,
|
|
4846
|
+
functionMetrics: true
|
|
4551
4847
|
});
|
|
4552
4848
|
if (!transformed) return void 0;
|
|
4553
4849
|
if (transformed.delta.alreadyInstrumented) return void 0;
|
|
@@ -4578,7 +4874,11 @@ var instrumentServerModule = (state, code, filePath, incomingMap, decideFunction
|
|
|
4578
4874
|
forgetModule(state, filePath);
|
|
4579
4875
|
return { code };
|
|
4580
4876
|
}
|
|
4581
|
-
|
|
4877
|
+
const nextCode = withFunctionMetricDeclarationRegistration(
|
|
4878
|
+
transformed.code,
|
|
4879
|
+
transformed.declarations
|
|
4880
|
+
);
|
|
4881
|
+
return transformed.map ? { code: nextCode, map: { ...transformed.map, names: transformed.map.names ?? [] } } : { code: nextCode };
|
|
4582
4882
|
};
|
|
4583
4883
|
|
|
4584
4884
|
// src/vite/upload-build-artifacts.ts
|
|
@@ -4679,6 +4979,9 @@ var snapshotServerInstrumentationManifest = (state) => {
|
|
|
4679
4979
|
for (const fn of delta.functions) {
|
|
4680
4980
|
const packageRelativePath = packagePathOf(fn.plan);
|
|
4681
4981
|
if (!packageRelativePath) continue;
|
|
4982
|
+
if (!fn.metricsDeclaration) {
|
|
4983
|
+
throw new Error(`Missing function metrics declaration: ${fn.functionId}`);
|
|
4984
|
+
}
|
|
4682
4985
|
const packageName = packageNameOf(fn.plan);
|
|
4683
4986
|
sourceByFunctionId.set(fn.functionId, { packageName, packageRelativePath });
|
|
4684
4987
|
functions.push({
|
|
@@ -4692,6 +4995,7 @@ var snapshotServerInstrumentationManifest = (state) => {
|
|
|
4692
4995
|
startColumn: fn.startColumn,
|
|
4693
4996
|
endLine: fn.endLine,
|
|
4694
4997
|
endColumn: fn.endColumn,
|
|
4998
|
+
metricsDeclaration: fn.metricsDeclaration,
|
|
4695
4999
|
...fn.instrumented === false ? { instrumented: false, ...fn.skipReason ? { skipReason: fn.skipReason } : {} } : {}
|
|
4696
5000
|
});
|
|
4697
5001
|
}
|