@eslint-react/core 1.23.1-beta.0 → 1.23.1-beta.6
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.mts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +43 -32
- package/dist/index.mjs +43 -33
- package/package.json +7 -8
package/dist/index.d.mts
CHANGED
|
@@ -80,12 +80,11 @@ type ERComponent = ERClassComponent | ERFunctionComponent;
|
|
|
80
80
|
declare function useComponentCollector(context: RuleContext, hint?: bigint): {
|
|
81
81
|
readonly ctx: {
|
|
82
82
|
readonly getAllComponents: (_: TSESTree.Program) => Map<string, ERFunctionComponent>;
|
|
83
|
-
readonly getCurrentComponents: () => Map<string, ERFunctionComponent>;
|
|
84
83
|
readonly getCurrentFunction: () => O.Option<[key: string, node: AST.TSESTreeFunction, isComponent: boolean, hookCalls: TSESTree.CallExpression[]]>;
|
|
85
84
|
readonly getCurrentFunctionStack: () => [key: string, node: AST.TSESTreeFunction, isComponent: boolean, hookCalls: TSESTree.CallExpression[]][];
|
|
86
85
|
};
|
|
87
86
|
readonly listeners: {
|
|
88
|
-
readonly ":function[type]": (node: AST.TSESTreeFunction) =>
|
|
87
|
+
readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
|
|
89
88
|
readonly ":function[type]:exit": () => [key: string, node: AST.TSESTreeFunction, isComponent: boolean, hookCalls: TSESTree.CallExpression[]] | undefined;
|
|
90
89
|
readonly "ArrowFunctionExpression[type][body.type!='BlockStatement']": () => void;
|
|
91
90
|
readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']": (node: TSESTree.Node) => void;
|
|
@@ -113,7 +112,6 @@ declare function isComponentWillUnmountFunction(node: TSESTree$1.Node): boolean;
|
|
|
113
112
|
declare function useComponentCollectorLegacy(): {
|
|
114
113
|
readonly ctx: {
|
|
115
114
|
readonly getAllComponents: (_: TSESTree$1.Program) => Map<string, ERClassComponent>;
|
|
116
|
-
readonly getCurrentComponents: () => Map<string, ERClassComponent>;
|
|
117
115
|
};
|
|
118
116
|
readonly listeners: {
|
|
119
117
|
readonly "ClassDeclaration[type]": (node: AST.TSESTreeClass) => void;
|
|
@@ -2560,4 +2558,11 @@ declare const isMemoCall: {
|
|
|
2560
2558
|
(node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
|
|
2561
2559
|
};
|
|
2562
2560
|
|
|
2563
|
-
|
|
2561
|
+
declare function next(): bigint;
|
|
2562
|
+
|
|
2563
|
+
declare const uid_next: typeof next;
|
|
2564
|
+
declare namespace uid {
|
|
2565
|
+
export { uid_next as next };
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, uid, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -80,12 +80,11 @@ type ERComponent = ERClassComponent | ERFunctionComponent;
|
|
|
80
80
|
declare function useComponentCollector(context: RuleContext, hint?: bigint): {
|
|
81
81
|
readonly ctx: {
|
|
82
82
|
readonly getAllComponents: (_: TSESTree.Program) => Map<string, ERFunctionComponent>;
|
|
83
|
-
readonly getCurrentComponents: () => Map<string, ERFunctionComponent>;
|
|
84
83
|
readonly getCurrentFunction: () => O.Option<[key: string, node: AST.TSESTreeFunction, isComponent: boolean, hookCalls: TSESTree.CallExpression[]]>;
|
|
85
84
|
readonly getCurrentFunctionStack: () => [key: string, node: AST.TSESTreeFunction, isComponent: boolean, hookCalls: TSESTree.CallExpression[]][];
|
|
86
85
|
};
|
|
87
86
|
readonly listeners: {
|
|
88
|
-
readonly ":function[type]": (node: AST.TSESTreeFunction) =>
|
|
87
|
+
readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
|
|
89
88
|
readonly ":function[type]:exit": () => [key: string, node: AST.TSESTreeFunction, isComponent: boolean, hookCalls: TSESTree.CallExpression[]] | undefined;
|
|
90
89
|
readonly "ArrowFunctionExpression[type][body.type!='BlockStatement']": () => void;
|
|
91
90
|
readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']": (node: TSESTree.Node) => void;
|
|
@@ -113,7 +112,6 @@ declare function isComponentWillUnmountFunction(node: TSESTree$1.Node): boolean;
|
|
|
113
112
|
declare function useComponentCollectorLegacy(): {
|
|
114
113
|
readonly ctx: {
|
|
115
114
|
readonly getAllComponents: (_: TSESTree$1.Program) => Map<string, ERClassComponent>;
|
|
116
|
-
readonly getCurrentComponents: () => Map<string, ERClassComponent>;
|
|
117
115
|
};
|
|
118
116
|
readonly listeners: {
|
|
119
117
|
readonly "ClassDeclaration[type]": (node: AST.TSESTreeClass) => void;
|
|
@@ -2560,4 +2558,11 @@ declare const isMemoCall: {
|
|
|
2560
2558
|
(node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
|
|
2561
2559
|
};
|
|
2562
2560
|
|
|
2563
|
-
|
|
2561
|
+
declare function next(): bigint;
|
|
2562
|
+
|
|
2563
|
+
declare const uid_next: typeof next;
|
|
2564
|
+
declare namespace uid {
|
|
2565
|
+
export { uid_next as next };
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, uid, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ var eff = require('@eslint-react/eff');
|
|
|
5
5
|
var JSX4 = require('@eslint-react/jsx');
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
7
|
var tsPattern = require('ts-pattern');
|
|
8
|
-
var uid = require('uid');
|
|
9
8
|
var shared = require('@eslint-react/shared');
|
|
10
9
|
var VAR = require('@eslint-react/var');
|
|
11
10
|
var types$1 = require('@eslint-react/types');
|
|
@@ -32,7 +31,11 @@ var AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
|
|
|
32
31
|
var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
|
|
33
32
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
var __defProp = Object.defineProperty;
|
|
35
|
+
var __export = (target, all) => {
|
|
36
|
+
for (var name in all)
|
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
+
};
|
|
36
39
|
function getElementRepresentName(node, context) {
|
|
37
40
|
const rawElementName = JSX4__namespace.getElementName(node);
|
|
38
41
|
if (rawElementName === rawElementName.toLowerCase()) return rawElementName;
|
|
@@ -125,6 +128,16 @@ var isCreateRefCall = isReactAPICallWithName("createRef");
|
|
|
125
128
|
var isForwardRefCall = isReactAPICallWithName("forwardRef");
|
|
126
129
|
var isMemoCall = isReactAPICallWithName("memo");
|
|
127
130
|
|
|
131
|
+
// src/utils/uid.ts
|
|
132
|
+
var uid_exports = {};
|
|
133
|
+
__export(uid_exports, {
|
|
134
|
+
next: () => next
|
|
135
|
+
});
|
|
136
|
+
var id = 0n;
|
|
137
|
+
function next() {
|
|
138
|
+
return id++;
|
|
139
|
+
}
|
|
140
|
+
|
|
128
141
|
// src/element/hierarchy.ts
|
|
129
142
|
function isInsideCreateElementProps(node, context) {
|
|
130
143
|
return eff.F.pipe(
|
|
@@ -156,7 +169,7 @@ function isReactHookName(name) {
|
|
|
156
169
|
function isReactHook(node) {
|
|
157
170
|
return eff.F.pipe(
|
|
158
171
|
AST9__namespace.getFunctionIdentifier(node),
|
|
159
|
-
eff.O.flatMapNullable((
|
|
172
|
+
eff.O.flatMapNullable((id2) => id2.name),
|
|
160
173
|
eff.O.exists(isReactHookName)
|
|
161
174
|
);
|
|
162
175
|
}
|
|
@@ -243,14 +256,14 @@ function useHookCollector() {
|
|
|
243
256
|
const hooks = /* @__PURE__ */ new Map();
|
|
244
257
|
const fStack = [];
|
|
245
258
|
const onFunctionEnter = (node) => {
|
|
246
|
-
const
|
|
247
|
-
const name = eff.O.flatMapNullable(
|
|
248
|
-
if (eff.O.isSome(
|
|
249
|
-
const key =
|
|
259
|
+
const id2 = AST9__namespace.getFunctionIdentifier(node);
|
|
260
|
+
const name = eff.O.flatMapNullable(id2, (id3) => id3.name);
|
|
261
|
+
if (eff.O.isSome(id2) && eff.O.isSome(name) && isReactHookName(name.value)) {
|
|
262
|
+
const key = uid_exports.next().toString();
|
|
250
263
|
fStack.push([node, eff.O.some(key)]);
|
|
251
264
|
hooks.set(key, {
|
|
252
265
|
_: key,
|
|
253
|
-
id,
|
|
266
|
+
id: id2,
|
|
254
267
|
kind: "function",
|
|
255
268
|
name,
|
|
256
269
|
node,
|
|
@@ -283,9 +296,9 @@ function useHookCollector() {
|
|
|
283
296
|
eff.F.pipe(
|
|
284
297
|
eff.O.Do,
|
|
285
298
|
eff.O.bind("id", () => hookId),
|
|
286
|
-
eff.O.bind("hook", ({ id }) => eff.O.fromNullable(hooks.get(
|
|
287
|
-
eff.O.map(({ id, hook }) => {
|
|
288
|
-
hooks.set(
|
|
299
|
+
eff.O.bind("hook", ({ id: id2 }) => eff.O.fromNullable(hooks.get(id2))),
|
|
300
|
+
eff.O.map(({ id: id2, hook }) => {
|
|
301
|
+
hooks.set(id2, {
|
|
289
302
|
...hook,
|
|
290
303
|
hookCalls: [
|
|
291
304
|
...hook.hookCalls,
|
|
@@ -399,23 +412,20 @@ function useComponentCollectorLegacy() {
|
|
|
399
412
|
const ctx = {
|
|
400
413
|
getAllComponents(_) {
|
|
401
414
|
return components;
|
|
402
|
-
},
|
|
403
|
-
getCurrentComponents() {
|
|
404
|
-
return new Map(components);
|
|
405
415
|
}
|
|
406
416
|
};
|
|
407
417
|
const collect = (node) => {
|
|
408
418
|
if (!isClassComponent(node)) return;
|
|
409
|
-
const
|
|
410
|
-
const key =
|
|
419
|
+
const id2 = AST9__namespace.getClassIdentifier(node);
|
|
420
|
+
const key = uid_exports.next().toString();
|
|
411
421
|
const flag = isPureComponent(node) ? ERClassComponentFlag.PureComponent : ERClassComponentFlag.None;
|
|
412
422
|
components.set(
|
|
413
423
|
key,
|
|
414
424
|
{
|
|
415
425
|
_: key,
|
|
416
|
-
id,
|
|
426
|
+
id: id2,
|
|
417
427
|
kind: "class",
|
|
418
|
-
name: eff.O.flatMapNullable(
|
|
428
|
+
name: eff.O.flatMapNullable(id2, (n) => n.name),
|
|
419
429
|
node,
|
|
420
430
|
// TODO: Get displayName of class component
|
|
421
431
|
displayName: eff.O.none(),
|
|
@@ -461,8 +471,8 @@ function hasNoneOrValidComponentName(node, context) {
|
|
|
461
471
|
getFunctionComponentIdentifier(node, context),
|
|
462
472
|
{
|
|
463
473
|
onNone: eff.F.constTrue,
|
|
464
|
-
onSome: (
|
|
465
|
-
const name = Array.isArray(
|
|
474
|
+
onSome: (id2) => {
|
|
475
|
+
const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
|
|
466
476
|
return !!name && isComponentName(name);
|
|
467
477
|
}
|
|
468
478
|
}
|
|
@@ -515,7 +525,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
515
525
|
const components = /* @__PURE__ */ new Map();
|
|
516
526
|
const functionStack = [];
|
|
517
527
|
const getCurrentFunction = () => eff.O.fromNullable(functionStack.at(-1));
|
|
518
|
-
const onFunctionEnter = (node) =>
|
|
528
|
+
const onFunctionEnter = (node) => {
|
|
529
|
+
const key = uid_exports.next().toString();
|
|
530
|
+
functionStack.push([key, node, false, []]);
|
|
531
|
+
};
|
|
519
532
|
const onFunctionExit = () => {
|
|
520
533
|
const [key, fn, isComponent] = functionStack.at(-1) ?? [];
|
|
521
534
|
if (!key || !fn || !isComponent) return functionStack.pop();
|
|
@@ -529,9 +542,6 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
529
542
|
getAllComponents(_) {
|
|
530
543
|
return components;
|
|
531
544
|
},
|
|
532
|
-
getCurrentComponents() {
|
|
533
|
-
return new Map(components);
|
|
534
|
-
},
|
|
535
545
|
getCurrentFunction,
|
|
536
546
|
getCurrentFunctionStack() {
|
|
537
547
|
return [...functionStack];
|
|
@@ -548,12 +558,12 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
548
558
|
const isComponent = hasNoneOrValidComponentName(currentFn, context) && JSX4__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(currentFn, context, hint);
|
|
549
559
|
if (!isComponent) return;
|
|
550
560
|
const initPath = AST9__namespace.getFunctionInitPath(currentFn);
|
|
551
|
-
const
|
|
552
|
-
const name = eff.O.flatMapNullable(
|
|
553
|
-
const key =
|
|
561
|
+
const id2 = getFunctionComponentIdentifier(currentFn, context);
|
|
562
|
+
const name = eff.O.flatMapNullable(id2, getComponentNameFromIdentifier);
|
|
563
|
+
const key = uid_exports.next().toString();
|
|
554
564
|
components.set(key, {
|
|
555
565
|
_: key,
|
|
556
|
-
id,
|
|
566
|
+
id: id2,
|
|
557
567
|
kind: "function",
|
|
558
568
|
name,
|
|
559
569
|
node: currentFn,
|
|
@@ -595,11 +605,11 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
595
605
|
functionStack.pop();
|
|
596
606
|
functionStack.push([key, currentFn, true, []]);
|
|
597
607
|
const initPath = AST9__namespace.getFunctionInitPath(currentFn);
|
|
598
|
-
const
|
|
599
|
-
const name = eff.O.flatMapNullable(
|
|
608
|
+
const id2 = getFunctionComponentIdentifier(currentFn, context);
|
|
609
|
+
const name = eff.O.flatMapNullable(id2, getComponentNameFromIdentifier);
|
|
600
610
|
components.set(key, {
|
|
601
611
|
_: key,
|
|
602
|
-
id,
|
|
612
|
+
id: id2,
|
|
603
613
|
kind: "function",
|
|
604
614
|
name,
|
|
605
615
|
node: currentFn,
|
|
@@ -656,7 +666,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
656
666
|
}
|
|
657
667
|
function isRenderFunctionLoose(node, context) {
|
|
658
668
|
const { body, parent } = node;
|
|
659
|
-
if (eff.O.exists(AST9__namespace.getFunctionIdentifier(node), (
|
|
669
|
+
if (eff.O.exists(AST9__namespace.getFunctionIdentifier(node), (id2) => id2.name.startsWith("render"))) {
|
|
660
670
|
return parent.type === types.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
661
671
|
}
|
|
662
672
|
return JSX4__namespace.isJSXValue(
|
|
@@ -758,6 +768,7 @@ exports.isUseRefCall = isUseRefCall;
|
|
|
758
768
|
exports.isUseStateCall = isUseStateCall;
|
|
759
769
|
exports.isUseSyncExternalStoreCall = isUseSyncExternalStoreCall;
|
|
760
770
|
exports.isUseTransitionCall = isUseTransitionCall;
|
|
771
|
+
exports.uid = uid_exports;
|
|
761
772
|
exports.useComponentCollector = useComponentCollector;
|
|
762
773
|
exports.useComponentCollectorLegacy = useComponentCollectorLegacy;
|
|
763
774
|
exports.useHookCollector = useHookCollector;
|
package/dist/index.mjs
CHANGED
|
@@ -3,12 +3,15 @@ import { F, isString, O } from '@eslint-react/eff';
|
|
|
3
3
|
import * as JSX4 from '@eslint-react/jsx';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import { isMatching, P, match } from 'ts-pattern';
|
|
6
|
-
import { uid } from 'uid';
|
|
7
6
|
import { normalizeSettings, decodeSettings, unsafeReadSettings } from '@eslint-react/shared';
|
|
8
7
|
import * as VAR from '@eslint-react/var';
|
|
9
8
|
import { birecord } from '@eslint-react/types';
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
12
15
|
function getElementRepresentName(node, context) {
|
|
13
16
|
const rawElementName = JSX4.getElementName(node);
|
|
14
17
|
if (rawElementName === rawElementName.toLowerCase()) return rawElementName;
|
|
@@ -101,6 +104,16 @@ var isCreateRefCall = isReactAPICallWithName("createRef");
|
|
|
101
104
|
var isForwardRefCall = isReactAPICallWithName("forwardRef");
|
|
102
105
|
var isMemoCall = isReactAPICallWithName("memo");
|
|
103
106
|
|
|
107
|
+
// src/utils/uid.ts
|
|
108
|
+
var uid_exports = {};
|
|
109
|
+
__export(uid_exports, {
|
|
110
|
+
next: () => next
|
|
111
|
+
});
|
|
112
|
+
var id = 0n;
|
|
113
|
+
function next() {
|
|
114
|
+
return id++;
|
|
115
|
+
}
|
|
116
|
+
|
|
104
117
|
// src/element/hierarchy.ts
|
|
105
118
|
function isInsideCreateElementProps(node, context) {
|
|
106
119
|
return F.pipe(
|
|
@@ -132,7 +145,7 @@ function isReactHookName(name) {
|
|
|
132
145
|
function isReactHook(node) {
|
|
133
146
|
return F.pipe(
|
|
134
147
|
AST9.getFunctionIdentifier(node),
|
|
135
|
-
O.flatMapNullable((
|
|
148
|
+
O.flatMapNullable((id2) => id2.name),
|
|
136
149
|
O.exists(isReactHookName)
|
|
137
150
|
);
|
|
138
151
|
}
|
|
@@ -219,14 +232,14 @@ function useHookCollector() {
|
|
|
219
232
|
const hooks = /* @__PURE__ */ new Map();
|
|
220
233
|
const fStack = [];
|
|
221
234
|
const onFunctionEnter = (node) => {
|
|
222
|
-
const
|
|
223
|
-
const name = O.flatMapNullable(
|
|
224
|
-
if (O.isSome(
|
|
225
|
-
const key =
|
|
235
|
+
const id2 = AST9.getFunctionIdentifier(node);
|
|
236
|
+
const name = O.flatMapNullable(id2, (id3) => id3.name);
|
|
237
|
+
if (O.isSome(id2) && O.isSome(name) && isReactHookName(name.value)) {
|
|
238
|
+
const key = uid_exports.next().toString();
|
|
226
239
|
fStack.push([node, O.some(key)]);
|
|
227
240
|
hooks.set(key, {
|
|
228
241
|
_: key,
|
|
229
|
-
id,
|
|
242
|
+
id: id2,
|
|
230
243
|
kind: "function",
|
|
231
244
|
name,
|
|
232
245
|
node,
|
|
@@ -259,9 +272,9 @@ function useHookCollector() {
|
|
|
259
272
|
F.pipe(
|
|
260
273
|
O.Do,
|
|
261
274
|
O.bind("id", () => hookId),
|
|
262
|
-
O.bind("hook", ({ id }) => O.fromNullable(hooks.get(
|
|
263
|
-
O.map(({ id, hook }) => {
|
|
264
|
-
hooks.set(
|
|
275
|
+
O.bind("hook", ({ id: id2 }) => O.fromNullable(hooks.get(id2))),
|
|
276
|
+
O.map(({ id: id2, hook }) => {
|
|
277
|
+
hooks.set(id2, {
|
|
265
278
|
...hook,
|
|
266
279
|
hookCalls: [
|
|
267
280
|
...hook.hookCalls,
|
|
@@ -375,23 +388,20 @@ function useComponentCollectorLegacy() {
|
|
|
375
388
|
const ctx = {
|
|
376
389
|
getAllComponents(_) {
|
|
377
390
|
return components;
|
|
378
|
-
},
|
|
379
|
-
getCurrentComponents() {
|
|
380
|
-
return new Map(components);
|
|
381
391
|
}
|
|
382
392
|
};
|
|
383
393
|
const collect = (node) => {
|
|
384
394
|
if (!isClassComponent(node)) return;
|
|
385
|
-
const
|
|
386
|
-
const key =
|
|
395
|
+
const id2 = AST9.getClassIdentifier(node);
|
|
396
|
+
const key = uid_exports.next().toString();
|
|
387
397
|
const flag = isPureComponent(node) ? ERClassComponentFlag.PureComponent : ERClassComponentFlag.None;
|
|
388
398
|
components.set(
|
|
389
399
|
key,
|
|
390
400
|
{
|
|
391
401
|
_: key,
|
|
392
|
-
id,
|
|
402
|
+
id: id2,
|
|
393
403
|
kind: "class",
|
|
394
|
-
name: O.flatMapNullable(
|
|
404
|
+
name: O.flatMapNullable(id2, (n) => n.name),
|
|
395
405
|
node,
|
|
396
406
|
// TODO: Get displayName of class component
|
|
397
407
|
displayName: O.none(),
|
|
@@ -437,8 +447,8 @@ function hasNoneOrValidComponentName(node, context) {
|
|
|
437
447
|
getFunctionComponentIdentifier(node, context),
|
|
438
448
|
{
|
|
439
449
|
onNone: F.constTrue,
|
|
440
|
-
onSome: (
|
|
441
|
-
const name = Array.isArray(
|
|
450
|
+
onSome: (id2) => {
|
|
451
|
+
const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
|
|
442
452
|
return !!name && isComponentName(name);
|
|
443
453
|
}
|
|
444
454
|
}
|
|
@@ -491,7 +501,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
491
501
|
const components = /* @__PURE__ */ new Map();
|
|
492
502
|
const functionStack = [];
|
|
493
503
|
const getCurrentFunction = () => O.fromNullable(functionStack.at(-1));
|
|
494
|
-
const onFunctionEnter = (node) =>
|
|
504
|
+
const onFunctionEnter = (node) => {
|
|
505
|
+
const key = uid_exports.next().toString();
|
|
506
|
+
functionStack.push([key, node, false, []]);
|
|
507
|
+
};
|
|
495
508
|
const onFunctionExit = () => {
|
|
496
509
|
const [key, fn, isComponent] = functionStack.at(-1) ?? [];
|
|
497
510
|
if (!key || !fn || !isComponent) return functionStack.pop();
|
|
@@ -505,9 +518,6 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
505
518
|
getAllComponents(_) {
|
|
506
519
|
return components;
|
|
507
520
|
},
|
|
508
|
-
getCurrentComponents() {
|
|
509
|
-
return new Map(components);
|
|
510
|
-
},
|
|
511
521
|
getCurrentFunction,
|
|
512
522
|
getCurrentFunctionStack() {
|
|
513
523
|
return [...functionStack];
|
|
@@ -524,12 +534,12 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
524
534
|
const isComponent = hasNoneOrValidComponentName(currentFn, context) && JSX4.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(currentFn, context, hint);
|
|
525
535
|
if (!isComponent) return;
|
|
526
536
|
const initPath = AST9.getFunctionInitPath(currentFn);
|
|
527
|
-
const
|
|
528
|
-
const name = O.flatMapNullable(
|
|
529
|
-
const key =
|
|
537
|
+
const id2 = getFunctionComponentIdentifier(currentFn, context);
|
|
538
|
+
const name = O.flatMapNullable(id2, getComponentNameFromIdentifier);
|
|
539
|
+
const key = uid_exports.next().toString();
|
|
530
540
|
components.set(key, {
|
|
531
541
|
_: key,
|
|
532
|
-
id,
|
|
542
|
+
id: id2,
|
|
533
543
|
kind: "function",
|
|
534
544
|
name,
|
|
535
545
|
node: currentFn,
|
|
@@ -571,11 +581,11 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
571
581
|
functionStack.pop();
|
|
572
582
|
functionStack.push([key, currentFn, true, []]);
|
|
573
583
|
const initPath = AST9.getFunctionInitPath(currentFn);
|
|
574
|
-
const
|
|
575
|
-
const name = O.flatMapNullable(
|
|
584
|
+
const id2 = getFunctionComponentIdentifier(currentFn, context);
|
|
585
|
+
const name = O.flatMapNullable(id2, getComponentNameFromIdentifier);
|
|
576
586
|
components.set(key, {
|
|
577
587
|
_: key,
|
|
578
|
-
id,
|
|
588
|
+
id: id2,
|
|
579
589
|
kind: "function",
|
|
580
590
|
name,
|
|
581
591
|
node: currentFn,
|
|
@@ -632,7 +642,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
632
642
|
}
|
|
633
643
|
function isRenderFunctionLoose(node, context) {
|
|
634
644
|
const { body, parent } = node;
|
|
635
|
-
if (O.exists(AST9.getFunctionIdentifier(node), (
|
|
645
|
+
if (O.exists(AST9.getFunctionIdentifier(node), (id2) => id2.name.startsWith("render"))) {
|
|
636
646
|
return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
637
647
|
}
|
|
638
648
|
return JSX4.isJSXValue(
|
|
@@ -652,4 +662,4 @@ function isThisSetState(node) {
|
|
|
652
662
|
return callee.type === AST_NODE_TYPES.MemberExpression && AST9.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
653
663
|
}
|
|
654
664
|
|
|
655
|
-
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
665
|
+
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, uid_exports as uid, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.23.1-beta.
|
|
3
|
+
"version": "1.23.1-beta.6",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
|
|
5
5
|
"homepage": "https://github.com/rEl1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -38,13 +38,12 @@
|
|
|
38
38
|
"@typescript-eslint/types": "^8.19.0",
|
|
39
39
|
"@typescript-eslint/utils": "^8.19.0",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/var": "1.23.1-beta.
|
|
46
|
-
"@eslint-react/jsx": "1.23.1-beta.
|
|
47
|
-
"@eslint-react/types": "1.23.1-beta.0"
|
|
41
|
+
"@eslint-react/ast": "1.23.1-beta.6",
|
|
42
|
+
"@eslint-react/eff": "1.23.1-beta.6",
|
|
43
|
+
"@eslint-react/shared": "1.23.1-beta.6",
|
|
44
|
+
"@eslint-react/types": "1.23.1-beta.6",
|
|
45
|
+
"@eslint-react/var": "1.23.1-beta.6",
|
|
46
|
+
"@eslint-react/jsx": "1.23.1-beta.6"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"tsup": "^8.3.5",
|