Skip to content

Commit 15eb421

Browse files
committed
refactor: replace '_' property with 'key' in ERSemanticNode
1 parent 6ca1df0 commit 15eb421

File tree

9 files changed

+59
-61
lines changed

9 files changed

+59
-61
lines changed

packages/core/docs/interfaces/ERClassComponent.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212

1313
## Properties
1414

15-
### \_
16-
17-
> **\_**: `string`
18-
19-
#### Inherited from
20-
21-
[`ERSemanticNode`](ERSemanticNode.md).[`_`](ERSemanticNode.md#_)
22-
23-
***
24-
2515
### displayName
2616

2717
> **displayName**: `undefined` \| `Expression`
@@ -58,6 +48,16 @@
5848

5949
***
6050

51+
### key
52+
53+
> **key**: `string`
54+
55+
#### Inherited from
56+
57+
[`ERSemanticNode`](ERSemanticNode.md).[`key`](ERSemanticNode.md#key)
58+
59+
***
60+
6161
### kind
6262

6363
> **kind**: `"class"`

packages/core/docs/interfaces/ERFunctionComponent.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212

1313
## Properties
1414

15-
### \_
16-
17-
> **\_**: `string`
18-
19-
#### Inherited from
20-
21-
[`ERSemanticNode`](ERSemanticNode.md).[`_`](ERSemanticNode.md#_)
22-
23-
***
24-
2515
### displayName
2616

2717
> **displayName**: `undefined` \| `Expression`
@@ -70,6 +60,16 @@
7060
7161
***
7262

63+
### key
64+
65+
> **key**: `string`
66+
67+
#### Inherited from
68+
69+
[`ERSemanticNode`](ERSemanticNode.md).[`key`](ERSemanticNode.md#key)
70+
71+
***
72+
7373
### kind
7474

7575
> **kind**: `"function"`

packages/core/docs/interfaces/ERHook.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212

1313
## Properties
1414

15-
### \_
16-
17-
> **\_**: `string`
18-
19-
#### Inherited from
20-
21-
[`ERSemanticNode`](ERSemanticNode.md).[`_`](ERSemanticNode.md#_)
22-
23-
***
24-
2515
### flag
2616

2717
> **flag**: `bigint`
@@ -58,6 +48,16 @@
5848

5949
***
6050

51+
### key
52+
53+
> **key**: `string`
54+
55+
#### Inherited from
56+
57+
[`ERSemanticNode`](ERSemanticNode.md).[`key`](ERSemanticNode.md#key)
58+
59+
***
60+
6161
### kind
6262

6363
> **kind**: `string`

packages/core/docs/interfaces/ERSemanticNode.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414

1515
## Properties
1616

17-
### \_
18-
19-
> **\_**: `string`
20-
21-
***
22-
2317
### flag
2418

2519
> **flag**: `bigint`
@@ -38,6 +32,12 @@
3832
3933
***
4034

35+
### key
36+
37+
> **key**: `string`
38+
39+
***
40+
4141
### kind
4242

4343
> **kind**: `string`

packages/core/src/component/component-collector-legacy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export function useComponentCollectorLegacy() {
2929
components.set(
3030
key,
3131
{
32-
_: key,
3332
id,
33+
key,
3434
kind: "class",
3535
name: id?.name,
3636
node,

packages/core/src/component/component-collector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function hasValidHierarchy(node: AST.TSESTreeFunction, context: RuleContext, hin
4848

4949
function getComponentFlag(initPath: ERFunctionComponent["initPath"]) {
5050
let flag = ERFunctionComponentFlag.None;
51-
if (initPath != null && AST.hasCallInFunctionInitPath("memo")(initPath)) {
51+
if (initPath != null && AST.hasCallInFunctionInitPath("memo", initPath)) {
5252
flag |= ERFunctionComponentFlag.Memo;
5353
}
54-
if (initPath != null && AST.hasCallInFunctionInitPath("forwardRef")(initPath)) {
54+
if (initPath != null && AST.hasCallInFunctionInitPath("forwardRef", initPath)) {
5555
flag |= ERFunctionComponentFlag.ForwardRef;
5656
}
5757
return flag;
@@ -125,8 +125,8 @@ export function useComponentCollector(
125125
const name = getComponentNameFromIdentifier(id);
126126
const key = getId();
127127
components.set(key, {
128-
_: key,
129128
id,
129+
key,
130130
kind: "function",
131131
name,
132132
node: entry.node,
@@ -149,7 +149,7 @@ export function useComponentCollector(
149149
if (component == null) {
150150
return;
151151
}
152-
components.set(component._, {
152+
components.set(component.key, {
153153
...component,
154154
displayName: right,
155155
});
@@ -182,8 +182,8 @@ export function useComponentCollector(
182182
const id = getFunctionComponentIdentifier(entry.node, context);
183183
const name = getComponentNameFromIdentifier(id);
184184
components.set(entry.key, {
185-
_: entry.key,
186185
id,
186+
key: entry.key,
187187
kind: "function",
188188
name,
189189
node: entry.node,

packages/core/src/hook/hook-collector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export function useHookCollector() {
1717
const key = getId();
1818
fEntries.push({ key, node });
1919
hooks.set(key, {
20-
_: key,
2120
id,
21+
key,
2222
kind: "function",
2323
name,
2424
node,
@@ -57,7 +57,7 @@ export function useHookCollector() {
5757
if (hook == null) {
5858
return;
5959
}
60-
hooks.set(hook._, {
60+
hooks.set(hook.key, {
6161
...hook,
6262
hookCalls: [
6363
...hook.hookCalls,

packages/core/src/semantic-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import type { _ } from "@eslint-react/eff";
22
import type { TSESTree } from "@typescript-eslint/types";
33

44
export interface ERSemanticNode {
5-
_: string;
65
id:
76
| _
87
| TSESTree.Identifier
98
| TSESTree.Identifier[];
9+
key: string;
1010
kind: string;
1111
name:
1212
| _

packages/utilities/ast/src/function-init-path.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,19 @@ export function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath |
177177
return _;
178178
}
179179

180-
export function hasCallInFunctionInitPath(callName: string) {
181-
return (initPath: FunctionInitPath) => {
182-
return initPath
183-
.some((n) => {
184-
if (n.type !== T.CallExpression) {
180+
export function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath) {
181+
return initPath
182+
.some((n) => {
183+
if (n.type !== T.CallExpression) {
184+
return false;
185+
}
186+
switch (n.callee.type) {
187+
case T.Identifier:
188+
return n.callee.name === callName;
189+
case T.MemberExpression:
190+
return "name" in n.callee.property && n.callee.property.name === callName;
191+
default:
185192
return false;
186-
}
187-
switch (n.callee.type) {
188-
case T.Identifier:
189-
return n.callee.name === callName;
190-
case T.MemberExpression:
191-
return "name" in n.callee.property && n.callee.property.name === callName;
192-
default:
193-
return false;
194-
}
195-
});
196-
};
193+
}
194+
});
197195
}

0 commit comments

Comments
 (0)