@suss/adapter-typescript 0.1.1 → 0.2.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.
Files changed (3) hide show
  1. package/dist/index.cjs +280 -191
  2. package/dist/index.js +280 -191
  3. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -35,25 +35,25 @@ import { Node as Node2, SyntaxKind } from "ts-morph";
35
35
  import { Node } from "ts-morph";
36
36
  var MAX_LAYERS = 16;
37
37
  function peelSyntax(node) {
38
- let current = node;
38
+ let current2 = node;
39
39
  for (let i = 0; i < MAX_LAYERS; i++) {
40
- if (Node.isAsExpression(current) || Node.isTypeAssertion(current) || Node.isParenthesizedExpression(current) || Node.isNonNullExpression(current) || Node.isSatisfiesExpression(current)) {
41
- current = current.getExpression();
40
+ if (Node.isAsExpression(current2) || Node.isTypeAssertion(current2) || Node.isParenthesizedExpression(current2) || Node.isNonNullExpression(current2) || Node.isSatisfiesExpression(current2)) {
41
+ current2 = current2.getExpression();
42
42
  continue;
43
43
  }
44
44
  break;
45
45
  }
46
- return current;
46
+ return current2;
47
47
  }
48
48
  function peelParens(node) {
49
- let current = node;
49
+ let current2 = node;
50
50
  for (let i = 0; i < MAX_LAYERS; i++) {
51
- if (!Node.isParenthesizedExpression(current)) {
51
+ if (!Node.isParenthesizedExpression(current2)) {
52
52
  break;
53
53
  }
54
- current = current.getExpression();
54
+ current2 = current2.getExpression();
55
55
  }
56
- return current;
56
+ return current2;
57
57
  }
58
58
 
59
59
  // src/resolve/astResolve.ts
@@ -924,15 +924,15 @@ function collectAncestorConditionInfos(terminalNode, functionRoot) {
924
924
  }
925
925
  function collectAncestorConditionInfosBelow(terminalNode, stopNode) {
926
926
  const result = [];
927
- let current = terminalNode;
928
- while (current !== void 0 && current !== stopNode) {
929
- const parent = current.getParent();
927
+ let current2 = terminalNode;
928
+ while (current2 !== void 0 && current2 !== stopNode) {
929
+ const parent = current2.getParent();
930
930
  if (parent !== void 0 && Node6.isIfStatement(parent)) {
931
931
  const thenBranch = parent.getThenStatement();
932
932
  const elseBranch = parent.getElseStatement();
933
933
  const expr = parent.getExpression();
934
- const inThen = isAncestorOrSelf(thenBranch, current);
935
- const inElse = elseBranch !== void 0 && isAncestorOrSelf(elseBranch, current);
934
+ const inThen = isAncestorOrSelf(thenBranch, current2);
935
+ const inElse = elseBranch !== void 0 && isAncestorOrSelf(elseBranch, current2);
936
936
  if (inThen) {
937
937
  result.unshift(
938
938
  makeConditionInfo(expr.getText(), "positive", "explicit", expr)
@@ -942,24 +942,24 @@ function collectAncestorConditionInfosBelow(terminalNode, stopNode) {
942
942
  makeConditionInfo(expr.getText(), "negative", "explicit", expr)
943
943
  );
944
944
  }
945
- } else if (Node6.isCaseClause(current)) {
946
- const switchStmt = current.getParent()?.getParent();
945
+ } else if (Node6.isCaseClause(current2)) {
946
+ const switchStmt = current2.getParent()?.getParent();
947
947
  if (switchStmt !== void 0 && Node6.isSwitchStatement(switchStmt)) {
948
948
  const switchExpr = switchStmt.getExpression().getText();
949
- const labels = collectFallthroughCaseLabels(current);
949
+ const labels = collectFallthroughCaseLabels(current2);
950
950
  const condText = labels.length === 1 ? `${switchExpr} === ${labels[0]}` : labels.map((l) => `${switchExpr} === ${l}`).join(" || ");
951
951
  result.unshift(
952
952
  makeConditionInfo(condText, "positive", "explicit", null)
953
953
  );
954
954
  }
955
- } else if (Node6.isCatchClause(current)) {
955
+ } else if (Node6.isCatchClause(current2)) {
956
956
  result.unshift(
957
957
  makeConditionInfo("catch", "positive", "catchBlock", null)
958
958
  );
959
959
  } else if (parent !== void 0 && Node6.isConditionalExpression(parent)) {
960
960
  const expr = parent.getCondition();
961
- const inTrue = isAncestorOrSelf(parent.getWhenTrue(), current);
962
- const inFalse = isAncestorOrSelf(parent.getWhenFalse(), current);
961
+ const inTrue = isAncestorOrSelf(parent.getWhenTrue(), current2);
962
+ const inFalse = isAncestorOrSelf(parent.getWhenFalse(), current2);
963
963
  if (inTrue) {
964
964
  result.unshift(
965
965
  makeConditionInfo(expr.getText(), "positive", "explicit", expr)
@@ -972,7 +972,7 @@ function collectAncestorConditionInfosBelow(terminalNode, stopNode) {
972
972
  } else if (parent !== void 0 && Node6.isBinaryExpression(parent)) {
973
973
  const op = parent.getOperatorToken().getText();
974
974
  const left = parent.getLeft();
975
- if (current === parent.getRight() || isAncestorOrSelf(parent.getRight(), current)) {
975
+ if (current2 === parent.getRight() || isAncestorOrSelf(parent.getRight(), current2)) {
976
976
  if (op === "&&") {
977
977
  result.unshift(
978
978
  makeConditionInfo(left.getText(), "positive", "explicit", left)
@@ -984,7 +984,7 @@ function collectAncestorConditionInfosBelow(terminalNode, stopNode) {
984
984
  }
985
985
  }
986
986
  }
987
- current = parent;
987
+ current2 = parent;
988
988
  }
989
989
  return result;
990
990
  }
@@ -994,12 +994,12 @@ function collectAncestorBranches(terminalNode, functionRoot) {
994
994
  );
995
995
  }
996
996
  function isAncestorOrSelf(maybeAncestor, node) {
997
- let current = node;
998
- while (current !== void 0) {
999
- if (current === maybeAncestor) {
997
+ let current2 = node;
998
+ while (current2 !== void 0) {
999
+ if (current2 === maybeAncestor) {
1000
1000
  return true;
1001
1001
  }
1002
- current = current.getParent();
1002
+ current2 = current2.getParent();
1003
1003
  }
1004
1004
  return false;
1005
1005
  }
@@ -1519,12 +1519,12 @@ function degradedResult(func, terminalNodes, reason) {
1519
1519
  return { byTerminal, fallthrough: [[marker]] };
1520
1520
  }
1521
1521
  function enclosingVisitedStatement(terminal, body, visited) {
1522
- let current = terminal;
1523
- while (current !== void 0 && current !== body) {
1524
- if (Node7.isStatement(current) && visited.has(current)) {
1525
- return current;
1522
+ let current2 = terminal;
1523
+ while (current2 !== void 0 && current2 !== body) {
1524
+ if (Node7.isStatement(current2) && visited.has(current2)) {
1525
+ return current2;
1526
1526
  }
1527
- current = current.getParent();
1527
+ current2 = current2.getParent();
1528
1528
  }
1529
1529
  return null;
1530
1530
  }
@@ -1562,12 +1562,12 @@ function isModuleScopeStop(node) {
1562
1562
  return Node8.isFunctionDeclaration(node) || Node8.isMethodDeclaration(node) || Node8.isArrowFunction(node) || Node8.isFunctionExpression(node) || Node8.isClassDeclaration(node) || Node8.isClassExpression(node);
1563
1563
  }
1564
1564
  function crossesNestedFunctionScope(node, func) {
1565
- let current = node;
1566
- while (current !== void 0 && current !== func) {
1567
- if (startsItsOwnScope(current)) {
1565
+ let current2 = node;
1566
+ while (current2 !== void 0 && current2 !== func) {
1567
+ if (startsItsOwnScope(current2)) {
1568
1568
  return true;
1569
1569
  }
1570
- current = current.getParent();
1570
+ current2 = current2.getParent();
1571
1571
  }
1572
1572
  return false;
1573
1573
  }
@@ -1890,13 +1890,13 @@ function inlineModuleBinding(ident, depth) {
1890
1890
  return null;
1891
1891
  }
1892
1892
  function isModuleScoped(decl) {
1893
- let current = decl.getParent();
1894
- while (current !== void 0) {
1895
- if (Node9.isSourceFile(current)) {
1893
+ let current2 = decl.getParent();
1894
+ while (current2 !== void 0) {
1895
+ if (Node9.isSourceFile(current2)) {
1896
1896
  return true;
1897
1897
  }
1898
- if (Node9.isVariableDeclarationList(current) || Node9.isVariableStatement(current)) {
1899
- current = current.getParent();
1898
+ if (Node9.isVariableDeclarationList(current2) || Node9.isVariableStatement(current2)) {
1899
+ current2 = current2.getParent();
1900
1900
  continue;
1901
1901
  }
1902
1902
  return false;
@@ -1919,12 +1919,12 @@ function unwrapCasts(node) {
1919
1919
  return node;
1920
1920
  }
1921
1921
  function enclosingStatementLine(node) {
1922
- let current = node;
1923
- while (current !== void 0) {
1924
- if (Node9.isStatement(current)) {
1925
- return startLineOf(current);
1922
+ let current2 = node;
1923
+ while (current2 !== void 0) {
1924
+ if (Node9.isStatement(current2)) {
1925
+ return startLineOf(current2);
1926
1926
  }
1927
- current = current.getParent();
1927
+ current2 = current2.getParent();
1928
1928
  }
1929
1929
  return startLineOf(node);
1930
1930
  }
@@ -2136,6 +2136,46 @@ import {
2136
2136
  SyntaxKind as SyntaxKind3
2137
2137
  } from "ts-morph";
2138
2138
 
2139
+ // src/shapes/typeShapes.ts
2140
+ import { createHash } from "crypto";
2141
+
2142
+ // src/shapes/definitions.ts
2143
+ var current = null;
2144
+ var definitionsInProgress = () => current;
2145
+ function createDefinitionTable() {
2146
+ const shapes = /* @__PURE__ */ new Map();
2147
+ return {
2148
+ has: (key) => shapes.has(key),
2149
+ reserve: (key) => {
2150
+ shapes.set(key, null);
2151
+ },
2152
+ define: (key, shape) => {
2153
+ shapes.set(key, shape);
2154
+ },
2155
+ collected: () => {
2156
+ const out = {};
2157
+ let any = false;
2158
+ for (const [key, shape] of shapes) {
2159
+ if (shape !== null) {
2160
+ out[key] = shape;
2161
+ any = true;
2162
+ }
2163
+ }
2164
+ return any ? out : null;
2165
+ }
2166
+ };
2167
+ }
2168
+ function withDefinitions(read) {
2169
+ const table = createDefinitionTable();
2170
+ const outer = current;
2171
+ current = table;
2172
+ try {
2173
+ return { value: read(), definitions: table.collected() };
2174
+ } finally {
2175
+ current = outer;
2176
+ }
2177
+ }
2178
+
2139
2179
  // src/shapes/typeShapes.ts
2140
2180
  var MAX_DEPTH = 6;
2141
2181
  var OPAQUE_NAMED_TYPES = /* @__PURE__ */ new Set([
@@ -2254,7 +2294,7 @@ function typeToShape(type, ctx) {
2254
2294
  return outsideRef;
2255
2295
  }
2256
2296
  if (type.isObject() || type.isClassOrInterface()) {
2257
- return objectToShape(type, ctx);
2297
+ return namedOnce(type, ctx) ?? objectToShape(type, ctx);
2258
2298
  }
2259
2299
  if (type.isEnum() || type.isEnumLiteral()) {
2260
2300
  return enumToShape(type, ctx);
@@ -2401,6 +2441,43 @@ function isOutsideProject(file) {
2401
2441
  outsideProjectByFile.set(key, outside);
2402
2442
  return outside;
2403
2443
  }
2444
+ function namedOnce(type, ctx) {
2445
+ const table = definitionsInProgress();
2446
+ if (table === null) {
2447
+ return null;
2448
+ }
2449
+ const named = refFromType(type, ctx);
2450
+ if (named.type !== "ref") {
2451
+ return null;
2452
+ }
2453
+ const symbol = type.getAliasSymbol() ?? type.getSymbol();
2454
+ const name = symbol?.getName();
2455
+ if (name === void 0 || name === "__type" || name === "__object") {
2456
+ return null;
2457
+ }
2458
+ const key = definitionKeyFor(type, named.name);
2459
+ const filed = { ...named, def: key };
2460
+ if (!table.has(key)) {
2461
+ table.reserve(key);
2462
+ const expanded = objectToShape(type, {
2463
+ enclosing: ctx.enclosing,
2464
+ depth: 0,
2465
+ seen: /* @__PURE__ */ new Set()
2466
+ });
2467
+ if (expanded === null) {
2468
+ return null;
2469
+ }
2470
+ table.define(key, expanded);
2471
+ }
2472
+ return filed;
2473
+ }
2474
+ function definitionKeyFor(type, name) {
2475
+ const written = withoutImportQualifiers(type.getText());
2476
+ return `${name}@${shortHash(written)}`;
2477
+ }
2478
+ function shortHash(text) {
2479
+ return createHash("sha1").update(text).digest("hex").slice(0, 12);
2480
+ }
2404
2481
  function refFromType(type, ctx) {
2405
2482
  const symbol = type.getAliasSymbol() ?? type.getSymbol();
2406
2483
  if (symbol) {
@@ -2959,22 +3036,22 @@ function branchCanRun(returnValue, substitutions) {
2959
3036
  function guardsAbove(returnValue) {
2960
3037
  const guards = [];
2961
3038
  let child = returnValue;
2962
- let current = returnValue.getParent();
2963
- while (current !== void 0) {
2964
- if (Node13.isIfStatement(current)) {
3039
+ let current2 = returnValue.getParent();
3040
+ while (current2 !== void 0) {
3041
+ if (Node13.isIfStatement(current2)) {
2965
3042
  guards.push({
2966
- condition: current.getExpression(),
2967
- whenTrue: current.getThenStatement() === child
3043
+ condition: current2.getExpression(),
3044
+ whenTrue: current2.getThenStatement() === child
2968
3045
  });
2969
3046
  }
2970
- if (Node13.isBlock(current)) {
2971
- guards.push(...earlyReturnGuardsBefore(current, child));
3047
+ if (Node13.isBlock(current2)) {
3048
+ guards.push(...earlyReturnGuardsBefore(current2, child));
2972
3049
  }
2973
- if (Node13.isFunctionDeclaration(current) || Node13.isArrowFunction(current) || Node13.isFunctionExpression(current)) {
3050
+ if (Node13.isFunctionDeclaration(current2) || Node13.isArrowFunction(current2) || Node13.isFunctionExpression(current2)) {
2974
3051
  break;
2975
3052
  }
2976
- child = current;
2977
- current = current.getParent();
3053
+ child = current2;
3054
+ current2 = current2.getParent();
2978
3055
  }
2979
3056
  return guards;
2980
3057
  }
@@ -3139,12 +3216,12 @@ function returnedObjects(fn) {
3139
3216
  return found;
3140
3217
  }
3141
3218
  function enclosingFunctionOf(node) {
3142
- let current = node.getParent();
3143
- while (current !== void 0) {
3144
- if (Node13.isFunctionDeclaration(current) || Node13.isArrowFunction(current) || Node13.isFunctionExpression(current) || Node13.isMethodDeclaration(current)) {
3145
- return current.getBody();
3219
+ let current2 = node.getParent();
3220
+ while (current2 !== void 0) {
3221
+ if (Node13.isFunctionDeclaration(current2) || Node13.isArrowFunction(current2) || Node13.isFunctionExpression(current2) || Node13.isMethodDeclaration(current2)) {
3222
+ return current2.getBody();
3146
3223
  }
3147
- current = current.getParent();
3224
+ current2 = current2.getParent();
3148
3225
  }
3149
3226
  return void 0;
3150
3227
  }
@@ -3162,16 +3239,16 @@ function bindArguments(callArgs, params) {
3162
3239
  // src/terminals/shared.ts
3163
3240
  import { Node as Node14 } from "ts-morph";
3164
3241
  function unwrapValue(node) {
3165
- let current = node;
3166
- while (Node14.isParenthesizedExpression(current) || Node14.isAwaitExpression(current) || Node14.isAsExpression(current) || Node14.isNonNullExpression(current) || Node14.isSatisfiesExpression(current)) {
3167
- current = current.getExpression();
3242
+ let current2 = node;
3243
+ while (Node14.isParenthesizedExpression(current2) || Node14.isAwaitExpression(current2) || Node14.isAsExpression(current2) || Node14.isNonNullExpression(current2) || Node14.isSatisfiesExpression(current2)) {
3244
+ current2 = current2.getExpression();
3168
3245
  }
3169
- return current;
3246
+ return current2;
3170
3247
  }
3171
3248
  function returnPositionOf(value) {
3172
- let current = value;
3249
+ let current2 = value;
3173
3250
  while (true) {
3174
- const parent = current.getParent();
3251
+ const parent = current2.getParent();
3175
3252
  if (parent === void 0) {
3176
3253
  return null;
3177
3254
  }
@@ -3179,14 +3256,14 @@ function returnPositionOf(value) {
3179
3256
  return parent;
3180
3257
  }
3181
3258
  if (Node14.isArrowFunction(parent)) {
3182
- return parent.getBody() === current ? current : null;
3259
+ return parent.getBody() === current2 ? current2 : null;
3183
3260
  }
3184
3261
  if (Node14.isParenthesizedExpression(parent) || Node14.isAwaitExpression(parent) || Node14.isAsExpression(parent) || Node14.isNonNullExpression(parent) || Node14.isSatisfiesExpression(parent)) {
3185
- current = parent;
3262
+ current2 = parent;
3186
3263
  continue;
3187
3264
  }
3188
- if (Node14.isConditionalExpression(parent) && (parent.getWhenTrue() === current || parent.getWhenFalse() === current)) {
3189
- current = parent;
3265
+ if (Node14.isConditionalExpression(parent) && (parent.getWhenTrue() === current2 || parent.getWhenFalse() === current2)) {
3266
+ current2 = parent;
3190
3267
  continue;
3191
3268
  }
3192
3269
  return null;
@@ -3330,12 +3407,12 @@ function writesRunInOrder(declaration, writes) {
3330
3407
  return last !== void 0 && !isReadBefore(declaration, last.node.getStart());
3331
3408
  }
3332
3409
  function statementOf(node) {
3333
- let current = node;
3334
- while (current !== void 0) {
3335
- if (Node15.isStatement(current)) {
3336
- return current;
3410
+ let current2 = node;
3411
+ while (current2 !== void 0) {
3412
+ if (Node15.isStatement(current2)) {
3413
+ return current2;
3337
3414
  }
3338
- current = current.getParent();
3415
+ current2 = current2.getParent();
3339
3416
  }
3340
3417
  return null;
3341
3418
  }
@@ -3429,11 +3506,11 @@ function numberOf(node) {
3429
3506
  return Number.isFinite(value) ? value : null;
3430
3507
  }
3431
3508
  function unwrap(node) {
3432
- let current = node;
3433
- while (Node16.isParenthesizedExpression(current) || Node16.isAsExpression(current) || Node16.isNonNullExpression(current)) {
3434
- current = current.getExpression();
3509
+ let current2 = node;
3510
+ while (Node16.isParenthesizedExpression(current2) || Node16.isAsExpression(current2) || Node16.isNonNullExpression(current2)) {
3511
+ current2 = current2.getExpression();
3435
3512
  }
3436
- return current;
3513
+ return current2;
3437
3514
  }
3438
3515
 
3439
3516
  // src/terminals/returns.ts
@@ -3442,17 +3519,17 @@ function unwrapMethodChain(call, methodChain, func, paramPos) {
3442
3519
  return null;
3443
3520
  }
3444
3521
  const collected = [];
3445
- let current = call;
3522
+ let current2 = call;
3446
3523
  for (let i = methodChain.length - 1; i >= 0; i--) {
3447
3524
  const expectedMethod = methodChain[i];
3448
- const callee = current.getExpression();
3525
+ const callee = current2.getExpression();
3449
3526
  if (!Node17.isPropertyAccessExpression(callee)) {
3450
3527
  return null;
3451
3528
  }
3452
3529
  if (callee.getName() !== expectedMethod) {
3453
3530
  return null;
3454
3531
  }
3455
- collected.unshift(current);
3532
+ collected.unshift(current2);
3456
3533
  const subject = callee.getExpression();
3457
3534
  if (i === 0) {
3458
3535
  if (!Node17.isIdentifier(subject)) {
@@ -3479,7 +3556,7 @@ function unwrapMethodChain(call, methodChain, func, paramPos) {
3479
3556
  if (!Node17.isCallExpression(subject)) {
3480
3557
  return null;
3481
3558
  }
3482
- current = subject;
3559
+ current2 = subject;
3483
3560
  }
3484
3561
  }
3485
3562
  return { calls: collected };
@@ -3654,8 +3731,8 @@ function statusArgument(calls, extraction) {
3654
3731
  return calls[0]?.getArguments()[from.position] ?? null;
3655
3732
  }
3656
3733
  function returnCoveredByParameterMethodCall(expr, func, patterns) {
3657
- const current = unwrapValue(expr);
3658
- if (!Node17.isCallExpression(current)) {
3734
+ const current2 = unwrapValue(expr);
3735
+ if (!Node17.isCallExpression(current2)) {
3659
3736
  return false;
3660
3737
  }
3661
3738
  for (const pattern of patterns) {
@@ -3663,7 +3740,7 @@ function returnCoveredByParameterMethodCall(expr, func, patterns) {
3663
3740
  continue;
3664
3741
  }
3665
3742
  const result = unwrapMethodChain(
3666
- current,
3743
+ current2,
3667
3744
  pattern.match.methodChain,
3668
3745
  func,
3669
3746
  pattern.match.parameterPosition
@@ -4243,17 +4320,17 @@ var ModuleGraph = class {
4243
4320
  const walked = /* @__PURE__ */ new Set();
4244
4321
  const stack = [root];
4245
4322
  while (stack.length > 0) {
4246
- const current = stack.pop();
4247
- const currentPath = current.getFilePath();
4323
+ const current2 = stack.pop();
4324
+ const currentPath = current2.getFilePath();
4248
4325
  if (walked.has(currentPath) || settled.has(currentPath)) {
4249
4326
  continue;
4250
4327
  }
4251
4328
  walked.add(currentPath);
4252
- if (namesPackage(this.specifiersOf(current), name)) {
4329
+ if (namesPackage(this.specifiersOf(current2), name)) {
4253
4330
  this.assert("importsPackage", [currentPath, name]);
4254
4331
  continue;
4255
4332
  }
4256
- stack.push(...this.importedFilesOf(current));
4333
+ stack.push(...this.importedFilesOf(current2));
4257
4334
  }
4258
4335
  for (const filePath of walked) {
4259
4336
  settled.add(filePath);
@@ -4576,7 +4653,7 @@ function indexFunctions(sf) {
4576
4653
  }
4577
4654
 
4578
4655
  // src/cache.ts
4579
- import { createHash } from "crypto";
4656
+ import { createHash as createHash2 } from "crypto";
4580
4657
  import fs2 from "fs/promises";
4581
4658
  import path2 from "path";
4582
4659
  var SCHEMA_VERSION = "3";
@@ -4655,7 +4732,7 @@ function entryDirFor(cacheDir, input) {
4655
4732
  input.adapterPacksDigest,
4656
4733
  input.tsconfigPath ?? ""
4657
4734
  ].join("\0");
4658
- const name = createHash("sha256").update(key).digest("hex").slice(0, 16);
4735
+ const name = createHash2("sha256").update(key).digest("hex").slice(0, 16);
4659
4736
  return path2.join(cacheDir, `${ENTRY_PREFIX}${name}`);
4660
4737
  }
4661
4738
  function isEntryDir(name) {
@@ -5353,12 +5430,12 @@ function toFunctionRoot(node) {
5353
5430
  return isFunctionRoot(node) ? declarationCarryingTheBody(node) : null;
5354
5431
  }
5355
5432
  function findEnclosingFunction(node) {
5356
- let current = node.getParent();
5357
- while (current !== void 0) {
5358
- if (Node23.isFunctionDeclaration(current) || Node23.isFunctionExpression(current) || Node23.isArrowFunction(current) || Node23.isMethodDeclaration(current)) {
5359
- return current;
5433
+ let current2 = node.getParent();
5434
+ while (current2 !== void 0) {
5435
+ if (Node23.isFunctionDeclaration(current2) || Node23.isFunctionExpression(current2) || Node23.isArrowFunction(current2) || Node23.isMethodDeclaration(current2)) {
5436
+ return current2;
5360
5437
  }
5361
- current = current.getParent();
5438
+ current2 = current2.getParent();
5362
5439
  }
5363
5440
  return null;
5364
5441
  }
@@ -6222,10 +6299,10 @@ function resolveTypedDocumentHeader(arg) {
6222
6299
  return null;
6223
6300
  }
6224
6301
  function documentNodeCastTypeArgs(node) {
6225
- let current = node;
6226
- while (Node30.isAsExpression(current) || Node30.isParenthesizedExpression(current)) {
6227
- if (Node30.isAsExpression(current)) {
6228
- const typeNode = current.getTypeNode();
6302
+ let current2 = node;
6303
+ while (Node30.isAsExpression(current2) || Node30.isParenthesizedExpression(current2)) {
6304
+ if (Node30.isAsExpression(current2)) {
6305
+ const typeNode = current2.getTypeNode();
6229
6306
  if (typeNode !== void 0 && Node30.isTypeReference(typeNode)) {
6230
6307
  const name = typeNode.getTypeName().getText();
6231
6308
  const simpleName = name.includes(".") ? name.split(".").pop() ?? name : name;
@@ -6234,7 +6311,7 @@ function documentNodeCastTypeArgs(node) {
6234
6311
  }
6235
6312
  }
6236
6313
  }
6237
- current = current.getExpression();
6314
+ current2 = current2.getExpression();
6238
6315
  }
6239
6316
  return null;
6240
6317
  }
@@ -6259,11 +6336,11 @@ function operationHeaderFromResultType(typeNode) {
6259
6336
  return null;
6260
6337
  }
6261
6338
  function stripDocumentNodeCasts(node) {
6262
- let current = node;
6263
- while (Node30.isAsExpression(current) || Node30.isParenthesizedExpression(current)) {
6264
- current = current.getExpression();
6339
+ let current2 = node;
6340
+ while (Node30.isAsExpression(current2) || Node30.isParenthesizedExpression(current2)) {
6341
+ current2 = current2.getExpression();
6265
6342
  }
6266
- return current;
6343
+ return current2;
6267
6344
  }
6268
6345
  function evaluateObjectLiteralAsJson(node) {
6269
6346
  if (Node30.isStringLiteral(node) || Node30.isNoSubstitutionTemplateLiteral(node)) {
@@ -6341,12 +6418,12 @@ function resolveGraphqlFileImport(decl) {
6341
6418
  }
6342
6419
  }
6343
6420
  function enclosingFunctionRoot(node) {
6344
- let current = node.getParent();
6345
- while (current !== void 0) {
6346
- if (Node30.isFunctionDeclaration(current) || Node30.isFunctionExpression(current) || Node30.isArrowFunction(current) || Node30.isMethodDeclaration(current)) {
6347
- return current;
6421
+ let current2 = node.getParent();
6422
+ while (current2 !== void 0) {
6423
+ if (Node30.isFunctionDeclaration(current2) || Node30.isFunctionExpression(current2) || Node30.isArrowFunction(current2) || Node30.isMethodDeclaration(current2)) {
6424
+ return current2;
6348
6425
  }
6349
- current = current.getParent();
6426
+ current2 = current2.getParent();
6350
6427
  }
6351
6428
  return null;
6352
6429
  }
@@ -6867,12 +6944,12 @@ function isScopeNode(node) {
6867
6944
  function trackFactoryBindings(sourceFile, recognize) {
6868
6945
  const scopes = /* @__PURE__ */ new Map();
6869
6946
  function scopeOf(node) {
6870
- let current = node.getParent();
6871
- while (current !== void 0) {
6872
- if (isScopeNode(current)) {
6873
- return current;
6947
+ let current2 = node.getParent();
6948
+ while (current2 !== void 0) {
6949
+ if (isScopeNode(current2)) {
6950
+ return current2;
6874
6951
  }
6875
- current = current.getParent();
6952
+ current2 = current2.getParent();
6876
6953
  }
6877
6954
  return sourceFile;
6878
6955
  }
@@ -6934,16 +7011,16 @@ function trackFactoryBindings(sourceFile, recognize) {
6934
7011
  }
6935
7012
  return {
6936
7013
  resolve(name, fromNode) {
6937
- let current = fromNode;
6938
- while (current !== void 0) {
6939
- const map = scopes.get(current);
7014
+ let current2 = fromNode;
7015
+ while (current2 !== void 0) {
7016
+ const map = scopes.get(current2);
6940
7017
  if (map !== void 0) {
6941
7018
  const found = map.get(name);
6942
7019
  if (found !== void 0) {
6943
7020
  return found;
6944
7021
  }
6945
7022
  }
6946
- current = current.getParent();
7023
+ current2 = current2.getParent();
6947
7024
  }
6948
7025
  return null;
6949
7026
  }
@@ -7233,21 +7310,21 @@ function literalIndexOf(index) {
7233
7310
  return null;
7234
7311
  }
7235
7312
  function unwrapExpression(expression) {
7236
- let current = expression;
7313
+ let current2 = expression;
7237
7314
  for (; ; ) {
7238
- if (Node37.isAwaitExpression(current)) {
7239
- current = current.getExpression();
7315
+ if (Node37.isAwaitExpression(current2)) {
7316
+ current2 = current2.getExpression();
7240
7317
  continue;
7241
7318
  }
7242
- if (Node37.isParenthesizedExpression(current)) {
7243
- current = current.getExpression();
7319
+ if (Node37.isParenthesizedExpression(current2)) {
7320
+ current2 = current2.getExpression();
7244
7321
  continue;
7245
7322
  }
7246
- if (Node37.isAsExpression(current) || Node37.isSatisfiesExpression(current)) {
7247
- current = current.getExpression();
7323
+ if (Node37.isAsExpression(current2) || Node37.isSatisfiesExpression(current2)) {
7324
+ current2 = current2.getExpression();
7248
7325
  continue;
7249
7326
  }
7250
- return current;
7327
+ return current2;
7251
7328
  }
7252
7329
  }
7253
7330
  function emitValue(db, table, value) {
@@ -7545,13 +7622,13 @@ function recordBodyNode(db, table, fnId, node) {
7545
7622
  return false;
7546
7623
  }
7547
7624
  function descendantIsReturned(fn) {
7548
- let current = fn.getParent();
7549
- while (current !== void 0) {
7550
- if (Node37.isReturnStatement(current)) {
7625
+ let current2 = fn.getParent();
7626
+ while (current2 !== void 0) {
7627
+ if (Node37.isReturnStatement(current2)) {
7551
7628
  return true;
7552
7629
  }
7553
- if (Node37.isParenthesizedExpression(current) || Node37.isAsExpression(current) || Node37.isSatisfiesExpression(current)) {
7554
- current = current.getParent();
7630
+ if (Node37.isParenthesizedExpression(current2) || Node37.isAsExpression(current2) || Node37.isSatisfiesExpression(current2)) {
7631
+ current2 = current2.getParent();
7555
7632
  continue;
7556
7633
  }
7557
7634
  return false;
@@ -8506,11 +8583,11 @@ function configString(arg, property, resolution) {
8506
8583
  return null;
8507
8584
  }
8508
8585
  function peelExpression(node) {
8509
- let current = node;
8510
- while (current !== void 0 && (Node43.isAsExpression(current) || Node43.isSatisfiesExpression(current) || Node43.isParenthesizedExpression(current) || Node43.isNonNullExpression(current))) {
8511
- current = current.getExpression();
8586
+ let current2 = node;
8587
+ while (current2 !== void 0 && (Node43.isAsExpression(current2) || Node43.isSatisfiesExpression(current2) || Node43.isParenthesizedExpression(current2) || Node43.isNonNullExpression(current2))) {
8588
+ current2 = current2.getExpression();
8512
8589
  }
8513
- return current;
8590
+ return current2;
8514
8591
  }
8515
8592
  function toObjectLiteral(node, resolution) {
8516
8593
  const peeled = peelExpression(node);
@@ -8573,11 +8650,11 @@ function hasJsxReturn(func) {
8573
8650
  return found;
8574
8651
  }
8575
8652
  function isJsxOrFragment(node) {
8576
- let current = node;
8577
- while (Node43.isParenthesizedExpression(current)) {
8578
- current = current.getExpression();
8653
+ let current2 = node;
8654
+ while (Node43.isParenthesizedExpression(current2)) {
8655
+ current2 = current2.getExpression();
8579
8656
  }
8580
- return Node43.isJsxElement(current) || Node43.isJsxSelfClosingElement(current) || Node43.isJsxFragment(current);
8657
+ return Node43.isJsxElement(current2) || Node43.isJsxSelfClosingElement(current2) || Node43.isJsxFragment(current2);
8581
8658
  }
8582
8659
 
8583
8660
  // src/facts/store.ts
@@ -9578,19 +9655,19 @@ function findBareRethrow(func, location) {
9578
9655
  return found;
9579
9656
  }
9580
9657
  function enclosingTry(throwStmt) {
9581
- let current = throwStmt.getParent();
9658
+ let current2 = throwStmt.getParent();
9582
9659
  let sawCatchClause = false;
9583
- while (current !== void 0) {
9584
- if (Node46.isCatchClause(current)) {
9660
+ while (current2 !== void 0) {
9661
+ if (Node46.isCatchClause(current2)) {
9585
9662
  sawCatchClause = true;
9586
9663
  }
9587
- if (Node46.isTryStatement(current)) {
9588
- return sawCatchClause ? current : null;
9664
+ if (Node46.isTryStatement(current2)) {
9665
+ return sawCatchClause ? current2 : null;
9589
9666
  }
9590
- if (Node46.isFunctionDeclaration(current) || Node46.isFunctionExpression(current) || Node46.isArrowFunction(current) || Node46.isMethodDeclaration(current)) {
9667
+ if (Node46.isFunctionDeclaration(current2) || Node46.isFunctionExpression(current2) || Node46.isArrowFunction(current2) || Node46.isMethodDeclaration(current2)) {
9591
9668
  return null;
9592
9669
  }
9593
- current = current.getParent();
9670
+ current2 = current2.getParent();
9594
9671
  }
9595
9672
  return null;
9596
9673
  }
@@ -9662,12 +9739,12 @@ import {
9662
9739
  Node as Node47
9663
9740
  } from "ts-morph";
9664
9741
  function findResponseAccessor(callExpr) {
9665
- let current = callExpr;
9666
- const parent1 = current.getParent();
9742
+ let current2 = callExpr;
9743
+ const parent1 = current2.getParent();
9667
9744
  if (parent1 !== void 0 && Node47.isAwaitExpression(parent1)) {
9668
- current = parent1;
9745
+ current2 = parent1;
9669
9746
  }
9670
- const parent2 = current.getParent();
9747
+ const parent2 = current2.getParent();
9671
9748
  if (parent2 === void 0 || !Node47.isVariableDeclaration(parent2)) {
9672
9749
  return null;
9673
9750
  }
@@ -9824,12 +9901,12 @@ function collectPropertyAccesses(subtree, accessor) {
9824
9901
  return;
9825
9902
  }
9826
9903
  const chain = [];
9827
- let current = node;
9828
- while (Node47.isPropertyAccessExpression(current)) {
9829
- chain.unshift(current.getName());
9830
- current = current.getExpression();
9904
+ let current2 = node;
9905
+ while (Node47.isPropertyAccessExpression(current2)) {
9906
+ chain.unshift(current2.getName());
9907
+ current2 = current2.getExpression();
9831
9908
  }
9832
- if (Node47.isIdentifier(current) && current.getText() === varName) {
9909
+ if (Node47.isIdentifier(current2) && current2.getText() === varName) {
9833
9910
  pushChain(chain);
9834
9911
  }
9835
9912
  });
@@ -9857,10 +9934,10 @@ function collectPropertyAccesses(subtree, accessor) {
9857
9934
  parent = chainTop.getParent();
9858
9935
  }
9859
9936
  const segments = [];
9860
- let current = chainTop;
9861
- while (Node47.isPropertyAccessExpression(current)) {
9862
- segments.push(current.getName());
9863
- current = current.getExpression();
9937
+ let current2 = chainTop;
9938
+ while (Node47.isPropertyAccessExpression(current2)) {
9939
+ segments.push(current2.getName());
9940
+ current2 = current2.getExpression();
9864
9941
  }
9865
9942
  segments.reverse();
9866
9943
  pushChain([...prefix, ...segments]);
@@ -9875,15 +9952,15 @@ function isBindingDeclarationSite(node) {
9875
9952
  return parent !== void 0 && Node47.isParameterDeclaration(parent) && parent.getNameNode() === node;
9876
9953
  }
9877
9954
  function isInsideObjectBindingPattern(node) {
9878
- let current = node.getParent();
9879
- while (current !== void 0) {
9880
- if (Node47.isObjectBindingPattern(current)) {
9955
+ let current2 = node.getParent();
9956
+ while (current2 !== void 0) {
9957
+ if (Node47.isObjectBindingPattern(current2)) {
9881
9958
  return true;
9882
9959
  }
9883
- if (Node47.isFunctionLikeDeclaration(current) || Node47.isVariableStatement(current)) {
9960
+ if (Node47.isFunctionLikeDeclaration(current2) || Node47.isVariableStatement(current2)) {
9884
9961
  break;
9885
9962
  }
9886
- current = current.getParent();
9963
+ current2 = current2.getParent();
9887
9964
  }
9888
9965
  return false;
9889
9966
  }
@@ -9937,9 +10014,9 @@ function findBranchSubtree(func, byLineRange, terminalStartLine, terminalEndLine
9937
10014
  if (terminalNode === null) {
9938
10015
  return func;
9939
10016
  }
9940
- let current = terminalNode;
9941
- while (current !== func) {
9942
- const parent = current.getParent();
10017
+ let current2 = terminalNode;
10018
+ while (current2 !== func) {
10019
+ const parent = current2.getParent();
9943
10020
  if (parent === void 0) {
9944
10021
  break;
9945
10022
  }
@@ -9954,17 +10031,17 @@ function findBranchSubtree(func, byLineRange, terminalStartLine, terminalEndLine
9954
10031
  return elseBlock;
9955
10032
  }
9956
10033
  }
9957
- current = parent;
10034
+ current2 = parent;
9958
10035
  }
9959
10036
  return func;
9960
10037
  }
9961
10038
  function isDescendantOf(node, ancestor) {
9962
- let current = node;
9963
- while (current !== void 0) {
9964
- if (current === ancestor) {
10039
+ let current2 = node;
10040
+ while (current2 !== void 0) {
10041
+ if (current2 === ancestor) {
9965
10042
  return true;
9966
10043
  }
9967
- current = current.getParent();
10044
+ current2 = current2.getParent();
9968
10045
  }
9969
10046
  return false;
9970
10047
  }
@@ -10120,12 +10197,12 @@ function tryExtractFunction(decl) {
10120
10197
  return null;
10121
10198
  }
10122
10199
  function isWithinFunction(node, func) {
10123
- let current = node.getParent();
10124
- while (current !== void 0) {
10125
- if (current === func) {
10200
+ let current2 = node.getParent();
10201
+ while (current2 !== void 0) {
10202
+ if (current2 === func) {
10126
10203
  return true;
10127
10204
  }
10128
- current = current.getParent();
10205
+ current2 = current2.getParent();
10129
10206
  }
10130
10207
  return false;
10131
10208
  }
@@ -10195,7 +10272,7 @@ function createTimer() {
10195
10272
  }
10196
10273
 
10197
10274
  // src/version.ts
10198
- import { createHash as createHash2 } from "crypto";
10275
+ import { createHash as createHash3 } from "crypto";
10199
10276
  import fs6 from "fs";
10200
10277
  import { createRequire } from "module";
10201
10278
  import path6 from "path";
@@ -10234,7 +10311,7 @@ function computeContentHash(paths) {
10234
10311
  if (paths.length === 0) {
10235
10312
  return "";
10236
10313
  }
10237
- const hash = createHash2("sha256");
10314
+ const hash = createHash3("sha256");
10238
10315
  for (const file of paths) {
10239
10316
  try {
10240
10317
  hash.update(fs6.readFileSync(file));
@@ -10541,6 +10618,18 @@ function announcedBoundaryStructure(unit) {
10541
10618
  };
10542
10619
  }
10543
10620
  function extractCodeStructure(unit, pack, invocationRecognizers = [], accessRecognizers = [], barriers = NO_BARRIERS) {
10621
+ const read = withDefinitions(
10622
+ () => readCodeStructure(
10623
+ unit,
10624
+ pack,
10625
+ invocationRecognizers,
10626
+ accessRecognizers,
10627
+ barriers
10628
+ )
10629
+ );
10630
+ return read.definitions === null ? read.value : { ...read.value, definitions: read.definitions };
10631
+ }
10632
+ function readCodeStructure(unit, pack, invocationRecognizers, accessRecognizers, barriers) {
10544
10633
  const { func, kind, name } = unit;
10545
10634
  if (func === null) {
10546
10635
  return announcedBoundaryStructure(unit);
@@ -11138,13 +11227,13 @@ function wrapperNameNode(func) {
11138
11227
  return null;
11139
11228
  }
11140
11229
  function enclosingCall(node) {
11141
- let current = node.getParent();
11142
- while (current !== void 0) {
11143
- if (Node49.isCallExpression(current)) {
11144
- return current;
11230
+ let current2 = node.getParent();
11231
+ while (current2 !== void 0) {
11232
+ if (Node49.isCallExpression(current2)) {
11233
+ return current2;
11145
11234
  }
11146
- if (Node49.isPropertyAccessExpression(current)) {
11147
- current = current.getParent();
11235
+ if (Node49.isPropertyAccessExpression(current2)) {
11236
+ current2 = current2.getParent();
11148
11237
  continue;
11149
11238
  }
11150
11239
  return null;
@@ -11152,12 +11241,12 @@ function enclosingCall(node) {
11152
11241
  return null;
11153
11242
  }
11154
11243
  function enclosingFunction(node) {
11155
- let current = node.getParent();
11156
- while (current !== void 0) {
11157
- if (Node49.isFunctionDeclaration(current) || Node49.isFunctionExpression(current) || Node49.isArrowFunction(current) || Node49.isMethodDeclaration(current)) {
11158
- return current;
11244
+ let current2 = node.getParent();
11245
+ while (current2 !== void 0) {
11246
+ if (Node49.isFunctionDeclaration(current2) || Node49.isFunctionExpression(current2) || Node49.isArrowFunction(current2) || Node49.isMethodDeclaration(current2)) {
11247
+ return current2;
11159
11248
  }
11160
- current = current.getParent();
11249
+ current2 = current2.getParent();
11161
11250
  }
11162
11251
  return null;
11163
11252
  }