@react-analyzer/core 0.0.5 → 0.0.8

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.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { isFalseLiteralType, isTrueLiteralType } from "ts-api-utils";
2
- import ts from "typescript";
3
1
  import { unit } from "@let/eff";
4
2
  import { AST, Context } from "tsl";
5
3
 
@@ -19,101 +17,6 @@ interface SemanticNode {
19
17
  hint: bigint;
20
18
  }
21
19
  //#endregion
22
- //#region src/type/type-is.d.ts
23
- declare const isAnyType: (type: ts.Type) => boolean;
24
- declare const isBigIntType: (type: ts.Type) => boolean;
25
- declare const isBooleanType: (type: ts.Type) => boolean;
26
- declare const isEnumType: (type: ts.Type) => boolean;
27
- declare const isFalsyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
28
- freshType: ts.FreshableType;
29
- regularType: ts.FreshableType;
30
- flags: ts.TypeFlags;
31
- symbol: ts.Symbol;
32
- pattern?: ts.DestructuringPattern;
33
- aliasSymbol?: ts.Symbol;
34
- aliasTypeArguments?: readonly ts.Type[];
35
- getFlags: () => ts.TypeFlags;
36
- getSymbol: () => ts.Symbol | undefined;
37
- getProperties: () => ts.Symbol[];
38
- getProperty: (propertyName: string) => ts.Symbol | undefined;
39
- getApparentProperties: () => ts.Symbol[];
40
- getCallSignatures: () => readonly ts.Signature[];
41
- getConstructSignatures: () => readonly ts.Signature[];
42
- getStringIndexType: () => ts.Type | undefined;
43
- getNumberIndexType: () => ts.Type | undefined;
44
- getBaseTypes: () => ts.BaseType[] | undefined;
45
- getNonNullableType: () => ts.Type;
46
- getConstraint: () => ts.Type | undefined;
47
- getDefault: () => ts.Type | undefined;
48
- isUnion: () => this is ts.UnionType;
49
- isIntersection: () => this is ts.IntersectionType;
50
- isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
51
- isLiteral: () => this is ts.LiteralType;
52
- isStringLiteral: () => this is ts.StringLiteralType;
53
- isNumberLiteral: () => this is ts.NumberLiteralType;
54
- isTypeParameter: () => this is ts.TypeParameter;
55
- isClassOrInterface: () => this is ts.InterfaceType;
56
- isClass: () => this is ts.InterfaceType;
57
- isIndexType: () => this is ts.IndexType;
58
- value: {
59
- negative: boolean;
60
- base10Value: "0";
61
- };
62
- };
63
- declare const isFalsyNumberType: (type: ts.Type) => boolean;
64
- declare const isFalsyStringType: (type: ts.Type) => boolean;
65
- declare const isNeverType: (type: ts.Type) => boolean;
66
- declare const isNullishType: (type: ts.Type) => boolean;
67
- declare const isNumberType: (type: ts.Type) => boolean;
68
- declare const isObjectType: (type: ts.Type) => boolean;
69
- declare const isStringType: (type: ts.Type) => boolean;
70
- declare const isTruthyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
71
- freshType: ts.FreshableType;
72
- regularType: ts.FreshableType;
73
- flags: ts.TypeFlags;
74
- symbol: ts.Symbol;
75
- pattern?: ts.DestructuringPattern;
76
- aliasSymbol?: ts.Symbol;
77
- aliasTypeArguments?: readonly ts.Type[];
78
- getFlags: () => ts.TypeFlags;
79
- getSymbol: () => ts.Symbol | undefined;
80
- getProperties: () => ts.Symbol[];
81
- getProperty: (propertyName: string) => ts.Symbol | undefined;
82
- getApparentProperties: () => ts.Symbol[];
83
- getCallSignatures: () => readonly ts.Signature[];
84
- getConstructSignatures: () => readonly ts.Signature[];
85
- getStringIndexType: () => ts.Type | undefined;
86
- getNumberIndexType: () => ts.Type | undefined;
87
- getBaseTypes: () => ts.BaseType[] | undefined;
88
- getNonNullableType: () => ts.Type;
89
- getConstraint: () => ts.Type | undefined;
90
- getDefault: () => ts.Type | undefined;
91
- isUnion: () => this is ts.UnionType;
92
- isIntersection: () => this is ts.IntersectionType;
93
- isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
94
- isLiteral: () => this is ts.LiteralType;
95
- isStringLiteral: () => this is ts.StringLiteralType;
96
- isNumberLiteral: () => this is ts.NumberLiteralType;
97
- isTypeParameter: () => this is ts.TypeParameter;
98
- isClassOrInterface: () => this is ts.InterfaceType;
99
- isClass: () => this is ts.InterfaceType;
100
- isIndexType: () => this is ts.IndexType;
101
- value: ts.PseudoBigInt;
102
- };
103
- declare const isTruthyNumberType: (type: ts.Type) => boolean;
104
- declare const isTruthyStringType: (type: ts.Type) => boolean;
105
- declare const isUnknownType: (type: ts.Type) => boolean;
106
- //#endregion
107
- //#region src/type/type-variant.d.ts
108
- type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nullish" | "number" | "object" | "string" | "unknown" | "falsy bigint" | "falsy boolean" | "falsy number" | "falsy string" | "truthy bigint" | "truthy boolean" | "truthy number" | "truthy string";
109
- /**
110
- * Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
111
- * Get the variants of an array of types.
112
- * @param types The types to get the variants of
113
- * @returns The variants of the types
114
- */
115
- declare function getVariantsOfTypes(types: ts.Type[]): Set<TypeVariant>;
116
- //#endregion
117
20
  //#region src/utils/is-react-api.d.ts
118
21
  declare namespace isReactAPI {
119
22
  type ReturnType = {
@@ -156,4 +59,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
156
59
  declare const isMemoCall: isReactAPICall.ReturnType;
157
60
  declare const isLazyCall: isReactAPICall.ReturnType;
158
61
  //#endregion
159
- export { SemanticEntry, SemanticNode, TypeVariant, getVariantsOfTypes, isAnyType, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isCloneElement, isCloneElementCall, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isReactAPI, isReactAPICall, isStringType, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType };
62
+ export { SemanticEntry, SemanticNode, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isCloneElement, isCloneElementCall, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isForwardRef, isForwardRefCall, isLazy, isLazyCall, isMemo, isMemoCall, isReactAPI, isReactAPICall };
package/dist/index.js CHANGED
@@ -1,71 +1,7 @@
1
- import { isFalseLiteralType, isTrueLiteralType, isTypeFlagSet } from "ts-api-utils";
2
- import { P, isMatching, match } from "ts-pattern";
3
- import ts, { SyntaxKind } from "typescript";
4
1
  import { dual, unit } from "@let/eff";
5
2
  import { toStringFormat } from "@react-analyzer/ast";
3
+ import { SyntaxKind } from "typescript";
6
4
 
7
- //#region src/type/type-is.ts
8
- const isAnyType = (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any);
9
- const isBigIntType = (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike);
10
- const isBooleanType = (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike);
11
- const isEnumType = (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike);
12
- const isFalsyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type);
13
- const isFalsyNumberType = (type) => type.isNumberLiteral() && type.value === 0;
14
- const isFalsyStringType = (type) => type.isStringLiteral() && type.value === "";
15
- const isNeverType = (type) => isTypeFlagSet(type, ts.TypeFlags.Never);
16
- const isNullishType = (type) => isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike);
17
- const isNumberType = (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike);
18
- const isObjectType = (type) => !isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.TypeParameter | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never);
19
- const isStringType = (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike);
20
- const isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type);
21
- const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
22
- const isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
23
- const isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
24
-
25
- //#endregion
26
- //#region src/type/type-variant.ts
27
- /**
28
- * Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
29
- * Get the variants of an array of types.
30
- * @param types The types to get the variants of
31
- * @returns The variants of the types
32
- */
33
- function getVariantsOfTypes(types) {
34
- const variants = /* @__PURE__ */ new Set();
35
- if (types.some(isUnknownType)) {
36
- variants.add("unknown");
37
- return variants;
38
- }
39
- if (types.some(isNullishType)) variants.add("nullish");
40
- const booleans = types.filter(isBooleanType);
41
- const boolean0 = booleans[0];
42
- if (booleans.length === 1 && boolean0 != null) {
43
- if (isFalseLiteralType(boolean0)) variants.add("falsy boolean");
44
- else if (isTrueLiteralType(boolean0)) variants.add("truthy boolean");
45
- } else if (booleans.length === 2) variants.add("boolean");
46
- const strings = types.filter(isStringType);
47
- if (strings.length > 0) {
48
- const evaluated = match(strings).when((types$1) => types$1.every(isTruthyStringType), () => "truthy string").when((types$1) => types$1.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
49
- variants.add(evaluated);
50
- }
51
- const bigints = types.filter(isBigIntType);
52
- if (bigints.length > 0) {
53
- const evaluated = match(bigints).when((types$1) => types$1.every(isTruthyBigIntType), () => "truthy bigint").when((types$1) => types$1.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
54
- variants.add(evaluated);
55
- }
56
- const numbers = types.filter(isNumberType);
57
- if (numbers.length > 0) {
58
- const evaluated = match(numbers).when((types$1) => types$1.every(isTruthyNumberType), () => "truthy number").when((types$1) => types$1.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
59
- variants.add(evaluated);
60
- }
61
- if (types.some(isEnumType)) variants.add("enum");
62
- if (types.some(isObjectType)) variants.add("object");
63
- if (types.some(isAnyType)) variants.add("any");
64
- if (types.some(isNeverType)) variants.add("never");
65
- return variants;
66
- }
67
-
68
- //#endregion
69
5
  //#region src/utils/is-react-api.ts
70
6
  function isReactAPI(api) {
71
7
  const func = (context, node) => {
@@ -113,4 +49,4 @@ const isMemoCall = isReactAPICall("memo");
113
49
  const isLazyCall = isReactAPICall("lazy");
114
50
 
115
51
  //#endregion
116
- export { getVariantsOfTypes, isAnyType, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isCloneElement, isCloneElementCall, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isReactAPI, isReactAPICall, isStringType, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType };
52
+ export { isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isCloneElement, isCloneElementCall, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isForwardRef, isForwardRefCall, isLazy, isLazyCall, isMemo, isMemoCall, isReactAPI, isReactAPICall };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-analyzer/core",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "description": "React Analyzer utility module for static analysis of React core APIs and patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/react-analyzer",
6
6
  "bugs": {
@@ -29,18 +29,17 @@
29
29
  "dependencies": {
30
30
  "@let/eff": "npm:@jsr/let__eff@^0.1.2",
31
31
  "ts-pattern": "^5.9.0",
32
- "@react-analyzer/ast": "0.0.5"
32
+ "@react-analyzer/ast": "0.0.8"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsconfig/node24": "^24.0.3",
36
- "@types/node": "^25.0.3",
37
- "tsdown": "^0.18.3",
38
- "type-fest": "^5.3.1",
35
+ "@tsconfig/node24": "^24.0.4",
36
+ "@types/node": "^25.0.9",
37
+ "tsdown": "^0.20.0-beta.4",
38
+ "type-fest": "^5.4.1",
39
39
  "@local/configs": "0.0.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "ts-api-utils": "^2.1.0",
43
- "tsl": "^1.0.27",
42
+ "tsl": "^1.0.28",
44
43
  "typescript": "^5.9.3"
45
44
  },
46
45
  "engines": {