@react-analyzer/core 0.0.1-next.1 → 0.0.2-next.1

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,6 +1,22 @@
1
+ import { AST, Context } from 'tsl';
2
+ import { unit } from '@react-analyzer/eff';
1
3
  import ts from 'typescript';
2
4
  export { isFalseLiteralType, isTrueLiteralType } from 'ts-api-utils';
3
5
 
6
+ interface SemanticEntry {
7
+ node: AST.AnyNode;
8
+ }
9
+
10
+ interface SemanticNode {
11
+ id: unit | AST.Identifier | AST.Identifier[];
12
+ key: string;
13
+ kind: string;
14
+ name: unit | string;
15
+ node: AST.AnyNode;
16
+ flag: bigint;
17
+ hint: bigint;
18
+ }
19
+
4
20
  declare const isAnyType: (type: ts.Type) => boolean;
5
21
  declare const isBigIntType: (type: ts.Type) => boolean;
6
22
  declare const isBooleanType: (type: ts.Type) => boolean;
@@ -94,4 +110,45 @@ type Variant = "any" | "bigint" | "boolean" | "enum" | "never" | "nullish" | "nu
94
110
  */
95
111
  declare function getVariantsOfTypes(types: ts.Type[]): Set<Variant>;
96
112
 
97
- export { type Variant, getVariantsOfTypes, isAnyType, isBigIntType, isBooleanType, isEnumType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isNeverType, isNullishType, isNumberType, isObjectType, isStringType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType };
113
+ declare namespace isReactAPI {
114
+ type ReturnType = {
115
+ (context: Context, node: unit | null | AST.AnyNode): node is AST.MemberExpression;
116
+ (context: Context): (node: unit | null | AST.AnyNode) => node is AST.MemberExpression;
117
+ };
118
+ }
119
+ declare function isReactAPI(api: string): isReactAPI.ReturnType;
120
+ declare namespace isReactAPICall {
121
+ type ReturnType = {
122
+ (context: Context, node: unit | null | AST.AnyNode): node is AST.CallExpression;
123
+ (context: Context): (node: unit | null | AST.AnyNode) => node is AST.CallExpression;
124
+ };
125
+ }
126
+ declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
127
+ declare const isCaptureOwnerStack: isReactAPI.ReturnType;
128
+ declare const isChildrenCount: isReactAPI.ReturnType;
129
+ declare const isChildrenForEach: isReactAPI.ReturnType;
130
+ declare const isChildrenMap: isReactAPI.ReturnType;
131
+ declare const isChildrenOnly: isReactAPI.ReturnType;
132
+ declare const isChildrenToArray: isReactAPI.ReturnType;
133
+ declare const isCloneElement: isReactAPI.ReturnType;
134
+ declare const isCreateContext: isReactAPI.ReturnType;
135
+ declare const isCreateElement: isReactAPI.ReturnType;
136
+ declare const isCreateRef: isReactAPI.ReturnType;
137
+ declare const isForwardRef: isReactAPI.ReturnType;
138
+ declare const isMemo: isReactAPI.ReturnType;
139
+ declare const isLazy: isReactAPI.ReturnType;
140
+ declare const isCaptureOwnerStackCall: isReactAPICall.ReturnType;
141
+ declare const isChildrenCountCall: isReactAPICall.ReturnType;
142
+ declare const isChildrenForEachCall: isReactAPICall.ReturnType;
143
+ declare const isChildrenMapCall: isReactAPICall.ReturnType;
144
+ declare const isChildrenOnlyCall: isReactAPICall.ReturnType;
145
+ declare const isChildrenToArrayCall: isReactAPICall.ReturnType;
146
+ declare const isCloneElementCall: isReactAPICall.ReturnType;
147
+ declare const isCreateContextCall: isReactAPICall.ReturnType;
148
+ declare const isCreateElementCall: isReactAPICall.ReturnType;
149
+ declare const isCreateRefCall: isReactAPICall.ReturnType;
150
+ declare const isForwardRefCall: isReactAPICall.ReturnType;
151
+ declare const isMemoCall: isReactAPICall.ReturnType;
152
+ declare const isLazyCall: isReactAPICall.ReturnType;
153
+
154
+ export { type SemanticEntry, type SemanticNode, type Variant, 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, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isReactAPI, isReactAPICall, isStringType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { isTypeFlagSet, isFalseLiteralType, isTrueLiteralType } from 'ts-api-utils';
2
2
  export { isFalseLiteralType, isTrueLiteralType } from 'ts-api-utils';
3
3
  import { isMatching, P, match } from 'ts-pattern';
4
- import ts from 'typescript';
4
+ import ts, { SyntaxKind } from 'typescript';
5
+ import { dual } from '@react-analyzer/eff';
6
+ import { toStringFormat } from '@react-analyzer/ast';
5
7
 
6
8
  // src/type/type-is.ts
7
9
  var isAnyType = (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any);
@@ -72,5 +74,49 @@ function getVariantsOfTypes(types) {
72
74
  }
73
75
  return variants;
74
76
  }
77
+ function isReactAPI(api) {
78
+ const func = (context, node) => {
79
+ if (node == null) return false;
80
+ const name = toStringFormat(node);
81
+ if (name === api) return true;
82
+ if (name.substring(name.indexOf(".") + 1) === api) return true;
83
+ return false;
84
+ };
85
+ return dual(2, func);
86
+ }
87
+ function isReactAPICall(api) {
88
+ const func = (context, node) => {
89
+ if (node == null) return false;
90
+ if (node.kind !== SyntaxKind.CallExpression) return false;
91
+ return isReactAPI(api)(context, node.expression);
92
+ };
93
+ return dual(2, func);
94
+ }
95
+ var isCaptureOwnerStack = isReactAPI("captureOwnerStack");
96
+ var isChildrenCount = isReactAPI("Children.count");
97
+ var isChildrenForEach = isReactAPI("Children.forEach");
98
+ var isChildrenMap = isReactAPI("Children.map");
99
+ var isChildrenOnly = isReactAPI("Children.only");
100
+ var isChildrenToArray = isReactAPI("Children.toArray");
101
+ var isCloneElement = isReactAPI("cloneElement");
102
+ var isCreateContext = isReactAPI("createContext");
103
+ var isCreateElement = isReactAPI("createElement");
104
+ var isCreateRef = isReactAPI("createRef");
105
+ var isForwardRef = isReactAPI("forwardRef");
106
+ var isMemo = isReactAPI("memo");
107
+ var isLazy = isReactAPI("lazy");
108
+ var isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
109
+ var isChildrenCountCall = isReactAPICall("Children.count");
110
+ var isChildrenForEachCall = isReactAPICall("Children.forEach");
111
+ var isChildrenMapCall = isReactAPICall("Children.map");
112
+ var isChildrenOnlyCall = isReactAPICall("Children.only");
113
+ var isChildrenToArrayCall = isReactAPICall("Children.toArray");
114
+ var isCloneElementCall = isReactAPICall("cloneElement");
115
+ var isCreateContextCall = isReactAPICall("createContext");
116
+ var isCreateElementCall = isReactAPICall("createElement");
117
+ var isCreateRefCall = isReactAPICall("createRef");
118
+ var isForwardRefCall = isReactAPICall("forwardRef");
119
+ var isMemoCall = isReactAPICall("memo");
120
+ var isLazyCall = isReactAPICall("lazy");
75
121
 
76
- export { getVariantsOfTypes, isAnyType, isBigIntType, isBooleanType, isEnumType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isNeverType, isNullishType, isNumberType, isObjectType, isStringType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType };
122
+ 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, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isReactAPI, isReactAPICall, isStringType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-analyzer/core",
3
- "version": "0.0.1-next.1",
3
+ "version": "0.0.2-next.1",
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": {
@@ -28,12 +28,13 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "ts-pattern": "^5.7.1",
31
- "@react-analyzer/eff": "0.0.1-next.1",
32
- "@react-analyzer/kit": "0.0.1-next.1"
31
+ "@react-analyzer/kit": "0.0.2-next.1",
32
+ "@react-analyzer/eff": "0.0.2-next.1",
33
+ "@react-analyzer/ast": "0.0.2-next.1"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@tsconfig/node22": "^22.0.2",
36
- "@types/node": "^24.0.12",
37
+ "@types/node": "^24.0.13",
37
38
  "tsup": "^8.5.0",
38
39
  "type-fest": "^4.41.0",
39
40
  "@local/configs": "0.0.0"