@react-analyzer/core 0.0.6 → 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,4 +1,3 @@
1
- import ts from "typescript";
2
1
  import { unit } from "@let/eff";
3
2
  import { AST, Context } from "tsl";
4
3
 
@@ -18,106 +17,6 @@ interface SemanticNode {
18
17
  hint: bigint;
19
18
  }
20
19
  //#endregion
21
- //#region src/type/type-is.d.ts
22
- declare function isBooleanLiteralType<TType extends ts.Type>(type: TType): type is TType & {
23
- intrinsicName: "false" | "true";
24
- };
25
- declare const isFalseLiteralType: (type: ts.Type) => boolean;
26
- declare const isTrueLiteralType: (type: ts.Type) => boolean;
27
- declare const isAnyType: (type: ts.Type) => boolean;
28
- declare const isBigIntType: (type: ts.Type) => boolean;
29
- declare const isBooleanType: (type: ts.Type) => boolean;
30
- declare const isEnumType: (type: ts.Type) => boolean;
31
- declare const isFalsyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
32
- freshType: ts.FreshableType;
33
- regularType: ts.FreshableType;
34
- flags: ts.TypeFlags;
35
- symbol: ts.Symbol;
36
- pattern?: ts.DestructuringPattern;
37
- aliasSymbol?: ts.Symbol;
38
- aliasTypeArguments?: readonly ts.Type[];
39
- getFlags: () => ts.TypeFlags;
40
- getSymbol: () => ts.Symbol | undefined;
41
- getProperties: () => ts.Symbol[];
42
- getProperty: (propertyName: string) => ts.Symbol | undefined;
43
- getApparentProperties: () => ts.Symbol[];
44
- getCallSignatures: () => readonly ts.Signature[];
45
- getConstructSignatures: () => readonly ts.Signature[];
46
- getStringIndexType: () => ts.Type | undefined;
47
- getNumberIndexType: () => ts.Type | undefined;
48
- getBaseTypes: () => ts.BaseType[] | undefined;
49
- getNonNullableType: () => ts.Type;
50
- getConstraint: () => ts.Type | undefined;
51
- getDefault: () => ts.Type | undefined;
52
- isUnion: () => this is ts.UnionType;
53
- isIntersection: () => this is ts.IntersectionType;
54
- isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
55
- isLiteral: () => this is ts.LiteralType;
56
- isStringLiteral: () => this is ts.StringLiteralType;
57
- isNumberLiteral: () => this is ts.NumberLiteralType;
58
- isTypeParameter: () => this is ts.TypeParameter;
59
- isClassOrInterface: () => this is ts.InterfaceType;
60
- isClass: () => this is ts.InterfaceType;
61
- isIndexType: () => this is ts.IndexType;
62
- value: {
63
- negative: boolean;
64
- base10Value: "0";
65
- };
66
- };
67
- declare const isFalsyNumberType: (type: ts.Type) => boolean;
68
- declare const isFalsyStringType: (type: ts.Type) => boolean;
69
- declare const isNeverType: (type: ts.Type) => boolean;
70
- declare const isNullishType: (type: ts.Type) => boolean;
71
- declare const isNumberType: (type: ts.Type) => boolean;
72
- declare const isObjectType: (type: ts.Type) => boolean;
73
- declare const isStringType: (type: ts.Type) => boolean;
74
- declare const isTruthyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
75
- freshType: ts.FreshableType;
76
- regularType: ts.FreshableType;
77
- flags: ts.TypeFlags;
78
- symbol: ts.Symbol;
79
- pattern?: ts.DestructuringPattern;
80
- aliasSymbol?: ts.Symbol;
81
- aliasTypeArguments?: readonly ts.Type[];
82
- getFlags: () => ts.TypeFlags;
83
- getSymbol: () => ts.Symbol | undefined;
84
- getProperties: () => ts.Symbol[];
85
- getProperty: (propertyName: string) => ts.Symbol | undefined;
86
- getApparentProperties: () => ts.Symbol[];
87
- getCallSignatures: () => readonly ts.Signature[];
88
- getConstructSignatures: () => readonly ts.Signature[];
89
- getStringIndexType: () => ts.Type | undefined;
90
- getNumberIndexType: () => ts.Type | undefined;
91
- getBaseTypes: () => ts.BaseType[] | undefined;
92
- getNonNullableType: () => ts.Type;
93
- getConstraint: () => ts.Type | undefined;
94
- getDefault: () => ts.Type | undefined;
95
- isUnion: () => this is ts.UnionType;
96
- isIntersection: () => this is ts.IntersectionType;
97
- isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
98
- isLiteral: () => this is ts.LiteralType;
99
- isStringLiteral: () => this is ts.StringLiteralType;
100
- isNumberLiteral: () => this is ts.NumberLiteralType;
101
- isTypeParameter: () => this is ts.TypeParameter;
102
- isClassOrInterface: () => this is ts.InterfaceType;
103
- isClass: () => this is ts.InterfaceType;
104
- isIndexType: () => this is ts.IndexType;
105
- value: ts.PseudoBigInt;
106
- };
107
- declare const isTruthyNumberType: (type: ts.Type) => boolean;
108
- declare const isTruthyStringType: (type: ts.Type) => boolean;
109
- declare const isUnknownType: (type: ts.Type) => boolean;
110
- //#endregion
111
- //#region src/type/type-variant.d.ts
112
- 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";
113
- /**
114
- * Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
115
- * Get the variants of an array of types.
116
- * @param types The types to get the variants of
117
- * @returns The variants of the types
118
- */
119
- declare function getVariantsOfTypes(types: ts.Type[]): Set<TypeVariant>;
120
- //#endregion
121
20
  //#region src/utils/is-react-api.d.ts
122
21
  declare namespace isReactAPI {
123
22
  type ReturnType = {
@@ -160,4 +59,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
160
59
  declare const isMemoCall: isReactAPICall.ReturnType;
161
60
  declare const isLazyCall: isReactAPICall.ReturnType;
162
61
  //#endregion
163
- export { SemanticEntry, SemanticNode, TypeVariant, getVariantsOfTypes, isAnyType, isBigIntType, isBooleanLiteralType, 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,82 +1,7 @@
1
- import { P, isMatching, match } from "ts-pattern";
2
- import ts, { SyntaxKind } from "typescript";
3
1
  import { dual, unit } from "@let/eff";
4
2
  import { toStringFormat } from "@react-analyzer/ast";
3
+ import { SyntaxKind } from "typescript";
5
4
 
6
- //#region src/type/type-is.ts
7
- function isFlagSet(allFlags, flag) {
8
- return (allFlags & flag) !== 0;
9
- }
10
- function isFlagSetOnObject(obj, flag) {
11
- return isFlagSet(obj.flags, flag);
12
- }
13
- const isTypeFlagSet = isFlagSetOnObject;
14
- function isBooleanLiteralType(type) {
15
- return isTypeFlagSet(type, ts.TypeFlags.BooleanLiteral);
16
- }
17
- const isFalseLiteralType = (type) => isBooleanLiteralType(type) && type.intrinsicName === "false";
18
- const isTrueLiteralType = (type) => isBooleanLiteralType(type) && type.intrinsicName === "true";
19
- const isAnyType = (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any);
20
- const isBigIntType = (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike);
21
- const isBooleanType = (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike);
22
- const isEnumType = (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike);
23
- const isFalsyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type);
24
- const isFalsyNumberType = (type) => type.isNumberLiteral() && type.value === 0;
25
- const isFalsyStringType = (type) => type.isStringLiteral() && type.value === "";
26
- const isNeverType = (type) => isTypeFlagSet(type, ts.TypeFlags.Never);
27
- const isNullishType = (type) => isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike);
28
- const isNumberType = (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike);
29
- 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);
30
- const isStringType = (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike);
31
- const isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type);
32
- const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
33
- const isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
34
- const isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
35
-
36
- //#endregion
37
- //#region src/type/type-variant.ts
38
- /**
39
- * Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
40
- * Get the variants of an array of types.
41
- * @param types The types to get the variants of
42
- * @returns The variants of the types
43
- */
44
- function getVariantsOfTypes(types) {
45
- const variants = /* @__PURE__ */ new Set();
46
- if (types.some(isUnknownType)) {
47
- variants.add("unknown");
48
- return variants;
49
- }
50
- if (types.some(isNullishType)) variants.add("nullish");
51
- const booleans = types.filter(isBooleanType);
52
- const boolean0 = booleans[0];
53
- if (booleans.length === 1 && boolean0 != null) {
54
- if (isFalseLiteralType(boolean0)) variants.add("falsy boolean");
55
- else if (isTrueLiteralType(boolean0)) variants.add("truthy boolean");
56
- } else if (booleans.length === 2) variants.add("boolean");
57
- const strings = types.filter(isStringType);
58
- if (strings.length > 0) {
59
- const evaluated = match(strings).when((types$1) => types$1.every(isTruthyStringType), () => "truthy string").when((types$1) => types$1.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
60
- variants.add(evaluated);
61
- }
62
- const bigints = types.filter(isBigIntType);
63
- if (bigints.length > 0) {
64
- const evaluated = match(bigints).when((types$1) => types$1.every(isTruthyBigIntType), () => "truthy bigint").when((types$1) => types$1.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
65
- variants.add(evaluated);
66
- }
67
- const numbers = types.filter(isNumberType);
68
- if (numbers.length > 0) {
69
- const evaluated = match(numbers).when((types$1) => types$1.every(isTruthyNumberType), () => "truthy number").when((types$1) => types$1.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
70
- variants.add(evaluated);
71
- }
72
- if (types.some(isEnumType)) variants.add("enum");
73
- if (types.some(isObjectType)) variants.add("object");
74
- if (types.some(isAnyType)) variants.add("any");
75
- if (types.some(isNeverType)) variants.add("never");
76
- return variants;
77
- }
78
-
79
- //#endregion
80
5
  //#region src/utils/is-react-api.ts
81
6
  function isReactAPI(api) {
82
7
  const func = (context, node) => {
@@ -124,4 +49,4 @@ const isMemoCall = isReactAPICall("memo");
124
49
  const isLazyCall = isReactAPICall("lazy");
125
50
 
126
51
  //#endregion
127
- export { getVariantsOfTypes, isAnyType, isBigIntType, isBooleanLiteralType, 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.6",
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,17 +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.6"
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
- "tsl": "^1.0.27",
42
+ "tsl": "^1.0.28",
43
43
  "typescript": "^5.9.3"
44
44
  },
45
45
  "engines": {