@suss/adapter-typescript 0.22.0 → 0.22.2
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/index.cjs +874 -478
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +872 -461
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import path10 from "path";
|
|
|
3
3
|
import {
|
|
4
4
|
Node as Node64,
|
|
5
5
|
Project,
|
|
6
|
-
SyntaxKind as
|
|
6
|
+
SyntaxKind as SyntaxKind12
|
|
7
7
|
} from "ts-morph";
|
|
8
8
|
import {
|
|
9
9
|
functionCallBinding as functionCallBinding2,
|
|
@@ -664,14 +664,14 @@ function parseConditionExpression(expr, depth = 0) {
|
|
|
664
664
|
if (expr.getOperatorToken() !== SyntaxKind2.ExclamationToken) {
|
|
665
665
|
return null;
|
|
666
666
|
}
|
|
667
|
-
const
|
|
668
|
-
const inner = parseConditionExpression(
|
|
667
|
+
const operand2 = expr.getOperand();
|
|
668
|
+
const inner = parseConditionExpression(operand2, depth);
|
|
669
669
|
if (inner === null) {
|
|
670
670
|
return {
|
|
671
671
|
type: "negation",
|
|
672
672
|
operand: {
|
|
673
673
|
type: "opaque",
|
|
674
|
-
sourceText:
|
|
674
|
+
sourceText: operand2.getText(),
|
|
675
675
|
reason: "complexExpression"
|
|
676
676
|
}
|
|
677
677
|
};
|
|
@@ -735,8 +735,8 @@ function parseConditionExpression(expr, depth = 0) {
|
|
|
735
735
|
const rightIsNull = isNullOrUndefined(right);
|
|
736
736
|
if (leftIsNull || rightIsNull) {
|
|
737
737
|
const subject = resolveSubject(leftIsNull ? right : left);
|
|
738
|
-
const
|
|
739
|
-
return { type: "nullCheck", subject, negated };
|
|
738
|
+
const negated2 = op === "neq";
|
|
739
|
+
return { type: "nullCheck", subject, negated: negated2 };
|
|
740
740
|
}
|
|
741
741
|
}
|
|
742
742
|
if (Node5.isTypeOfExpression(left) && Node5.isStringLiteral(right) && (opText === "===" || opText === "==")) {
|
|
@@ -2583,7 +2583,7 @@ function isNotYetPlaceholder(value) {
|
|
|
2583
2583
|
return value.getKind() === SyntaxKind3.NullKeyword || Node13.isIdentifier(value) && value.getText() === "undefined";
|
|
2584
2584
|
}
|
|
2585
2585
|
function isConstruction(value) {
|
|
2586
|
-
return Node13.isCallExpression(value) || Node13.isNewExpression(value);
|
|
2586
|
+
return Node13.isCallExpression(value) || Node13.isNewExpression(value) || Node13.isObjectLiteralExpression(value) || Node13.isArrayLiteralExpression(value);
|
|
2587
2587
|
}
|
|
2588
2588
|
function sourceOf(node) {
|
|
2589
2589
|
return node.getText().replace(/\s+/g, " ").trim();
|
|
@@ -3054,10 +3054,10 @@ function emitValue(db, table, value) {
|
|
|
3054
3054
|
}
|
|
3055
3055
|
return id;
|
|
3056
3056
|
}
|
|
3057
|
-
const
|
|
3058
|
-
if (
|
|
3059
|
-
fact(db, "fallbackBranch", id, emitValue(db, table,
|
|
3060
|
-
fact(db, "fallbackBranch", id, emitValue(db, table,
|
|
3057
|
+
const fallback2 = asFallbackExpression(expression);
|
|
3058
|
+
if (fallback2 !== null) {
|
|
3059
|
+
fact(db, "fallbackBranch", id, emitValue(db, table, fallback2.getLeft()));
|
|
3060
|
+
fact(db, "fallbackBranch", id, emitValue(db, table, fallback2.getRight()));
|
|
3061
3061
|
return id;
|
|
3062
3062
|
}
|
|
3063
3063
|
if (Node14.isCallExpression(expression) || Node14.isNewExpression(expression)) {
|
|
@@ -3145,9 +3145,9 @@ function emitBindingElementFacts(db, table, element) {
|
|
|
3145
3145
|
property.getText()
|
|
3146
3146
|
);
|
|
3147
3147
|
}
|
|
3148
|
-
const
|
|
3149
|
-
if (
|
|
3150
|
-
fact(db, "binds", id, emitValue(db, table,
|
|
3148
|
+
const fallback2 = element.getInitializer();
|
|
3149
|
+
if (fallback2 !== void 0) {
|
|
3150
|
+
fact(db, "binds", id, emitValue(db, table, fallback2));
|
|
3151
3151
|
}
|
|
3152
3152
|
return id;
|
|
3153
3153
|
}
|
|
@@ -4352,7 +4352,7 @@ function declarationOf(value) {
|
|
|
4352
4352
|
}
|
|
4353
4353
|
|
|
4354
4354
|
// src/discovery/clientCall.ts
|
|
4355
|
-
import { Node as
|
|
4355
|
+
import { Node as Node18 } from "ts-morph";
|
|
4356
4356
|
|
|
4357
4357
|
// src/discovery/importScan.ts
|
|
4358
4358
|
import path3 from "path";
|
|
@@ -4381,8 +4381,8 @@ function commonDirectoryOf(files) {
|
|
|
4381
4381
|
}
|
|
4382
4382
|
shared = shared.slice(0, i);
|
|
4383
4383
|
}
|
|
4384
|
-
const
|
|
4385
|
-
return
|
|
4384
|
+
const joined2 = shared.join(path2.sep);
|
|
4385
|
+
return joined2.length > 1 ? joined2 : void 0;
|
|
4386
4386
|
}
|
|
4387
4387
|
var DEFAULT_RESOLUTION = {
|
|
4388
4388
|
moduleResolution: ts3.ModuleResolutionKind.Bundler,
|
|
@@ -4649,15 +4649,609 @@ function resolveImportedLocalName(sourceFile, importModule, importName) {
|
|
|
4649
4649
|
}
|
|
4650
4650
|
|
|
4651
4651
|
// src/discovery/resolveValue.ts
|
|
4652
|
-
import { Node as
|
|
4652
|
+
import { Node as Node17 } from "ts-morph";
|
|
4653
|
+
import { force as force2, literalOf } from "@suss/values";
|
|
4654
|
+
|
|
4655
|
+
// src/values/evaluator.ts
|
|
4656
|
+
import { Evaluator, force } from "@suss/values";
|
|
4657
|
+
|
|
4658
|
+
// src/values/lowering.ts
|
|
4659
|
+
import { Node as Node16, SyntaxKind as SyntaxKind5 } from "ts-morph";
|
|
4660
|
+
var ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
4661
|
+
"=",
|
|
4662
|
+
"+=",
|
|
4663
|
+
"-=",
|
|
4664
|
+
"*=",
|
|
4665
|
+
"/=",
|
|
4666
|
+
"??=",
|
|
4667
|
+
"||=",
|
|
4668
|
+
"&&="
|
|
4669
|
+
]);
|
|
4670
|
+
var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
4671
|
+
"push",
|
|
4672
|
+
"pop",
|
|
4673
|
+
"shift",
|
|
4674
|
+
"unshift",
|
|
4675
|
+
"splice",
|
|
4676
|
+
"sort",
|
|
4677
|
+
"reverse",
|
|
4678
|
+
"fill",
|
|
4679
|
+
"copyWithin"
|
|
4680
|
+
]);
|
|
4681
|
+
function typescriptLowering(options) {
|
|
4682
|
+
const { resolution, rows } = options;
|
|
4683
|
+
const rowModules = [
|
|
4684
|
+
...new Set(
|
|
4685
|
+
rows.flatMap((row) => row.kind === "callee" ? [row.origin.module] : [])
|
|
4686
|
+
)
|
|
4687
|
+
];
|
|
4688
|
+
const mutatedByRoot = /* @__PURE__ */ new Map();
|
|
4689
|
+
const originOf = (callee) => {
|
|
4690
|
+
const chain = memberChainOf(callee);
|
|
4691
|
+
if (chain === null) {
|
|
4692
|
+
return null;
|
|
4693
|
+
}
|
|
4694
|
+
const name = chain.names[chain.names.length - 1] ?? null;
|
|
4695
|
+
if (name === null) {
|
|
4696
|
+
return null;
|
|
4697
|
+
}
|
|
4698
|
+
const origins = resolution?.importOriginsOf(chain.root, rowModules) ?? [];
|
|
4699
|
+
const first = origins[0];
|
|
4700
|
+
if (first !== void 0) {
|
|
4701
|
+
return { module: first.module, name };
|
|
4702
|
+
}
|
|
4703
|
+
const local = resolution !== void 0 && resolution.resolveCallable(callee) !== null;
|
|
4704
|
+
if (chain.names.length > 1 || local) {
|
|
4705
|
+
return null;
|
|
4706
|
+
}
|
|
4707
|
+
return { module: "global", name };
|
|
4708
|
+
};
|
|
4709
|
+
return {
|
|
4710
|
+
expression: (node) => expressionOf(peelValue(node), originOf),
|
|
4711
|
+
statement: statementOf2,
|
|
4712
|
+
siteOf,
|
|
4713
|
+
functionOf,
|
|
4714
|
+
writtenTo: (node) => {
|
|
4715
|
+
if (resolution === void 0) {
|
|
4716
|
+
return null;
|
|
4717
|
+
}
|
|
4718
|
+
const target = peelValue(node);
|
|
4719
|
+
return resolution.resolveWrittenValue(target) ?? resolution.resolveObject(target);
|
|
4720
|
+
},
|
|
4721
|
+
callable: (node) => {
|
|
4722
|
+
const call = peelValue(node);
|
|
4723
|
+
if (resolution === void 0 || !Node16.isCallExpression(call) && !Node16.isNewExpression(call)) {
|
|
4724
|
+
return null;
|
|
4725
|
+
}
|
|
4726
|
+
const target = resolution.resolveCallable(call.getExpression());
|
|
4727
|
+
return target !== null && Node16.isFunctionLikeDeclaration(target) ? target : null;
|
|
4728
|
+
},
|
|
4729
|
+
mutatedInNestedFunction: (root, name) => {
|
|
4730
|
+
let mutated = mutatedByRoot.get(root);
|
|
4731
|
+
if (mutated === void 0) {
|
|
4732
|
+
mutated = namesMutatedInNestedFunctions(root);
|
|
4733
|
+
mutatedByRoot.set(root, mutated);
|
|
4734
|
+
}
|
|
4735
|
+
return mutated.has(name);
|
|
4736
|
+
},
|
|
4737
|
+
freeNamesOf,
|
|
4738
|
+
holeNameOf: placeholderName,
|
|
4739
|
+
rows
|
|
4740
|
+
};
|
|
4741
|
+
}
|
|
4742
|
+
function placeholderName(expr) {
|
|
4743
|
+
if (Node16.isIdentifier(expr)) {
|
|
4744
|
+
return expr.getText();
|
|
4745
|
+
}
|
|
4746
|
+
if (Node16.isPropertyAccessExpression(expr)) {
|
|
4747
|
+
return expr.getName();
|
|
4748
|
+
}
|
|
4749
|
+
return "param";
|
|
4750
|
+
}
|
|
4751
|
+
function expressionOf(node, originOf) {
|
|
4752
|
+
if (Node16.isStringLiteral(node) || Node16.isNoSubstitutionTemplateLiteral(node)) {
|
|
4753
|
+
return { kind: "literal", value: node.getLiteralValue() };
|
|
4754
|
+
}
|
|
4755
|
+
if (Node16.isNumericLiteral(node)) {
|
|
4756
|
+
return { kind: "literal", value: node.getLiteralValue() };
|
|
4757
|
+
}
|
|
4758
|
+
if (Node16.isTrueLiteral(node)) {
|
|
4759
|
+
return { kind: "literal", value: true };
|
|
4760
|
+
}
|
|
4761
|
+
if (Node16.isFalseLiteral(node)) {
|
|
4762
|
+
return { kind: "literal", value: false };
|
|
4763
|
+
}
|
|
4764
|
+
if (Node16.isNullLiteral(node)) {
|
|
4765
|
+
return { kind: "literal", value: null };
|
|
4766
|
+
}
|
|
4767
|
+
if (Node16.isIdentifier(node)) {
|
|
4768
|
+
return node.getText() === "undefined" ? { kind: "literal", value: void 0 } : { kind: "name", text: node.getText() };
|
|
4769
|
+
}
|
|
4770
|
+
if (Node16.isTemplateExpression(node)) {
|
|
4771
|
+
return {
|
|
4772
|
+
kind: "template",
|
|
4773
|
+
parts: [
|
|
4774
|
+
{ text: node.getHead().getLiteralText() },
|
|
4775
|
+
...node.getTemplateSpans().flatMap((span) => [
|
|
4776
|
+
{ expression: span.getExpression() },
|
|
4777
|
+
{ text: span.getLiteral().getLiteralText() }
|
|
4778
|
+
])
|
|
4779
|
+
]
|
|
4780
|
+
};
|
|
4781
|
+
}
|
|
4782
|
+
if (Node16.isPropertyAccessExpression(node)) {
|
|
4783
|
+
return {
|
|
4784
|
+
kind: "member",
|
|
4785
|
+
object: node.getExpression(),
|
|
4786
|
+
name: node.getName()
|
|
4787
|
+
};
|
|
4788
|
+
}
|
|
4789
|
+
if (Node16.isElementAccessExpression(node)) {
|
|
4790
|
+
const index = node.getArgumentExpression();
|
|
4791
|
+
return index === void 0 ? { kind: "opaque" } : { kind: "element", object: node.getExpression(), index };
|
|
4792
|
+
}
|
|
4793
|
+
if (Node16.isArrayLiteralExpression(node)) {
|
|
4794
|
+
return { kind: "array", items: node.getElements().map(elementOf) };
|
|
4795
|
+
}
|
|
4796
|
+
if (Node16.isObjectLiteralExpression(node)) {
|
|
4797
|
+
return { kind: "record", fields: node.getProperties().flatMap(fieldOf) };
|
|
4798
|
+
}
|
|
4799
|
+
if (Node16.isCallExpression(node) || Node16.isNewExpression(node)) {
|
|
4800
|
+
return {
|
|
4801
|
+
kind: "call",
|
|
4802
|
+
callee: calleeOf(node.getExpression(), originOf),
|
|
4803
|
+
args: node.getArguments().map(elementOf),
|
|
4804
|
+
constructs: Node16.isNewExpression(node)
|
|
4805
|
+
};
|
|
4806
|
+
}
|
|
4807
|
+
if (Node16.isBinaryExpression(node)) {
|
|
4808
|
+
const operator = node.getOperatorToken().getText();
|
|
4809
|
+
return ASSIGNMENT_OPERATORS.has(operator) ? { kind: "opaque" } : {
|
|
4810
|
+
kind: "operator",
|
|
4811
|
+
operator,
|
|
4812
|
+
operands: [node.getLeft(), node.getRight()]
|
|
4813
|
+
};
|
|
4814
|
+
}
|
|
4815
|
+
if (Node16.isPrefixUnaryExpression(node)) {
|
|
4816
|
+
const operator = node.getOperatorToken();
|
|
4817
|
+
return operator === SyntaxKind5.ExclamationToken ? { kind: "operator", operator: "!", operands: [node.getOperand()] } : { kind: "opaque" };
|
|
4818
|
+
}
|
|
4819
|
+
if (Node16.isConditionalExpression(node)) {
|
|
4820
|
+
return {
|
|
4821
|
+
kind: "conditional",
|
|
4822
|
+
condition: node.getCondition(),
|
|
4823
|
+
whenTrue: node.getWhenTrue(),
|
|
4824
|
+
whenFalse: node.getWhenFalse()
|
|
4825
|
+
};
|
|
4826
|
+
}
|
|
4827
|
+
if (Node16.isArrowFunction(node) || Node16.isFunctionExpression(node)) {
|
|
4828
|
+
return { kind: "function", node };
|
|
4829
|
+
}
|
|
4830
|
+
return { kind: "opaque" };
|
|
4831
|
+
}
|
|
4832
|
+
function elementOf(node) {
|
|
4833
|
+
return Node16.isSpreadElement(node) ? { kind: "spread", node: node.getExpression() } : { kind: "value", node };
|
|
4834
|
+
}
|
|
4835
|
+
function fieldOf(property) {
|
|
4836
|
+
if (Node16.isSpreadAssignment(property)) {
|
|
4837
|
+
return [{ kind: "spread", node: property.getExpression() }];
|
|
4838
|
+
}
|
|
4839
|
+
if (Node16.isShorthandPropertyAssignment(property)) {
|
|
4840
|
+
const nameNode2 = property.getNameNode();
|
|
4841
|
+
return [{ kind: "field", name: nameNode2.getText(), value: nameNode2 }];
|
|
4842
|
+
}
|
|
4843
|
+
if (!Node16.isPropertyAssignment(property)) {
|
|
4844
|
+
return [];
|
|
4845
|
+
}
|
|
4846
|
+
const value = property.getInitializer();
|
|
4847
|
+
if (value === void 0) {
|
|
4848
|
+
return [];
|
|
4849
|
+
}
|
|
4850
|
+
const nameNode = property.getNameNode();
|
|
4851
|
+
if (Node16.isComputedPropertyName(nameNode)) {
|
|
4852
|
+
return [{ kind: "computed", name: nameNode.getExpression(), value }];
|
|
4853
|
+
}
|
|
4854
|
+
const name = Node16.isStringLiteral(nameNode) || Node16.isNumericLiteral(nameNode) ? String(nameNode.getLiteralValue()) : nameNode.getText();
|
|
4855
|
+
return [{ kind: "field", name, value }];
|
|
4856
|
+
}
|
|
4857
|
+
function calleeOf(expression, originOf) {
|
|
4858
|
+
const callee = peelValue(expression);
|
|
4859
|
+
if (Node16.isPropertyAccessExpression(callee)) {
|
|
4860
|
+
return {
|
|
4861
|
+
receiver: callee.getExpression(),
|
|
4862
|
+
name: callee.getName(),
|
|
4863
|
+
origin: () => originOf(callee)
|
|
4864
|
+
};
|
|
4865
|
+
}
|
|
4866
|
+
if (Node16.isIdentifier(callee)) {
|
|
4867
|
+
return {
|
|
4868
|
+
receiver: null,
|
|
4869
|
+
name: callee.getText(),
|
|
4870
|
+
origin: () => originOf(callee)
|
|
4871
|
+
};
|
|
4872
|
+
}
|
|
4873
|
+
return { receiver: null, name: null, origin: () => null };
|
|
4874
|
+
}
|
|
4875
|
+
function memberChainOf(node) {
|
|
4876
|
+
const names = [];
|
|
4877
|
+
let current2 = peelValue(node);
|
|
4878
|
+
while (Node16.isPropertyAccessExpression(current2)) {
|
|
4879
|
+
names.unshift(current2.getName());
|
|
4880
|
+
current2 = peelValue(current2.getExpression());
|
|
4881
|
+
}
|
|
4882
|
+
if (!Node16.isIdentifier(current2)) {
|
|
4883
|
+
return null;
|
|
4884
|
+
}
|
|
4885
|
+
return { root: current2, names: [current2.getText(), ...names] };
|
|
4886
|
+
}
|
|
4887
|
+
function statementOf2(node) {
|
|
4888
|
+
if (Node16.isVariableStatement(node)) {
|
|
4889
|
+
return {
|
|
4890
|
+
kind: "declare",
|
|
4891
|
+
bindings: node.getDeclarationList().getDeclarations().flatMap(
|
|
4892
|
+
(declaration) => declarationsOf2(
|
|
4893
|
+
declaration.getNameNode(),
|
|
4894
|
+
declaration.getInitializer() ?? null
|
|
4895
|
+
)
|
|
4896
|
+
)
|
|
4897
|
+
};
|
|
4898
|
+
}
|
|
4899
|
+
if (Node16.isExpressionStatement(node)) {
|
|
4900
|
+
const expression = peelValue(node.getExpression());
|
|
4901
|
+
if (Node16.isBinaryExpression(expression)) {
|
|
4902
|
+
const operator = expression.getOperatorToken().getText();
|
|
4903
|
+
if (ASSIGNMENT_OPERATORS.has(operator)) {
|
|
4904
|
+
return {
|
|
4905
|
+
kind: "assign",
|
|
4906
|
+
target: expression.getLeft(),
|
|
4907
|
+
operator: operator === "=" ? null : operator.slice(0, -1),
|
|
4908
|
+
value: expression.getRight()
|
|
4909
|
+
};
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
return { kind: "expression", value: node.getExpression() };
|
|
4913
|
+
}
|
|
4914
|
+
if (Node16.isIfStatement(node)) {
|
|
4915
|
+
const otherwise = node.getElseStatement();
|
|
4916
|
+
return {
|
|
4917
|
+
kind: "branch",
|
|
4918
|
+
condition: node.getExpression(),
|
|
4919
|
+
arms: [
|
|
4920
|
+
armOf(node.getThenStatement()),
|
|
4921
|
+
otherwise === void 0 ? [] : armOf(otherwise)
|
|
4922
|
+
]
|
|
4923
|
+
};
|
|
4924
|
+
}
|
|
4925
|
+
if (Node16.isSwitchStatement(node)) {
|
|
4926
|
+
return {
|
|
4927
|
+
kind: "branch",
|
|
4928
|
+
condition: null,
|
|
4929
|
+
arms: node.getClauses().map((clause) => clause.getStatements())
|
|
4930
|
+
};
|
|
4931
|
+
}
|
|
4932
|
+
if (Node16.isIterationStatement(node)) {
|
|
4933
|
+
return { kind: "loop", body: armOf(node.getStatement()) };
|
|
4934
|
+
}
|
|
4935
|
+
if (Node16.isReturnStatement(node)) {
|
|
4936
|
+
return { kind: "return", value: node.getExpression() ?? null };
|
|
4937
|
+
}
|
|
4938
|
+
if (Node16.isBlock(node)) {
|
|
4939
|
+
return { kind: "block", body: node.getStatements() };
|
|
4940
|
+
}
|
|
4941
|
+
if (Node16.isTryStatement(node)) {
|
|
4942
|
+
return {
|
|
4943
|
+
kind: "block",
|
|
4944
|
+
body: [
|
|
4945
|
+
...node.getTryBlock().getStatements(),
|
|
4946
|
+
...node.getFinallyBlock()?.getStatements() ?? []
|
|
4947
|
+
]
|
|
4948
|
+
};
|
|
4949
|
+
}
|
|
4950
|
+
return { kind: "opaque" };
|
|
4951
|
+
}
|
|
4952
|
+
function armOf(statement) {
|
|
4953
|
+
return Node16.isBlock(statement) ? statement.getStatements() : [statement];
|
|
4954
|
+
}
|
|
4955
|
+
function declarationsOf2(nameNode, value) {
|
|
4956
|
+
if (Node16.isIdentifier(nameNode)) {
|
|
4957
|
+
return [{ name: nameNode.getText(), value }];
|
|
4958
|
+
}
|
|
4959
|
+
if (Node16.isObjectBindingPattern(nameNode) || Node16.isArrayBindingPattern(nameNode)) {
|
|
4960
|
+
return nameNode.getElements().flatMap(
|
|
4961
|
+
(element) => Node16.isBindingElement(element) ? declarationsOf2(element.getNameNode(), null) : []
|
|
4962
|
+
);
|
|
4963
|
+
}
|
|
4964
|
+
return [];
|
|
4965
|
+
}
|
|
4966
|
+
function isRoot(node) {
|
|
4967
|
+
return Node16.isSourceFile(node) || Node16.isFunctionLikeDeclaration(node);
|
|
4968
|
+
}
|
|
4969
|
+
function isStandaloneBlock(node) {
|
|
4970
|
+
const parent = node.getParent();
|
|
4971
|
+
return parent !== void 0 && (Node16.isBlock(parent) || Node16.isSourceFile(parent) || Node16.isModuleBlock(parent) || Node16.isCaseClause(parent) || Node16.isDefaultClause(parent));
|
|
4972
|
+
}
|
|
4973
|
+
function isPathStatement(node) {
|
|
4974
|
+
if (Node16.isBlock(node)) {
|
|
4975
|
+
return isStandaloneBlock(node);
|
|
4976
|
+
}
|
|
4977
|
+
return Node16.isStatement(node) && !Node16.isFunctionDeclaration(node);
|
|
4978
|
+
}
|
|
4979
|
+
function siteOf(node) {
|
|
4980
|
+
const path14 = [];
|
|
4981
|
+
let current2 = node;
|
|
4982
|
+
for (; ; ) {
|
|
4983
|
+
const parent = current2.getParent();
|
|
4984
|
+
if (parent === void 0) {
|
|
4985
|
+
return null;
|
|
4986
|
+
}
|
|
4987
|
+
if (isPathStatement(current2)) {
|
|
4988
|
+
path14.unshift(current2);
|
|
4989
|
+
}
|
|
4990
|
+
if (isRoot(parent)) {
|
|
4991
|
+
return { root: parent, path: path14 };
|
|
4992
|
+
}
|
|
4993
|
+
current2 = parent;
|
|
4994
|
+
}
|
|
4995
|
+
}
|
|
4996
|
+
function functionOf(node) {
|
|
4997
|
+
if (Node16.isSourceFile(node)) {
|
|
4998
|
+
return { parameters: [], body: node.getStatements() };
|
|
4999
|
+
}
|
|
5000
|
+
if (!Node16.isFunctionLikeDeclaration(node)) {
|
|
5001
|
+
return null;
|
|
5002
|
+
}
|
|
5003
|
+
const parameters = node.getParameters().flatMap((parameter) => {
|
|
5004
|
+
const nameNode = parameter.getNameNode();
|
|
5005
|
+
return Node16.isIdentifier(nameNode) ? [
|
|
5006
|
+
{
|
|
5007
|
+
name: nameNode.getText(),
|
|
5008
|
+
default: parameter.getInitializer() ?? null
|
|
5009
|
+
}
|
|
5010
|
+
] : [];
|
|
5011
|
+
});
|
|
5012
|
+
const body = Node16.isBodied(node) ? node.getBody() : Node16.isBodyable(node) ? node.getBody() : void 0;
|
|
5013
|
+
if (body === void 0) {
|
|
5014
|
+
return { parameters, body: [] };
|
|
5015
|
+
}
|
|
5016
|
+
return Node16.isBlock(body) ? { parameters, body: body.getStatements() } : { parameters, body: { expression: body } };
|
|
5017
|
+
}
|
|
5018
|
+
function namesMutatedInNestedFunctions(root) {
|
|
5019
|
+
const mutated = /* @__PURE__ */ new Set();
|
|
5020
|
+
root.forEachDescendant((descendant) => {
|
|
5021
|
+
const written = writtenNameOf(descendant);
|
|
5022
|
+
if (written !== null && enclosingRootOf(descendant) !== root) {
|
|
5023
|
+
mutated.add(written);
|
|
5024
|
+
}
|
|
5025
|
+
});
|
|
5026
|
+
return mutated;
|
|
5027
|
+
}
|
|
5028
|
+
function writtenNameOf(node) {
|
|
5029
|
+
if (Node16.isBinaryExpression(node)) {
|
|
5030
|
+
const target = peelValue(node.getLeft());
|
|
5031
|
+
return ASSIGNMENT_OPERATORS.has(node.getOperatorToken().getText()) && Node16.isIdentifier(target) ? target.getText() : null;
|
|
5032
|
+
}
|
|
5033
|
+
if (Node16.isPostfixUnaryExpression(node) || Node16.isPrefixUnaryExpression(node)) {
|
|
5034
|
+
const operand2 = peelValue(node.getOperand());
|
|
5035
|
+
return Node16.isIdentifier(operand2) ? operand2.getText() : null;
|
|
5036
|
+
}
|
|
5037
|
+
if (Node16.isCallExpression(node)) {
|
|
5038
|
+
const callee = peelValue(node.getExpression());
|
|
5039
|
+
if (!Node16.isPropertyAccessExpression(callee)) {
|
|
5040
|
+
return null;
|
|
5041
|
+
}
|
|
5042
|
+
const receiver = peelValue(callee.getExpression());
|
|
5043
|
+
return MUTATING_METHODS.has(callee.getName()) && Node16.isIdentifier(receiver) ? receiver.getText() : null;
|
|
5044
|
+
}
|
|
5045
|
+
return null;
|
|
5046
|
+
}
|
|
5047
|
+
function enclosingRootOf(node) {
|
|
5048
|
+
let current2 = node.getParent();
|
|
5049
|
+
while (current2 !== void 0 && !isRoot(current2)) {
|
|
5050
|
+
current2 = current2.getParent();
|
|
5051
|
+
}
|
|
5052
|
+
return current2;
|
|
5053
|
+
}
|
|
5054
|
+
function freeNamesOf(fn) {
|
|
5055
|
+
const declared = /* @__PURE__ */ new Set();
|
|
5056
|
+
const read2 = /* @__PURE__ */ new Set();
|
|
5057
|
+
fn.forEachDescendant((descendant) => {
|
|
5058
|
+
if (!Node16.isIdentifier(descendant)) {
|
|
5059
|
+
return;
|
|
5060
|
+
}
|
|
5061
|
+
const parent = descendant.getParent();
|
|
5062
|
+
if (Node16.isPropertyAccessExpression(parent) && parent.getNameNode() === descendant) {
|
|
5063
|
+
return;
|
|
5064
|
+
}
|
|
5065
|
+
if (Node16.isVariableDeclaration(parent) || Node16.isParameterDeclaration(parent) || Node16.isBindingElement(parent) || Node16.isFunctionDeclaration(parent)) {
|
|
5066
|
+
declared.add(descendant.getText());
|
|
5067
|
+
return;
|
|
5068
|
+
}
|
|
5069
|
+
if (Node16.isPropertyAssignment(parent) && parent.getNameNode() === descendant) {
|
|
5070
|
+
return;
|
|
5071
|
+
}
|
|
5072
|
+
read2.add(descendant.getText());
|
|
5073
|
+
});
|
|
5074
|
+
return [...read2].filter((name) => !declared.has(name));
|
|
5075
|
+
}
|
|
5076
|
+
|
|
5077
|
+
// src/values/rows.ts
|
|
5078
|
+
import {
|
|
5079
|
+
appended,
|
|
5080
|
+
concat,
|
|
5081
|
+
constant,
|
|
5082
|
+
equals,
|
|
5083
|
+
extended,
|
|
5084
|
+
fallback,
|
|
5085
|
+
isPresent,
|
|
5086
|
+
joined,
|
|
5087
|
+
joinedPath,
|
|
5088
|
+
negated,
|
|
5089
|
+
operand,
|
|
5090
|
+
plus,
|
|
5091
|
+
readableFallback,
|
|
5092
|
+
truthOf
|
|
5093
|
+
} from "@suss/values";
|
|
5094
|
+
var PATH_MODULES = ["path", "node:path", "path/posix", "node:path/posix"];
|
|
5095
|
+
var operatorRows = [
|
|
5096
|
+
{
|
|
5097
|
+
kind: "operator",
|
|
5098
|
+
operator: "+",
|
|
5099
|
+
arity: 2,
|
|
5100
|
+
apply: ([a, b]) => plus(operand(a), operand(b))
|
|
5101
|
+
},
|
|
5102
|
+
{
|
|
5103
|
+
kind: "operator",
|
|
5104
|
+
operator: "===",
|
|
5105
|
+
arity: 2,
|
|
5106
|
+
apply: ([a, b]) => equals(operand(a), operand(b))
|
|
5107
|
+
},
|
|
5108
|
+
{
|
|
5109
|
+
kind: "operator",
|
|
5110
|
+
operator: "==",
|
|
5111
|
+
arity: 2,
|
|
5112
|
+
apply: ([a, b]) => equals(operand(a), operand(b))
|
|
5113
|
+
},
|
|
5114
|
+
{
|
|
5115
|
+
kind: "operator",
|
|
5116
|
+
operator: "!==",
|
|
5117
|
+
arity: 2,
|
|
5118
|
+
apply: ([a, b]) => negated(equals(operand(a), operand(b)))
|
|
5119
|
+
},
|
|
5120
|
+
{
|
|
5121
|
+
kind: "operator",
|
|
5122
|
+
operator: "!=",
|
|
5123
|
+
arity: 2,
|
|
5124
|
+
apply: ([a, b]) => negated(equals(operand(a), operand(b)))
|
|
5125
|
+
},
|
|
5126
|
+
{
|
|
5127
|
+
kind: "operator",
|
|
5128
|
+
operator: "!",
|
|
5129
|
+
arity: 1,
|
|
5130
|
+
apply: ([a]) => negated(operand(a))
|
|
5131
|
+
},
|
|
5132
|
+
{
|
|
5133
|
+
kind: "operator",
|
|
5134
|
+
operator: "??",
|
|
5135
|
+
arity: 2,
|
|
5136
|
+
apply: ([a, b]) => readableFallback(operand(a), operand(b), isPresent)
|
|
5137
|
+
},
|
|
5138
|
+
{
|
|
5139
|
+
kind: "operator",
|
|
5140
|
+
operator: "||",
|
|
5141
|
+
arity: 2,
|
|
5142
|
+
apply: ([a, b]) => readableFallback(operand(a), operand(b), truthOf)
|
|
5143
|
+
},
|
|
5144
|
+
{
|
|
5145
|
+
kind: "operator",
|
|
5146
|
+
operator: "&&",
|
|
5147
|
+
arity: 2,
|
|
5148
|
+
apply: ([a, b]) => fallback(operand(a), operand(b), (left) => {
|
|
5149
|
+
const truth = truthOf(left);
|
|
5150
|
+
return truth === null ? null : !truth;
|
|
5151
|
+
})
|
|
5152
|
+
}
|
|
5153
|
+
];
|
|
5154
|
+
var stringRows = [
|
|
5155
|
+
{
|
|
5156
|
+
kind: "method",
|
|
5157
|
+
method: "toString",
|
|
5158
|
+
on: "string",
|
|
5159
|
+
apply: () => ({ result: "receiver" })
|
|
5160
|
+
},
|
|
5161
|
+
{
|
|
5162
|
+
kind: "method",
|
|
5163
|
+
method: "toString",
|
|
5164
|
+
on: "constant",
|
|
5165
|
+
apply: ({ receiver }) => ({ result: concat([operand(receiver)]) })
|
|
5166
|
+
},
|
|
5167
|
+
{
|
|
5168
|
+
kind: "method",
|
|
5169
|
+
method: "concat",
|
|
5170
|
+
on: "string",
|
|
5171
|
+
apply: ({ receiver, args }) => ({
|
|
5172
|
+
result: concat([operand(receiver), ...args])
|
|
5173
|
+
})
|
|
5174
|
+
}
|
|
5175
|
+
];
|
|
5176
|
+
var sequenceRows = ["sequence", "unbounded"].flatMap((on) => [
|
|
5177
|
+
{
|
|
5178
|
+
kind: "method",
|
|
5179
|
+
method: "push",
|
|
5180
|
+
on,
|
|
5181
|
+
apply: ({ receiver, args }) => ({
|
|
5182
|
+
result: constant(0),
|
|
5183
|
+
receiver: appended(operand(receiver), args)
|
|
5184
|
+
})
|
|
5185
|
+
},
|
|
5186
|
+
{
|
|
5187
|
+
kind: "method",
|
|
5188
|
+
method: "concat",
|
|
5189
|
+
on,
|
|
5190
|
+
apply: ({ receiver, args, contentOf }) => ({
|
|
5191
|
+
result: args.reduce(
|
|
5192
|
+
(sequence, other) => extended(sequence, contentOf(other)),
|
|
5193
|
+
operand(receiver)
|
|
5194
|
+
)
|
|
5195
|
+
})
|
|
5196
|
+
},
|
|
5197
|
+
{
|
|
5198
|
+
kind: "method",
|
|
5199
|
+
method: "join",
|
|
5200
|
+
on,
|
|
5201
|
+
apply: ({ receiver, args }) => ({
|
|
5202
|
+
result: joined(operand(receiver), args[0])
|
|
5203
|
+
})
|
|
5204
|
+
}
|
|
5205
|
+
]);
|
|
5206
|
+
var calleeRows = [
|
|
5207
|
+
{
|
|
5208
|
+
kind: "callee",
|
|
5209
|
+
origin: { module: "global", name: "String" },
|
|
5210
|
+
apply: ({ args }) => ({ result: concat([operand(args[0])]) })
|
|
5211
|
+
},
|
|
5212
|
+
...PATH_MODULES.map(
|
|
5213
|
+
(module) => ({
|
|
5214
|
+
kind: "callee",
|
|
5215
|
+
origin: { module, name: "join" },
|
|
5216
|
+
apply: ({ args }) => ({ result: joinedPath(args) })
|
|
5217
|
+
})
|
|
5218
|
+
)
|
|
5219
|
+
];
|
|
5220
|
+
var typescriptRows = [
|
|
5221
|
+
...operatorRows,
|
|
5222
|
+
...stringRows,
|
|
5223
|
+
...sequenceRows,
|
|
5224
|
+
...calleeRows
|
|
5225
|
+
];
|
|
5226
|
+
|
|
5227
|
+
// src/values/evaluator.ts
|
|
5228
|
+
var evaluators = /* @__PURE__ */ new WeakMap();
|
|
5229
|
+
function evaluatorFor(node, resolution) {
|
|
5230
|
+
const key = resolution ?? node.getProject();
|
|
5231
|
+
let evaluator = evaluators.get(key);
|
|
5232
|
+
if (evaluator === void 0) {
|
|
5233
|
+
evaluator = new Evaluator(
|
|
5234
|
+
typescriptLowering(
|
|
5235
|
+
resolution === void 0 ? { rows: typescriptRows } : { resolution, rows: typescriptRows }
|
|
5236
|
+
)
|
|
5237
|
+
);
|
|
5238
|
+
evaluators.set(key, evaluator);
|
|
5239
|
+
}
|
|
5240
|
+
return evaluator;
|
|
5241
|
+
}
|
|
5242
|
+
function evaluatedValue(node, resolution) {
|
|
5243
|
+
return force(evaluatorFor(node, resolution).evaluate(node));
|
|
5244
|
+
}
|
|
5245
|
+
|
|
5246
|
+
// src/discovery/resolveValue.ts
|
|
4653
5247
|
function couldNameAValue(value) {
|
|
4654
|
-
return
|
|
5248
|
+
return Node17.isIdentifier(value) || Node17.isPropertyAccessExpression(value) || Node17.isElementAccessExpression(value) || Node17.isCallExpression(value);
|
|
4655
5249
|
}
|
|
4656
5250
|
function propertyValueOf(property) {
|
|
4657
|
-
if (
|
|
5251
|
+
if (Node17.isPropertyAssignment(property)) {
|
|
4658
5252
|
return property.getInitializer() ?? null;
|
|
4659
5253
|
}
|
|
4660
|
-
if (
|
|
5254
|
+
if (Node17.isShorthandPropertyAssignment(property)) {
|
|
4661
5255
|
return property.getNameNode();
|
|
4662
5256
|
}
|
|
4663
5257
|
return null;
|
|
@@ -4678,7 +5272,7 @@ function objectLiteralOf(value, resolution) {
|
|
|
4678
5272
|
return literalValueOf(
|
|
4679
5273
|
value,
|
|
4680
5274
|
resolution,
|
|
4681
|
-
(node) =>
|
|
5275
|
+
(node) => Node17.isObjectLiteralExpression(node)
|
|
4682
5276
|
);
|
|
4683
5277
|
}
|
|
4684
5278
|
function propertiesOf(object, resolution) {
|
|
@@ -4690,7 +5284,7 @@ function propertiesReached(object, resolution, seen) {
|
|
|
4690
5284
|
}
|
|
4691
5285
|
seen.add(object);
|
|
4692
5286
|
return object.getProperties().flatMap((property) => {
|
|
4693
|
-
if (!
|
|
5287
|
+
if (!Node17.isSpreadAssignment(property)) {
|
|
4694
5288
|
return [property];
|
|
4695
5289
|
}
|
|
4696
5290
|
const spread = objectLiteralOf(property.getExpression(), resolution);
|
|
@@ -4699,17 +5293,17 @@ function propertiesReached(object, resolution, seen) {
|
|
|
4699
5293
|
}
|
|
4700
5294
|
function writtenNodeOf(value, resolution) {
|
|
4701
5295
|
const written = factKeyOf(value);
|
|
4702
|
-
if (
|
|
5296
|
+
if (Node17.isNewExpression(written)) {
|
|
4703
5297
|
return written;
|
|
4704
5298
|
}
|
|
4705
|
-
if (
|
|
5299
|
+
if (Node17.isCallExpression(written)) {
|
|
4706
5300
|
return writtenThroughCall(written, resolution);
|
|
4707
5301
|
}
|
|
4708
5302
|
if (resolution === void 0 || !couldNameAValue(written)) {
|
|
4709
5303
|
return null;
|
|
4710
5304
|
}
|
|
4711
5305
|
const resolved = resolution.resolveWrittenValue(written);
|
|
4712
|
-
return resolved !== null &&
|
|
5306
|
+
return resolved !== null && Node17.isCallExpression(resolved) ? writtenThroughCall(resolved, resolution) : resolved;
|
|
4713
5307
|
}
|
|
4714
5308
|
function writtenThroughCall(call, resolution) {
|
|
4715
5309
|
if (resolution !== void 0 && resolution.resolveCallable(call.getExpression()) !== null) {
|
|
@@ -4721,24 +5315,21 @@ function writtenThroughCall(call, resolution) {
|
|
|
4721
5315
|
return call;
|
|
4722
5316
|
}
|
|
4723
5317
|
function stringValueOf(value, resolution) {
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
if (
|
|
5318
|
+
return literalOf(evaluatedValue(value, resolution));
|
|
5319
|
+
}
|
|
5320
|
+
function stringPropertyOf(object, name, resolution) {
|
|
5321
|
+
const record2 = evaluatedValue(object, resolution);
|
|
5322
|
+
if (record2.kind !== "record") {
|
|
4729
5323
|
return null;
|
|
4730
5324
|
}
|
|
4731
|
-
const
|
|
4732
|
-
return
|
|
4733
|
-
}
|
|
4734
|
-
function isStringNode(node) {
|
|
4735
|
-
return Node16.isStringLiteral(node) || Node16.isNoSubstitutionTemplateLiteral(node);
|
|
5325
|
+
const field = record2.fields.get(name);
|
|
5326
|
+
return field === void 0 ? null : literalOf(force2(field.value));
|
|
4736
5327
|
}
|
|
4737
5328
|
function arrayLiteralOf(value, resolution) {
|
|
4738
5329
|
return literalValueOf(
|
|
4739
5330
|
value,
|
|
4740
5331
|
resolution,
|
|
4741
|
-
(node) =>
|
|
5332
|
+
(node) => Node17.isArrayLiteralExpression(node)
|
|
4742
5333
|
);
|
|
4743
5334
|
}
|
|
4744
5335
|
function literalValueOf(value, resolution, isWanted) {
|
|
@@ -4761,26 +5352,26 @@ function discoverClientCalls(sourceFile, match, kind, resolution) {
|
|
|
4761
5352
|
if (!isGlobal) {
|
|
4762
5353
|
for (const varDecl of sourceFile.getVariableDeclarations()) {
|
|
4763
5354
|
const init = varDecl.getInitializer();
|
|
4764
|
-
if (init !== void 0 && (
|
|
5355
|
+
if (init !== void 0 && (Node18.isCallExpression(init) || Node18.isNewExpression(init)) && isCreationCall(init, match, resolution)) {
|
|
4765
5356
|
clientVarNames.add(varDecl.getName());
|
|
4766
5357
|
}
|
|
4767
5358
|
}
|
|
4768
5359
|
}
|
|
4769
5360
|
const methodFilter = match.methodFilter !== void 0 ? new Set(match.methodFilter) : null;
|
|
4770
5361
|
sourceFile.forEachDescendant((node) => {
|
|
4771
|
-
if (!
|
|
5362
|
+
if (!Node18.isCallExpression(node)) {
|
|
4772
5363
|
return;
|
|
4773
5364
|
}
|
|
4774
5365
|
const callee = node.getExpression();
|
|
4775
5366
|
let methodName = null;
|
|
4776
5367
|
let matched = false;
|
|
4777
|
-
if (isGlobal &&
|
|
5368
|
+
if (isGlobal && Node18.isIdentifier(callee)) {
|
|
4778
5369
|
if (callee.getText() === match.importName) {
|
|
4779
5370
|
matched = true;
|
|
4780
5371
|
}
|
|
4781
|
-
} else if (
|
|
5372
|
+
} else if (Node18.isPropertyAccessExpression(callee)) {
|
|
4782
5373
|
const subject = callee.getExpression();
|
|
4783
|
-
if (
|
|
5374
|
+
if (Node18.isIdentifier(subject) && (isClientImport(subject, match, resolution, true) || clientVarNames.has(subject.getText())) || resolvesToKnownInstance(subject, match, resolution)) {
|
|
4784
5375
|
methodName = callee.getName();
|
|
4785
5376
|
if (methodFilter === null || methodFilter.has(methodName)) {
|
|
4786
5377
|
matched = true;
|
|
@@ -4814,16 +5405,16 @@ function clientReceiverCheckFor(sourceFile, match, resolution) {
|
|
|
4814
5405
|
);
|
|
4815
5406
|
const constructedHere = /* @__PURE__ */ new Set();
|
|
4816
5407
|
sourceFile.forEachDescendant((node) => {
|
|
4817
|
-
if (
|
|
5408
|
+
if (Node18.isVariableDeclaration(node)) {
|
|
4818
5409
|
const init = node.getInitializer();
|
|
4819
|
-
if (init !== void 0 && (
|
|
5410
|
+
if (init !== void 0 && (Node18.isCallExpression(init) || Node18.isNewExpression(init)) && isCreationCall(init, match, resolution) || localName !== null && typedAsClient(node.getTypeNode(), localName)) {
|
|
4820
5411
|
constructedHere.add(node.getName());
|
|
4821
5412
|
}
|
|
4822
5413
|
return;
|
|
4823
5414
|
}
|
|
4824
|
-
if (
|
|
5415
|
+
if (Node18.isParameterDeclaration(node) && localName !== null && typedAsClient(node.getTypeNode(), localName)) {
|
|
4825
5416
|
const written = node.getNameNode();
|
|
4826
|
-
if (
|
|
5417
|
+
if (Node18.isIdentifier(written)) {
|
|
4827
5418
|
constructedHere.add(written.getText());
|
|
4828
5419
|
}
|
|
4829
5420
|
}
|
|
@@ -4834,10 +5425,10 @@ function clientReceiverCheckFor(sourceFile, match, resolution) {
|
|
|
4834
5425
|
importName: match.importName,
|
|
4835
5426
|
...match.factoryMethods === void 0 ? {} : { factoryMethods: match.factoryMethods }
|
|
4836
5427
|
};
|
|
4837
|
-
return (subject) => isClientImport(subject, match, resolution, true) ||
|
|
5428
|
+
return (subject) => isClientImport(subject, match, resolution, true) || Node18.isIdentifier(subject) && constructedHere.has(subject.getText()) || resolvesToKnownInstance(subject, full, resolution);
|
|
4838
5429
|
}
|
|
4839
5430
|
function typedAsClient(typeNode, localName) {
|
|
4840
|
-
if (typeNode === void 0 || !
|
|
5431
|
+
if (typeNode === void 0 || !Node18.isTypeReference(typeNode)) {
|
|
4841
5432
|
return false;
|
|
4842
5433
|
}
|
|
4843
5434
|
return typeNode.getTypeName().getText() === localName;
|
|
@@ -4847,27 +5438,27 @@ function resolvesToKnownInstance(subject, match, resolution) {
|
|
|
4847
5438
|
return false;
|
|
4848
5439
|
}
|
|
4849
5440
|
const written = writtenNodeOf(subject, resolution);
|
|
4850
|
-
if (written === null || !
|
|
5441
|
+
if (written === null || !Node18.isCallExpression(written) && !Node18.isNewExpression(written)) {
|
|
4851
5442
|
return false;
|
|
4852
5443
|
}
|
|
4853
5444
|
return isCreationCall(written, match, resolution);
|
|
4854
5445
|
}
|
|
4855
5446
|
function isCreationCall(call, match, resolution) {
|
|
4856
5447
|
const callee = call.getExpression();
|
|
4857
|
-
if (
|
|
5448
|
+
if (Node18.isIdentifier(callee)) {
|
|
4858
5449
|
return isClientImport(callee, match, resolution, false);
|
|
4859
5450
|
}
|
|
4860
|
-
if (!
|
|
5451
|
+
if (!Node18.isPropertyAccessExpression(callee)) {
|
|
4861
5452
|
return false;
|
|
4862
5453
|
}
|
|
4863
5454
|
const base = callee.getExpression();
|
|
4864
|
-
return
|
|
5455
|
+
return Node18.isIdentifier(base) && (match.factoryMethods?.includes(callee.getName()) ?? false) && isClientImport(base, match, resolution, false);
|
|
4865
5456
|
}
|
|
4866
5457
|
function isPathShaped(specifier) {
|
|
4867
5458
|
return specifier.startsWith(".") || specifier.startsWith("/");
|
|
4868
5459
|
}
|
|
4869
5460
|
function isClientImport(subject, match, resolution, strictDefaultName) {
|
|
4870
|
-
if (!
|
|
5461
|
+
if (!Node18.isIdentifier(subject)) {
|
|
4871
5462
|
return false;
|
|
4872
5463
|
}
|
|
4873
5464
|
if (resolution === void 0) {
|
|
@@ -4915,27 +5506,27 @@ function resolvedImportLocalName(sourceFile, importModule, importName, strictDef
|
|
|
4915
5506
|
return null;
|
|
4916
5507
|
}
|
|
4917
5508
|
function clientUnitName(enclosingFunc, methodName) {
|
|
4918
|
-
if (
|
|
5509
|
+
if (Node18.isFunctionDeclaration(enclosingFunc)) {
|
|
4919
5510
|
return enclosingFunc.getName() ?? methodName ?? "anonymous";
|
|
4920
5511
|
}
|
|
4921
|
-
if (
|
|
5512
|
+
if (Node18.isMethodDeclaration(enclosingFunc)) {
|
|
4922
5513
|
return enclosingFunc.getName();
|
|
4923
5514
|
}
|
|
4924
5515
|
const parent = enclosingFunc.getParent();
|
|
4925
|
-
if (parent !== void 0 &&
|
|
5516
|
+
if (parent !== void 0 && Node18.isVariableDeclaration(parent)) {
|
|
4926
5517
|
return parent.getName();
|
|
4927
5518
|
}
|
|
4928
|
-
if (parent !== void 0 &&
|
|
5519
|
+
if (parent !== void 0 && Node18.isPropertyAssignment(parent)) {
|
|
4929
5520
|
return parent.getName();
|
|
4930
5521
|
}
|
|
4931
5522
|
return methodName ?? "anonymous";
|
|
4932
5523
|
}
|
|
4933
5524
|
|
|
4934
5525
|
// src/discovery/decoratedMethod.ts
|
|
4935
|
-
import { Node as
|
|
5526
|
+
import { Node as Node21 } from "ts-morph";
|
|
4936
5527
|
|
|
4937
5528
|
// src/discovery/decoratedMembers.ts
|
|
4938
|
-
import { Node as
|
|
5529
|
+
import { Node as Node19 } from "ts-morph";
|
|
4939
5530
|
function importedDecoratorLocals(sourceFile, acceptedModules, canonicalNames) {
|
|
4940
5531
|
const localToCanonical = /* @__PURE__ */ new Map();
|
|
4941
5532
|
for (const importDecl of sourceFile.getImportDeclarations()) {
|
|
@@ -4955,7 +5546,7 @@ function importedDecoratorLocals(sourceFile, acceptedModules, canonicalNames) {
|
|
|
4955
5546
|
function decoratedCallablesOf(cls, decoratorNames) {
|
|
4956
5547
|
const callables = [];
|
|
4957
5548
|
for (const member of cls.getMembers()) {
|
|
4958
|
-
if (!
|
|
5549
|
+
if (!Node19.isMethodDeclaration(member) && !Node19.isPropertyDeclaration(member)) {
|
|
4959
5550
|
continue;
|
|
4960
5551
|
}
|
|
4961
5552
|
const func = callableOf(member);
|
|
@@ -4979,7 +5570,7 @@ function decoratedCallablesOf(cls, decoratorNames) {
|
|
|
4979
5570
|
return callables;
|
|
4980
5571
|
}
|
|
4981
5572
|
function callableOf(member) {
|
|
4982
|
-
if (
|
|
5573
|
+
if (Node19.isMethodDeclaration(member)) {
|
|
4983
5574
|
return toFunctionRoot(member);
|
|
4984
5575
|
}
|
|
4985
5576
|
const held = member.getInitializer();
|
|
@@ -4987,7 +5578,7 @@ function callableOf(member) {
|
|
|
4987
5578
|
}
|
|
4988
5579
|
|
|
4989
5580
|
// src/discovery/decoratorComposition.ts
|
|
4990
|
-
import { Node as
|
|
5581
|
+
import { Node as Node20, SyntaxKind as SyntaxKind6 } from "ts-morph";
|
|
4991
5582
|
function classDecoratorStandingFor(cls, names, modules, resolution) {
|
|
4992
5583
|
for (const candidate of names) {
|
|
4993
5584
|
const decorator = cls.getDecorator(candidate);
|
|
@@ -5003,7 +5594,7 @@ function classDecoratorStandingFor(cls, names, modules, resolution) {
|
|
|
5003
5594
|
return null;
|
|
5004
5595
|
}
|
|
5005
5596
|
for (const decorator of cls.getDecorators()) {
|
|
5006
|
-
const applied = resolution.importedNamesOf(
|
|
5597
|
+
const applied = resolution.importedNamesOf(calleeOf2(decorator), modules);
|
|
5007
5598
|
const standsFor = names.find((name) => applied.includes(name));
|
|
5008
5599
|
if (standsFor === void 0) {
|
|
5009
5600
|
continue;
|
|
@@ -5021,11 +5612,11 @@ function frameworkArgs(decorator, standsFor, modules, resolution) {
|
|
|
5021
5612
|
if (atClass.length > 0) {
|
|
5022
5613
|
return atClass;
|
|
5023
5614
|
}
|
|
5024
|
-
const wrapper = resolution.resolveCallable(
|
|
5615
|
+
const wrapper = resolution.resolveCallable(calleeOf2(decorator));
|
|
5025
5616
|
if (wrapper === null) {
|
|
5026
5617
|
return atClass;
|
|
5027
5618
|
}
|
|
5028
|
-
for (const call of wrapper.getDescendantsOfKind(
|
|
5619
|
+
for (const call of wrapper.getDescendantsOfKind(SyntaxKind6.CallExpression)) {
|
|
5029
5620
|
const names = resolution.importedNamesOf(call.getExpression(), modules);
|
|
5030
5621
|
if (!names.includes(standsFor)) {
|
|
5031
5622
|
continue;
|
|
@@ -5036,17 +5627,17 @@ function frameworkArgs(decorator, standsFor, modules, resolution) {
|
|
|
5036
5627
|
return atClass;
|
|
5037
5628
|
}
|
|
5038
5629
|
function statesAValue(arg, wrapper) {
|
|
5039
|
-
const identifiers =
|
|
5630
|
+
const identifiers = Node20.isIdentifier(arg) ? [arg] : arg.getDescendantsOfKind(SyntaxKind6.Identifier);
|
|
5040
5631
|
return !identifiers.some(
|
|
5041
5632
|
(identifier) => identifier.getSymbol()?.getDeclarations().some(
|
|
5042
|
-
(declaration) =>
|
|
5633
|
+
(declaration) => Node20.isParameterDeclaration(declaration) && isWithin(declaration, wrapper)
|
|
5043
5634
|
)
|
|
5044
5635
|
);
|
|
5045
5636
|
}
|
|
5046
5637
|
function isWithin(node, container) {
|
|
5047
5638
|
return node.getSourceFile() === container.getSourceFile() && node.getStart() >= container.getStart() && node.getEnd() <= container.getEnd();
|
|
5048
5639
|
}
|
|
5049
|
-
function
|
|
5640
|
+
function calleeOf2(decorator) {
|
|
5050
5641
|
const call = decorator.getCallExpression();
|
|
5051
5642
|
if (call !== void 0) {
|
|
5052
5643
|
return call.getExpression();
|
|
@@ -5059,39 +5650,39 @@ function resolverTypeName(args) {
|
|
|
5059
5650
|
return args.typeMap[args.decoratorName] ?? args.classTypeName ?? null;
|
|
5060
5651
|
}
|
|
5061
5652
|
function resolveResolverClassTypeName(decoratorArg) {
|
|
5062
|
-
if (
|
|
5653
|
+
if (Node21.isArrowFunction(decoratorArg)) {
|
|
5063
5654
|
const body = decoratorArg.getBody();
|
|
5064
|
-
if (
|
|
5655
|
+
if (Node21.isIdentifier(body)) {
|
|
5065
5656
|
return body.getText();
|
|
5066
5657
|
}
|
|
5067
5658
|
return null;
|
|
5068
5659
|
}
|
|
5069
|
-
if (
|
|
5660
|
+
if (Node21.isStringLiteral(decoratorArg)) {
|
|
5070
5661
|
return decoratorArg.getLiteralValue();
|
|
5071
5662
|
}
|
|
5072
|
-
if (
|
|
5663
|
+
if (Node21.isIdentifier(decoratorArg)) {
|
|
5073
5664
|
return decoratorArg.getText();
|
|
5074
5665
|
}
|
|
5075
5666
|
return null;
|
|
5076
5667
|
}
|
|
5077
5668
|
function resolveOperationNameOverride(decorator) {
|
|
5078
|
-
if (!
|
|
5669
|
+
if (!Node21.isDecorator(decorator)) {
|
|
5079
5670
|
return null;
|
|
5080
5671
|
}
|
|
5081
5672
|
const args = decorator.getArguments();
|
|
5082
5673
|
for (const arg of args) {
|
|
5083
|
-
if (!
|
|
5674
|
+
if (!Node21.isObjectLiteralExpression(arg)) {
|
|
5084
5675
|
continue;
|
|
5085
5676
|
}
|
|
5086
5677
|
const prop = arg.getProperty("name");
|
|
5087
|
-
if (prop === void 0 || !
|
|
5678
|
+
if (prop === void 0 || !Node21.isPropertyAssignment(prop)) {
|
|
5088
5679
|
continue;
|
|
5089
5680
|
}
|
|
5090
5681
|
const init = prop.getInitializer();
|
|
5091
5682
|
if (init === void 0) {
|
|
5092
5683
|
continue;
|
|
5093
5684
|
}
|
|
5094
|
-
if (
|
|
5685
|
+
if (Node21.isStringLiteral(init) || Node21.isNoSubstitutionTemplateLiteral(init)) {
|
|
5095
5686
|
return init.getLiteralValue();
|
|
5096
5687
|
}
|
|
5097
5688
|
}
|
|
@@ -5144,9 +5735,9 @@ function discoverDecoratedMethods(sourceFile, match, kind, resolution) {
|
|
|
5144
5735
|
}
|
|
5145
5736
|
|
|
5146
5737
|
// src/discovery/decoratedRoute.ts
|
|
5147
|
-
import { Node as
|
|
5738
|
+
import { Node as Node22 } from "ts-morph";
|
|
5148
5739
|
function resolveRoutePathArg(decorator, resolution) {
|
|
5149
|
-
if (!
|
|
5740
|
+
if (!Node22.isDecorator(decorator)) {
|
|
5150
5741
|
return "";
|
|
5151
5742
|
}
|
|
5152
5743
|
return routePathOf(decorator.getArguments(), resolution);
|
|
@@ -5174,7 +5765,7 @@ function declaredChannelOf(source, decorator, resolution) {
|
|
|
5174
5765
|
if (source.from === "unstated") {
|
|
5175
5766
|
return null;
|
|
5176
5767
|
}
|
|
5177
|
-
if (!
|
|
5768
|
+
if (!Node22.isDecorator(decorator)) {
|
|
5178
5769
|
return null;
|
|
5179
5770
|
}
|
|
5180
5771
|
const arg = decorator.getArguments()[source.position];
|
|
@@ -5185,7 +5776,7 @@ function declaredChannelOf(source, decorator, resolution) {
|
|
|
5185
5776
|
return text === null || text === "" ? null : text;
|
|
5186
5777
|
}
|
|
5187
5778
|
function literalStringOf(node, resolution) {
|
|
5188
|
-
if (
|
|
5779
|
+
if (Node22.isStringLiteral(node) || Node22.isNoSubstitutionTemplateLiteral(node)) {
|
|
5189
5780
|
return node.getLiteralValue();
|
|
5190
5781
|
}
|
|
5191
5782
|
const written = resolution?.resolveWrittenValue(node) ?? null;
|
|
@@ -5256,32 +5847,32 @@ import picomatch from "picomatch";
|
|
|
5256
5847
|
|
|
5257
5848
|
// src/discovery/namedExport.ts
|
|
5258
5849
|
import {
|
|
5259
|
-
Node as
|
|
5850
|
+
Node as Node23
|
|
5260
5851
|
} from "ts-morph";
|
|
5261
5852
|
function nameWrittenAt(expression) {
|
|
5262
|
-
if (
|
|
5853
|
+
if (Node23.isIdentifier(expression)) {
|
|
5263
5854
|
return expression.getText();
|
|
5264
5855
|
}
|
|
5265
|
-
if (
|
|
5856
|
+
if (Node23.isPropertyAccessExpression(expression)) {
|
|
5266
5857
|
return expression.getName();
|
|
5267
5858
|
}
|
|
5268
5859
|
return null;
|
|
5269
5860
|
}
|
|
5270
5861
|
function resolveDefaultExportName(decl, fn) {
|
|
5271
|
-
if (
|
|
5862
|
+
if (Node23.isFunctionDeclaration(fn) || Node23.isFunctionExpression(fn)) {
|
|
5272
5863
|
const n = fn.getName?.();
|
|
5273
5864
|
if (typeof n === "string" && n.length > 0) {
|
|
5274
5865
|
return n;
|
|
5275
5866
|
}
|
|
5276
5867
|
}
|
|
5277
|
-
if (
|
|
5868
|
+
if (Node23.isVariableDeclaration(decl)) {
|
|
5278
5869
|
const name = decl.getName();
|
|
5279
5870
|
if (name.length > 0) {
|
|
5280
5871
|
return name;
|
|
5281
5872
|
}
|
|
5282
5873
|
}
|
|
5283
5874
|
const binding = fn.getParent();
|
|
5284
|
-
if (binding !== void 0 &&
|
|
5875
|
+
if (binding !== void 0 && Node23.isVariableDeclaration(binding)) {
|
|
5285
5876
|
const name = binding.getName();
|
|
5286
5877
|
if (name.length > 0) {
|
|
5287
5878
|
return name;
|
|
@@ -5336,7 +5927,7 @@ function discoverNamedExports(sourceFile, match, kind, resolution) {
|
|
|
5336
5927
|
}
|
|
5337
5928
|
continue;
|
|
5338
5929
|
}
|
|
5339
|
-
if (
|
|
5930
|
+
if (Node23.isArrowFunction(init) || Node23.isFunctionExpression(init)) {
|
|
5340
5931
|
results.push({
|
|
5341
5932
|
func: init,
|
|
5342
5933
|
kind,
|
|
@@ -5445,7 +6036,7 @@ function discoverFileConventions(sourceFile, match, kind, resolution) {
|
|
|
5445
6036
|
}
|
|
5446
6037
|
|
|
5447
6038
|
// src/discovery/graphqlHookCall.ts
|
|
5448
|
-
import { Node as
|
|
6039
|
+
import { Node as Node26 } from "ts-morph";
|
|
5449
6040
|
|
|
5450
6041
|
// src/discovery/graphqlShared.ts
|
|
5451
6042
|
import fs2 from "fs";
|
|
@@ -5455,7 +6046,7 @@ import {
|
|
|
5455
6046
|
parse as graphqlParse,
|
|
5456
6047
|
print as graphqlPrint
|
|
5457
6048
|
} from "graphql";
|
|
5458
|
-
import { Node as
|
|
6049
|
+
import { Node as Node24 } from "ts-morph";
|
|
5459
6050
|
var DOCUMENT_TAGS = /* @__PURE__ */ new Set(["gql", "graphql"]);
|
|
5460
6051
|
var UNQUALIFIED_DOCUMENT_TAG = "gql";
|
|
5461
6052
|
function parseGraphqlOperation(source) {
|
|
@@ -5521,10 +6112,10 @@ function startAssembly(resolution) {
|
|
|
5521
6112
|
};
|
|
5522
6113
|
}
|
|
5523
6114
|
function assembledTemplateText(template, assembly) {
|
|
5524
|
-
if (
|
|
6115
|
+
if (Node24.isNoSubstitutionTemplateLiteral(template)) {
|
|
5525
6116
|
return innerTemplateText(template);
|
|
5526
6117
|
}
|
|
5527
|
-
if (!
|
|
6118
|
+
if (!Node24.isTemplateExpression(template)) {
|
|
5528
6119
|
return null;
|
|
5529
6120
|
}
|
|
5530
6121
|
let text = template.getHead().getLiteralText();
|
|
@@ -5660,7 +6251,7 @@ function collectDanglingSpreads(selectionSet, defined, dangling) {
|
|
|
5660
6251
|
}
|
|
5661
6252
|
}
|
|
5662
6253
|
function documentTextFromExpression(node, assembly) {
|
|
5663
|
-
if (
|
|
6254
|
+
if (Node24.isTaggedTemplateExpression(node)) {
|
|
5664
6255
|
if (!isDocumentTag(node.getTag())) {
|
|
5665
6256
|
return null;
|
|
5666
6257
|
}
|
|
@@ -5670,7 +6261,7 @@ function documentTextFromExpression(node, assembly) {
|
|
|
5670
6261
|
assembly.seen.add(node);
|
|
5671
6262
|
return assembledTemplateText(node.getTemplate(), assembly);
|
|
5672
6263
|
}
|
|
5673
|
-
if (!
|
|
6264
|
+
if (!Node24.isCallExpression(node)) {
|
|
5674
6265
|
return null;
|
|
5675
6266
|
}
|
|
5676
6267
|
if (!isDocumentTag(node.getExpression())) {
|
|
@@ -5681,7 +6272,7 @@ function documentTextFromExpression(node, assembly) {
|
|
|
5681
6272
|
return null;
|
|
5682
6273
|
}
|
|
5683
6274
|
const template = stripDocumentNodeCasts(first);
|
|
5684
|
-
if (!
|
|
6275
|
+
if (!Node24.isNoSubstitutionTemplateLiteral(template) && !Node24.isTemplateExpression(template)) {
|
|
5685
6276
|
return null;
|
|
5686
6277
|
}
|
|
5687
6278
|
if (assembly.seen.has(node)) {
|
|
@@ -5691,7 +6282,7 @@ function documentTextFromExpression(node, assembly) {
|
|
|
5691
6282
|
return assembledTemplateText(template, assembly);
|
|
5692
6283
|
}
|
|
5693
6284
|
function isDocumentTag(tag) {
|
|
5694
|
-
if (!
|
|
6285
|
+
if (!Node24.isIdentifier(tag)) {
|
|
5695
6286
|
return false;
|
|
5696
6287
|
}
|
|
5697
6288
|
if (tag.getText() === UNQUALIFIED_DOCUMENT_TAG) {
|
|
@@ -5702,14 +6293,14 @@ function isDocumentTag(tag) {
|
|
|
5702
6293
|
return false;
|
|
5703
6294
|
}
|
|
5704
6295
|
for (const declaration of symbol.getDeclarations()) {
|
|
5705
|
-
if (
|
|
6296
|
+
if (Node24.isImportSpecifier(declaration) && DOCUMENT_TAGS.has(declaration.getName())) {
|
|
5706
6297
|
return true;
|
|
5707
6298
|
}
|
|
5708
6299
|
}
|
|
5709
6300
|
return false;
|
|
5710
6301
|
}
|
|
5711
6302
|
function resolveThroughFacts(arg, assembly) {
|
|
5712
|
-
if (assembly.resolution === void 0 || !
|
|
6303
|
+
if (assembly.resolution === void 0 || !Node24.isIdentifier(arg)) {
|
|
5713
6304
|
return null;
|
|
5714
6305
|
}
|
|
5715
6306
|
const written = assembly.resolution.resolveWrittenValue(arg);
|
|
@@ -5758,7 +6349,7 @@ function singleLine(text) {
|
|
|
5758
6349
|
return collapsed.length > 80 ? `${collapsed.slice(0, 79)}\u2026` : collapsed;
|
|
5759
6350
|
}
|
|
5760
6351
|
function importedVariableInitializers(identifier) {
|
|
5761
|
-
if (!
|
|
6352
|
+
if (!Node24.isIdentifier(identifier)) {
|
|
5762
6353
|
return [];
|
|
5763
6354
|
}
|
|
5764
6355
|
const symbol = identifier.getSymbol();
|
|
@@ -5768,7 +6359,7 @@ function importedVariableInitializers(identifier) {
|
|
|
5768
6359
|
const resolved = resolveAliasedSymbol(symbol) ?? symbol;
|
|
5769
6360
|
const inits = [];
|
|
5770
6361
|
for (const decl of resolved.getDeclarations()) {
|
|
5771
|
-
if (
|
|
6362
|
+
if (Node24.isVariableDeclaration(decl)) {
|
|
5772
6363
|
const init = decl.getInitializer();
|
|
5773
6364
|
if (init !== void 0) {
|
|
5774
6365
|
inits.push(init);
|
|
@@ -5782,7 +6373,7 @@ function resolveGqlTemplateText(arg, assembly) {
|
|
|
5782
6373
|
if (direct !== null) {
|
|
5783
6374
|
return direct;
|
|
5784
6375
|
}
|
|
5785
|
-
if (!
|
|
6376
|
+
if (!Node24.isIdentifier(arg)) {
|
|
5786
6377
|
return null;
|
|
5787
6378
|
}
|
|
5788
6379
|
const symbol = arg.getSymbol();
|
|
@@ -5790,7 +6381,7 @@ function resolveGqlTemplateText(arg, assembly) {
|
|
|
5790
6381
|
return null;
|
|
5791
6382
|
}
|
|
5792
6383
|
for (const decl of symbol.getDeclarations()) {
|
|
5793
|
-
if (
|
|
6384
|
+
if (Node24.isImportClause(decl) || Node24.isImportSpecifier(decl)) {
|
|
5794
6385
|
const fromGraphqlFile = resolveGraphqlFileImport(decl);
|
|
5795
6386
|
if (fromGraphqlFile !== null) {
|
|
5796
6387
|
return fromGraphqlFile;
|
|
@@ -5809,7 +6400,7 @@ function resolveGqlTemplateText(arg, assembly) {
|
|
|
5809
6400
|
return null;
|
|
5810
6401
|
}
|
|
5811
6402
|
function resolveTypedDocumentSource(arg) {
|
|
5812
|
-
if (!
|
|
6403
|
+
if (!Node24.isIdentifier(arg)) {
|
|
5813
6404
|
return null;
|
|
5814
6405
|
}
|
|
5815
6406
|
for (const init of importedVariableInitializers(arg)) {
|
|
@@ -5822,7 +6413,7 @@ function resolveTypedDocumentSource(arg) {
|
|
|
5822
6413
|
}
|
|
5823
6414
|
function typedDocumentSourceOf(node) {
|
|
5824
6415
|
const inner = stripDocumentNodeCasts(node);
|
|
5825
|
-
if (!
|
|
6416
|
+
if (!Node24.isObjectLiteralExpression(inner)) {
|
|
5826
6417
|
return null;
|
|
5827
6418
|
}
|
|
5828
6419
|
const evaluated = evaluateObjectLiteralAsJson(inner);
|
|
@@ -5840,7 +6431,7 @@ function typedDocumentSourceOf(node) {
|
|
|
5840
6431
|
}
|
|
5841
6432
|
}
|
|
5842
6433
|
function resolveTypedDocumentHeader(arg) {
|
|
5843
|
-
if (!
|
|
6434
|
+
if (!Node24.isIdentifier(arg)) {
|
|
5844
6435
|
return null;
|
|
5845
6436
|
}
|
|
5846
6437
|
const reference = arg.getText();
|
|
@@ -5850,7 +6441,7 @@ function resolveTypedDocumentHeader(arg) {
|
|
|
5850
6441
|
}
|
|
5851
6442
|
const resolved = resolveAliasedSymbol(symbol) ?? symbol;
|
|
5852
6443
|
for (const decl of resolved.getDeclarations()) {
|
|
5853
|
-
if (!
|
|
6444
|
+
if (!Node24.isVariableDeclaration(decl)) {
|
|
5854
6445
|
continue;
|
|
5855
6446
|
}
|
|
5856
6447
|
const init = decl.getInitializer();
|
|
@@ -5883,10 +6474,10 @@ function resolveTypedDocumentHeader(arg) {
|
|
|
5883
6474
|
}
|
|
5884
6475
|
function documentNodeCastTypeArgs(node) {
|
|
5885
6476
|
let current2 = node;
|
|
5886
|
-
while (
|
|
5887
|
-
if (
|
|
6477
|
+
while (Node24.isAsExpression(current2) || Node24.isParenthesizedExpression(current2)) {
|
|
6478
|
+
if (Node24.isAsExpression(current2)) {
|
|
5888
6479
|
const typeNode = current2.getTypeNode();
|
|
5889
|
-
if (typeNode !== void 0 &&
|
|
6480
|
+
if (typeNode !== void 0 && Node24.isTypeReference(typeNode)) {
|
|
5890
6481
|
const name = typeNode.getTypeName().getText();
|
|
5891
6482
|
const simpleName = name.includes(".") ? name.split(".").pop() ?? name : name;
|
|
5892
6483
|
if (simpleName === "TypedDocumentNode" || simpleName === "DocumentNode") {
|
|
@@ -5899,7 +6490,7 @@ function documentNodeCastTypeArgs(node) {
|
|
|
5899
6490
|
return null;
|
|
5900
6491
|
}
|
|
5901
6492
|
function operationHeaderFromResultType(typeNode) {
|
|
5902
|
-
if (typeNode === void 0 || !
|
|
6493
|
+
if (typeNode === void 0 || !Node24.isTypeReference(typeNode)) {
|
|
5903
6494
|
return null;
|
|
5904
6495
|
}
|
|
5905
6496
|
const name = typeNode.getTypeName().getText();
|
|
@@ -5920,16 +6511,16 @@ function operationHeaderFromResultType(typeNode) {
|
|
|
5920
6511
|
}
|
|
5921
6512
|
function stripDocumentNodeCasts(node) {
|
|
5922
6513
|
let current2 = node;
|
|
5923
|
-
while (
|
|
6514
|
+
while (Node24.isAsExpression(current2) || Node24.isParenthesizedExpression(current2)) {
|
|
5924
6515
|
current2 = current2.getExpression();
|
|
5925
6516
|
}
|
|
5926
6517
|
return current2;
|
|
5927
6518
|
}
|
|
5928
6519
|
function evaluateObjectLiteralAsJson(node) {
|
|
5929
|
-
if (
|
|
6520
|
+
if (Node24.isStringLiteral(node) || Node24.isNoSubstitutionTemplateLiteral(node)) {
|
|
5930
6521
|
return node.getLiteralValue();
|
|
5931
6522
|
}
|
|
5932
|
-
if (
|
|
6523
|
+
if (Node24.isNumericLiteral(node)) {
|
|
5933
6524
|
return Number(node.getText());
|
|
5934
6525
|
}
|
|
5935
6526
|
const kind = node.getText();
|
|
@@ -5942,17 +6533,17 @@ function evaluateObjectLiteralAsJson(node) {
|
|
|
5942
6533
|
if (kind === "null") {
|
|
5943
6534
|
return null;
|
|
5944
6535
|
}
|
|
5945
|
-
if (
|
|
6536
|
+
if (Node24.isObjectLiteralExpression(node)) {
|
|
5946
6537
|
const out = {};
|
|
5947
6538
|
for (const prop of node.getProperties()) {
|
|
5948
|
-
if (!
|
|
6539
|
+
if (!Node24.isPropertyAssignment(prop)) {
|
|
5949
6540
|
return null;
|
|
5950
6541
|
}
|
|
5951
6542
|
const nameNode = prop.getNameNode();
|
|
5952
6543
|
let name;
|
|
5953
|
-
if (
|
|
6544
|
+
if (Node24.isIdentifier(nameNode)) {
|
|
5954
6545
|
name = nameNode.getText();
|
|
5955
|
-
} else if (
|
|
6546
|
+
} else if (Node24.isStringLiteral(nameNode) || Node24.isNoSubstitutionTemplateLiteral(nameNode)) {
|
|
5956
6547
|
name = nameNode.getLiteralValue();
|
|
5957
6548
|
} else {
|
|
5958
6549
|
return null;
|
|
@@ -5969,7 +6560,7 @@ function evaluateObjectLiteralAsJson(node) {
|
|
|
5969
6560
|
}
|
|
5970
6561
|
return out;
|
|
5971
6562
|
}
|
|
5972
|
-
if (
|
|
6563
|
+
if (Node24.isArrayLiteralExpression(node)) {
|
|
5973
6564
|
const out = [];
|
|
5974
6565
|
for (const el of node.getElements()) {
|
|
5975
6566
|
const value = evaluateObjectLiteralAsJson(el);
|
|
@@ -5983,8 +6574,8 @@ function evaluateObjectLiteralAsJson(node) {
|
|
|
5983
6574
|
return void 0;
|
|
5984
6575
|
}
|
|
5985
6576
|
function resolveGraphqlFileImport(decl) {
|
|
5986
|
-
const importDecl =
|
|
5987
|
-
if (importDecl === null || importDecl === void 0 || !
|
|
6577
|
+
const importDecl = Node24.isImportSpecifier(decl) ? decl.getImportDeclaration() : Node24.isImportClause(decl) ? decl.getParent() : null;
|
|
6578
|
+
if (importDecl === null || importDecl === void 0 || !Node24.isImportDeclaration(importDecl)) {
|
|
5988
6579
|
return null;
|
|
5989
6580
|
}
|
|
5990
6581
|
const specifier = importDecl.getModuleSpecifierValue();
|
|
@@ -6003,7 +6594,7 @@ function resolveGraphqlFileImport(decl) {
|
|
|
6003
6594
|
function enclosingFunctionRoot(node) {
|
|
6004
6595
|
let current2 = node.getParent();
|
|
6005
6596
|
while (current2 !== void 0) {
|
|
6006
|
-
if (
|
|
6597
|
+
if (Node24.isFunctionDeclaration(current2) || Node24.isFunctionExpression(current2) || Node24.isArrowFunction(current2) || Node24.isMethodDeclaration(current2)) {
|
|
6007
6598
|
return current2;
|
|
6008
6599
|
}
|
|
6009
6600
|
current2 = current2.getParent();
|
|
@@ -6011,18 +6602,18 @@ function enclosingFunctionRoot(node) {
|
|
|
6011
6602
|
return null;
|
|
6012
6603
|
}
|
|
6013
6604
|
function functionNameOrAnon(func) {
|
|
6014
|
-
if (
|
|
6605
|
+
if (Node24.isFunctionDeclaration(func) || Node24.isMethodDeclaration(func)) {
|
|
6015
6606
|
return func.getName() ?? "<anon>";
|
|
6016
6607
|
}
|
|
6017
6608
|
const parent = func.getParent();
|
|
6018
|
-
if (parent !== void 0 &&
|
|
6609
|
+
if (parent !== void 0 && Node24.isVariableDeclaration(parent)) {
|
|
6019
6610
|
return parent.getName();
|
|
6020
6611
|
}
|
|
6021
6612
|
return "<anon>";
|
|
6022
6613
|
}
|
|
6023
6614
|
|
|
6024
6615
|
// src/discovery/importedCalls.ts
|
|
6025
|
-
import { Node as
|
|
6616
|
+
import { Node as Node25 } from "ts-morph";
|
|
6026
6617
|
function callsResolvingTo(sourceFile, resolution, spec) {
|
|
6027
6618
|
return [
|
|
6028
6619
|
...callsByOriginName(
|
|
@@ -6036,11 +6627,11 @@ function callsResolvingTo(sourceFile, resolution, spec) {
|
|
|
6036
6627
|
function callsByOriginName(sourceFile, resolution, module, names) {
|
|
6037
6628
|
const candidates = [];
|
|
6038
6629
|
sourceFile.forEachDescendant((node) => {
|
|
6039
|
-
if (!
|
|
6630
|
+
if (!Node25.isCallExpression(node) && !Node25.isNewExpression(node)) {
|
|
6040
6631
|
return;
|
|
6041
6632
|
}
|
|
6042
6633
|
const callee = node.getExpression();
|
|
6043
|
-
if (
|
|
6634
|
+
if (Node25.isIdentifier(callee) && !declaredLocally(callee)) {
|
|
6044
6635
|
candidates.push(node);
|
|
6045
6636
|
}
|
|
6046
6637
|
});
|
|
@@ -6066,7 +6657,7 @@ function callsByOriginName(sourceFile, resolution, module, names) {
|
|
|
6066
6657
|
function declaredLocally(callee) {
|
|
6067
6658
|
const declarations = callee.getSymbol()?.getDeclarations() ?? [];
|
|
6068
6659
|
return declarations.length > 0 && declarations.every(
|
|
6069
|
-
(declaration) => (
|
|
6660
|
+
(declaration) => (Node25.isFunctionDeclaration(declaration) || Node25.isClassDeclaration(declaration)) && !declaration.getSourceFile().isInNodeModules()
|
|
6070
6661
|
);
|
|
6071
6662
|
}
|
|
6072
6663
|
|
|
@@ -6084,7 +6675,7 @@ function discoverGraphqlHookCalls(sourceFile, match, kind, resolution) {
|
|
|
6084
6675
|
);
|
|
6085
6676
|
const results = [];
|
|
6086
6677
|
for (const [node, canonical] of hookCalls) {
|
|
6087
|
-
if (!
|
|
6678
|
+
if (!Node26.isCallExpression(node)) {
|
|
6088
6679
|
continue;
|
|
6089
6680
|
}
|
|
6090
6681
|
const operationType = operationTypeByHook.get(canonical);
|
|
@@ -6121,7 +6712,7 @@ function discoverGraphqlHookCalls(sourceFile, match, kind, resolution) {
|
|
|
6121
6712
|
}
|
|
6122
6713
|
|
|
6123
6714
|
// src/discovery/graphqlImperativeCall.ts
|
|
6124
|
-
import { Node as
|
|
6715
|
+
import { Node as Node27 } from "ts-morph";
|
|
6125
6716
|
function discoverGraphqlImperativeCalls(sourceFile, match, kind, resolution) {
|
|
6126
6717
|
const isTheClient = clientReceiverCheckFor(sourceFile, match, resolution);
|
|
6127
6718
|
const methodSpec = /* @__PURE__ */ new Map();
|
|
@@ -6133,11 +6724,11 @@ function discoverGraphqlImperativeCalls(sourceFile, match, kind, resolution) {
|
|
|
6133
6724
|
}
|
|
6134
6725
|
const results = [];
|
|
6135
6726
|
sourceFile.forEachDescendant((node) => {
|
|
6136
|
-
if (!
|
|
6727
|
+
if (!Node27.isCallExpression(node)) {
|
|
6137
6728
|
return;
|
|
6138
6729
|
}
|
|
6139
6730
|
const callee = node.getExpression();
|
|
6140
|
-
if (!
|
|
6731
|
+
if (!Node27.isPropertyAccessExpression(callee)) {
|
|
6141
6732
|
return;
|
|
6142
6733
|
}
|
|
6143
6734
|
const methodName = callee.getName();
|
|
@@ -6149,7 +6740,7 @@ function discoverGraphqlImperativeCalls(sourceFile, match, kind, resolution) {
|
|
|
6149
6740
|
return;
|
|
6150
6741
|
}
|
|
6151
6742
|
const args = node.getArguments();
|
|
6152
|
-
if (args.length === 0 || !
|
|
6743
|
+
if (args.length === 0 || !Node27.isObjectLiteralExpression(args[0])) {
|
|
6153
6744
|
return;
|
|
6154
6745
|
}
|
|
6155
6746
|
const config = args[0];
|
|
@@ -6185,16 +6776,16 @@ function discoverGraphqlImperativeCalls(sourceFile, match, kind, resolution) {
|
|
|
6185
6776
|
return results;
|
|
6186
6777
|
}
|
|
6187
6778
|
function imperativeConfigValue(prop) {
|
|
6188
|
-
if (
|
|
6779
|
+
if (Node27.isPropertyAssignment(prop)) {
|
|
6189
6780
|
return prop.getInitializer() ?? null;
|
|
6190
6781
|
}
|
|
6191
|
-
if (
|
|
6782
|
+
if (Node27.isShorthandPropertyAssignment(prop)) {
|
|
6192
6783
|
const valueSymbol = prop.getValueSymbol();
|
|
6193
6784
|
if (valueSymbol === void 0) {
|
|
6194
6785
|
return null;
|
|
6195
6786
|
}
|
|
6196
6787
|
for (const decl of valueSymbol.getDeclarations()) {
|
|
6197
|
-
if (
|
|
6788
|
+
if (Node27.isVariableDeclaration(decl)) {
|
|
6198
6789
|
const init = decl.getInitializer();
|
|
6199
6790
|
if (init !== void 0) {
|
|
6200
6791
|
return init;
|
|
@@ -6207,7 +6798,7 @@ function imperativeConfigValue(prop) {
|
|
|
6207
6798
|
}
|
|
6208
6799
|
|
|
6209
6800
|
// src/discovery/jsxElementRoute.ts
|
|
6210
|
-
import { Node as
|
|
6801
|
+
import { Node as Node28 } from "ts-morph";
|
|
6211
6802
|
var PATH_NOT_LITERAL = "The path this route declares is not written as a string literal, so no path is claimed and this route pairs with nothing";
|
|
6212
6803
|
var ENCLOSING_PATH_NOT_LITERAL = "A route this one is nested under declares its path as something other than a string literal, so the full path is not claimed and this route pairs with nothing";
|
|
6213
6804
|
var SPREAD_NOT_ENUMERATED = "A spread stands in for routes declared elsewhere in this array, and they are not read here, so no path is claimed for any of them";
|
|
@@ -6239,7 +6830,7 @@ function discoverJsxElementRoutes(sourceFile, match, kind, resolution) {
|
|
|
6239
6830
|
}
|
|
6240
6831
|
return;
|
|
6241
6832
|
}
|
|
6242
|
-
if (
|
|
6833
|
+
if (Node28.isCallExpression(node) && callsAFactory(node, factoryNames)) {
|
|
6243
6834
|
results.push(
|
|
6244
6835
|
...unitsForRouteArray(node, match, elementsNames, kind, resolution)
|
|
6245
6836
|
);
|
|
@@ -6261,7 +6852,7 @@ function localNamesFor(sourceFile, match, exported) {
|
|
|
6261
6852
|
return local;
|
|
6262
6853
|
}
|
|
6263
6854
|
function asRouteJsx(node, routeNames) {
|
|
6264
|
-
if (!
|
|
6855
|
+
if (!Node28.isJsxSelfClosingElement(node) && !Node28.isJsxElement(node)) {
|
|
6265
6856
|
return null;
|
|
6266
6857
|
}
|
|
6267
6858
|
return isRouteJsx(node, routeNames) ? node : null;
|
|
@@ -6271,15 +6862,15 @@ function isRouteJsx(node, routeNames) {
|
|
|
6271
6862
|
return tag !== null && routeNames.has(tag.getText());
|
|
6272
6863
|
}
|
|
6273
6864
|
function tagNameOf(node) {
|
|
6274
|
-
const tag =
|
|
6275
|
-
return
|
|
6865
|
+
const tag = Node28.isJsxElement(node) ? node.getOpeningElement().getTagNameNode() : node.getTagNameNode();
|
|
6866
|
+
return Node28.isIdentifier(tag) ? tag : null;
|
|
6276
6867
|
}
|
|
6277
6868
|
function attributesOf(node) {
|
|
6278
|
-
return
|
|
6869
|
+
return Node28.isJsxElement(node) ? node.getOpeningElement().getAttributes() : node.getAttributes();
|
|
6279
6870
|
}
|
|
6280
6871
|
function attributeValueOf(node, name) {
|
|
6281
6872
|
for (const attribute of attributesOf(node)) {
|
|
6282
|
-
if (!
|
|
6873
|
+
if (!Node28.isJsxAttribute(attribute)) {
|
|
6283
6874
|
continue;
|
|
6284
6875
|
}
|
|
6285
6876
|
if (attribute.getNameNode().getText() !== name) {
|
|
@@ -6290,8 +6881,8 @@ function attributeValueOf(node, name) {
|
|
|
6290
6881
|
return null;
|
|
6291
6882
|
}
|
|
6292
6883
|
function literalStringOf2(value) {
|
|
6293
|
-
const unwrapped2 =
|
|
6294
|
-
if (
|
|
6884
|
+
const unwrapped2 = Node28.isJsxExpression(value) ? value.getExpression() ?? value : value;
|
|
6885
|
+
if (Node28.isStringLiteral(unwrapped2) || Node28.isNoSubstitutionTemplateLiteral(unwrapped2)) {
|
|
6295
6886
|
return unwrapped2.getLiteralValue();
|
|
6296
6887
|
}
|
|
6297
6888
|
return null;
|
|
@@ -6311,8 +6902,8 @@ function elementTargetOfValue(value) {
|
|
|
6311
6902
|
if (value === null) {
|
|
6312
6903
|
return { kind: "absent" };
|
|
6313
6904
|
}
|
|
6314
|
-
const unwrapped2 =
|
|
6315
|
-
if (!
|
|
6905
|
+
const unwrapped2 = Node28.isJsxExpression(value) ? value.getExpression() ?? value : value;
|
|
6906
|
+
if (!Node28.isJsxSelfClosingElement(unwrapped2) && !Node28.isJsxElement(unwrapped2)) {
|
|
6316
6907
|
return { kind: "unreadable" };
|
|
6317
6908
|
}
|
|
6318
6909
|
const tag = tagNameOf(unwrapped2);
|
|
@@ -6324,7 +6915,7 @@ function elementTargetOfValue(value) {
|
|
|
6324
6915
|
function composedPrefixOf(node, match, routeNames) {
|
|
6325
6916
|
const enclosing = [];
|
|
6326
6917
|
for (const ancestor of node.getAncestors()) {
|
|
6327
|
-
if (
|
|
6918
|
+
if (Node28.isJsxElement(ancestor) && isRouteJsx(ancestor, routeNames)) {
|
|
6328
6919
|
enclosing.push(ancestor);
|
|
6329
6920
|
}
|
|
6330
6921
|
}
|
|
@@ -6440,14 +7031,14 @@ function abstention(at, kind, sentence, label) {
|
|
|
6440
7031
|
}
|
|
6441
7032
|
function callsAFactory(call, factoryNames) {
|
|
6442
7033
|
const callee = call.getExpression();
|
|
6443
|
-
return
|
|
7034
|
+
return Node28.isIdentifier(callee) && factoryNames.has(callee.getText());
|
|
6444
7035
|
}
|
|
6445
7036
|
function unitsForRouteArray(call, match, elementsNames, kind, resolution) {
|
|
6446
7037
|
const first = call.getArguments()[0];
|
|
6447
7038
|
if (first === void 0) {
|
|
6448
7039
|
return [];
|
|
6449
7040
|
}
|
|
6450
|
-
if (
|
|
7041
|
+
if (Node28.isJsxElement(first) || Node28.isJsxSelfClosingElement(first) || Node28.isCallExpression(first) && callsAFactory(first, elementsNames)) {
|
|
6451
7042
|
return [];
|
|
6452
7043
|
}
|
|
6453
7044
|
const array = arrayLiteralOf(first, resolution);
|
|
@@ -6472,7 +7063,7 @@ function unitsOfArrayElements(array, match, kind, resolution, prefix, ancestry)
|
|
|
6472
7063
|
const nestedIn = new Set(ancestry).add(array);
|
|
6473
7064
|
const results = [];
|
|
6474
7065
|
for (const element of array.getElements()) {
|
|
6475
|
-
if (
|
|
7066
|
+
if (Node28.isSpreadElement(element)) {
|
|
6476
7067
|
results.push(
|
|
6477
7068
|
abstention(
|
|
6478
7069
|
element,
|
|
@@ -6483,7 +7074,7 @@ function unitsOfArrayElements(array, match, kind, resolution, prefix, ancestry)
|
|
|
6483
7074
|
);
|
|
6484
7075
|
continue;
|
|
6485
7076
|
}
|
|
6486
|
-
if (!
|
|
7077
|
+
if (!Node28.isObjectLiteralExpression(element)) {
|
|
6487
7078
|
results.push(
|
|
6488
7079
|
abstention(
|
|
6489
7080
|
element,
|
|
@@ -6572,7 +7163,7 @@ function ownPathOfObject(object, match) {
|
|
|
6572
7163
|
}
|
|
6573
7164
|
if (match.indexAttribute !== void 0) {
|
|
6574
7165
|
const indexValue = routePropertyOf(object, match.indexAttribute);
|
|
6575
|
-
if (indexValue !== null &&
|
|
7166
|
+
if (indexValue !== null && Node28.isTrueLiteral(indexValue)) {
|
|
6576
7167
|
return { kind: "inherited" };
|
|
6577
7168
|
}
|
|
6578
7169
|
}
|
|
@@ -6586,17 +7177,17 @@ function objectLabelOf(target) {
|
|
|
6586
7177
|
return target.kind === "named" ? target.identifier.getText() : "declaration";
|
|
6587
7178
|
}
|
|
6588
7179
|
function labelOfExpression(node) {
|
|
6589
|
-
if (
|
|
7180
|
+
if (Node28.isIdentifier(node)) {
|
|
6590
7181
|
return node.getText();
|
|
6591
7182
|
}
|
|
6592
|
-
if (
|
|
7183
|
+
if (Node28.isCallExpression(node)) {
|
|
6593
7184
|
return node.getExpression().getText();
|
|
6594
7185
|
}
|
|
6595
7186
|
return node.getKindName();
|
|
6596
7187
|
}
|
|
6597
7188
|
|
|
6598
7189
|
// src/discovery/packageExports.ts
|
|
6599
|
-
import { Node as
|
|
7190
|
+
import { Node as Node30 } from "ts-morph";
|
|
6600
7191
|
|
|
6601
7192
|
// src/packageExports.ts
|
|
6602
7193
|
import fs3 from "fs";
|
|
@@ -6788,13 +7379,13 @@ function sameDeclaration(a, b) {
|
|
|
6788
7379
|
}
|
|
6789
7380
|
|
|
6790
7381
|
// src/discovery/factorySurface.ts
|
|
6791
|
-
import { Node as
|
|
7382
|
+
import { Node as Node29, SyntaxKind as SyntaxKind7 } from "ts-morph";
|
|
6792
7383
|
var MAX_BUILDER_HOPS = 2;
|
|
6793
7384
|
function surfaceMethods(decl) {
|
|
6794
|
-
if (
|
|
7385
|
+
if (Node29.isClassDeclaration(decl)) {
|
|
6795
7386
|
return surfaceClassMethods(decl);
|
|
6796
7387
|
}
|
|
6797
|
-
if (
|
|
7388
|
+
if (Node29.isFunctionDeclaration(decl) || Node29.isFunctionExpression(decl) || Node29.isArrowFunction(decl) || Node29.isMethodDeclaration(decl)) {
|
|
6798
7389
|
return surfaceFactoryReturnMethods(decl);
|
|
6799
7390
|
}
|
|
6800
7391
|
return [];
|
|
@@ -6803,7 +7394,7 @@ function surfaceClassMethods(cls) {
|
|
|
6803
7394
|
const out = [];
|
|
6804
7395
|
const seen = /* @__PURE__ */ new Set();
|
|
6805
7396
|
for (const method of cls.getInstanceMethods()) {
|
|
6806
|
-
if (method.hasModifier(
|
|
7397
|
+
if (method.hasModifier(SyntaxKind7.PrivateKeyword)) {
|
|
6807
7398
|
continue;
|
|
6808
7399
|
}
|
|
6809
7400
|
const name = method.getName();
|
|
@@ -6814,7 +7405,7 @@ function surfaceClassMethods(cls) {
|
|
|
6814
7405
|
out.push({ func: method, name });
|
|
6815
7406
|
}
|
|
6816
7407
|
for (const method of cls.getStaticMethods()) {
|
|
6817
|
-
if (method.hasModifier(
|
|
7408
|
+
if (method.hasModifier(SyntaxKind7.PrivateKeyword)) {
|
|
6818
7409
|
continue;
|
|
6819
7410
|
}
|
|
6820
7411
|
const name = method.getName();
|
|
@@ -6833,9 +7424,9 @@ function surfaceFactoryReturnMethods(fn) {
|
|
|
6833
7424
|
return out;
|
|
6834
7425
|
}
|
|
6835
7426
|
function collectFromFunctionReturns(fn, out, seen, depth) {
|
|
6836
|
-
if (
|
|
7427
|
+
if (Node29.isArrowFunction(fn)) {
|
|
6837
7428
|
const body2 = fn.getBody();
|
|
6838
|
-
if (
|
|
7429
|
+
if (Node29.isExpression(body2)) {
|
|
6839
7430
|
collectFromReturnValue(body2, out, seen, depth);
|
|
6840
7431
|
return;
|
|
6841
7432
|
}
|
|
@@ -6846,11 +7437,11 @@ function collectFromFunctionReturns(fn, out, seen, depth) {
|
|
|
6846
7437
|
}
|
|
6847
7438
|
const returns = [];
|
|
6848
7439
|
body.forEachDescendant((node, traversal) => {
|
|
6849
|
-
if (
|
|
7440
|
+
if (Node29.isFunctionDeclaration(node) || Node29.isFunctionExpression(node) || Node29.isArrowFunction(node) || Node29.isMethodDeclaration(node) || Node29.isConstructorDeclaration(node) || Node29.isGetAccessorDeclaration(node) || Node29.isSetAccessorDeclaration(node)) {
|
|
6850
7441
|
traversal.skip();
|
|
6851
7442
|
return;
|
|
6852
7443
|
}
|
|
6853
|
-
if (
|
|
7444
|
+
if (Node29.isReturnStatement(node)) {
|
|
6854
7445
|
returns.push(node);
|
|
6855
7446
|
}
|
|
6856
7447
|
});
|
|
@@ -6864,15 +7455,15 @@ function collectFromFunctionReturns(fn, out, seen, depth) {
|
|
|
6864
7455
|
}
|
|
6865
7456
|
function collectFromReturnValue(node, out, seen, depth) {
|
|
6866
7457
|
const expr = peelParens(node);
|
|
6867
|
-
if (
|
|
7458
|
+
if (Node29.isObjectLiteralExpression(expr)) {
|
|
6868
7459
|
collectFromObjectLiteral(expr, out, seen);
|
|
6869
7460
|
return;
|
|
6870
7461
|
}
|
|
6871
|
-
if (depth >= MAX_BUILDER_HOPS || !
|
|
7462
|
+
if (depth >= MAX_BUILDER_HOPS || !Node29.isCallExpression(expr)) {
|
|
6872
7463
|
return;
|
|
6873
7464
|
}
|
|
6874
7465
|
const callee = expr.getExpression();
|
|
6875
|
-
if (!
|
|
7466
|
+
if (!Node29.isIdentifier(callee)) {
|
|
6876
7467
|
return;
|
|
6877
7468
|
}
|
|
6878
7469
|
const helper = sameFileFunctionBehind(callee);
|
|
@@ -6895,12 +7486,12 @@ function functionAmong(declarations, filePath) {
|
|
|
6895
7486
|
if (decl.getSourceFile().getFilePath() !== filePath) {
|
|
6896
7487
|
continue;
|
|
6897
7488
|
}
|
|
6898
|
-
if (
|
|
7489
|
+
if (Node29.isFunctionDeclaration(decl)) {
|
|
6899
7490
|
return decl;
|
|
6900
7491
|
}
|
|
6901
|
-
if (
|
|
7492
|
+
if (Node29.isVariableDeclaration(decl)) {
|
|
6902
7493
|
const init = decl.getInitializer();
|
|
6903
|
-
if (init !== void 0 && (
|
|
7494
|
+
if (init !== void 0 && (Node29.isArrowFunction(init) || Node29.isFunctionExpression(init))) {
|
|
6904
7495
|
return init;
|
|
6905
7496
|
}
|
|
6906
7497
|
}
|
|
@@ -6909,11 +7500,11 @@ function functionAmong(declarations, filePath) {
|
|
|
6909
7500
|
}
|
|
6910
7501
|
function collectFromObjectLiteral(node, out, seen) {
|
|
6911
7502
|
const e = peelParens(node);
|
|
6912
|
-
if (!
|
|
7503
|
+
if (!Node29.isObjectLiteralExpression(e)) {
|
|
6913
7504
|
return;
|
|
6914
7505
|
}
|
|
6915
7506
|
for (const prop of e.getProperties()) {
|
|
6916
|
-
if (
|
|
7507
|
+
if (Node29.isMethodDeclaration(prop)) {
|
|
6917
7508
|
const name = prop.getName();
|
|
6918
7509
|
if (seen.has(name)) {
|
|
6919
7510
|
continue;
|
|
@@ -6922,16 +7513,16 @@ function collectFromObjectLiteral(node, out, seen) {
|
|
|
6922
7513
|
out.push({ func: prop, name });
|
|
6923
7514
|
continue;
|
|
6924
7515
|
}
|
|
6925
|
-
if (
|
|
7516
|
+
if (Node29.isPropertyAssignment(prop)) {
|
|
6926
7517
|
const init = prop.getInitializer();
|
|
6927
7518
|
if (init === void 0) {
|
|
6928
7519
|
continue;
|
|
6929
7520
|
}
|
|
6930
7521
|
let v3 = init;
|
|
6931
|
-
while (
|
|
7522
|
+
while (Node29.isParenthesizedExpression(v3)) {
|
|
6932
7523
|
v3 = v3.getExpression();
|
|
6933
7524
|
}
|
|
6934
|
-
if (
|
|
7525
|
+
if (Node29.isArrowFunction(v3) || Node29.isFunctionExpression(v3)) {
|
|
6935
7526
|
const name = prop.getName();
|
|
6936
7527
|
if (seen.has(name)) {
|
|
6937
7528
|
continue;
|
|
@@ -6940,7 +7531,7 @@ function collectFromObjectLiteral(node, out, seen) {
|
|
|
6940
7531
|
out.push({ func: v3, name });
|
|
6941
7532
|
}
|
|
6942
7533
|
}
|
|
6943
|
-
if (
|
|
7534
|
+
if (Node29.isShorthandPropertyAssignment(prop)) {
|
|
6944
7535
|
collectShorthandFunction(prop, out, seen);
|
|
6945
7536
|
}
|
|
6946
7537
|
}
|
|
@@ -7003,9 +7594,9 @@ function discoverPackageExports(sourceFile, match, kind, resolution) {
|
|
|
7003
7594
|
(decl) => sourceDeclarationsBehind(decl, resolution)
|
|
7004
7595
|
);
|
|
7005
7596
|
for (const decl of candidates) {
|
|
7006
|
-
if (
|
|
7597
|
+
if (Node30.isVariableDeclaration(decl)) {
|
|
7007
7598
|
const init = decl.getInitializer();
|
|
7008
|
-
if (init !== void 0 && (
|
|
7599
|
+
if (init !== void 0 && (Node30.isArrowFunction(init) || Node30.isFunctionExpression(init))) {
|
|
7009
7600
|
results.push(buildUnit(init, kind, exportName, entry));
|
|
7010
7601
|
for (const m of surfaceMethods(init)) {
|
|
7011
7602
|
results.push(buildSurfacedUnit(m, kind, exportName, entry));
|
|
@@ -7015,7 +7606,7 @@ function discoverPackageExports(sourceFile, match, kind, resolution) {
|
|
|
7015
7606
|
}
|
|
7016
7607
|
continue;
|
|
7017
7608
|
}
|
|
7018
|
-
if (
|
|
7609
|
+
if (Node30.isClassDeclaration(decl)) {
|
|
7019
7610
|
for (const m of surfaceMethods(decl)) {
|
|
7020
7611
|
results.push(buildSurfacedUnit(m, kind, exportName, entry));
|
|
7021
7612
|
}
|
|
@@ -7061,7 +7652,7 @@ function buildSurfacedUnit(m, kind, parentExportName, entry) {
|
|
|
7061
7652
|
|
|
7062
7653
|
// src/discovery/packageImport.ts
|
|
7063
7654
|
import {
|
|
7064
|
-
Node as
|
|
7655
|
+
Node as Node31
|
|
7065
7656
|
} from "ts-morph";
|
|
7066
7657
|
function isLanguageLib(file) {
|
|
7067
7658
|
return /[\\/]typescript[\\/]lib[\\/]lib\..*\.d\.ts$/.test(file.getFilePath());
|
|
@@ -7083,13 +7674,13 @@ function splitPackageSpec(spec) {
|
|
|
7083
7674
|
};
|
|
7084
7675
|
}
|
|
7085
7676
|
function enclosingFunctionName(func) {
|
|
7086
|
-
if (
|
|
7677
|
+
if (Node31.isFunctionDeclaration(func) || Node31.isMethodDeclaration(func)) {
|
|
7087
7678
|
const n = func.getName?.();
|
|
7088
7679
|
if (typeof n === "string" && n.length > 0) {
|
|
7089
7680
|
return n;
|
|
7090
7681
|
}
|
|
7091
7682
|
}
|
|
7092
|
-
if (
|
|
7683
|
+
if (Node31.isFunctionExpression(func)) {
|
|
7093
7684
|
const n = func.getName();
|
|
7094
7685
|
if (typeof n === "string" && n.length > 0) {
|
|
7095
7686
|
return n;
|
|
@@ -7097,10 +7688,10 @@ function enclosingFunctionName(func) {
|
|
|
7097
7688
|
}
|
|
7098
7689
|
const parent = func.getParent();
|
|
7099
7690
|
if (parent !== void 0) {
|
|
7100
|
-
if (
|
|
7691
|
+
if (Node31.isVariableDeclaration(parent)) {
|
|
7101
7692
|
return parent.getName();
|
|
7102
7693
|
}
|
|
7103
|
-
if (
|
|
7694
|
+
if (Node31.isPropertyAssignment(parent)) {
|
|
7104
7695
|
return parent.getName();
|
|
7105
7696
|
}
|
|
7106
7697
|
}
|
|
@@ -7119,7 +7710,7 @@ function attributedCalls(sourceFile, packages, resolution) {
|
|
|
7119
7710
|
const calls = [];
|
|
7120
7711
|
const candidates = /* @__PURE__ */ new Set();
|
|
7121
7712
|
sourceFile.forEachDescendant((node) => {
|
|
7122
|
-
if (!
|
|
7713
|
+
if (!Node31.isCallExpression(node)) {
|
|
7123
7714
|
return;
|
|
7124
7715
|
}
|
|
7125
7716
|
calls.push(node);
|
|
@@ -7127,7 +7718,7 @@ function attributedCalls(sourceFile, packages, resolution) {
|
|
|
7127
7718
|
if (couldBePackageLinked(callee, packages)) {
|
|
7128
7719
|
candidates.add(callee);
|
|
7129
7720
|
}
|
|
7130
|
-
if (
|
|
7721
|
+
if (Node31.isPropertyAccessExpression(callee) && couldBePackageLinked(callee.getExpression(), packages)) {
|
|
7131
7722
|
candidates.add(callee.getExpression());
|
|
7132
7723
|
}
|
|
7133
7724
|
});
|
|
@@ -7149,7 +7740,7 @@ function attributedCalls(sourceFile, packages, resolution) {
|
|
|
7149
7740
|
if (direct !== null) {
|
|
7150
7741
|
return direct;
|
|
7151
7742
|
}
|
|
7152
|
-
if (!
|
|
7743
|
+
if (!Node31.isPropertyAccessExpression(callee)) {
|
|
7153
7744
|
return null;
|
|
7154
7745
|
}
|
|
7155
7746
|
const subject = originOf(callee.getExpression());
|
|
@@ -7174,7 +7765,7 @@ function attributedCalls(sourceFile, packages, resolution) {
|
|
|
7174
7765
|
return results;
|
|
7175
7766
|
}
|
|
7176
7767
|
function couldBePackageLinked(value, packages) {
|
|
7177
|
-
if (!
|
|
7768
|
+
if (!Node31.isIdentifier(value)) {
|
|
7178
7769
|
return true;
|
|
7179
7770
|
}
|
|
7180
7771
|
const declarations = value.getSymbol()?.getDeclarations() ?? [];
|
|
@@ -7182,7 +7773,7 @@ function couldBePackageLinked(value, packages) {
|
|
|
7182
7773
|
return true;
|
|
7183
7774
|
}
|
|
7184
7775
|
return !declarations.every(
|
|
7185
|
-
(declaration) =>
|
|
7776
|
+
(declaration) => Node31.isFunctionDeclaration(declaration) || Node31.isMethodDeclaration(declaration) || Node31.isClassDeclaration(declaration) || Node31.isImportSpecifier(declaration) && importAimsElsewhere(declaration, packages)
|
|
7186
7777
|
);
|
|
7187
7778
|
}
|
|
7188
7779
|
function importAimsElsewhere(declaration, packages) {
|
|
@@ -7239,156 +7830,9 @@ import { Node as Node32 } from "ts-morph";
|
|
|
7239
7830
|
import { joinMountedPath } from "@suss/resolution";
|
|
7240
7831
|
|
|
7241
7832
|
// src/resolve/routePath.ts
|
|
7242
|
-
import {
|
|
7243
|
-
import { patternHole } from "@suss/behavioral-ir";
|
|
7244
|
-
var URL_SCHEME = /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//;
|
|
7245
|
-
var URL_ORIGIN = /^[a-zA-Z][a-zA-Z\d+.-]*:\/\/[^/]*/;
|
|
7246
|
-
var PROTOCOL_RELATIVE = /^\/\//;
|
|
7247
|
-
var PROTOCOL_RELATIVE_ORIGIN = /^\/\/[^/]*/;
|
|
7248
|
-
function isAbsoluteUrlLiteral(text) {
|
|
7249
|
-
return URL_SCHEME.test(text) || PROTOCOL_RELATIVE.test(text);
|
|
7250
|
-
}
|
|
7251
|
-
function stripOriginManually(text) {
|
|
7252
|
-
if (URL_SCHEME.test(text)) {
|
|
7253
|
-
return text.replace(URL_ORIGIN, "");
|
|
7254
|
-
}
|
|
7255
|
-
if (PROTOCOL_RELATIVE.test(text)) {
|
|
7256
|
-
return text.replace(PROTOCOL_RELATIVE_ORIGIN, "");
|
|
7257
|
-
}
|
|
7258
|
-
return text;
|
|
7259
|
-
}
|
|
7260
|
-
function stripQueryAndFragment(text) {
|
|
7261
|
-
const idx = text.search(/[?#]/);
|
|
7262
|
-
return idx === -1 ? text : text.slice(0, idx);
|
|
7263
|
-
}
|
|
7264
|
-
var SUBSTITUTION = "\uFFFF";
|
|
7265
|
-
var AUTHORITY_OPENER = /^(?:[-+.\uFFFFa-zA-Z0-9]+:\/\/|\/\/)/;
|
|
7266
|
-
function originEndOf(flattened) {
|
|
7267
|
-
const opener = AUTHORITY_OPENER.exec(flattened);
|
|
7268
|
-
if (opener === null) {
|
|
7269
|
-
return 0;
|
|
7270
|
-
}
|
|
7271
|
-
const slash = flattened.indexOf("/", opener[0].length);
|
|
7272
|
-
return slash === -1 ? flattened.length : slash;
|
|
7273
|
-
}
|
|
7274
|
-
function appendPathText(path14, text) {
|
|
7275
|
-
const idx = text.search(/[?#]/);
|
|
7276
|
-
if (idx === -1) {
|
|
7277
|
-
return { path: path14 + text, stop: false };
|
|
7278
|
-
}
|
|
7279
|
-
return { path: path14 + text.slice(0, idx), stop: true };
|
|
7280
|
-
}
|
|
7281
|
-
function parseAbsoluteUrl(text) {
|
|
7282
|
-
try {
|
|
7283
|
-
return new URL(text);
|
|
7284
|
-
} catch {
|
|
7285
|
-
}
|
|
7286
|
-
if (!PROTOCOL_RELATIVE.test(text)) {
|
|
7287
|
-
return void 0;
|
|
7288
|
-
}
|
|
7289
|
-
try {
|
|
7290
|
-
return new URL(`https:${text}`);
|
|
7291
|
-
} catch {
|
|
7292
|
-
return void 0;
|
|
7293
|
-
}
|
|
7294
|
-
}
|
|
7295
|
-
function pathnameOfAbsoluteLiteral(text) {
|
|
7296
|
-
const parsed = parseAbsoluteUrl(text);
|
|
7297
|
-
if (parsed !== void 0) {
|
|
7298
|
-
return parsed.pathname;
|
|
7299
|
-
}
|
|
7300
|
-
return stripQueryAndFragment(stripOriginManually(text));
|
|
7301
|
-
}
|
|
7302
|
-
function pathFromLiteralUrl(text) {
|
|
7303
|
-
const path14 = isAbsoluteUrlLiteral(text) ? pathnameOfAbsoluteLiteral(text) : stripQueryAndFragment(text);
|
|
7304
|
-
return path14 === "" ? void 0 : path14;
|
|
7305
|
-
}
|
|
7306
|
-
function pathFromTemplateUrl(arg, resolution) {
|
|
7307
|
-
const headText = arg.getHead().getLiteralText();
|
|
7308
|
-
const spans = arg.getTemplateSpans();
|
|
7309
|
-
const tails = spans.map((span) => span.getLiteral().getLiteralText());
|
|
7310
|
-
const originEnd = originEndOf([headText, ...tails].join(SUBSTITUTION));
|
|
7311
|
-
const head = appendPathText("", headText.slice(originEnd));
|
|
7312
|
-
let path14 = head.path;
|
|
7313
|
-
let stop = head.stop;
|
|
7314
|
-
let at = headText.length;
|
|
7315
|
-
for (let i = 0; i < spans.length && !stop; i++) {
|
|
7316
|
-
const span = spans[i];
|
|
7317
|
-
const tailText = tails[i];
|
|
7318
|
-
if (span === void 0 || tailText === void 0) {
|
|
7319
|
-
continue;
|
|
7320
|
-
}
|
|
7321
|
-
if (at >= originEnd) {
|
|
7322
|
-
path14 += holeText(span.getExpression(), resolution);
|
|
7323
|
-
}
|
|
7324
|
-
at += SUBSTITUTION.length;
|
|
7325
|
-
const appended = appendPathText(
|
|
7326
|
-
path14,
|
|
7327
|
-
tailText.slice(Math.max(0, originEnd - at))
|
|
7328
|
-
);
|
|
7329
|
-
path14 = appended.path;
|
|
7330
|
-
stop = appended.stop;
|
|
7331
|
-
at += tailText.length;
|
|
7332
|
-
}
|
|
7333
|
-
return path14 === "" ? void 0 : path14;
|
|
7334
|
-
}
|
|
7335
|
-
function pathFromUrlNode(node, resolution) {
|
|
7336
|
-
if (Node31.isStringLiteral(node)) {
|
|
7337
|
-
return pathFromLiteralUrl(node.getLiteralValue());
|
|
7338
|
-
}
|
|
7339
|
-
if (Node31.isNoSubstitutionTemplateLiteral(node)) {
|
|
7340
|
-
return pathFromLiteralUrl(node.getLiteralValue());
|
|
7341
|
-
}
|
|
7342
|
-
if (Node31.isTemplateExpression(node)) {
|
|
7343
|
-
return pathFromTemplateUrl(node, resolution);
|
|
7344
|
-
}
|
|
7345
|
-
if (Node31.isBinaryExpression(node)) {
|
|
7346
|
-
const joined = joinedStringOf(node, resolution);
|
|
7347
|
-
return joined === void 0 ? void 0 : pathFromLiteralUrl(joined);
|
|
7348
|
-
}
|
|
7349
|
-
return void 0;
|
|
7350
|
-
}
|
|
7351
|
-
function joinedStringOf(node, resolution) {
|
|
7352
|
-
if (Node31.isStringLiteral(node) || Node31.isNoSubstitutionTemplateLiteral(node)) {
|
|
7353
|
-
return node.getLiteralValue();
|
|
7354
|
-
}
|
|
7355
|
-
if (Node31.isBinaryExpression(node) && node.getOperatorToken().getText() === "+") {
|
|
7356
|
-
const left = joinedStringOf(node.getLeft(), resolution);
|
|
7357
|
-
const right = joinedStringOf(node.getRight(), resolution);
|
|
7358
|
-
return left === void 0 || right === void 0 ? void 0 : left + right;
|
|
7359
|
-
}
|
|
7360
|
-
const written = resolution?.resolveWrittenValue(node) ?? null;
|
|
7361
|
-
return written === null || written === node ? void 0 : joinedStringOf(written, resolution);
|
|
7362
|
-
}
|
|
7363
|
-
function placeholderName(expr) {
|
|
7364
|
-
if (Node31.isIdentifier(expr)) {
|
|
7365
|
-
return expr.getText();
|
|
7366
|
-
}
|
|
7367
|
-
if (Node31.isPropertyAccessExpression(expr)) {
|
|
7368
|
-
return expr.getName();
|
|
7369
|
-
}
|
|
7370
|
-
return "param";
|
|
7371
|
-
}
|
|
7372
|
-
function holeText(expr, resolution) {
|
|
7373
|
-
const written = resolution?.resolveWrittenValue(expr) ?? null;
|
|
7374
|
-
if (written === null) {
|
|
7375
|
-
return patternHole(placeholderName(expr));
|
|
7376
|
-
}
|
|
7377
|
-
if (emptyStringLiteral(written)) {
|
|
7378
|
-
return "";
|
|
7379
|
-
}
|
|
7380
|
-
return pathFromUrlNode(written, resolution) ?? patternHole(placeholderName(expr));
|
|
7381
|
-
}
|
|
7382
|
-
function emptyStringLiteral(node) {
|
|
7383
|
-
return (Node31.isStringLiteral(node) || Node31.isNoSubstitutionTemplateLiteral(node)) && node.getLiteralValue() === "";
|
|
7384
|
-
}
|
|
7833
|
+
import { pathOf } from "@suss/values";
|
|
7385
7834
|
function pathFromArgument(arg, resolution) {
|
|
7386
|
-
|
|
7387
|
-
if (written !== void 0) {
|
|
7388
|
-
return written;
|
|
7389
|
-
}
|
|
7390
|
-
const resolved = resolution?.resolveWrittenValue(arg) ?? null;
|
|
7391
|
-
return resolved !== null ? pathFromUrlNode(resolved, resolution) : void 0;
|
|
7835
|
+
return pathOf(evaluatedValue(arg, resolution));
|
|
7392
7836
|
}
|
|
7393
7837
|
|
|
7394
7838
|
// src/discovery/registrationCall.ts
|
|
@@ -7801,32 +8245,14 @@ function mountTargetsAmong(args, targetPosition, knownSubjectIds, resolution) {
|
|
|
7801
8245
|
}
|
|
7802
8246
|
return targets;
|
|
7803
8247
|
}
|
|
7804
|
-
function stringProperty(obj, name) {
|
|
7805
|
-
if (!Node32.isObjectLiteralExpression(obj)) {
|
|
7806
|
-
return null;
|
|
7807
|
-
}
|
|
7808
|
-
const property = obj.getProperty(name);
|
|
7809
|
-
if (property === void 0 || !Node32.isPropertyAssignment(property)) {
|
|
7810
|
-
return null;
|
|
7811
|
-
}
|
|
7812
|
-
const value = property.getInitializer();
|
|
7813
|
-
if (value !== void 0 && (Node32.isStringLiteral(value) || Node32.isNoSubstitutionTemplateLiteral(value))) {
|
|
7814
|
-
return value.getLiteralValue();
|
|
7815
|
-
}
|
|
7816
|
-
return null;
|
|
7817
|
-
}
|
|
7818
8248
|
function extractRouteInfoFromBinding(call, methodName, binding, resolution) {
|
|
7819
8249
|
if (binding.method.type === "fromArgumentProperty" && binding.path.type === "fromArgumentProperty" && binding.method.position === binding.path.position) {
|
|
7820
8250
|
const arg = call.getArguments()[binding.method.position];
|
|
7821
8251
|
if (arg === void 0) {
|
|
7822
8252
|
return null;
|
|
7823
8253
|
}
|
|
7824
|
-
const
|
|
7825
|
-
|
|
7826
|
-
return null;
|
|
7827
|
-
}
|
|
7828
|
-
const method2 = stringProperty(routeObject, binding.method.property);
|
|
7829
|
-
const path15 = stringProperty(routeObject, binding.path.property);
|
|
8254
|
+
const method2 = stringPropertyOf(arg, binding.method.property, resolution);
|
|
8255
|
+
const path15 = stringPropertyOf(arg, binding.path.property, resolution);
|
|
7830
8256
|
if (method2 === null || path15 === null) {
|
|
7831
8257
|
return null;
|
|
7832
8258
|
}
|
|
@@ -8027,7 +8453,7 @@ import { joinMountedPath as joinMountedPath2 } from "@suss/resolution";
|
|
|
8027
8453
|
// src/resolve/unfollowedCall.ts
|
|
8028
8454
|
import {
|
|
8029
8455
|
Node as Node34,
|
|
8030
|
-
SyntaxKind as
|
|
8456
|
+
SyntaxKind as SyntaxKind8
|
|
8031
8457
|
} from "ts-morph";
|
|
8032
8458
|
import {
|
|
8033
8459
|
unfollowedCallGap,
|
|
@@ -8053,14 +8479,14 @@ function isExternalDeclaration(declaration) {
|
|
|
8053
8479
|
return true;
|
|
8054
8480
|
}
|
|
8055
8481
|
if (Node34.isImportSpecifier(declaration) || Node34.isImportClause(declaration) || Node34.isNamespaceImport(declaration)) {
|
|
8056
|
-
const target = declaration.getFirstAncestorByKind(
|
|
8482
|
+
const target = declaration.getFirstAncestorByKind(SyntaxKind8.ImportDeclaration)?.getModuleSpecifierSourceFile();
|
|
8057
8483
|
return target === void 0 || isInExternalCode(target);
|
|
8058
8484
|
}
|
|
8059
8485
|
return declaresAnotherModule(declaration);
|
|
8060
8486
|
}
|
|
8061
8487
|
function declaresAnotherModule(declaration) {
|
|
8062
8488
|
const module = declaration.getFirstAncestorByKind(
|
|
8063
|
-
|
|
8489
|
+
SyntaxKind8.ModuleDeclaration
|
|
8064
8490
|
);
|
|
8065
8491
|
return module !== void 0 && Node34.isStringLiteral(module.getNameNode());
|
|
8066
8492
|
}
|
|
@@ -8686,8 +9112,8 @@ function parameterReads(func, parameterNames2, barriers = NO_BARRIERS) {
|
|
|
8686
9112
|
}
|
|
8687
9113
|
|
|
8688
9114
|
// src/resolve/readName.ts
|
|
8689
|
-
import { Node as Node39, SyntaxKind as
|
|
8690
|
-
import { patternHole
|
|
9115
|
+
import { Node as Node39, SyntaxKind as SyntaxKind9 } from "ts-morph";
|
|
9116
|
+
import { patternHole, referenceName } from "@suss/behavioral-ir";
|
|
8691
9117
|
var MAX_HELPER_HOPS = 2;
|
|
8692
9118
|
var UNNAMED_HOLE = "param";
|
|
8693
9119
|
function readName(expr, options = {}) {
|
|
@@ -8787,7 +9213,7 @@ function isFallbackBranch(node) {
|
|
|
8787
9213
|
return false;
|
|
8788
9214
|
}
|
|
8789
9215
|
const operator = step.getOperatorToken().getKind();
|
|
8790
|
-
return operator ===
|
|
9216
|
+
return operator === SyntaxKind9.BarBarToken || operator === SyntaxKind9.QuestionQuestionToken;
|
|
8791
9217
|
}
|
|
8792
9218
|
function fromTemplate(expr, ctx) {
|
|
8793
9219
|
if (!Node39.isTemplateExpression(expr)) {
|
|
@@ -8805,10 +9231,10 @@ function fromBinary(expr, ctx) {
|
|
|
8805
9231
|
return null;
|
|
8806
9232
|
}
|
|
8807
9233
|
const operator = expr.getOperatorToken().getKind();
|
|
8808
|
-
if (operator ===
|
|
9234
|
+
if (operator === SyntaxKind9.BarBarToken || operator === SyntaxKind9.QuestionQuestionToken) {
|
|
8809
9235
|
return ctx.insideHole ? null : read(expr.getRight(), ctx);
|
|
8810
9236
|
}
|
|
8811
|
-
if (operator !==
|
|
9237
|
+
if (operator !== SyntaxKind9.PlusToken) {
|
|
8812
9238
|
return null;
|
|
8813
9239
|
}
|
|
8814
9240
|
const parts = { ...ctx, insideHole: true };
|
|
@@ -8951,7 +9377,7 @@ function boundOnce(expr, ctx) {
|
|
|
8951
9377
|
}
|
|
8952
9378
|
function readOrHole(expr, ctx) {
|
|
8953
9379
|
const name = read(expr, ctx);
|
|
8954
|
-
return name ??
|
|
9380
|
+
return name ?? patternHole(holeName(expr, ctx));
|
|
8955
9381
|
}
|
|
8956
9382
|
function holeName(expr, ctx) {
|
|
8957
9383
|
const bound = boundOnce(expr, ctx);
|
|
@@ -9018,7 +9444,7 @@ function madeExpression(receiver) {
|
|
|
9018
9444
|
}
|
|
9019
9445
|
function callOpsFor(call, resolveWrittenValue, originatesFrom, anchorCallsOf) {
|
|
9020
9446
|
const resolve2 = resolveWrittenValue ?? (() => null);
|
|
9021
|
-
const expression =
|
|
9447
|
+
const expression = calleeOf3(call);
|
|
9022
9448
|
const callee = Node40.isPropertyAccessExpression(expression) ? expression : null;
|
|
9023
9449
|
let args = null;
|
|
9024
9450
|
const argumentsOf = () => {
|
|
@@ -9070,7 +9496,7 @@ function anchorCallBehind(subject, origin, resolve2, originatesFrom, anchorCalls
|
|
|
9070
9496
|
if (!Node40.isCallExpression(candidate) && !Node40.isNewExpression(candidate)) {
|
|
9071
9497
|
return false;
|
|
9072
9498
|
}
|
|
9073
|
-
const candidateCallee =
|
|
9499
|
+
const candidateCallee = calleeOf3(candidate);
|
|
9074
9500
|
if (origin.named !== void 0 && !origin.named.includes(constructorName(candidate))) {
|
|
9075
9501
|
return false;
|
|
9076
9502
|
}
|
|
@@ -9204,7 +9630,7 @@ function opsOverCall(value, resolve2) {
|
|
|
9204
9630
|
function isCalled(value) {
|
|
9205
9631
|
return Node40.isCallExpression(value) || Node40.isNewExpression(value) || Node40.isTaggedTemplateExpression(value);
|
|
9206
9632
|
}
|
|
9207
|
-
function
|
|
9633
|
+
function calleeOf3(call) {
|
|
9208
9634
|
return Node40.isTaggedTemplateExpression(call) ? call.getTag() : call.getExpression();
|
|
9209
9635
|
}
|
|
9210
9636
|
function argumentsIn(call) {
|
|
@@ -9983,7 +10409,7 @@ import {
|
|
|
9983
10409
|
// src/shapes/shapes.ts
|
|
9984
10410
|
import {
|
|
9985
10411
|
Node as Node45,
|
|
9986
|
-
SyntaxKind as
|
|
10412
|
+
SyntaxKind as SyntaxKind10
|
|
9987
10413
|
} from "ts-morph";
|
|
9988
10414
|
|
|
9989
10415
|
// src/shapes/typeShapes.ts
|
|
@@ -10469,13 +10895,13 @@ function extractShapeInner(node) {
|
|
|
10469
10895
|
}
|
|
10470
10896
|
if (Node45.isPrefixUnaryExpression(unwrapped2)) {
|
|
10471
10897
|
const op = unwrapped2.getOperatorToken();
|
|
10472
|
-
if (op ===
|
|
10898
|
+
if (op === SyntaxKind10.MinusToken || op === SyntaxKind10.PlusToken) {
|
|
10473
10899
|
const inner = unwrapped2.getOperand();
|
|
10474
10900
|
if (Node45.isNumericLiteral(inner)) {
|
|
10475
10901
|
const v3 = inner.getLiteralValue();
|
|
10476
|
-
const signed = op ===
|
|
10902
|
+
const signed = op === SyntaxKind10.MinusToken ? -v3 : v3;
|
|
10477
10903
|
const rawBody = inner.getText();
|
|
10478
|
-
const raw = op ===
|
|
10904
|
+
const raw = op === SyntaxKind10.MinusToken ? `-${rawBody}` : rawBody;
|
|
10479
10905
|
return numericLiteralShape(signed, raw);
|
|
10480
10906
|
}
|
|
10481
10907
|
}
|
|
@@ -10484,13 +10910,13 @@ function extractShapeInner(node) {
|
|
|
10484
10910
|
return { type: "ref", name: "bigint" };
|
|
10485
10911
|
}
|
|
10486
10912
|
const kind = unwrapped2.getKind();
|
|
10487
|
-
if (kind ===
|
|
10913
|
+
if (kind === SyntaxKind10.TrueKeyword) {
|
|
10488
10914
|
return { type: "literal", value: true };
|
|
10489
10915
|
}
|
|
10490
|
-
if (kind ===
|
|
10916
|
+
if (kind === SyntaxKind10.FalseKeyword) {
|
|
10491
10917
|
return { type: "literal", value: false };
|
|
10492
10918
|
}
|
|
10493
|
-
if (kind ===
|
|
10919
|
+
if (kind === SyntaxKind10.NullKeyword) {
|
|
10494
10920
|
return { type: "null" };
|
|
10495
10921
|
}
|
|
10496
10922
|
if (Node45.isIdentifier(unwrapped2) && unwrapped2.getText() === "undefined") {
|
|
@@ -10619,6 +11045,7 @@ function collapseVariants2(shapes) {
|
|
|
10619
11045
|
import {
|
|
10620
11046
|
Node as Node46
|
|
10621
11047
|
} from "ts-morph";
|
|
11048
|
+
import { constantOf } from "@suss/values";
|
|
10622
11049
|
function unwrapAs(node) {
|
|
10623
11050
|
return peelSyntax(node);
|
|
10624
11051
|
}
|
|
@@ -10675,15 +11102,11 @@ function matchConstructorCode(ctorText, codes) {
|
|
|
10675
11102
|
return null;
|
|
10676
11103
|
}
|
|
10677
11104
|
function statusOf(value, ctx) {
|
|
10678
|
-
const
|
|
10679
|
-
if (
|
|
10680
|
-
return { type: "literal", value:
|
|
10681
|
-
}
|
|
10682
|
-
const resolved = ctx.resolveWrittenValue?.(unwrapped2) ?? null;
|
|
10683
|
-
if (resolved !== null && Node46.isNumericLiteral(resolved)) {
|
|
10684
|
-
return { type: "literal", value: Number(resolved.getText()) };
|
|
11105
|
+
const status = constantOf(evaluatedValue(value, ctx.resolution));
|
|
11106
|
+
if (typeof status === "number") {
|
|
11107
|
+
return { type: "literal", value: status };
|
|
10685
11108
|
}
|
|
10686
|
-
return { type: "dynamic", sourceText:
|
|
11109
|
+
return { type: "dynamic", sourceText: unwrapAs(value).getText() };
|
|
10687
11110
|
}
|
|
10688
11111
|
function statusFromProperty(obj, name, ctx) {
|
|
10689
11112
|
const prop = obj.getProperty(name);
|
|
@@ -10863,7 +11286,7 @@ function extractBody(ctx) {
|
|
|
10863
11286
|
}
|
|
10864
11287
|
|
|
10865
11288
|
// src/terminals/helperResolution.ts
|
|
10866
|
-
import { Node as Node47, SyntaxKind as
|
|
11289
|
+
import { Node as Node47, SyntaxKind as SyntaxKind11 } from "ts-morph";
|
|
10867
11290
|
function resolveHelperReturn(call, resolveCallee2) {
|
|
10868
11291
|
const callee = call.getExpression();
|
|
10869
11292
|
if (!Node47.isIdentifier(callee)) {
|
|
@@ -11075,7 +11498,7 @@ function returnedObjects(fn) {
|
|
|
11075
11498
|
}
|
|
11076
11499
|
const found = [];
|
|
11077
11500
|
for (const statement of body.getDescendantsOfKind(
|
|
11078
|
-
|
|
11501
|
+
SyntaxKind11.ReturnStatement
|
|
11079
11502
|
)) {
|
|
11080
11503
|
if (enclosingFunctionOf(statement) !== body) {
|
|
11081
11504
|
continue;
|
|
@@ -11114,13 +11537,14 @@ function bindArguments(callArgs, params) {
|
|
|
11114
11537
|
|
|
11115
11538
|
// src/terminals/statusBranches.ts
|
|
11116
11539
|
import { Node as Node48 } from "ts-morph";
|
|
11117
|
-
|
|
11540
|
+
import { constantOf as constantOf2 } from "@suss/values";
|
|
11541
|
+
function statusChoicesOf(argument, resolution) {
|
|
11118
11542
|
const chosen = asConditional(argument);
|
|
11119
11543
|
if (chosen === null) {
|
|
11120
11544
|
return null;
|
|
11121
11545
|
}
|
|
11122
|
-
const whenTrue = numberOf(chosen.getWhenTrue());
|
|
11123
|
-
const whenFalse = numberOf(chosen.getWhenFalse());
|
|
11546
|
+
const whenTrue = numberOf(chosen.getWhenTrue(), resolution);
|
|
11547
|
+
const whenFalse = numberOf(chosen.getWhenFalse(), resolution);
|
|
11124
11548
|
if (whenTrue === null || whenFalse === null) {
|
|
11125
11549
|
return null;
|
|
11126
11550
|
}
|
|
@@ -11151,20 +11575,14 @@ function asConditional(node) {
|
|
|
11151
11575
|
return only === void 0 ? null : toConditional(only);
|
|
11152
11576
|
}
|
|
11153
11577
|
var toConditional = (node) => Node48.isConditionalExpression(node) ? node : null;
|
|
11154
|
-
function numberOf(node) {
|
|
11155
|
-
const
|
|
11156
|
-
|
|
11157
|
-
return null;
|
|
11158
|
-
}
|
|
11159
|
-
const value = Number(inner.getText());
|
|
11160
|
-
return Number.isFinite(value) ? value : null;
|
|
11161
|
-
}
|
|
11162
|
-
function unwrap(node) {
|
|
11163
|
-
return peelSyntax(node);
|
|
11578
|
+
function numberOf(node, resolution) {
|
|
11579
|
+
const value = constantOf2(evaluatedValue(node, resolution));
|
|
11580
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
11164
11581
|
}
|
|
11165
11582
|
|
|
11166
11583
|
// src/terminals/returns.ts
|
|
11167
|
-
function unwrapMethodChain(call,
|
|
11584
|
+
function unwrapMethodChain(call, match, func) {
|
|
11585
|
+
const { methodChain, parameterPosition: paramPos } = match;
|
|
11168
11586
|
if (methodChain.length === 0) {
|
|
11169
11587
|
return null;
|
|
11170
11588
|
}
|
|
@@ -11180,7 +11598,10 @@ function unwrapMethodChain(call, methodChain, func, paramPos) {
|
|
|
11180
11598
|
return null;
|
|
11181
11599
|
}
|
|
11182
11600
|
collected.unshift(current2);
|
|
11183
|
-
const subject =
|
|
11601
|
+
const subject = withoutPassThroughCalls(
|
|
11602
|
+
callee.getExpression(),
|
|
11603
|
+
match.passThroughMethods ?? []
|
|
11604
|
+
);
|
|
11184
11605
|
if (i === 0) {
|
|
11185
11606
|
if (parameterPositionOf(subject, func) !== paramPos) {
|
|
11186
11607
|
return null;
|
|
@@ -11194,11 +11615,22 @@ function unwrapMethodChain(call, methodChain, func, paramPos) {
|
|
|
11194
11615
|
}
|
|
11195
11616
|
return { calls: collected };
|
|
11196
11617
|
}
|
|
11618
|
+
function withoutPassThroughCalls(subject, passThrough) {
|
|
11619
|
+
let current2 = subject;
|
|
11620
|
+
while (Node49.isCallExpression(current2)) {
|
|
11621
|
+
const callee = current2.getExpression();
|
|
11622
|
+
if (!Node49.isPropertyAccessExpression(callee) || !passThrough.includes(callee.getName())) {
|
|
11623
|
+
break;
|
|
11624
|
+
}
|
|
11625
|
+
current2 = callee.getExpression();
|
|
11626
|
+
}
|
|
11627
|
+
return current2;
|
|
11628
|
+
}
|
|
11197
11629
|
function returnedValueOf(returnStatement) {
|
|
11198
11630
|
const written = returnStatement.getExpression();
|
|
11199
11631
|
return written === void 0 ? null : unwrapValue(written);
|
|
11200
11632
|
}
|
|
11201
|
-
function tryMatchReturnShape(node, pattern, match,
|
|
11633
|
+
function tryMatchReturnShape(node, pattern, match, resolution, resolveCallee2) {
|
|
11202
11634
|
if (Node49.isObjectLiteralExpression(node)) {
|
|
11203
11635
|
const source = returnPositionOf(node);
|
|
11204
11636
|
if (source === null) {
|
|
@@ -11213,7 +11645,7 @@ function tryMatchReturnShape(node, pattern, match, resolveWrittenValue, resolveC
|
|
|
11213
11645
|
pattern,
|
|
11214
11646
|
match,
|
|
11215
11647
|
void 0,
|
|
11216
|
-
|
|
11648
|
+
resolution
|
|
11217
11649
|
);
|
|
11218
11650
|
return terminal === null ? [] : [{ ...terminal, source }];
|
|
11219
11651
|
}
|
|
@@ -11231,7 +11663,7 @@ function tryMatchReturnShape(node, pattern, match, resolveWrittenValue, resolveC
|
|
|
11231
11663
|
pattern,
|
|
11232
11664
|
match,
|
|
11233
11665
|
void 0,
|
|
11234
|
-
|
|
11666
|
+
resolution
|
|
11235
11667
|
);
|
|
11236
11668
|
return terminal === null ? [] : [terminal];
|
|
11237
11669
|
}
|
|
@@ -11259,7 +11691,7 @@ function tryMatchReturnShape(node, pattern, match, resolveWrittenValue, resolveC
|
|
|
11259
11691
|
pattern,
|
|
11260
11692
|
match,
|
|
11261
11693
|
resolved.substitutions,
|
|
11262
|
-
|
|
11694
|
+
resolution
|
|
11263
11695
|
);
|
|
11264
11696
|
if (terminal !== null) {
|
|
11265
11697
|
terminals.push(terminal);
|
|
@@ -11267,7 +11699,7 @@ function tryMatchReturnShape(node, pattern, match, resolveWrittenValue, resolveC
|
|
|
11267
11699
|
}
|
|
11268
11700
|
return terminals;
|
|
11269
11701
|
}
|
|
11270
|
-
function terminalFromReturnedObject(obj, anchor, pattern, match, substitutions,
|
|
11702
|
+
function terminalFromReturnedObject(obj, anchor, pattern, match, substitutions, resolution) {
|
|
11271
11703
|
const required = match.requiredProperties;
|
|
11272
11704
|
if (required !== void 0 && required.length > 0) {
|
|
11273
11705
|
const presentNames = /* @__PURE__ */ new Set();
|
|
@@ -11286,7 +11718,7 @@ function terminalFromReturnedObject(obj, anchor, pattern, match, substitutions,
|
|
|
11286
11718
|
extraction: pattern.extraction,
|
|
11287
11719
|
returnedObj: obj,
|
|
11288
11720
|
...substitutions !== void 0 ? { substitutions } : {},
|
|
11289
|
-
...
|
|
11721
|
+
...resolution !== void 0 ? { resolution } : {}
|
|
11290
11722
|
};
|
|
11291
11723
|
const statusCode = extractStatusCode(ctx);
|
|
11292
11724
|
let body = extractBody(ctx);
|
|
@@ -11316,16 +11748,11 @@ function terminalFromReturnedObject(obj, anchor, pattern, match, substitutions,
|
|
|
11316
11748
|
}
|
|
11317
11749
|
};
|
|
11318
11750
|
}
|
|
11319
|
-
function tryMatchParameterMethodCall(node, func, pattern, match,
|
|
11751
|
+
function tryMatchParameterMethodCall(node, func, pattern, match, resolution) {
|
|
11320
11752
|
if (!Node49.isCallExpression(node)) {
|
|
11321
11753
|
return [];
|
|
11322
11754
|
}
|
|
11323
|
-
const result = unwrapMethodChain(
|
|
11324
|
-
node,
|
|
11325
|
-
match.methodChain,
|
|
11326
|
-
func,
|
|
11327
|
-
match.parameterPosition
|
|
11328
|
-
);
|
|
11755
|
+
const result = unwrapMethodChain(node, match, func);
|
|
11329
11756
|
if (result === null) {
|
|
11330
11757
|
return [];
|
|
11331
11758
|
}
|
|
@@ -11334,7 +11761,7 @@ function tryMatchParameterMethodCall(node, func, pattern, match, resolveWrittenV
|
|
|
11334
11761
|
const ctx = {
|
|
11335
11762
|
extraction: pattern.extraction,
|
|
11336
11763
|
calls,
|
|
11337
|
-
...
|
|
11764
|
+
...resolution !== void 0 ? { resolution } : {}
|
|
11338
11765
|
};
|
|
11339
11766
|
const statusCode = extractStatusCode(ctx);
|
|
11340
11767
|
const body = extractBody(ctx);
|
|
@@ -11355,7 +11782,7 @@ function tryMatchParameterMethodCall(node, func, pattern, match, resolveWrittenV
|
|
|
11355
11782
|
};
|
|
11356
11783
|
const base = { node, ...source !== null ? { source } : {} };
|
|
11357
11784
|
const argument = statusArgument(calls, pattern.extraction);
|
|
11358
|
-
const choices = argument === null ? null : statusChoicesOf(argument);
|
|
11785
|
+
const choices = argument === null ? null : statusChoicesOf(argument, resolution);
|
|
11359
11786
|
if (choices === null) {
|
|
11360
11787
|
return [{ ...base, terminal }];
|
|
11361
11788
|
}
|
|
@@ -11389,12 +11816,7 @@ function returnCoveredByParameterMethodCall(expr, func, patterns) {
|
|
|
11389
11816
|
if (pattern.match.type !== "parameterMethodCall") {
|
|
11390
11817
|
continue;
|
|
11391
11818
|
}
|
|
11392
|
-
const result = unwrapMethodChain(
|
|
11393
|
-
current2,
|
|
11394
|
-
pattern.match.methodChain,
|
|
11395
|
-
func,
|
|
11396
|
-
pattern.match.parameterPosition
|
|
11397
|
-
);
|
|
11819
|
+
const result = unwrapMethodChain(current2, pattern.match, func);
|
|
11398
11820
|
if (result !== null) {
|
|
11399
11821
|
return true;
|
|
11400
11822
|
}
|
|
@@ -11492,7 +11914,7 @@ function calleeSubject(callee) {
|
|
|
11492
11914
|
}
|
|
11493
11915
|
return null;
|
|
11494
11916
|
}
|
|
11495
|
-
function tryMatchFunctionCall(node, pattern, match,
|
|
11917
|
+
function tryMatchFunctionCall(node, pattern, match, resolution, originatesFrom) {
|
|
11496
11918
|
if (!Node49.isCallExpression(node) && !Node49.isNewExpression(node)) {
|
|
11497
11919
|
return null;
|
|
11498
11920
|
}
|
|
@@ -11511,7 +11933,7 @@ function tryMatchFunctionCall(node, pattern, match, resolveWrittenValue, origina
|
|
|
11511
11933
|
const ctx = {
|
|
11512
11934
|
extraction: pattern.extraction,
|
|
11513
11935
|
throwCallArgs: callArgs,
|
|
11514
|
-
...
|
|
11936
|
+
...resolution !== void 0 ? { resolution } : {}
|
|
11515
11937
|
};
|
|
11516
11938
|
const statusCode = extractStatusCode(ctx);
|
|
11517
11939
|
const body = extractBody(ctx);
|
|
@@ -11536,7 +11958,7 @@ function tryMatchFunctionCall(node, pattern, match, resolveWrittenValue, origina
|
|
|
11536
11958
|
|
|
11537
11959
|
// src/terminals/throws.ts
|
|
11538
11960
|
import { Node as Node50 } from "ts-morph";
|
|
11539
|
-
function tryMatchThrowExpression(node, pattern, match,
|
|
11961
|
+
function tryMatchThrowExpression(node, pattern, match, resolution) {
|
|
11540
11962
|
if (!Node50.isThrowStatement(node)) {
|
|
11541
11963
|
return null;
|
|
11542
11964
|
}
|
|
@@ -11551,7 +11973,7 @@ function tryMatchThrowExpression(node, pattern, match, resolveWrittenValue) {
|
|
|
11551
11973
|
extraction: pattern.extraction,
|
|
11552
11974
|
...callArgs !== null ? { throwCallArgs: callArgs } : {},
|
|
11553
11975
|
...exceptionType !== null ? { exceptionType } : {},
|
|
11554
|
-
...
|
|
11976
|
+
...resolution !== void 0 ? { resolution } : {}
|
|
11555
11977
|
};
|
|
11556
11978
|
const statusCode = extractStatusCode(ctx);
|
|
11557
11979
|
const body = extractBody(ctx);
|
|
@@ -11607,7 +12029,7 @@ function classifyThrownExpression(thrown, constructorPattern) {
|
|
|
11607
12029
|
|
|
11608
12030
|
// src/terminals/index.ts
|
|
11609
12031
|
var NESTED_ESCAPING_MATCH_TYPES = /* @__PURE__ */ new Set(["parameterMethodCall"]);
|
|
11610
|
-
function findTerminals(func, patterns, barriers = NO_BARRIERS,
|
|
12032
|
+
function findTerminals(func, patterns, barriers = NO_BARRIERS, resolution, originatesFrom, resolveCallee2) {
|
|
11611
12033
|
const results = [];
|
|
11612
12034
|
func.forEachDescendant((node, traversal) => {
|
|
11613
12035
|
if (isDescentStop(node, func, barriers)) {
|
|
@@ -11625,7 +12047,7 @@ function findTerminals(func, patterns, barriers = NO_BARRIERS, resolveWrittenVal
|
|
|
11625
12047
|
node,
|
|
11626
12048
|
pattern,
|
|
11627
12049
|
pattern.match,
|
|
11628
|
-
|
|
12050
|
+
resolution,
|
|
11629
12051
|
resolveCallee2
|
|
11630
12052
|
);
|
|
11631
12053
|
if (matches.length > 0) {
|
|
@@ -11640,7 +12062,7 @@ function findTerminals(func, patterns, barriers = NO_BARRIERS, resolveWrittenVal
|
|
|
11640
12062
|
func,
|
|
11641
12063
|
pattern,
|
|
11642
12064
|
pattern.match,
|
|
11643
|
-
|
|
12065
|
+
resolution
|
|
11644
12066
|
);
|
|
11645
12067
|
if (matches.length > 0) {
|
|
11646
12068
|
results.push(...matches);
|
|
@@ -11657,14 +12079,14 @@ function findTerminals(func, patterns, barriers = NO_BARRIERS, resolveWrittenVal
|
|
|
11657
12079
|
node,
|
|
11658
12080
|
pattern,
|
|
11659
12081
|
pattern.match,
|
|
11660
|
-
|
|
12082
|
+
resolution
|
|
11661
12083
|
);
|
|
11662
12084
|
} else if (pattern.match.type === "functionCall") {
|
|
11663
12085
|
found = tryMatchFunctionCall(
|
|
11664
12086
|
node,
|
|
11665
12087
|
pattern,
|
|
11666
12088
|
pattern.match,
|
|
11667
|
-
|
|
12089
|
+
resolution,
|
|
11668
12090
|
originatesFrom
|
|
11669
12091
|
);
|
|
11670
12092
|
} else if (pattern.match.type === "parameterCall") {
|
|
@@ -11820,15 +12242,16 @@ function countUnmatchedReturns(func, terminals, barriers = NO_BARRIERS) {
|
|
|
11820
12242
|
});
|
|
11821
12243
|
return unmatched;
|
|
11822
12244
|
}
|
|
11823
|
-
function extractRawBranches(func, terminalPatterns, invocationRecognizers = [], accessRecognizers = [], barriers = NO_BARRIERS,
|
|
12245
|
+
function extractRawBranches(func, terminalPatterns, invocationRecognizers = [], accessRecognizers = [], barriers = NO_BARRIERS, resolution, originatesFrom, anchorCallsOf, resolveCallee2) {
|
|
11824
12246
|
const terminals = findTerminals(
|
|
11825
12247
|
func,
|
|
11826
12248
|
terminalPatterns,
|
|
11827
12249
|
barriers,
|
|
11828
|
-
|
|
12250
|
+
resolution,
|
|
11829
12251
|
originatesFrom,
|
|
11830
12252
|
resolveCallee2
|
|
11831
12253
|
);
|
|
12254
|
+
const resolveWrittenValue = resolution === void 0 ? void 0 : (value) => resolution.resolveWrittenValue(value);
|
|
11832
12255
|
const invocations = extractInvocationEffects(func, barriers);
|
|
11833
12256
|
const recognized = [
|
|
11834
12257
|
...runInvocationRecognizers(
|
|
@@ -13793,7 +14216,7 @@ function extractReachableSummary(candidate, options, recognizers) {
|
|
|
13793
14216
|
recognizers.invocation,
|
|
13794
14217
|
recognizers.access,
|
|
13795
14218
|
void 0,
|
|
13796
|
-
recognizers.
|
|
14219
|
+
recognizers.resolution
|
|
13797
14220
|
);
|
|
13798
14221
|
raw.boundaryBinding = functionCallBinding({
|
|
13799
14222
|
transport: "in-process",
|
|
@@ -14398,7 +14821,7 @@ function prefixOfExpr(expr, responseCall, depth) {
|
|
|
14398
14821
|
if (depth >= MAX_PREFIX_DEPTH) {
|
|
14399
14822
|
return null;
|
|
14400
14823
|
}
|
|
14401
|
-
const node =
|
|
14824
|
+
const node = unwrap(expr);
|
|
14402
14825
|
if (node === responseCall) {
|
|
14403
14826
|
return [];
|
|
14404
14827
|
}
|
|
@@ -14451,7 +14874,7 @@ function firstCallbackParamName(callback) {
|
|
|
14451
14874
|
const nameNode = param.getNameNode();
|
|
14452
14875
|
return Node62.isIdentifier(nameNode) ? nameNode.getText() : null;
|
|
14453
14876
|
}
|
|
14454
|
-
function
|
|
14877
|
+
function unwrap(expr) {
|
|
14455
14878
|
let node = expr;
|
|
14456
14879
|
while (Node62.isAwaitExpression(node) || Node62.isParenthesizedExpression(node) || Node62.isAsExpression(node)) {
|
|
14457
14880
|
node = node.getExpression();
|
|
@@ -14466,7 +14889,7 @@ function chainRootedAt(expr, rootName) {
|
|
|
14466
14889
|
return Node62.isIdentifier(chain.root) && chain.root.getText() === rootName ? chain.segments : null;
|
|
14467
14890
|
}
|
|
14468
14891
|
function memberChain(expr) {
|
|
14469
|
-
let node = Node62.isExpression(expr) ?
|
|
14892
|
+
let node = Node62.isExpression(expr) ? unwrap(expr) : expr;
|
|
14470
14893
|
if (Node62.isCallExpression(node)) {
|
|
14471
14894
|
node = node.getExpression();
|
|
14472
14895
|
}
|
|
@@ -15369,7 +15792,7 @@ function announcedBoundaryStructure(unit) {
|
|
|
15369
15792
|
declaredContract: null
|
|
15370
15793
|
};
|
|
15371
15794
|
}
|
|
15372
|
-
function extractCodeStructure(unit, pack, invocationRecognizers = [], accessRecognizers = [], barriers = NO_BARRIERS,
|
|
15795
|
+
function extractCodeStructure(unit, pack, invocationRecognizers = [], accessRecognizers = [], barriers = NO_BARRIERS, resolution, originatesFrom, anchorCallsOf, resolveCallee2) {
|
|
15373
15796
|
const read2 = withDefinitions(
|
|
15374
15797
|
() => readCodeStructure(
|
|
15375
15798
|
unit,
|
|
@@ -15377,7 +15800,7 @@ function extractCodeStructure(unit, pack, invocationRecognizers = [], accessReco
|
|
|
15377
15800
|
invocationRecognizers,
|
|
15378
15801
|
accessRecognizers,
|
|
15379
15802
|
barriers,
|
|
15380
|
-
|
|
15803
|
+
resolution,
|
|
15381
15804
|
originatesFrom,
|
|
15382
15805
|
anchorCallsOf,
|
|
15383
15806
|
resolveCallee2
|
|
@@ -15462,7 +15885,7 @@ function terminalsFor(unit, pack) {
|
|
|
15462
15885
|
}
|
|
15463
15886
|
return [...declared, FUNCTION_FALLTHROUGH_TERMINAL];
|
|
15464
15887
|
}
|
|
15465
|
-
function readCodeStructure(unit, pack, invocationRecognizers, accessRecognizers, barriers,
|
|
15888
|
+
function readCodeStructure(unit, pack, invocationRecognizers, accessRecognizers, barriers, resolution, originatesFrom, anchorCallsOf, resolveCallee2) {
|
|
15466
15889
|
const { func, kind, name } = unit;
|
|
15467
15890
|
if (func === null) {
|
|
15468
15891
|
return announcedBoundaryStructure(unit);
|
|
@@ -15477,7 +15900,7 @@ function readCodeStructure(unit, pack, invocationRecognizers, accessRecognizers,
|
|
|
15477
15900
|
invocationRecognizers,
|
|
15478
15901
|
accessRecognizers,
|
|
15479
15902
|
barriers,
|
|
15480
|
-
|
|
15903
|
+
resolution,
|
|
15481
15904
|
originatesFrom,
|
|
15482
15905
|
anchorCallsOf,
|
|
15483
15906
|
resolveCallee2
|
|
@@ -15599,21 +16022,9 @@ function extractBindingMethod(binding, callSite, pack, resolution) {
|
|
|
15599
16022
|
return resolveContractField(callSite, pack, "method", resolution);
|
|
15600
16023
|
}
|
|
15601
16024
|
if (m.type === "fromArgumentProperty") {
|
|
15602
|
-
const
|
|
15603
|
-
const
|
|
15604
|
-
|
|
15605
|
-
const prop = arg.getProperty(m.property);
|
|
15606
|
-
if (prop !== void 0 && Node64.isPropertyAssignment(prop)) {
|
|
15607
|
-
const init = prop.getInitializer();
|
|
15608
|
-
if (init !== void 0) {
|
|
15609
|
-
const value = stringValueOf(init, resolution);
|
|
15610
|
-
if (value !== null) {
|
|
15611
|
-
return value;
|
|
15612
|
-
}
|
|
15613
|
-
}
|
|
15614
|
-
}
|
|
15615
|
-
}
|
|
15616
|
-
return m.default;
|
|
16025
|
+
const arg = callSite.callExpression.getArguments()[m.position];
|
|
16026
|
+
const value = arg === void 0 ? null : stringPropertyOf(arg, m.property, resolution);
|
|
16027
|
+
return value ?? m.default;
|
|
15617
16028
|
}
|
|
15618
16029
|
if (m.type === "literal") {
|
|
15619
16030
|
return m.value;
|
|
@@ -15816,7 +16227,7 @@ function extractFromSourceFile(sourceFile, frameworks, claimedUnits, options, ta
|
|
|
15816
16227
|
allInvocationRecognizers,
|
|
15817
16228
|
allAccessRecognizers,
|
|
15818
16229
|
barriers,
|
|
15819
|
-
resolution
|
|
16230
|
+
resolution,
|
|
15820
16231
|
resolution === void 0 ? void 0 : (value, module) => resolution.importOriginsOf(value, [module]).length > 0,
|
|
15821
16232
|
resolution === void 0 ? void 0 : (value, matches) => resolution.anchorCallsOf(value, matches),
|
|
15822
16233
|
resolution === void 0 ? void 0 : (value) => resolution.resolveCallable(value)
|
|
@@ -16178,7 +16589,7 @@ function findWrapperPathParam(summary, lookup) {
|
|
|
16178
16589
|
if (names.length === 0) {
|
|
16179
16590
|
return null;
|
|
16180
16591
|
}
|
|
16181
|
-
for (const call of func.getDescendantsOfKind(
|
|
16592
|
+
for (const call of func.getDescendantsOfKind(SyntaxKind12.CallExpression)) {
|
|
16182
16593
|
const first = call.getArguments()[0];
|
|
16183
16594
|
if (first === void 0 || !Node64.isIdentifier(first)) {
|
|
16184
16595
|
continue;
|
|
@@ -16650,7 +17061,7 @@ function createTypeScriptAdapter(suppliedConfig) {
|
|
|
16650
17061
|
...projectHelpers.contributedRecognizers()
|
|
16651
17062
|
],
|
|
16652
17063
|
access: collectAccessRecognizers(config.frameworks, tallies),
|
|
16653
|
-
|
|
17064
|
+
resolution,
|
|
16654
17065
|
resolveCallableSources: (value, alsoFrom) => resolution.resolveCallableSources(value, alsoFrom),
|
|
16655
17066
|
sourceDeclarationsBehind: (declaration) => sourceDeclarationsBehind(declaration, resolution)
|
|
16656
17067
|
},
|
|
@@ -17189,7 +17600,7 @@ function findNearestTsconfig(startDir) {
|
|
|
17189
17600
|
|
|
17190
17601
|
// src/facts/why.ts
|
|
17191
17602
|
import path12 from "path";
|
|
17192
|
-
import { Node as Node65, Project as Project3, SyntaxKind as
|
|
17603
|
+
import { Node as Node65, Project as Project3, SyntaxKind as SyntaxKind13 } from "ts-morph";
|
|
17193
17604
|
import { explainResolutionProof, renderExplanation } from "@suss/resolution";
|
|
17194
17605
|
var JS_PHRASES = {
|
|
17195
17606
|
bind: ({ tuple, describe }) => ({
|
|
@@ -17236,7 +17647,7 @@ var TypeScriptWhySession = class {
|
|
|
17236
17647
|
return null;
|
|
17237
17648
|
}
|
|
17238
17649
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
17239
|
-
|
|
17650
|
+
SyntaxKind13.CallExpression
|
|
17240
17651
|
)) {
|
|
17241
17652
|
const line = call.getStartLineNumber();
|
|
17242
17653
|
if (line < startLine || line > endLine) {
|