@suss/adapter-typescript 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +307 -189
- package/dist/index.js +308 -185
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// src/adapter.ts
|
|
2
2
|
import path9 from "path";
|
|
3
3
|
import {
|
|
4
|
-
Node as
|
|
5
|
-
Project
|
|
4
|
+
Node as Node54,
|
|
5
|
+
Project,
|
|
6
|
+
SyntaxKind as SyntaxKind11
|
|
6
7
|
} from "ts-morph";
|
|
7
8
|
import {
|
|
8
9
|
functionCallBinding as functionCallBinding2,
|
|
@@ -10058,14 +10059,16 @@ import {
|
|
|
10058
10059
|
import {
|
|
10059
10060
|
ANSWER_RELATIONS,
|
|
10060
10061
|
RESOLUTION_QUESTIONS,
|
|
10061
|
-
RESOLUTION_RULES as SHARED_RULES
|
|
10062
|
+
RESOLUTION_RULES as SHARED_RULES,
|
|
10063
|
+
VALUE_STEP
|
|
10062
10064
|
} from "@suss/resolution";
|
|
10063
10065
|
var JS_RULES = [
|
|
10064
|
-
// f.bind(...)
|
|
10066
|
+
// f.bind(...) leads wherever f leads. Stated as a step, so the
|
|
10067
|
+
// questions other than `comesTo` follow it too.
|
|
10065
10068
|
rule2(
|
|
10066
|
-
"
|
|
10067
|
-
[v2("r"), v2("
|
|
10068
|
-
[lit2("bindCall", v2("r"), v2("t"))
|
|
10069
|
+
"stepsTo",
|
|
10070
|
+
[v2("r"), v2("t"), VALUE_STEP],
|
|
10071
|
+
[lit2("bindCall", v2("r"), v2("t"))]
|
|
10069
10072
|
)
|
|
10070
10073
|
];
|
|
10071
10074
|
var RESOLUTION_PROGRAM = process.env.SUSS_RESOLUTION_ON_DEMAND === "0" ? {
|
|
@@ -10537,7 +10540,10 @@ function bindingLabel(binding) {
|
|
|
10537
10540
|
if (semantics.name === "graphql-operation") {
|
|
10538
10541
|
return `${semantics.operationType} ${semantics.operationName ?? ""}`.trim();
|
|
10539
10542
|
}
|
|
10540
|
-
|
|
10543
|
+
if ("exportName" in semantics || "module" in semantics) {
|
|
10544
|
+
return semantics.exportName ?? semantics.module ?? binding.recognition;
|
|
10545
|
+
}
|
|
10546
|
+
return binding.recognition;
|
|
10541
10547
|
}
|
|
10542
10548
|
function effectFact(effect) {
|
|
10543
10549
|
if (effect.type === "invocation") {
|
|
@@ -10609,10 +10615,103 @@ function deriveBoundaryEffects(summaries, facts) {
|
|
|
10609
10615
|
}
|
|
10610
10616
|
|
|
10611
10617
|
// src/resolve/reachableClosure.ts
|
|
10612
|
-
import { Node as
|
|
10618
|
+
import { Node as Node50 } from "ts-morph";
|
|
10613
10619
|
import { functionCallBinding } from "@suss/behavioral-ir";
|
|
10614
10620
|
import { Database as Database3, evaluate as evaluate4, lit as lit4, rule as rule4, variable as variable2 } from "@suss/datalog";
|
|
10615
10621
|
import { assembleSummary as assembleSummary2 } from "@suss/extractor";
|
|
10622
|
+
|
|
10623
|
+
// src/resolve/unfollowedCall.ts
|
|
10624
|
+
import {
|
|
10625
|
+
Node as Node49,
|
|
10626
|
+
SyntaxKind as SyntaxKind10
|
|
10627
|
+
} from "ts-morph";
|
|
10628
|
+
function isInExternalCode(sourceFile) {
|
|
10629
|
+
if (sourceFile.isDeclarationFile()) {
|
|
10630
|
+
return true;
|
|
10631
|
+
}
|
|
10632
|
+
return sourceFile.getFilePath().includes("/node_modules/");
|
|
10633
|
+
}
|
|
10634
|
+
function hasBody(fn) {
|
|
10635
|
+
if (Node49.isFunctionDeclaration(fn) || Node49.isMethodDeclaration(fn) || Node49.isFunctionExpression(fn)) {
|
|
10636
|
+
return fn.getBody?.() !== void 0;
|
|
10637
|
+
}
|
|
10638
|
+
return true;
|
|
10639
|
+
}
|
|
10640
|
+
function isDeclaredShape(declaration) {
|
|
10641
|
+
return (Node49.isMethodSignature(declaration) || Node49.isPropertySignature(declaration)) && !isInExternalCode(declaration.getSourceFile());
|
|
10642
|
+
}
|
|
10643
|
+
function isExternalDeclaration(declaration) {
|
|
10644
|
+
if (isInExternalCode(declaration.getSourceFile())) {
|
|
10645
|
+
return true;
|
|
10646
|
+
}
|
|
10647
|
+
if (Node49.isImportSpecifier(declaration) || Node49.isImportClause(declaration) || Node49.isNamespaceImport(declaration)) {
|
|
10648
|
+
const target = declaration.getFirstAncestorByKind(SyntaxKind10.ImportDeclaration)?.getModuleSpecifierSourceFile();
|
|
10649
|
+
return target === void 0 || isInExternalCode(target);
|
|
10650
|
+
}
|
|
10651
|
+
return declaresAnotherModule(declaration);
|
|
10652
|
+
}
|
|
10653
|
+
function declaresAnotherModule(declaration) {
|
|
10654
|
+
const module = declaration.getFirstAncestorByKind(
|
|
10655
|
+
SyntaxKind10.ModuleDeclaration
|
|
10656
|
+
);
|
|
10657
|
+
return module !== void 0 && Node49.isStringLiteral(module.getNameNode());
|
|
10658
|
+
}
|
|
10659
|
+
function statesShapeOnly(declaration) {
|
|
10660
|
+
if (isExternalDeclaration(declaration)) {
|
|
10661
|
+
return false;
|
|
10662
|
+
}
|
|
10663
|
+
if (Node49.isMethodSignature(declaration) || Node49.isPropertySignature(declaration)) {
|
|
10664
|
+
return true;
|
|
10665
|
+
}
|
|
10666
|
+
if (Node49.isFunctionDeclaration(declaration) || Node49.isMethodDeclaration(declaration)) {
|
|
10667
|
+
return declaration.getBody() === void 0;
|
|
10668
|
+
}
|
|
10669
|
+
return false;
|
|
10670
|
+
}
|
|
10671
|
+
function declarationsBehind(symbol) {
|
|
10672
|
+
if (symbol === void 0) {
|
|
10673
|
+
return [];
|
|
10674
|
+
}
|
|
10675
|
+
const behind = symbol.getAliasedSymbol()?.getDeclarations() ?? [];
|
|
10676
|
+
return behind.length > 0 ? behind : symbol.getDeclarations();
|
|
10677
|
+
}
|
|
10678
|
+
function classifyStop(declarations) {
|
|
10679
|
+
if (declarations.length === 0) {
|
|
10680
|
+
return "noDeclaration";
|
|
10681
|
+
}
|
|
10682
|
+
if (declarations.every(isExternalDeclaration)) {
|
|
10683
|
+
return "outsideRun";
|
|
10684
|
+
}
|
|
10685
|
+
if (declarations.some(statesShapeOnly)) {
|
|
10686
|
+
return "noBody";
|
|
10687
|
+
}
|
|
10688
|
+
return "unsettledValue";
|
|
10689
|
+
}
|
|
10690
|
+
var RECORDED = {
|
|
10691
|
+
noBody: true,
|
|
10692
|
+
unsettledValue: true,
|
|
10693
|
+
outsideRun: false,
|
|
10694
|
+
noDeclaration: false
|
|
10695
|
+
};
|
|
10696
|
+
function worthRecording(reason) {
|
|
10697
|
+
return RECORDED[reason];
|
|
10698
|
+
}
|
|
10699
|
+
var STOP_SENTENCE = {
|
|
10700
|
+
noBody: (callee) => `The call to ${callee} lands on a declaration with no body, so whatever runs there is missing from this summary`,
|
|
10701
|
+
unsettledValue: (callee) => `The call to ${callee} goes through a value this run could not settle, so whatever runs there is missing from this summary`,
|
|
10702
|
+
outsideRun: (callee) => `The call to ${callee} lands in a package whose source is not in this run, so whatever runs there is missing from this summary`,
|
|
10703
|
+
noDeclaration: (callee) => `The call to ${callee} has no declaration this run could find, so whatever runs there is missing from this summary`
|
|
10704
|
+
};
|
|
10705
|
+
function unfollowedCallGap(stop) {
|
|
10706
|
+
return {
|
|
10707
|
+
type: "unfollowedCall",
|
|
10708
|
+
conditions: [],
|
|
10709
|
+
consequence: "unknown",
|
|
10710
|
+
description: STOP_SENTENCE[stop.reason](stop.callee)
|
|
10711
|
+
};
|
|
10712
|
+
}
|
|
10713
|
+
|
|
10714
|
+
// src/resolve/reachableClosure.ts
|
|
10616
10715
|
var reachablePack = {
|
|
10617
10716
|
name: "reachable",
|
|
10618
10717
|
languages: ["typescript"],
|
|
@@ -10635,23 +10734,6 @@ function nodeKey2(func) {
|
|
|
10635
10734
|
const sf = func.getSourceFile();
|
|
10636
10735
|
return `${sf.getFilePath()}:${func.getStart()}-${func.getEnd()}`;
|
|
10637
10736
|
}
|
|
10638
|
-
function isInExternalCode(sourceFile) {
|
|
10639
|
-
if (sourceFile.isDeclarationFile()) {
|
|
10640
|
-
return true;
|
|
10641
|
-
}
|
|
10642
|
-
const filePath = sourceFile.getFilePath();
|
|
10643
|
-
if (filePath.includes("/node_modules/")) {
|
|
10644
|
-
return true;
|
|
10645
|
-
}
|
|
10646
|
-
return false;
|
|
10647
|
-
}
|
|
10648
|
-
function hasBody(fn) {
|
|
10649
|
-
if (Node49.isFunctionDeclaration(fn) || Node49.isMethodDeclaration(fn) || Node49.isFunctionExpression(fn)) {
|
|
10650
|
-
const body = fn.getBody?.();
|
|
10651
|
-
return body !== void 0;
|
|
10652
|
-
}
|
|
10653
|
-
return true;
|
|
10654
|
-
}
|
|
10655
10737
|
function resolveDecl(decl, calleeName) {
|
|
10656
10738
|
if (isInExternalCode(decl.getSourceFile())) {
|
|
10657
10739
|
return null;
|
|
@@ -10663,14 +10745,14 @@ function resolveDecl(decl, calleeName) {
|
|
|
10663
10745
|
}
|
|
10664
10746
|
return { func: fn, name: declName(decl) ?? calleeName };
|
|
10665
10747
|
}
|
|
10666
|
-
if (
|
|
10748
|
+
if (Node50.isVariableDeclaration(decl)) {
|
|
10667
10749
|
const init = decl.getInitializer();
|
|
10668
|
-
if (init !== void 0 && (
|
|
10750
|
+
if (init !== void 0 && (Node50.isArrowFunction(init) || Node50.isFunctionExpression(init))) {
|
|
10669
10751
|
return { func: init, name: decl.getName() };
|
|
10670
10752
|
}
|
|
10671
10753
|
return null;
|
|
10672
10754
|
}
|
|
10673
|
-
if (
|
|
10755
|
+
if (Node50.isImportSpecifier(decl)) {
|
|
10674
10756
|
const importDecl = decl.getImportDeclaration();
|
|
10675
10757
|
const sf = importDecl.getModuleSpecifierSourceFile();
|
|
10676
10758
|
if (sf === void 0 || isInExternalCode(sf)) {
|
|
@@ -10691,78 +10773,85 @@ function resolveDecl(decl, calleeName) {
|
|
|
10691
10773
|
return null;
|
|
10692
10774
|
}
|
|
10693
10775
|
function declName(decl) {
|
|
10694
|
-
if (
|
|
10776
|
+
if (Node50.isFunctionDeclaration(decl) || Node50.isMethodDeclaration(decl)) {
|
|
10695
10777
|
const n = decl.getName?.();
|
|
10696
10778
|
if (typeof n === "string" && n.length > 0) {
|
|
10697
10779
|
return n;
|
|
10698
10780
|
}
|
|
10699
10781
|
}
|
|
10700
|
-
if (
|
|
10782
|
+
if (Node50.isFunctionExpression(decl)) {
|
|
10701
10783
|
const n = decl.getName();
|
|
10702
10784
|
if (typeof n === "string" && n.length > 0) {
|
|
10703
10785
|
return n;
|
|
10704
10786
|
}
|
|
10705
10787
|
}
|
|
10706
10788
|
const parent = decl.getParent();
|
|
10707
|
-
if (parent !== void 0 &&
|
|
10789
|
+
if (parent !== void 0 && Node50.isVariableDeclaration(parent)) {
|
|
10708
10790
|
return parent.getName();
|
|
10709
10791
|
}
|
|
10710
10792
|
return null;
|
|
10711
10793
|
}
|
|
10712
10794
|
function resolveCallee(call, calleeName, scan) {
|
|
10713
|
-
if (!
|
|
10795
|
+
if (!Node50.isCallExpression(call)) {
|
|
10714
10796
|
return null;
|
|
10715
10797
|
}
|
|
10716
10798
|
const callee = call.getExpression();
|
|
10717
|
-
const
|
|
10799
|
+
const symbol = callee.getSymbol();
|
|
10800
|
+
const declarations = symbol?.getDeclarations() ?? [];
|
|
10718
10801
|
for (const decl of declarations) {
|
|
10719
10802
|
const resolved = resolveDecl(decl, calleeName);
|
|
10720
10803
|
if (resolved !== null) {
|
|
10721
|
-
return resolved;
|
|
10804
|
+
return { kind: "followed", candidate: resolved };
|
|
10722
10805
|
}
|
|
10723
10806
|
}
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
return value === null ? null : resolveDecl(value, calleeName);
|
|
10732
|
-
}
|
|
10733
|
-
function readsAField(callee) {
|
|
10734
|
-
if (!Node49.isPropertyAccessExpression(callee)) {
|
|
10735
|
-
return false;
|
|
10736
|
-
}
|
|
10737
|
-
let receiver = callee.getExpression();
|
|
10738
|
-
while (Node49.isPropertyAccessExpression(receiver)) {
|
|
10739
|
-
receiver = receiver.getExpression();
|
|
10807
|
+
const resolveCallable = scan.resolveCallable;
|
|
10808
|
+
if (resolveCallable !== void 0 && Node50.isPropertyAccessExpression(callee) && declarations.some(isDeclaredShape)) {
|
|
10809
|
+
const value = resolveCallable(callee, scan.reachedFrom);
|
|
10810
|
+
const resolved = value === null ? null : resolveDecl(value, calleeName);
|
|
10811
|
+
if (resolved !== null) {
|
|
10812
|
+
return { kind: "followed", candidate: resolved };
|
|
10813
|
+
}
|
|
10740
10814
|
}
|
|
10741
|
-
return
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10815
|
+
return {
|
|
10816
|
+
kind: "stopped",
|
|
10817
|
+
stop: {
|
|
10818
|
+
callee: calleeName,
|
|
10819
|
+
reason: classifyStop(declarationsBehind(symbol))
|
|
10820
|
+
}
|
|
10821
|
+
};
|
|
10745
10822
|
}
|
|
10746
10823
|
function collectReachable(func, scan) {
|
|
10747
|
-
const
|
|
10824
|
+
const candidates = [];
|
|
10825
|
+
const stops = [];
|
|
10748
10826
|
const seen = /* @__PURE__ */ new Set();
|
|
10749
10827
|
func.forEachDescendant((node) => {
|
|
10750
|
-
if (!
|
|
10828
|
+
if (!Node50.isCallExpression(node)) {
|
|
10751
10829
|
return;
|
|
10752
10830
|
}
|
|
10753
|
-
const calleeText = node.getExpression().getText();
|
|
10754
|
-
const
|
|
10755
|
-
if (
|
|
10831
|
+
const calleeText = normalizeCallee(node.getExpression().getText());
|
|
10832
|
+
const outcome = resolveCallee(node, calleeText, scan);
|
|
10833
|
+
if (outcome === null) {
|
|
10834
|
+
return;
|
|
10835
|
+
}
|
|
10836
|
+
if (outcome.kind === "stopped") {
|
|
10837
|
+
const stopKey = `${outcome.stop.reason}:${outcome.stop.callee}`;
|
|
10838
|
+
if (!seen.has(stopKey) && worthRecording(outcome.stop.reason)) {
|
|
10839
|
+
seen.add(stopKey);
|
|
10840
|
+
stops.push(outcome.stop);
|
|
10841
|
+
}
|
|
10756
10842
|
return;
|
|
10757
10843
|
}
|
|
10758
|
-
const key = nodeKey2(
|
|
10844
|
+
const key = nodeKey2(outcome.candidate.func);
|
|
10759
10845
|
if (seen.has(key)) {
|
|
10760
10846
|
return;
|
|
10761
10847
|
}
|
|
10762
10848
|
seen.add(key);
|
|
10763
|
-
|
|
10849
|
+
candidates.push(outcome.candidate);
|
|
10764
10850
|
});
|
|
10765
|
-
return
|
|
10851
|
+
return { candidates, stops };
|
|
10852
|
+
}
|
|
10853
|
+
function normalizeCallee(text) {
|
|
10854
|
+
return text.replace(/\s+/g, " ").trim();
|
|
10766
10855
|
}
|
|
10767
10856
|
function extractReachableSummary(candidate, options, recognizers) {
|
|
10768
10857
|
const unit = {
|
|
@@ -10802,6 +10891,8 @@ function expandReachableClosure(seeds, project, options, projectFileSet, facts,
|
|
|
10802
10891
|
const functionByKey = /* @__PURE__ */ new Map();
|
|
10803
10892
|
const seedKeys = /* @__PURE__ */ new Set();
|
|
10804
10893
|
const scanned = /* @__PURE__ */ new Set();
|
|
10894
|
+
const stopsByKey = /* @__PURE__ */ new Map();
|
|
10895
|
+
const summariesByKey = /* @__PURE__ */ new Map();
|
|
10805
10896
|
const reachedFrom = /* @__PURE__ */ new Map();
|
|
10806
10897
|
for (const seed of seeds) {
|
|
10807
10898
|
const func = lookup.functionAt(seed.location);
|
|
@@ -10810,6 +10901,7 @@ function expandReachableClosure(seeds, project, options, projectFileSet, facts,
|
|
|
10810
10901
|
seedKeys.add(key);
|
|
10811
10902
|
functionByKey.set(key, { func, name: seed.identity.name });
|
|
10812
10903
|
facts?.unitKeyBySummary.set(seed, key);
|
|
10904
|
+
rememberSummary(summariesByKey, key, seed);
|
|
10813
10905
|
db.add("entry", [key]);
|
|
10814
10906
|
}
|
|
10815
10907
|
}
|
|
@@ -10830,7 +10922,11 @@ function expandReachableClosure(seeds, project, options, projectFileSet, facts,
|
|
|
10830
10922
|
...recognizers.resolveCallable === void 0 ? {} : { resolveCallable: recognizers.resolveCallable },
|
|
10831
10923
|
...cameFrom === void 0 ? {} : { reachedFrom: cameFrom }
|
|
10832
10924
|
};
|
|
10833
|
-
|
|
10925
|
+
const { candidates, stops } = collectReachable(source.func, scan);
|
|
10926
|
+
if (stops.length > 0) {
|
|
10927
|
+
stopsByKey.set(key, stops);
|
|
10928
|
+
}
|
|
10929
|
+
for (const candidate of candidates) {
|
|
10834
10930
|
const calleeKey = nodeKey2(candidate.func);
|
|
10835
10931
|
if (!functionByKey.has(calleeKey)) {
|
|
10836
10932
|
functionByKey.set(calleeKey, candidate);
|
|
@@ -10861,13 +10957,30 @@ function expandReachableClosure(seeds, project, options, projectFileSet, facts,
|
|
|
10861
10957
|
}
|
|
10862
10958
|
const summary = extractReachableSummary(candidate, options, recognizers);
|
|
10863
10959
|
facts?.unitKeyBySummary.set(summary, key);
|
|
10960
|
+
rememberSummary(summariesByKey, key, summary);
|
|
10864
10961
|
reached.push(summary);
|
|
10865
10962
|
}
|
|
10963
|
+
recordStops(stopsByKey, summariesByKey, options);
|
|
10866
10964
|
return [...seeds, ...reached];
|
|
10867
10965
|
}
|
|
10966
|
+
function rememberSummary(summariesByKey, key, summary) {
|
|
10967
|
+
const bucket = summariesByKey.get(key) ?? [];
|
|
10968
|
+
bucket.push(summary);
|
|
10969
|
+
summariesByKey.set(key, bucket);
|
|
10970
|
+
}
|
|
10971
|
+
function recordStops(stopsByKey, summariesByKey, options) {
|
|
10972
|
+
if (options?.gapHandling === "silent") {
|
|
10973
|
+
return;
|
|
10974
|
+
}
|
|
10975
|
+
for (const [key, stops] of stopsByKey) {
|
|
10976
|
+
for (const summary of summariesByKey.get(key) ?? []) {
|
|
10977
|
+
summary.gaps.push(...stops.map(unfollowedCallGap));
|
|
10978
|
+
}
|
|
10979
|
+
}
|
|
10980
|
+
}
|
|
10868
10981
|
|
|
10869
10982
|
// src/resolve/rethrowEnrichment.ts
|
|
10870
|
-
import { Node as
|
|
10983
|
+
import { Node as Node51 } from "ts-morph";
|
|
10871
10984
|
import { Database as Database4, evaluate as evaluate5, lit as lit5, rule as rule5, variable as variable3 } from "@suss/datalog";
|
|
10872
10985
|
var RETHROW_RULES = [
|
|
10873
10986
|
rule5(
|
|
@@ -11007,7 +11120,7 @@ function findBareRethrow(func, location) {
|
|
|
11007
11120
|
traversal.stop();
|
|
11008
11121
|
return;
|
|
11009
11122
|
}
|
|
11010
|
-
if (!
|
|
11123
|
+
if (!Node51.isThrowStatement(node)) {
|
|
11011
11124
|
return;
|
|
11012
11125
|
}
|
|
11013
11126
|
if (startLineOf(node) !== location.start) {
|
|
@@ -11017,7 +11130,7 @@ function findBareRethrow(func, location) {
|
|
|
11017
11130
|
return;
|
|
11018
11131
|
}
|
|
11019
11132
|
const thrown = node.getExpression();
|
|
11020
|
-
if (thrown !== void 0 &&
|
|
11133
|
+
if (thrown !== void 0 && Node51.isIdentifier(thrown)) {
|
|
11021
11134
|
found = node;
|
|
11022
11135
|
}
|
|
11023
11136
|
});
|
|
@@ -11027,13 +11140,13 @@ function enclosingTry(throwStmt) {
|
|
|
11027
11140
|
let current2 = throwStmt.getParent();
|
|
11028
11141
|
let sawCatchClause = false;
|
|
11029
11142
|
while (current2 !== void 0) {
|
|
11030
|
-
if (
|
|
11143
|
+
if (Node51.isCatchClause(current2)) {
|
|
11031
11144
|
sawCatchClause = true;
|
|
11032
11145
|
}
|
|
11033
|
-
if (
|
|
11146
|
+
if (Node51.isTryStatement(current2)) {
|
|
11034
11147
|
return sawCatchClause ? current2 : null;
|
|
11035
11148
|
}
|
|
11036
|
-
if (
|
|
11149
|
+
if (Node51.isFunctionDeclaration(current2) || Node51.isFunctionExpression(current2) || Node51.isArrowFunction(current2) || Node51.isMethodDeclaration(current2)) {
|
|
11037
11150
|
return null;
|
|
11038
11151
|
}
|
|
11039
11152
|
current2 = current2.getParent();
|
|
@@ -11041,14 +11154,14 @@ function enclosingTry(throwStmt) {
|
|
|
11041
11154
|
return null;
|
|
11042
11155
|
}
|
|
11043
11156
|
function collectTryBodyCallees(tryStmt, index, keyFor) {
|
|
11044
|
-
if (!
|
|
11157
|
+
if (!Node51.isTryStatement(tryStmt)) {
|
|
11045
11158
|
return [];
|
|
11046
11159
|
}
|
|
11047
11160
|
const tryBlock = tryStmt.getTryBlock();
|
|
11048
11161
|
const callees = [];
|
|
11049
11162
|
const seen = /* @__PURE__ */ new Set();
|
|
11050
11163
|
tryBlock.forEachDescendant((node) => {
|
|
11051
|
-
if (!
|
|
11164
|
+
if (!Node51.isCallExpression(node)) {
|
|
11052
11165
|
return;
|
|
11053
11166
|
}
|
|
11054
11167
|
const calleeSummary = resolveCalleeSummary(node, index);
|
|
@@ -11065,7 +11178,7 @@ function collectTryBodyCallees(tryStmt, index, keyFor) {
|
|
|
11065
11178
|
return callees;
|
|
11066
11179
|
}
|
|
11067
11180
|
function resolveCalleeSummary(call, index) {
|
|
11068
|
-
if (!
|
|
11181
|
+
if (!Node51.isCallExpression(call)) {
|
|
11069
11182
|
return null;
|
|
11070
11183
|
}
|
|
11071
11184
|
const callee = call.getExpression();
|
|
@@ -11091,12 +11204,12 @@ function resolveCalleeSummary(call, index) {
|
|
|
11091
11204
|
return null;
|
|
11092
11205
|
}
|
|
11093
11206
|
function functionFromDecl(decl) {
|
|
11094
|
-
if (
|
|
11207
|
+
if (Node51.isFunctionDeclaration(decl) || Node51.isFunctionExpression(decl) || Node51.isArrowFunction(decl) || Node51.isMethodDeclaration(decl)) {
|
|
11095
11208
|
return decl;
|
|
11096
11209
|
}
|
|
11097
|
-
if (
|
|
11210
|
+
if (Node51.isVariableDeclaration(decl)) {
|
|
11098
11211
|
const init = decl.getInitializer();
|
|
11099
|
-
if (init !== void 0 && (
|
|
11212
|
+
if (init !== void 0 && (Node51.isArrowFunction(init) || Node51.isFunctionExpression(init))) {
|
|
11100
11213
|
return init;
|
|
11101
11214
|
}
|
|
11102
11215
|
}
|
|
@@ -11105,23 +11218,23 @@ function functionFromDecl(decl) {
|
|
|
11105
11218
|
|
|
11106
11219
|
// src/shapes/fieldAccesses.ts
|
|
11107
11220
|
import {
|
|
11108
|
-
Node as
|
|
11221
|
+
Node as Node52
|
|
11109
11222
|
} from "ts-morph";
|
|
11110
11223
|
function findResponseAccessor(callExpr) {
|
|
11111
11224
|
let current2 = callExpr;
|
|
11112
11225
|
const parent1 = current2.getParent();
|
|
11113
|
-
if (parent1 !== void 0 &&
|
|
11226
|
+
if (parent1 !== void 0 && Node52.isAwaitExpression(parent1)) {
|
|
11114
11227
|
current2 = parent1;
|
|
11115
11228
|
}
|
|
11116
11229
|
const parent2 = current2.getParent();
|
|
11117
|
-
if (parent2 === void 0 || !
|
|
11230
|
+
if (parent2 === void 0 || !Node52.isVariableDeclaration(parent2)) {
|
|
11118
11231
|
return null;
|
|
11119
11232
|
}
|
|
11120
11233
|
const nameNode = parent2.getNameNode();
|
|
11121
|
-
if (
|
|
11234
|
+
if (Node52.isIdentifier(nameNode)) {
|
|
11122
11235
|
return { kind: "identifier", name: nameNode.getText() };
|
|
11123
11236
|
}
|
|
11124
|
-
if (
|
|
11237
|
+
if (Node52.isObjectBindingPattern(nameNode)) {
|
|
11125
11238
|
const bindings = /* @__PURE__ */ new Map();
|
|
11126
11239
|
for (const element of nameNode.getElements()) {
|
|
11127
11240
|
if (element.getDotDotDotToken() !== void 0) {
|
|
@@ -11142,11 +11255,11 @@ function findResponseAccessor(callExpr) {
|
|
|
11142
11255
|
function buildThenChainAccessor(callExpr, func) {
|
|
11143
11256
|
const bindings = /* @__PURE__ */ new Map();
|
|
11144
11257
|
func.forEachDescendant((node) => {
|
|
11145
|
-
if (!
|
|
11258
|
+
if (!Node52.isParameterDeclaration(node)) {
|
|
11146
11259
|
return;
|
|
11147
11260
|
}
|
|
11148
11261
|
const nameNode = node.getNameNode();
|
|
11149
|
-
if (!
|
|
11262
|
+
if (!Node52.isIdentifier(nameNode)) {
|
|
11150
11263
|
return;
|
|
11151
11264
|
}
|
|
11152
11265
|
const prefix = prefixOfThenParam(node, callExpr, 0);
|
|
@@ -11178,7 +11291,7 @@ function prefixOfExpr(expr, responseCall, depth) {
|
|
|
11178
11291
|
if (node === responseCall) {
|
|
11179
11292
|
return [];
|
|
11180
11293
|
}
|
|
11181
|
-
if (
|
|
11294
|
+
if (Node52.isCallExpression(node)) {
|
|
11182
11295
|
const hop = thenLikeCall(node);
|
|
11183
11296
|
if (hop !== null) {
|
|
11184
11297
|
if (hop.method === "catch") {
|
|
@@ -11210,14 +11323,14 @@ function prefixOfMemberExpr(expr, responseCall, depth) {
|
|
|
11210
11323
|
return null;
|
|
11211
11324
|
}
|
|
11212
11325
|
const decl = chain.root.getSymbol()?.getDeclarations()?.[0];
|
|
11213
|
-
if (decl === void 0 || !
|
|
11326
|
+
if (decl === void 0 || !Node52.isParameterDeclaration(decl)) {
|
|
11214
11327
|
return null;
|
|
11215
11328
|
}
|
|
11216
11329
|
const base = prefixOfThenParam(decl, responseCall, depth + 1);
|
|
11217
11330
|
return base === null ? null : [...base, ...chain.segments];
|
|
11218
11331
|
}
|
|
11219
11332
|
function firstCallbackParamName(callback) {
|
|
11220
|
-
if (callback === void 0 || !(
|
|
11333
|
+
if (callback === void 0 || !(Node52.isArrowFunction(callback) || Node52.isFunctionExpression(callback))) {
|
|
11221
11334
|
return null;
|
|
11222
11335
|
}
|
|
11223
11336
|
const param = callback.getParameters()[0];
|
|
@@ -11225,11 +11338,11 @@ function firstCallbackParamName(callback) {
|
|
|
11225
11338
|
return null;
|
|
11226
11339
|
}
|
|
11227
11340
|
const nameNode = param.getNameNode();
|
|
11228
|
-
return
|
|
11341
|
+
return Node52.isIdentifier(nameNode) ? nameNode.getText() : null;
|
|
11229
11342
|
}
|
|
11230
11343
|
function unwrap2(expr) {
|
|
11231
11344
|
let node = expr;
|
|
11232
|
-
while (
|
|
11345
|
+
while (Node52.isAwaitExpression(node) || Node52.isParenthesizedExpression(node) || Node52.isAsExpression(node)) {
|
|
11233
11346
|
node = node.getExpression();
|
|
11234
11347
|
}
|
|
11235
11348
|
return node;
|
|
@@ -11239,15 +11352,15 @@ function chainRootedAt(expr, rootName) {
|
|
|
11239
11352
|
if (chain === null) {
|
|
11240
11353
|
return null;
|
|
11241
11354
|
}
|
|
11242
|
-
return
|
|
11355
|
+
return Node52.isIdentifier(chain.root) && chain.root.getText() === rootName ? chain.segments : null;
|
|
11243
11356
|
}
|
|
11244
11357
|
function memberChain(expr) {
|
|
11245
|
-
let node =
|
|
11246
|
-
if (
|
|
11358
|
+
let node = Node52.isExpression(expr) ? unwrap2(expr) : expr;
|
|
11359
|
+
if (Node52.isCallExpression(node)) {
|
|
11247
11360
|
node = node.getExpression();
|
|
11248
11361
|
}
|
|
11249
11362
|
const segments = [];
|
|
11250
|
-
while (
|
|
11363
|
+
while (Node52.isPropertyAccessExpression(node)) {
|
|
11251
11364
|
segments.unshift(node.getName());
|
|
11252
11365
|
node = node.getExpression();
|
|
11253
11366
|
}
|
|
@@ -11266,16 +11379,16 @@ function collectPropertyAccesses(subtree, accessor) {
|
|
|
11266
11379
|
if (accessor.kind === "identifier") {
|
|
11267
11380
|
const varName = accessor.name;
|
|
11268
11381
|
subtree.forEachDescendant((node) => {
|
|
11269
|
-
if (!
|
|
11382
|
+
if (!Node52.isPropertyAccessExpression(node)) {
|
|
11270
11383
|
return;
|
|
11271
11384
|
}
|
|
11272
11385
|
const chain = [];
|
|
11273
11386
|
let current2 = node;
|
|
11274
|
-
while (
|
|
11387
|
+
while (Node52.isPropertyAccessExpression(current2)) {
|
|
11275
11388
|
chain.unshift(current2.getName());
|
|
11276
11389
|
current2 = current2.getExpression();
|
|
11277
11390
|
}
|
|
11278
|
-
if (
|
|
11391
|
+
if (Node52.isIdentifier(current2) && current2.getText() === varName) {
|
|
11279
11392
|
pushChain(chain);
|
|
11280
11393
|
}
|
|
11281
11394
|
});
|
|
@@ -11286,7 +11399,7 @@ function collectPropertyAccesses(subtree, accessor) {
|
|
|
11286
11399
|
return source === void 0 ? void 0 : [source];
|
|
11287
11400
|
} : (name) => accessor.bindings.get(name);
|
|
11288
11401
|
subtree.forEachDescendant((node) => {
|
|
11289
|
-
if (!
|
|
11402
|
+
if (!Node52.isIdentifier(node)) {
|
|
11290
11403
|
return;
|
|
11291
11404
|
}
|
|
11292
11405
|
const prefix = prefixOf(node.getText());
|
|
@@ -11298,13 +11411,13 @@ function collectPropertyAccesses(subtree, accessor) {
|
|
|
11298
11411
|
}
|
|
11299
11412
|
let chainTop = node;
|
|
11300
11413
|
let parent = chainTop.getParent();
|
|
11301
|
-
while (parent !== void 0 &&
|
|
11414
|
+
while (parent !== void 0 && Node52.isPropertyAccessExpression(parent) && parent.getExpression() === chainTop) {
|
|
11302
11415
|
chainTop = parent;
|
|
11303
11416
|
parent = chainTop.getParent();
|
|
11304
11417
|
}
|
|
11305
11418
|
const segments = [];
|
|
11306
11419
|
let current2 = chainTop;
|
|
11307
|
-
while (
|
|
11420
|
+
while (Node52.isPropertyAccessExpression(current2)) {
|
|
11308
11421
|
segments.push(current2.getName());
|
|
11309
11422
|
current2 = current2.getExpression();
|
|
11310
11423
|
}
|
|
@@ -11318,15 +11431,15 @@ function isBindingDeclarationSite(node) {
|
|
|
11318
11431
|
return true;
|
|
11319
11432
|
}
|
|
11320
11433
|
const parent = node.getParent();
|
|
11321
|
-
return parent !== void 0 &&
|
|
11434
|
+
return parent !== void 0 && Node52.isParameterDeclaration(parent) && parent.getNameNode() === node;
|
|
11322
11435
|
}
|
|
11323
11436
|
function isInsideObjectBindingPattern(node) {
|
|
11324
11437
|
let current2 = node.getParent();
|
|
11325
11438
|
while (current2 !== void 0) {
|
|
11326
|
-
if (
|
|
11439
|
+
if (Node52.isObjectBindingPattern(current2)) {
|
|
11327
11440
|
return true;
|
|
11328
11441
|
}
|
|
11329
|
-
if (
|
|
11442
|
+
if (Node52.isFunctionLikeDeclaration(current2) || Node52.isVariableStatement(current2)) {
|
|
11330
11443
|
break;
|
|
11331
11444
|
}
|
|
11332
11445
|
current2 = current2.getParent();
|
|
@@ -11389,7 +11502,7 @@ function findBranchSubtree(func, byLineRange, terminalStartLine, terminalEndLine
|
|
|
11389
11502
|
if (parent === void 0) {
|
|
11390
11503
|
break;
|
|
11391
11504
|
}
|
|
11392
|
-
if (
|
|
11505
|
+
if (Node52.isIfStatement(parent)) {
|
|
11393
11506
|
const ifStmt = parent;
|
|
11394
11507
|
const thenBlock = ifStmt.getThenStatement();
|
|
11395
11508
|
const elseBlock = ifStmt.getElseStatement();
|
|
@@ -11452,7 +11565,7 @@ function buildNonBodyPropertySet(semantics) {
|
|
|
11452
11565
|
|
|
11453
11566
|
// src/subUnitContext.ts
|
|
11454
11567
|
import {
|
|
11455
|
-
Node as
|
|
11568
|
+
Node as Node53
|
|
11456
11569
|
} from "ts-morph";
|
|
11457
11570
|
function createTsSubUnitContext() {
|
|
11458
11571
|
return {
|
|
@@ -11466,7 +11579,7 @@ function createTsSubUnitContext() {
|
|
|
11466
11579
|
}
|
|
11467
11580
|
function skipNestedFunctions(parent) {
|
|
11468
11581
|
return (node, traversal) => {
|
|
11469
|
-
if (node !== parent && (
|
|
11582
|
+
if (node !== parent && (Node53.isFunctionDeclaration(node) || Node53.isFunctionExpression(node) || Node53.isArrowFunction(node) || Node53.isMethodDeclaration(node))) {
|
|
11470
11583
|
traversal.skip();
|
|
11471
11584
|
return true;
|
|
11472
11585
|
}
|
|
@@ -11480,18 +11593,18 @@ function findJsxAttributes(parent) {
|
|
|
11480
11593
|
if (skip(node, traversal)) {
|
|
11481
11594
|
return;
|
|
11482
11595
|
}
|
|
11483
|
-
if (!
|
|
11596
|
+
if (!Node53.isJsxOpeningElement(node) && !Node53.isJsxSelfClosingElement(node)) {
|
|
11484
11597
|
return;
|
|
11485
11598
|
}
|
|
11486
11599
|
const tag = node.getTagNameNode().getText();
|
|
11487
11600
|
for (const attr of node.getAttributes()) {
|
|
11488
|
-
if (!
|
|
11601
|
+
if (!Node53.isJsxAttribute(attr)) {
|
|
11489
11602
|
continue;
|
|
11490
11603
|
}
|
|
11491
11604
|
const initializer = attr.getInitializer();
|
|
11492
11605
|
let valueExpression = null;
|
|
11493
11606
|
if (initializer !== void 0) {
|
|
11494
|
-
if (
|
|
11607
|
+
if (Node53.isJsxExpression(initializer)) {
|
|
11495
11608
|
const inner = initializer.getExpression();
|
|
11496
11609
|
valueExpression = inner ?? null;
|
|
11497
11610
|
} else {
|
|
@@ -11514,11 +11627,11 @@ function findCallExpressionsByName(parent, name) {
|
|
|
11514
11627
|
if (skip(node, traversal)) {
|
|
11515
11628
|
return;
|
|
11516
11629
|
}
|
|
11517
|
-
if (!
|
|
11630
|
+
if (!Node53.isCallExpression(node)) {
|
|
11518
11631
|
return;
|
|
11519
11632
|
}
|
|
11520
11633
|
const callee = node.getExpression();
|
|
11521
|
-
if (
|
|
11634
|
+
if (Node53.isIdentifier(callee) && callee.getText() === name) {
|
|
11522
11635
|
out.push(node);
|
|
11523
11636
|
}
|
|
11524
11637
|
});
|
|
@@ -11529,10 +11642,10 @@ function resolveAttributeValueFunction(attr, parent) {
|
|
|
11529
11642
|
if (expr === null) {
|
|
11530
11643
|
return null;
|
|
11531
11644
|
}
|
|
11532
|
-
if (
|
|
11645
|
+
if (Node53.isArrowFunction(expr) || Node53.isFunctionExpression(expr)) {
|
|
11533
11646
|
return { func: expr, localName: null };
|
|
11534
11647
|
}
|
|
11535
|
-
if (
|
|
11648
|
+
if (Node53.isIdentifier(expr)) {
|
|
11536
11649
|
const symbol = expr.getSymbol();
|
|
11537
11650
|
if (symbol === void 0) {
|
|
11538
11651
|
return null;
|
|
@@ -11551,15 +11664,15 @@ function resolveAttributeValueFunction(attr, parent) {
|
|
|
11551
11664
|
return null;
|
|
11552
11665
|
}
|
|
11553
11666
|
function tryExtractFunction(decl) {
|
|
11554
|
-
if (
|
|
11667
|
+
if (Node53.isFunctionDeclaration(decl)) {
|
|
11555
11668
|
return decl;
|
|
11556
11669
|
}
|
|
11557
|
-
if (
|
|
11670
|
+
if (Node53.isVariableDeclaration(decl)) {
|
|
11558
11671
|
const init = decl.getInitializer();
|
|
11559
11672
|
if (init === void 0) {
|
|
11560
11673
|
return null;
|
|
11561
11674
|
}
|
|
11562
|
-
if (
|
|
11675
|
+
if (Node53.isArrowFunction(init) || Node53.isFunctionExpression(init)) {
|
|
11563
11676
|
return init;
|
|
11564
11677
|
}
|
|
11565
11678
|
}
|
|
@@ -11580,7 +11693,7 @@ function getCallArgumentFunction(call, position) {
|
|
|
11580
11693
|
if (arg === void 0) {
|
|
11581
11694
|
return null;
|
|
11582
11695
|
}
|
|
11583
|
-
if (
|
|
11696
|
+
if (Node53.isArrowFunction(arg) || Node53.isFunctionExpression(arg)) {
|
|
11584
11697
|
return arg;
|
|
11585
11698
|
}
|
|
11586
11699
|
return null;
|
|
@@ -11592,7 +11705,7 @@ function readArrayLiteralText(node) {
|
|
|
11592
11705
|
if (node === null) {
|
|
11593
11706
|
return null;
|
|
11594
11707
|
}
|
|
11595
|
-
if (
|
|
11708
|
+
if (Node53.isArrayLiteralExpression(node)) {
|
|
11596
11709
|
return node.getElements().map((e) => e.getText());
|
|
11597
11710
|
}
|
|
11598
11711
|
return [node.getText()];
|
|
@@ -11817,13 +11930,13 @@ var raise = (msg) => {
|
|
|
11817
11930
|
throw new Error(msg);
|
|
11818
11931
|
};
|
|
11819
11932
|
function bindingPatternNames(nameNode) {
|
|
11820
|
-
if (
|
|
11933
|
+
if (Node54.isObjectBindingPattern(nameNode)) {
|
|
11821
11934
|
return nameNode.getElements().map((e) => e.getName());
|
|
11822
11935
|
}
|
|
11823
|
-
if (
|
|
11936
|
+
if (Node54.isArrayBindingPattern(nameNode)) {
|
|
11824
11937
|
const names = [];
|
|
11825
11938
|
for (const element of nameNode.getElements()) {
|
|
11826
|
-
if (
|
|
11939
|
+
if (Node54.isOmittedExpression(element)) {
|
|
11827
11940
|
continue;
|
|
11828
11941
|
}
|
|
11829
11942
|
names.push(element.getName());
|
|
@@ -11834,7 +11947,7 @@ function bindingPatternNames(nameNode) {
|
|
|
11834
11947
|
}
|
|
11835
11948
|
function componentPropsParameters(param, mapping) {
|
|
11836
11949
|
const nameNode = param.getNameNode();
|
|
11837
|
-
if (!
|
|
11950
|
+
if (!Node54.isObjectBindingPattern(nameNode)) {
|
|
11838
11951
|
const type = param.getType();
|
|
11839
11952
|
return [
|
|
11840
11953
|
{
|
|
@@ -11960,11 +12073,11 @@ function extractParameters(func, inputMapping) {
|
|
|
11960
12073
|
function extractDependencyCalls(func) {
|
|
11961
12074
|
const results = [];
|
|
11962
12075
|
func.forEachDescendant((node, traversal) => {
|
|
11963
|
-
if (node !== func && (
|
|
12076
|
+
if (node !== func && (Node54.isFunctionDeclaration(node) || Node54.isFunctionExpression(node) || Node54.isArrowFunction(node) || Node54.isMethodDeclaration(node))) {
|
|
11964
12077
|
traversal.skip();
|
|
11965
12078
|
return;
|
|
11966
12079
|
}
|
|
11967
|
-
if (!
|
|
12080
|
+
if (!Node54.isVariableDeclaration(node)) {
|
|
11968
12081
|
return;
|
|
11969
12082
|
}
|
|
11970
12083
|
const init = node.getInitializer();
|
|
@@ -11973,19 +12086,19 @@ function extractDependencyCalls(func) {
|
|
|
11973
12086
|
}
|
|
11974
12087
|
let isAsync = false;
|
|
11975
12088
|
let callExpr = init;
|
|
11976
|
-
if (
|
|
12089
|
+
if (Node54.isAwaitExpression(init)) {
|
|
11977
12090
|
isAsync = true;
|
|
11978
12091
|
callExpr = init.getExpression();
|
|
11979
12092
|
}
|
|
11980
|
-
if (!
|
|
12093
|
+
if (!Node54.isCallExpression(callExpr)) {
|
|
11981
12094
|
return;
|
|
11982
12095
|
}
|
|
11983
12096
|
const calleeName = callExpr.getExpression().getText();
|
|
11984
12097
|
const nameNode = node.getNameNode();
|
|
11985
|
-
const assignedTo =
|
|
12098
|
+
const assignedTo = Node54.isIdentifier(nameNode) ? nameNode.getText() : null;
|
|
11986
12099
|
const declList = node.getParent();
|
|
11987
12100
|
const varStmt = declList?.getParent();
|
|
11988
|
-
const locationNode = varStmt !== void 0 &&
|
|
12101
|
+
const locationNode = varStmt !== void 0 && Node54.isVariableStatement(varStmt) ? varStmt : node;
|
|
11989
12102
|
results.push({
|
|
11990
12103
|
name: calleeName,
|
|
11991
12104
|
assignedTo,
|
|
@@ -12241,9 +12354,9 @@ function extractBindingMethod(binding, callSite, pack, resolution) {
|
|
|
12241
12354
|
if (m.type === "fromArgumentProperty") {
|
|
12242
12355
|
const args = callSite.callExpression.getArguments();
|
|
12243
12356
|
const arg = args[m.position];
|
|
12244
|
-
if (arg !== void 0 &&
|
|
12357
|
+
if (arg !== void 0 && Node54.isObjectLiteralExpression(arg)) {
|
|
12245
12358
|
const prop = arg.getProperty(m.property);
|
|
12246
|
-
if (prop !== void 0 &&
|
|
12359
|
+
if (prop !== void 0 && Node54.isPropertyAssignment(prop)) {
|
|
12247
12360
|
const init = prop.getInitializer();
|
|
12248
12361
|
if (init !== void 0) {
|
|
12249
12362
|
const value = stringValueOf(init, resolution);
|
|
@@ -12372,22 +12485,22 @@ function extractBindingPath(binding, callSite, pack, resolution) {
|
|
|
12372
12485
|
return void 0;
|
|
12373
12486
|
}
|
|
12374
12487
|
function pathFromUrlNode(node) {
|
|
12375
|
-
if (
|
|
12488
|
+
if (Node54.isStringLiteral(node)) {
|
|
12376
12489
|
return pathFromLiteralUrl(node.getLiteralValue());
|
|
12377
12490
|
}
|
|
12378
|
-
if (
|
|
12491
|
+
if (Node54.isNoSubstitutionTemplateLiteral(node)) {
|
|
12379
12492
|
return pathFromLiteralUrl(node.getLiteralValue());
|
|
12380
12493
|
}
|
|
12381
|
-
if (
|
|
12494
|
+
if (Node54.isTemplateExpression(node)) {
|
|
12382
12495
|
return pathFromTemplateUrl(node);
|
|
12383
12496
|
}
|
|
12384
12497
|
return void 0;
|
|
12385
12498
|
}
|
|
12386
12499
|
function placeholderName(expr) {
|
|
12387
|
-
if (
|
|
12500
|
+
if (Node54.isIdentifier(expr)) {
|
|
12388
12501
|
return expr.getText();
|
|
12389
12502
|
}
|
|
12390
|
-
if (
|
|
12503
|
+
if (Node54.isPropertyAccessExpression(expr)) {
|
|
12391
12504
|
return expr.getName();
|
|
12392
12505
|
}
|
|
12393
12506
|
return "param";
|
|
@@ -12822,7 +12935,7 @@ function expandWrapperCallers(summaries, project, options) {
|
|
|
12822
12935
|
continue;
|
|
12823
12936
|
}
|
|
12824
12937
|
const binding = s.identity.boundaryBinding;
|
|
12825
|
-
if (binding === null || binding.semantics.name !== "rest" || binding.semantics.method === null
|
|
12938
|
+
if (binding === null || binding.semantics.name !== "rest" || binding.semantics.method === null) {
|
|
12826
12939
|
continue;
|
|
12827
12940
|
}
|
|
12828
12941
|
lookup ??= createSourceFileLookup(project);
|
|
@@ -12850,11 +12963,21 @@ function findWrapperPathParam(summary, lookup) {
|
|
|
12850
12963
|
if (func === null) {
|
|
12851
12964
|
return null;
|
|
12852
12965
|
}
|
|
12853
|
-
const
|
|
12854
|
-
if (
|
|
12966
|
+
const names = func.getParameters().map((p) => p.getName());
|
|
12967
|
+
if (names.length === 0) {
|
|
12855
12968
|
return null;
|
|
12856
12969
|
}
|
|
12857
|
-
|
|
12970
|
+
for (const call of func.getDescendantsOfKind(SyntaxKind11.CallExpression)) {
|
|
12971
|
+
const first = call.getArguments()[0];
|
|
12972
|
+
if (first === void 0 || !Node54.isIdentifier(first)) {
|
|
12973
|
+
continue;
|
|
12974
|
+
}
|
|
12975
|
+
const at = names.indexOf(first.getText());
|
|
12976
|
+
if (at !== -1) {
|
|
12977
|
+
return { func, pathParamPosition: at };
|
|
12978
|
+
}
|
|
12979
|
+
}
|
|
12980
|
+
return null;
|
|
12858
12981
|
}
|
|
12859
12982
|
function synthesizeCallerSummaries(wrapper, _project, options) {
|
|
12860
12983
|
const nameNode = wrapperNameNode(wrapper.func);
|
|
@@ -12895,16 +13018,16 @@ function synthesizeCallerSummaries(wrapper, _project, options) {
|
|
|
12895
13018
|
return out;
|
|
12896
13019
|
}
|
|
12897
13020
|
function wrapperNameNode(func) {
|
|
12898
|
-
if (
|
|
13021
|
+
if (Node54.isFunctionDeclaration(func) || Node54.isMethodDeclaration(func)) {
|
|
12899
13022
|
const name = func.getNameNode();
|
|
12900
|
-
if (name !== void 0 &&
|
|
13023
|
+
if (name !== void 0 && Node54.isIdentifier(name)) {
|
|
12901
13024
|
return name;
|
|
12902
13025
|
}
|
|
12903
13026
|
}
|
|
12904
13027
|
const parent = func.getParent();
|
|
12905
|
-
if (parent !== void 0 &&
|
|
13028
|
+
if (parent !== void 0 && Node54.isVariableDeclaration(parent)) {
|
|
12906
13029
|
const nameNode = parent.getNameNode();
|
|
12907
|
-
if (
|
|
13030
|
+
if (Node54.isIdentifier(nameNode)) {
|
|
12908
13031
|
return nameNode;
|
|
12909
13032
|
}
|
|
12910
13033
|
}
|
|
@@ -12913,10 +13036,10 @@ function wrapperNameNode(func) {
|
|
|
12913
13036
|
function enclosingCall(node) {
|
|
12914
13037
|
let current2 = node.getParent();
|
|
12915
13038
|
while (current2 !== void 0) {
|
|
12916
|
-
if (
|
|
13039
|
+
if (Node54.isCallExpression(current2)) {
|
|
12917
13040
|
return current2;
|
|
12918
13041
|
}
|
|
12919
|
-
if (
|
|
13042
|
+
if (Node54.isPropertyAccessExpression(current2)) {
|
|
12920
13043
|
current2 = current2.getParent();
|
|
12921
13044
|
continue;
|
|
12922
13045
|
}
|
|
@@ -12927,7 +13050,7 @@ function enclosingCall(node) {
|
|
|
12927
13050
|
function enclosingFunction(node) {
|
|
12928
13051
|
let current2 = node.getParent();
|
|
12929
13052
|
while (current2 !== void 0) {
|
|
12930
|
-
if (
|
|
13053
|
+
if (Node54.isFunctionDeclaration(current2) || Node54.isFunctionExpression(current2) || Node54.isArrowFunction(current2) || Node54.isMethodDeclaration(current2)) {
|
|
12931
13054
|
return current2;
|
|
12932
13055
|
}
|
|
12933
13056
|
current2 = current2.getParent();
|
|
@@ -12935,13 +13058,13 @@ function enclosingFunction(node) {
|
|
|
12935
13058
|
return null;
|
|
12936
13059
|
}
|
|
12937
13060
|
function literalOrTemplate(arg) {
|
|
12938
|
-
if (
|
|
13061
|
+
if (Node54.isStringLiteral(arg)) {
|
|
12939
13062
|
return arg.getLiteralValue();
|
|
12940
13063
|
}
|
|
12941
|
-
if (
|
|
13064
|
+
if (Node54.isNoSubstitutionTemplateLiteral(arg)) {
|
|
12942
13065
|
return arg.getLiteralValue();
|
|
12943
13066
|
}
|
|
12944
|
-
if (
|
|
13067
|
+
if (Node54.isTemplateExpression(arg)) {
|
|
12945
13068
|
let path11 = arg.getHead().getLiteralText();
|
|
12946
13069
|
for (const span of arg.getTemplateSpans()) {
|
|
12947
13070
|
path11 += `{${placeholderName(span.getExpression())}}`;
|
|
@@ -12952,13 +13075,13 @@ function literalOrTemplate(arg) {
|
|
|
12952
13075
|
return void 0;
|
|
12953
13076
|
}
|
|
12954
13077
|
function callerName(func) {
|
|
12955
|
-
if (
|
|
13078
|
+
if (Node54.isFunctionDeclaration(func) || Node54.isMethodDeclaration(func)) {
|
|
12956
13079
|
return func.getName() ?? "anonymous";
|
|
12957
13080
|
}
|
|
12958
13081
|
const parent = func.getParent();
|
|
12959
|
-
if (parent !== void 0 &&
|
|
13082
|
+
if (parent !== void 0 && Node54.isVariableDeclaration(parent)) {
|
|
12960
13083
|
const nameNode = parent.getNameNode();
|
|
12961
|
-
if (
|
|
13084
|
+
if (Node54.isIdentifier(nameNode)) {
|
|
12962
13085
|
return nameNode.getText();
|
|
12963
13086
|
}
|
|
12964
13087
|
}
|
|
@@ -13504,10 +13627,10 @@ function findNearestTsconfig(startDir) {
|
|
|
13504
13627
|
}
|
|
13505
13628
|
|
|
13506
13629
|
// src/configuredCall.ts
|
|
13507
|
-
import { Node as
|
|
13630
|
+
import { Node as Node55 } from "ts-morph";
|
|
13508
13631
|
function readConfiguredCall(call, ctx, spec) {
|
|
13509
13632
|
const callee = call.getExpression();
|
|
13510
|
-
if (!
|
|
13633
|
+
if (!Node55.isPropertyAccessExpression(callee)) {
|
|
13511
13634
|
return null;
|
|
13512
13635
|
}
|
|
13513
13636
|
if (callee.getName() !== spec.method) {
|
|
@@ -13552,10 +13675,10 @@ function readStringArg(arg) {
|
|
|
13552
13675
|
}
|
|
13553
13676
|
function rootIdentifier(node) {
|
|
13554
13677
|
let current2 = node;
|
|
13555
|
-
while (
|
|
13678
|
+
while (Node55.isPropertyAccessExpression(current2)) {
|
|
13556
13679
|
current2 = current2.getExpression();
|
|
13557
13680
|
}
|
|
13558
|
-
return
|
|
13681
|
+
return Node55.isIdentifier(current2) ? current2 : null;
|
|
13559
13682
|
}
|
|
13560
13683
|
|
|
13561
13684
|
// src/packHealth.ts
|
|
@@ -13671,7 +13794,7 @@ function formatPackHealth(checks, audiences) {
|
|
|
13671
13794
|
}
|
|
13672
13795
|
|
|
13673
13796
|
// src/resolve/readName.ts
|
|
13674
|
-
import { Node as
|
|
13797
|
+
import { Node as Node56, SyntaxKind as SyntaxKind12 } from "ts-morph";
|
|
13675
13798
|
var MAX_HELPER_HOPS = 2;
|
|
13676
13799
|
var UNNAMED_HOLE = "param";
|
|
13677
13800
|
function readName(expr, options = {}) {
|
|
@@ -13700,25 +13823,25 @@ function read(expr, ctx) {
|
|
|
13700
13823
|
}
|
|
13701
13824
|
const seen = new Set(ctx.seen).add(expr);
|
|
13702
13825
|
const inner = { ...ctx, seen };
|
|
13703
|
-
if (
|
|
13826
|
+
if (Node56.isStringLiteral(expr) || Node56.isNoSubstitutionTemplateLiteral(expr)) {
|
|
13704
13827
|
return expr.getLiteralValue();
|
|
13705
13828
|
}
|
|
13706
|
-
if (
|
|
13829
|
+
if (Node56.isNumericLiteral(expr)) {
|
|
13707
13830
|
return expr.getLiteralText();
|
|
13708
13831
|
}
|
|
13709
|
-
if (
|
|
13832
|
+
if (Node56.isTemplateExpression(expr)) {
|
|
13710
13833
|
return fromTemplate(expr, inner);
|
|
13711
13834
|
}
|
|
13712
|
-
if (
|
|
13835
|
+
if (Node56.isParenthesizedExpression(expr)) {
|
|
13713
13836
|
return read(expr.getExpression(), inner);
|
|
13714
13837
|
}
|
|
13715
|
-
if (
|
|
13838
|
+
if (Node56.isBinaryExpression(expr)) {
|
|
13716
13839
|
return fromBinary(expr, inner);
|
|
13717
13840
|
}
|
|
13718
|
-
if (
|
|
13841
|
+
if (Node56.isCallExpression(expr)) {
|
|
13719
13842
|
return fromCall(expr, inner);
|
|
13720
13843
|
}
|
|
13721
|
-
if (
|
|
13844
|
+
if (Node56.isIdentifier(expr)) {
|
|
13722
13845
|
const only = boundOnce(expr, ctx);
|
|
13723
13846
|
if (only !== null) {
|
|
13724
13847
|
return read(only.node, { ...inner, bindings: only.scope });
|
|
@@ -13728,7 +13851,7 @@ function read(expr, ctx) {
|
|
|
13728
13851
|
return written === null || written === expr ? null : read(written, inner);
|
|
13729
13852
|
}
|
|
13730
13853
|
function fromTemplate(expr, ctx) {
|
|
13731
|
-
if (!
|
|
13854
|
+
if (!Node56.isTemplateExpression(expr)) {
|
|
13732
13855
|
return null;
|
|
13733
13856
|
}
|
|
13734
13857
|
let name = expr.getHead().getLiteralText();
|
|
@@ -13739,28 +13862,28 @@ function fromTemplate(expr, ctx) {
|
|
|
13739
13862
|
return name;
|
|
13740
13863
|
}
|
|
13741
13864
|
function fromBinary(expr, ctx) {
|
|
13742
|
-
if (!
|
|
13865
|
+
if (!Node56.isBinaryExpression(expr)) {
|
|
13743
13866
|
return null;
|
|
13744
13867
|
}
|
|
13745
13868
|
const operator = expr.getOperatorToken().getKind();
|
|
13746
|
-
if (operator ===
|
|
13869
|
+
if (operator === SyntaxKind12.BarBarToken || operator === SyntaxKind12.QuestionQuestionToken) {
|
|
13747
13870
|
return ctx.insideHole ? null : read(expr.getRight(), ctx);
|
|
13748
13871
|
}
|
|
13749
|
-
if (operator !==
|
|
13872
|
+
if (operator !== SyntaxKind12.PlusToken) {
|
|
13750
13873
|
return null;
|
|
13751
13874
|
}
|
|
13752
13875
|
const parts = { ...ctx, insideHole: true };
|
|
13753
13876
|
return readOrHole(expr.getLeft(), parts) + readOrHole(expr.getRight(), parts);
|
|
13754
13877
|
}
|
|
13755
13878
|
function fromCall(expr, ctx) {
|
|
13756
|
-
if (!
|
|
13879
|
+
if (!Node56.isCallExpression(expr)) {
|
|
13757
13880
|
return null;
|
|
13758
13881
|
}
|
|
13759
13882
|
const callee = expr.getExpression();
|
|
13760
|
-
if (
|
|
13883
|
+
if (Node56.isPropertyAccessExpression(callee) && callee.getName() === "join") {
|
|
13761
13884
|
return fromJoin(callee.getExpression(), expr.getArguments(), ctx);
|
|
13762
13885
|
}
|
|
13763
|
-
if (
|
|
13886
|
+
if (Node56.isIdentifier(callee) && callee.getText() === "String") {
|
|
13764
13887
|
const only = expr.getArguments()[0];
|
|
13765
13888
|
return only === void 0 ? null : readOrHole(only, ctx);
|
|
13766
13889
|
}
|
|
@@ -13779,7 +13902,7 @@ function fromCall(expr, ctx) {
|
|
|
13779
13902
|
}
|
|
13780
13903
|
function fromJoin(subject, args, ctx) {
|
|
13781
13904
|
const separator = args[0];
|
|
13782
|
-
if (separator === void 0 || !
|
|
13905
|
+
if (separator === void 0 || !Node56.isStringLiteral(separator)) {
|
|
13783
13906
|
return null;
|
|
13784
13907
|
}
|
|
13785
13908
|
const parts = elementsOf(subject, ctx);
|
|
@@ -13795,17 +13918,17 @@ function fromJoin(subject, args, ctx) {
|
|
|
13795
13918
|
).join(separator.getLiteralValue());
|
|
13796
13919
|
}
|
|
13797
13920
|
function elementsOf(subject, ctx) {
|
|
13798
|
-
if (
|
|
13921
|
+
if (Node56.isArrayLiteralExpression(subject)) {
|
|
13799
13922
|
return subject.getElements().map((element) => here(element, ctx));
|
|
13800
13923
|
}
|
|
13801
|
-
if (
|
|
13924
|
+
if (Node56.isCallExpression(subject)) {
|
|
13802
13925
|
const callee = subject.getExpression();
|
|
13803
|
-
if (
|
|
13926
|
+
if (Node56.isPropertyAccessExpression(callee) && callee.getName() === "map") {
|
|
13804
13927
|
return elementsOf(callee.getExpression(), ctx);
|
|
13805
13928
|
}
|
|
13806
13929
|
return null;
|
|
13807
13930
|
}
|
|
13808
|
-
if (!
|
|
13931
|
+
if (!Node56.isIdentifier(subject)) {
|
|
13809
13932
|
return null;
|
|
13810
13933
|
}
|
|
13811
13934
|
const bound = ctx.bindings.get(subject.getText());
|
|
@@ -13813,7 +13936,7 @@ function elementsOf(subject, ctx) {
|
|
|
13813
13936
|
return null;
|
|
13814
13937
|
}
|
|
13815
13938
|
const only = bound.length === 1 ? bound[0] : void 0;
|
|
13816
|
-
return only !== void 0 &&
|
|
13939
|
+
return only !== void 0 && Node56.isArrayLiteralExpression(only.node) ? only.node.getElements().map((element) => here(element, ctx)) : bound;
|
|
13817
13940
|
}
|
|
13818
13941
|
function singleReturnBody(callee, ctx) {
|
|
13819
13942
|
const declaration = declarationOf2(callee, ctx);
|
|
@@ -13828,22 +13951,22 @@ function singleReturnBody(callee, ctx) {
|
|
|
13828
13951
|
if (body === void 0) {
|
|
13829
13952
|
return null;
|
|
13830
13953
|
}
|
|
13831
|
-
if (
|
|
13954
|
+
if (Node56.isExpression(body)) {
|
|
13832
13955
|
return { parameters, returned: body };
|
|
13833
13956
|
}
|
|
13834
|
-
if (!
|
|
13957
|
+
if (!Node56.isBlock(body)) {
|
|
13835
13958
|
return null;
|
|
13836
13959
|
}
|
|
13837
13960
|
const statements = body.getStatements();
|
|
13838
13961
|
const only = statements[0];
|
|
13839
|
-
if (statements.length !== 1 || only === void 0 || !
|
|
13962
|
+
if (statements.length !== 1 || only === void 0 || !Node56.isReturnStatement(only)) {
|
|
13840
13963
|
return null;
|
|
13841
13964
|
}
|
|
13842
13965
|
const returned = only.getExpression();
|
|
13843
13966
|
return returned === void 0 ? null : { parameters, returned };
|
|
13844
13967
|
}
|
|
13845
13968
|
function declarationOf2(callee, ctx) {
|
|
13846
|
-
const symbol =
|
|
13969
|
+
const symbol = Node56.isPropertyAccessExpression(callee) ? callee.getNameNode().getSymbol() : callee.getSymbol();
|
|
13847
13970
|
const declarations = symbol?.getAliasedSymbol()?.getDeclarations() ?? symbol?.getDeclarations() ?? [];
|
|
13848
13971
|
for (const declaration of declarations) {
|
|
13849
13972
|
const callable = asCallable(declaration);
|
|
@@ -13855,14 +13978,14 @@ function declarationOf2(callee, ctx) {
|
|
|
13855
13978
|
return written === null || written === callee ? null : declarationOf2(written, { ...ctx, resolve: () => null });
|
|
13856
13979
|
}
|
|
13857
13980
|
function asCallable(declaration) {
|
|
13858
|
-
if (
|
|
13981
|
+
if (Node56.isFunctionDeclaration(declaration) || Node56.isMethodDeclaration(declaration) || Node56.isArrowFunction(declaration) || Node56.isFunctionExpression(declaration)) {
|
|
13859
13982
|
return declaration;
|
|
13860
13983
|
}
|
|
13861
|
-
if (!
|
|
13984
|
+
if (!Node56.isVariableDeclaration(declaration)) {
|
|
13862
13985
|
return null;
|
|
13863
13986
|
}
|
|
13864
13987
|
const initializer = declaration.getInitializer();
|
|
13865
|
-
if (initializer !== void 0 && (
|
|
13988
|
+
if (initializer !== void 0 && (Node56.isArrowFunction(initializer) || Node56.isFunctionExpression(initializer))) {
|
|
13866
13989
|
return initializer;
|
|
13867
13990
|
}
|
|
13868
13991
|
return null;
|
|
@@ -13884,7 +14007,7 @@ function here(node, ctx) {
|
|
|
13884
14007
|
return { node, scope: ctx.bindings };
|
|
13885
14008
|
}
|
|
13886
14009
|
function boundOnce(expr, ctx) {
|
|
13887
|
-
const bound =
|
|
14010
|
+
const bound = Node56.isIdentifier(expr) ? ctx.bindings.get(expr.getText()) : void 0;
|
|
13888
14011
|
return bound !== void 0 && bound.length === 1 ? bound[0] : null;
|
|
13889
14012
|
}
|
|
13890
14013
|
function readOrHole(expr, ctx) {
|
|
@@ -13896,10 +14019,10 @@ function holeName(expr, ctx) {
|
|
|
13896
14019
|
if (bound !== null) {
|
|
13897
14020
|
return holeName(bound.node, { ...ctx, bindings: bound.scope });
|
|
13898
14021
|
}
|
|
13899
|
-
if (
|
|
14022
|
+
if (Node56.isIdentifier(expr)) {
|
|
13900
14023
|
return expr.getText();
|
|
13901
14024
|
}
|
|
13902
|
-
if (
|
|
14025
|
+
if (Node56.isPropertyAccessExpression(expr)) {
|
|
13903
14026
|
return expr.getName();
|
|
13904
14027
|
}
|
|
13905
14028
|
return UNNAMED_HOLE;
|