tstyche 6.0.1 → 6.0.3
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/tstyche.js +116 -107
- package/package.json +1 -1
package/dist/tstyche.js
CHANGED
|
@@ -4569,9 +4569,6 @@ function getSignatures(type, kind, compiler, typeChecker) {
|
|
|
4569
4569
|
function getThisTypeOfSignature(signature, typeChecker) {
|
|
4570
4570
|
return signature.thisParameter && typeChecker.getTypeOfSymbol(signature.thisParameter);
|
|
4571
4571
|
}
|
|
4572
|
-
function getTypeParametersOfSignature(signature) {
|
|
4573
|
-
return signature.typeParameters ?? [];
|
|
4574
|
-
}
|
|
4575
4572
|
function getTypeParameterModifiers(typeParameter, compiler) {
|
|
4576
4573
|
if (!typeParameter.symbol.declarations) {
|
|
4577
4574
|
return compiler.ModifierFlags.None;
|
|
@@ -4656,26 +4653,12 @@ function isReadonlyProperty(symbol, compiler) {
|
|
|
4656
4653
|
(symbol.flags & compiler.SymbolFlags.Accessor && !(symbol.flags & compiler.SymbolFlags.SetAccessor)));
|
|
4657
4654
|
}
|
|
4658
4655
|
|
|
4659
|
-
class SeenService {
|
|
4660
|
-
#cache = new Map();
|
|
4661
|
-
memoized(a, b, compare) {
|
|
4662
|
-
const key = [a.id, b.id].sort().join(":");
|
|
4663
|
-
const result = this.#cache.get(key);
|
|
4664
|
-
if (result !== undefined) {
|
|
4665
|
-
return result !== 2;
|
|
4666
|
-
}
|
|
4667
|
-
this.#cache.set(key, 0);
|
|
4668
|
-
const isSame = compare();
|
|
4669
|
-
this.#cache.set(key, isSame ? 1 : 2);
|
|
4670
|
-
return isSame;
|
|
4671
|
-
}
|
|
4672
|
-
}
|
|
4673
|
-
|
|
4674
4656
|
class Structure {
|
|
4675
4657
|
#compiler;
|
|
4676
4658
|
#compilerOptions;
|
|
4677
|
-
#seen = new SeenService();
|
|
4678
4659
|
#typeChecker;
|
|
4660
|
+
#deduplicateCache = new WeakMap();
|
|
4661
|
+
#memoizeCache = new Map();
|
|
4679
4662
|
constructor(compiler, program) {
|
|
4680
4663
|
this.#compiler = compiler;
|
|
4681
4664
|
this.#compilerOptions = program.getCompilerOptions();
|
|
@@ -4690,7 +4673,7 @@ class Structure {
|
|
|
4690
4673
|
compare(a, b) {
|
|
4691
4674
|
a = this.#normalize(a);
|
|
4692
4675
|
b = this.#normalize(b);
|
|
4693
|
-
if (a
|
|
4676
|
+
if (a === b) {
|
|
4694
4677
|
return true;
|
|
4695
4678
|
}
|
|
4696
4679
|
if (a.flags & this.#compiler.TypeFlags.Any) {
|
|
@@ -4702,17 +4685,24 @@ class Structure {
|
|
|
4702
4685
|
if (a.flags & this.#compiler.TypeFlags.Undefined) {
|
|
4703
4686
|
return !!(b.flags & this.#compiler.TypeFlags.Undefined);
|
|
4704
4687
|
}
|
|
4705
|
-
if ((a.flags | b.flags) & this.#compiler.TypeFlags.
|
|
4706
|
-
if (a.flags & b.flags & this.#compiler.TypeFlags.
|
|
4707
|
-
|
|
4708
|
-
return true;
|
|
4709
|
-
}
|
|
4688
|
+
if ((a.flags | b.flags) & this.#compiler.TypeFlags.StructuredType) {
|
|
4689
|
+
if (a.flags & this.#compiler.TypeFlags.StructuredType && b.flags & this.#compiler.TypeFlags.StructuredType) {
|
|
4690
|
+
return this.#memoize(a, b, () => this.compareStructured(a, b));
|
|
4710
4691
|
}
|
|
4711
|
-
|
|
4712
|
-
|
|
4692
|
+
return false;
|
|
4693
|
+
}
|
|
4694
|
+
if ((a.flags | b.flags) & this.#compiler.TypeFlags.Instantiable) {
|
|
4695
|
+
if (a.flags & this.#compiler.TypeFlags.Instantiable && b.flags & this.#compiler.TypeFlags.Instantiable) {
|
|
4696
|
+
return this.#memoize(a, b, () => this.compareInstantiable(a, b));
|
|
4713
4697
|
}
|
|
4714
|
-
|
|
4715
|
-
|
|
4698
|
+
return false;
|
|
4699
|
+
}
|
|
4700
|
+
return false;
|
|
4701
|
+
}
|
|
4702
|
+
compareStructured(a, b) {
|
|
4703
|
+
if (this.#typeChecker.isTupleType(a) || this.#typeChecker.isTupleType(b)) {
|
|
4704
|
+
if (this.#typeChecker.isTupleType(a) && this.#typeChecker.isTupleType(b)) {
|
|
4705
|
+
return this.compareTuples(a, b);
|
|
4716
4706
|
}
|
|
4717
4707
|
return false;
|
|
4718
4708
|
}
|
|
@@ -4722,24 +4712,30 @@ class Structure {
|
|
|
4722
4712
|
}
|
|
4723
4713
|
return false;
|
|
4724
4714
|
}
|
|
4715
|
+
if ((a.flags | b.flags) & this.#compiler.TypeFlags.Intersection) {
|
|
4716
|
+
if (a.flags & b.flags & this.#compiler.TypeFlags.Intersection) {
|
|
4717
|
+
if (this.compareIntersections(a, b)) {
|
|
4718
|
+
return true;
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
if (containsInstantiable(a, this.#compiler) || containsInstantiable(b, this.#compiler)) {
|
|
4722
|
+
return false;
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
4725
|
if ((a.flags | b.flags) & this.#compiler.TypeFlags.Object) {
|
|
4726
4726
|
if (a.flags & b.flags & this.#compiler.TypeFlags.Object) {
|
|
4727
|
-
return this
|
|
4727
|
+
return this.compareObjects(a, b);
|
|
4728
4728
|
}
|
|
4729
|
-
return false;
|
|
4730
4729
|
}
|
|
4730
|
+
return this.compareStructures(a, b);
|
|
4731
|
+
}
|
|
4732
|
+
compareInstantiable(a, b) {
|
|
4731
4733
|
if ((a.flags | b.flags) & this.#compiler.TypeFlags.TypeParameter) {
|
|
4732
4734
|
if (a.flags & b.flags & this.#compiler.TypeFlags.TypeParameter) {
|
|
4733
4735
|
return this.compareTypeParameters(a, b);
|
|
4734
4736
|
}
|
|
4735
4737
|
return false;
|
|
4736
4738
|
}
|
|
4737
|
-
if ((a.flags | b.flags) & this.#compiler.TypeFlags.Index) {
|
|
4738
|
-
if (a.flags & b.flags & this.#compiler.TypeFlags.Index) {
|
|
4739
|
-
return this.compare(a.type, b.type);
|
|
4740
|
-
}
|
|
4741
|
-
return false;
|
|
4742
|
-
}
|
|
4743
4739
|
if ((a.flags | b.flags) & this.#compiler.TypeFlags.IndexedAccess) {
|
|
4744
4740
|
if (a.flags & b.flags & this.#compiler.TypeFlags.IndexedAccess) {
|
|
4745
4741
|
return this.compareIndexedAccessTypes(a, b);
|
|
@@ -4758,6 +4754,12 @@ class Structure {
|
|
|
4758
4754
|
}
|
|
4759
4755
|
return false;
|
|
4760
4756
|
}
|
|
4757
|
+
if ((a.flags | b.flags) & this.#compiler.TypeFlags.Index) {
|
|
4758
|
+
if (a.flags & b.flags & this.#compiler.TypeFlags.Index) {
|
|
4759
|
+
return this.compare(a.type, b.type);
|
|
4760
|
+
}
|
|
4761
|
+
return false;
|
|
4762
|
+
}
|
|
4761
4763
|
if ((a.flags | b.flags) & this.#compiler.TypeFlags.TemplateLiteral) {
|
|
4762
4764
|
if (a.flags & b.flags & this.#compiler.TypeFlags.TemplateLiteral) {
|
|
4763
4765
|
return this.compareTemplateLiteralTypes(a, b);
|
|
@@ -4768,21 +4770,24 @@ class Structure {
|
|
|
4768
4770
|
if (a.flags & b.flags & this.#compiler.TypeFlags.StringMapping) {
|
|
4769
4771
|
return this.compareStringMappingTypes(a, b);
|
|
4770
4772
|
}
|
|
4771
|
-
return false;
|
|
4772
4773
|
}
|
|
4773
4774
|
return false;
|
|
4774
4775
|
}
|
|
4775
4776
|
compareIntersections(a, b) {
|
|
4776
|
-
|
|
4777
|
+
const aTypes = this.#deduplicate(a);
|
|
4778
|
+
const bTypes = this.#deduplicate(b);
|
|
4779
|
+
if (aTypes.length !== bTypes.length) {
|
|
4777
4780
|
return false;
|
|
4778
4781
|
}
|
|
4779
|
-
return
|
|
4782
|
+
return aTypes.every((aType, i) => this.compare(aType, bTypes[i]));
|
|
4780
4783
|
}
|
|
4781
4784
|
compareUnions(a, b) {
|
|
4782
|
-
|
|
4785
|
+
const aTypes = this.#deduplicate(a);
|
|
4786
|
+
const bTypes = this.#deduplicate(b);
|
|
4787
|
+
if (aTypes.length !== bTypes.length) {
|
|
4783
4788
|
return false;
|
|
4784
4789
|
}
|
|
4785
|
-
return
|
|
4790
|
+
return aTypes.every((aType) => bTypes.some((bType) => this.compare(aType, bType)));
|
|
4786
4791
|
}
|
|
4787
4792
|
compareObjects(a, b) {
|
|
4788
4793
|
if (a.objectFlags & b.objectFlags & this.#compiler.ObjectFlags.Reference) {
|
|
@@ -4790,29 +4795,23 @@ class Structure {
|
|
|
4790
4795
|
return this.compareTypeReferences(a, b);
|
|
4791
4796
|
}
|
|
4792
4797
|
}
|
|
4793
|
-
return this.
|
|
4798
|
+
return this.compareStructures(a, b);
|
|
4794
4799
|
}
|
|
4795
4800
|
compareTypeReferences(a, b) {
|
|
4796
|
-
if ((a.target
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
return false;
|
|
4801
|
-
}
|
|
4802
|
-
if (!this.compare(a.target, b.target)) {
|
|
4803
|
-
return this.compareStructuredTypes(a, b);
|
|
4804
|
-
}
|
|
4805
|
-
const aTypeArguments = this.#typeChecker.getTypeArguments(a);
|
|
4806
|
-
const bTypeArguments = this.#typeChecker.getTypeArguments(b);
|
|
4807
|
-
if (aTypeArguments.length !== bTypeArguments.length) {
|
|
4808
|
-
return false;
|
|
4809
|
-
}
|
|
4810
|
-
for (let i = 0; i < aTypeArguments.length; i++) {
|
|
4811
|
-
if (!this.compare(aTypeArguments[i], bTypeArguments[i])) {
|
|
4801
|
+
if (this.compare(a.target, b.target)) {
|
|
4802
|
+
const aTypeArguments = this.#typeChecker.getTypeArguments(a);
|
|
4803
|
+
const bTypeArguments = this.#typeChecker.getTypeArguments(b);
|
|
4804
|
+
if (aTypeArguments.length !== bTypeArguments.length) {
|
|
4812
4805
|
return false;
|
|
4813
4806
|
}
|
|
4807
|
+
for (let i = 0; i < aTypeArguments.length; i++) {
|
|
4808
|
+
if (!this.compare(aTypeArguments[i], bTypeArguments[i])) {
|
|
4809
|
+
return false;
|
|
4810
|
+
}
|
|
4811
|
+
}
|
|
4812
|
+
return true;
|
|
4814
4813
|
}
|
|
4815
|
-
return
|
|
4814
|
+
return this.compareStructures(a, b);
|
|
4816
4815
|
}
|
|
4817
4816
|
compareTuples(a, b) {
|
|
4818
4817
|
if (a.target.readonly !== b.target.readonly) {
|
|
@@ -4833,7 +4832,7 @@ class Structure {
|
|
|
4833
4832
|
}
|
|
4834
4833
|
return true;
|
|
4835
4834
|
}
|
|
4836
|
-
|
|
4835
|
+
compareStructures(a, b) {
|
|
4837
4836
|
if (!this.compareProperties(a, b)) {
|
|
4838
4837
|
return false;
|
|
4839
4838
|
}
|
|
@@ -4895,56 +4894,41 @@ class Structure {
|
|
|
4895
4894
|
return false;
|
|
4896
4895
|
}
|
|
4897
4896
|
for (let i = 0; i < aSignatures.length; i++) {
|
|
4898
|
-
|
|
4897
|
+
const aThisType = getThisTypeOfSignature(aSignatures[i], this.#typeChecker);
|
|
4898
|
+
const bThisType = getThisTypeOfSignature(bSignatures[i], this.#typeChecker);
|
|
4899
|
+
if (!this.#compareMaybeNullish(aThisType, bThisType)) {
|
|
4899
4900
|
return false;
|
|
4900
4901
|
}
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
#compareSignature(a, b) {
|
|
4905
|
-
const aTypeParameters = getTypeParametersOfSignature(a);
|
|
4906
|
-
const bTypeParameters = getTypeParametersOfSignature(b);
|
|
4907
|
-
if (aTypeParameters.length !== bTypeParameters.length) {
|
|
4908
|
-
return false;
|
|
4909
|
-
}
|
|
4910
|
-
for (let i = 0; i < aTypeParameters.length; i++) {
|
|
4911
|
-
if (!this.compareTypeParameters(aTypeParameters[i], bTypeParameters[i])) {
|
|
4902
|
+
const aParametersCount = getParameterCount(aSignatures[i], this.#compiler, this.#typeChecker);
|
|
4903
|
+
const bParametersCount = getParameterCount(bSignatures[i], this.#compiler, this.#typeChecker);
|
|
4904
|
+
if (aParametersCount !== bParametersCount) {
|
|
4912
4905
|
return false;
|
|
4913
4906
|
}
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
return true;
|
|
4931
|
-
}
|
|
4932
|
-
compareParameters(a, b) {
|
|
4933
|
-
const aParametersCount = getParameterCount(a, this.#compiler, this.#typeChecker);
|
|
4934
|
-
const bParametersCount = getParameterCount(b, this.#compiler, this.#typeChecker);
|
|
4935
|
-
if (aParametersCount !== bParametersCount) {
|
|
4936
|
-
return false;
|
|
4937
|
-
}
|
|
4938
|
-
for (let i = 0; i < aParametersCount; i++) {
|
|
4939
|
-
const aParameter = getParameterFacts(a, i, this.#compiler, this.#typeChecker);
|
|
4940
|
-
const bParameter = getParameterFacts(b, i, this.#compiler, this.#typeChecker);
|
|
4941
|
-
if (aParameter.isOptional !== bParameter.isOptional) {
|
|
4907
|
+
for (let j = 0; j < aParametersCount; j++) {
|
|
4908
|
+
const aParameter = getParameterFacts(aSignatures[i], j, this.#compiler, this.#typeChecker);
|
|
4909
|
+
const bParameter = getParameterFacts(bSignatures[i], j, this.#compiler, this.#typeChecker);
|
|
4910
|
+
if (aParameter.isOptional !== bParameter.isOptional) {
|
|
4911
|
+
return false;
|
|
4912
|
+
}
|
|
4913
|
+
if (aParameter.isRest !== bParameter.isRest) {
|
|
4914
|
+
return false;
|
|
4915
|
+
}
|
|
4916
|
+
if (!this.compare(aParameter.getType(this.#typeChecker), bParameter.getType(this.#typeChecker))) {
|
|
4917
|
+
return false;
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
const aReturnType = this.#typeChecker.getReturnTypeOfSignature(aSignatures[i]);
|
|
4921
|
+
const bReturnType = this.#typeChecker.getReturnTypeOfSignature(bSignatures[i]);
|
|
4922
|
+
if (!this.compare(aReturnType, bReturnType)) {
|
|
4942
4923
|
return false;
|
|
4943
4924
|
}
|
|
4944
|
-
|
|
4925
|
+
const aTypePredicate = this.#typeChecker.getTypePredicateOfSignature(aSignatures[i]);
|
|
4926
|
+
const bTypePredicate = this.#typeChecker.getTypePredicateOfSignature(bSignatures[i]);
|
|
4927
|
+
if (aTypePredicate?.parameterIndex !== bTypePredicate?.parameterIndex) {
|
|
4945
4928
|
return false;
|
|
4946
4929
|
}
|
|
4947
|
-
if (
|
|
4930
|
+
if (aTypePredicate?.kind !== bTypePredicate?.kind ||
|
|
4931
|
+
!this.#compareMaybeNullish(aTypePredicate?.type, bTypePredicate?.type)) {
|
|
4948
4932
|
return false;
|
|
4949
4933
|
}
|
|
4950
4934
|
}
|
|
@@ -5037,14 +5021,39 @@ class Structure {
|
|
|
5037
5021
|
}
|
|
5038
5022
|
return true;
|
|
5039
5023
|
}
|
|
5024
|
+
#deduplicate(target) {
|
|
5025
|
+
let result = this.#deduplicateCache.get(target);
|
|
5026
|
+
if (result) {
|
|
5027
|
+
return result;
|
|
5028
|
+
}
|
|
5029
|
+
result = target.types.slice(0, 1);
|
|
5030
|
+
for (let i = 1; i < target.types.length; i++) {
|
|
5031
|
+
if (!result.some((existing) => this.compare(existing, target.types[i]))) {
|
|
5032
|
+
result.push(target.types[i]);
|
|
5033
|
+
}
|
|
5034
|
+
}
|
|
5035
|
+
this.#deduplicateCache.set(target, result);
|
|
5036
|
+
return result;
|
|
5037
|
+
}
|
|
5038
|
+
#memoize(a, b, compare) {
|
|
5039
|
+
const key = [a.id, b.id].sort().join(":");
|
|
5040
|
+
const result = this.#memoizeCache.get(key);
|
|
5041
|
+
if (result !== undefined) {
|
|
5042
|
+
return result !== 2;
|
|
5043
|
+
}
|
|
5044
|
+
this.#memoizeCache.set(key, 0);
|
|
5045
|
+
const isSame = compare();
|
|
5046
|
+
this.#memoizeCache.set(key, isSame ? 1 : 2);
|
|
5047
|
+
return isSame;
|
|
5048
|
+
}
|
|
5040
5049
|
#normalize(type) {
|
|
5041
5050
|
if (type.flags & this.#compiler.TypeFlags.Freshable && type.freshType === type) {
|
|
5042
5051
|
return type.regularType;
|
|
5043
5052
|
}
|
|
5044
5053
|
if (type.flags & this.#compiler.TypeFlags.UnionOrIntersection) {
|
|
5045
|
-
const
|
|
5046
|
-
if (
|
|
5047
|
-
return
|
|
5054
|
+
const parts = this.#deduplicate(type);
|
|
5055
|
+
if (parts.length === 1) {
|
|
5056
|
+
return parts.at(0);
|
|
5048
5057
|
}
|
|
5049
5058
|
}
|
|
5050
5059
|
return type;
|
|
@@ -5905,7 +5914,7 @@ class FileRunner {
|
|
|
5905
5914
|
class Runner {
|
|
5906
5915
|
#eventEmitter = new EventEmitter();
|
|
5907
5916
|
#resolvedConfig;
|
|
5908
|
-
static version = "6.0.
|
|
5917
|
+
static version = "6.0.3";
|
|
5909
5918
|
constructor(resolvedConfig) {
|
|
5910
5919
|
this.#resolvedConfig = resolvedConfig;
|
|
5911
5920
|
}
|