tstyche 7.2.2 → 7.2.4

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 (2) hide show
  1. package/dist/api.js +43 -2
  2. package/package.json +1 -1
package/dist/api.js CHANGED
@@ -612,7 +612,7 @@ class Fetcher {
612
612
  }
613
613
  async get(request, diagnostic, options) {
614
614
  let delay = 3000;
615
- request.headers.set("User-Agent", `tstyche/7.2.2 ${process.platform} ${process.arch}`);
615
+ request.headers.set("User-Agent", `tstyche/7.2.4 ${process.platform} ${process.arch}`);
616
616
  for (let attempt = 0; attempt <= this.#retries; attempt++) {
617
617
  const isLastAttempt = attempt === this.#retries;
618
618
  const suppressErrors = options?.suppressErrors || !isLastAttempt;
@@ -4675,6 +4675,13 @@ function getIndexSignatures(type, compiler, typeChecker) {
4675
4675
  }
4676
4676
  return typeChecker.getIndexInfosOfType(type);
4677
4677
  }
4678
+ function getReducedType(type, typeChecker) {
4679
+ typeChecker.typeToString(type);
4680
+ if ("resolvedReducedType" in type) {
4681
+ return type.resolvedReducedType;
4682
+ }
4683
+ return type;
4684
+ }
4678
4685
  function getSignatures(type, kind, compiler, typeChecker) {
4679
4686
  if (type.flags & compiler.TypeFlags.Intersection) {
4680
4687
  return type.types.flatMap((type) => getSignatures(type, kind, compiler, typeChecker));
@@ -4774,6 +4781,7 @@ class Structure {
4774
4781
  #typeChecker;
4775
4782
  #deduplicateCache = new WeakMap();
4776
4783
  #memoizeCache = new Map();
4784
+ #recursionStack = [];
4777
4785
  constructor(compiler, program) {
4778
4786
  this.#compiler = compiler;
4779
4787
  this.#compilerOptions = program.getCompilerOptions();
@@ -5152,18 +5160,51 @@ class Structure {
5152
5160
  this.#deduplicateCache.set(target, result);
5153
5161
  return result;
5154
5162
  }
5163
+ #getRecursionIdentity(type) {
5164
+ return type.aliasSymbol ?? type.symbol;
5165
+ }
5166
+ #isInfiniteRecursion(a, b) {
5167
+ const aIdentity = this.#getRecursionIdentity(a);
5168
+ const bIdentity = this.#getRecursionIdentity(b);
5169
+ if (!aIdentity || !bIdentity) {
5170
+ return false;
5171
+ }
5172
+ let matches = 0;
5173
+ for (const frame of this.#recursionStack) {
5174
+ if (frame.aIdentity === aIdentity && frame.bIdentity === bIdentity && a.id > frame.aId && b.id > frame.bId) {
5175
+ matches++;
5176
+ if (matches >= 2) {
5177
+ return true;
5178
+ }
5179
+ }
5180
+ }
5181
+ return false;
5182
+ }
5155
5183
  #memoize(a, b, compare) {
5156
5184
  const key = [a.id, b.id].sort((a, b) => a - b).join(":");
5157
5185
  const result = this.#memoizeCache.get(key);
5158
5186
  if (result !== undefined) {
5159
5187
  return result !== 2;
5160
5188
  }
5189
+ if (this.#isInfiniteRecursion(a, b)) {
5190
+ this.#memoizeCache.set(key, 1);
5191
+ return true;
5192
+ }
5161
5193
  this.#memoizeCache.set(key, 0);
5194
+ const aIdentity = this.#getRecursionIdentity(a);
5195
+ const bIdentity = this.#getRecursionIdentity(b);
5196
+ if (aIdentity != null && bIdentity != null) {
5197
+ this.#recursionStack.push({ aId: a.id, bId: b.id, aIdentity, bIdentity });
5198
+ }
5162
5199
  const isSame = compare();
5200
+ if (aIdentity != null && bIdentity != null) {
5201
+ this.#recursionStack.pop();
5202
+ }
5163
5203
  this.#memoizeCache.set(key, isSame ? 1 : 2);
5164
5204
  return isSame;
5165
5205
  }
5166
5206
  #normalize(type) {
5207
+ type = getReducedType(type, this.#typeChecker);
5167
5208
  if (type.flags & this.#compiler.TypeFlags.Freshable && type.freshType === type) {
5168
5209
  return type.regularType;
5169
5210
  }
@@ -5901,7 +5942,7 @@ class FileRunner {
5901
5942
  class Runner {
5902
5943
  #eventEmitter = new EventEmitter();
5903
5944
  #resolvedConfig;
5904
- static version = "7.2.2";
5945
+ static version = "7.2.4";
5905
5946
  constructor(resolvedConfig) {
5906
5947
  this.#resolvedConfig = resolvedConfig;
5907
5948
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tstyche",
3
- "version": "7.2.2",
3
+ "version": "7.2.4",
4
4
  "description": "Everything You Need for Type Testing.",
5
5
  "keywords": [
6
6
  "typescript",