tstyche 7.2.3 → 7.2.5

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 +72 -5
  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.3 ${process.platform} ${process.arch}`);
615
+ request.headers.set("User-Agent", `tstyche/7.2.5 ${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;
@@ -4781,6 +4781,8 @@ class Structure {
4781
4781
  #typeChecker;
4782
4782
  #deduplicateCache = new WeakMap();
4783
4783
  #memoizeCache = new Map();
4784
+ #recursionStack = [];
4785
+ #unusedTypeParametersLookup = new WeakMap();
4784
4786
  constructor(compiler, program) {
4785
4787
  this.#compiler = compiler;
4786
4788
  this.#compilerOptions = program.getCompilerOptions();
@@ -4923,10 +4925,11 @@ class Structure {
4923
4925
  if (this.compare(a.target, b.target)) {
4924
4926
  const aTypeArguments = this.#typeChecker.getTypeArguments(a);
4925
4927
  const bTypeArguments = this.#typeChecker.getTypeArguments(b);
4926
- if (aTypeArguments.length !== bTypeArguments.length) {
4927
- return false;
4928
- }
4928
+ const unusedTypeParameters = this.#getUnusedTypeParameterIndexes(a.target);
4929
4929
  for (let i = 0; i < aTypeArguments.length; i++) {
4930
+ if (unusedTypeParameters.has(i)) {
4931
+ continue;
4932
+ }
4930
4933
  if (!this.compare(aTypeArguments[i], bTypeArguments[i])) {
4931
4934
  return false;
4932
4935
  }
@@ -4935,6 +4938,38 @@ class Structure {
4935
4938
  }
4936
4939
  return this.compareStructures(a, b);
4937
4940
  }
4941
+ #getUnusedTypeParameterIndexes(type) {
4942
+ const result = new Set();
4943
+ if (type.typeParameters != null) {
4944
+ const symbol = type.getSymbol();
4945
+ const declarations = symbol?.getDeclarations();
4946
+ if (symbol != null && declarations != null) {
4947
+ const cached = this.#unusedTypeParametersLookup.get(symbol);
4948
+ if (cached != null) {
4949
+ return cached;
4950
+ }
4951
+ for (let i = 0; i < type.typeParameters.length; i++) {
4952
+ const symbol = type.typeParameters[i].getSymbol();
4953
+ const identifier = symbol.declarations[0].name;
4954
+ const isUsed = declarations.some((declaration) => this.#isSymbolUsedIn(declaration, symbol, identifier));
4955
+ if (!isUsed) {
4956
+ result.add(i);
4957
+ }
4958
+ }
4959
+ this.#unusedTypeParametersLookup.set(symbol, result);
4960
+ }
4961
+ }
4962
+ return result;
4963
+ }
4964
+ #isSymbolUsedIn(node, symbol, identifier, enclosingNode = node) {
4965
+ if (node === identifier || (this.#compiler.isTypeParameterDeclaration(node) && node.parent === enclosingNode)) {
4966
+ return false;
4967
+ }
4968
+ if (this.#compiler.isIdentifier(node) && this.#typeChecker.getSymbolAtLocation(node) === symbol) {
4969
+ return true;
4970
+ }
4971
+ return node.forEachChild((child) => this.#isSymbolUsedIn(child, symbol, identifier, enclosingNode)) ?? false;
4972
+ }
4938
4973
  compareTuples(a, b) {
4939
4974
  if (a.target.readonly !== b.target.readonly) {
4940
4975
  return false;
@@ -5159,14 +5194,46 @@ class Structure {
5159
5194
  this.#deduplicateCache.set(target, result);
5160
5195
  return result;
5161
5196
  }
5197
+ #getRecursionIdentity(type) {
5198
+ return type.aliasSymbol ?? type.symbol;
5199
+ }
5200
+ #isInfiniteRecursion(a, b) {
5201
+ const aIdentity = this.#getRecursionIdentity(a);
5202
+ const bIdentity = this.#getRecursionIdentity(b);
5203
+ if (!aIdentity || !bIdentity) {
5204
+ return false;
5205
+ }
5206
+ let matches = 0;
5207
+ for (const frame of this.#recursionStack) {
5208
+ if (frame.aIdentity === aIdentity && frame.bIdentity === bIdentity && a.id > frame.aId && b.id > frame.bId) {
5209
+ matches++;
5210
+ if (matches >= 2) {
5211
+ return true;
5212
+ }
5213
+ }
5214
+ }
5215
+ return false;
5216
+ }
5162
5217
  #memoize(a, b, compare) {
5163
5218
  const key = [a.id, b.id].sort((a, b) => a - b).join(":");
5164
5219
  const result = this.#memoizeCache.get(key);
5165
5220
  if (result !== undefined) {
5166
5221
  return result !== 2;
5167
5222
  }
5223
+ if (this.#isInfiniteRecursion(a, b)) {
5224
+ this.#memoizeCache.set(key, 1);
5225
+ return true;
5226
+ }
5168
5227
  this.#memoizeCache.set(key, 0);
5228
+ const aIdentity = this.#getRecursionIdentity(a);
5229
+ const bIdentity = this.#getRecursionIdentity(b);
5230
+ if (aIdentity != null && bIdentity != null) {
5231
+ this.#recursionStack.push({ aId: a.id, bId: b.id, aIdentity, bIdentity });
5232
+ }
5169
5233
  const isSame = compare();
5234
+ if (aIdentity != null && bIdentity != null) {
5235
+ this.#recursionStack.pop();
5236
+ }
5170
5237
  this.#memoizeCache.set(key, isSame ? 1 : 2);
5171
5238
  return isSame;
5172
5239
  }
@@ -5909,7 +5976,7 @@ class FileRunner {
5909
5976
  class Runner {
5910
5977
  #eventEmitter = new EventEmitter();
5911
5978
  #resolvedConfig;
5912
- static version = "7.2.3";
5979
+ static version = "7.2.5";
5913
5980
  constructor(resolvedConfig) {
5914
5981
  this.#resolvedConfig = resolvedConfig;
5915
5982
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tstyche",
3
- "version": "7.2.3",
3
+ "version": "7.2.5",
4
4
  "description": "Everything You Need for Type Testing.",
5
5
  "keywords": [
6
6
  "typescript",