Skip to content

Commit c00dd8b

Browse files
committed
refactor(ast): restructure the module
1 parent 3f33303 commit c00dd8b

26 files changed

+279
-292
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@
4343
"mdx.server.enable": true,
4444
"npm.packageManager": "pnpm",
4545
"typescript.preferences.importModuleSpecifier": "non-relative",
46-
"typescript.tsdk": "node_modules/typescript/lib",
47-
}
46+
"typescript.tsdk": "node_modules/typescript/lib"
47+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function useComponentCollectorLegacy(): useComponentCollectorLegacy.Retur
3434
if (!isClassComponent(node)) {
3535
return;
3636
}
37-
const id = AST.getClassIdentifier(node);
37+
const id = AST.getClassId(node);
3838
const key = getId();
3939
const flag = isPureComponent(node)
4040
? ComponentFlag.PureComponent

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function getFunctionComponentId(
99
context: RuleContext,
1010
node: AST.TSESTreeFunction,
1111
): TSESTree.Identifier | TSESTree.Identifier[] | _ {
12-
const functionId = AST.getFunctionIdentifier(node);
12+
const functionId = AST.getFunctionId(node);
1313
if (functionId != null) {
1414
return functionId;
1515
}

packages/core/src/component/component-render-prop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { isJsxLike, JSXDetectionHint } from "../jsx";
1919
export function isRenderFunctionLoose(context: RuleContext, node: AST.TSESTreeFunction) {
2020
const { body, parent } = node;
2121
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
22-
if (AST.getFunctionIdentifier(node)?.name.startsWith("render")) {
22+
if (AST.getFunctionId(node)?.name.startsWith("render")) {
2323
return parent.type === T.JSXExpressionContainer
2424
&& parent.parent.type === T.JSXAttribute
2525
&& parent.parent.name.type === T.JSXIdentifier

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function useHookCollector(): useHookCollector.ReturnType {
2525
const hooks = new Map<string, Hook>();
2626
const functionEntries: FunctionEntry[] = [];
2727
const onFunctionEnter = (node: AST.TSESTreeFunction) => {
28-
const id = AST.getFunctionIdentifier(node);
28+
const id = AST.getFunctionId(node);
2929
const key = getId();
3030
const name = id?.name;
3131
if (name != null && isReactHookName(name)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isReactHookName } from "./hook-name";
1212

1313
export function isReactHook(node: AST.TSESTreeFunction | _) {
1414
if (node == null) return false;
15-
const id = AST.getFunctionIdentifier(node);
15+
const id = AST.getFunctionId(node);
1616
return id?.name != null && isReactHookName(id.name);
1717
}
1818

packages/plugins/eslint-plugin-react-naming-convention/src/rules/component-name.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function create(context: RuleContext<MessageID, Options>): RuleListener {
112112
const functionComponents = collector.ctx.getAllComponents(program);
113113
const classComponents = collectorLegacy.ctx.getAllComponents(program);
114114
for (const { node: component } of functionComponents.values()) {
115-
const id = AST.getFunctionIdentifier(component);
115+
const id = AST.getFunctionId(component);
116116
if (id?.name == null) continue;
117117
const name = id.name;
118118
if (isValidName(name, options)) return;
@@ -123,7 +123,7 @@ export function create(context: RuleContext<MessageID, Options>): RuleListener {
123123
});
124124
}
125125
for (const { node: component } of classComponents.values()) {
126-
const id = AST.getClassIdentifier(component);
126+
const id = AST.getClassId(component);
127127
if (id?.name == null) continue;
128128
const name = id.name;
129129
if (isValidName(name, options)) continue;

packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
5050
if (!ER.isForwardRefCall(context, node)) {
5151
return;
5252
}
53-
const id = AST.getFunctionIdentifier(node);
53+
const id = AST.getFunctionId(node);
5454
context.report({
5555
messageId: "noForwardRef",
5656
node: id ?? node,

packages/plugins/eslint-plugin-react-x/src/rules/no-missing-component-display-name.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
4848
const components = ctx.getAllComponents(program);
4949
for (const { node, displayName, flag } of components.values()) {
5050
const isMemoOrForwardRef = (flag & (ER.ComponentFlag.ForwardRef | ER.ComponentFlag.Memo)) > 0n;
51-
if (AST.getFunctionIdentifier(node) != null) {
51+
if (AST.getFunctionId(node) != null) {
5252
continue;
5353
}
5454
if (!isMemoOrForwardRef) {
5555
continue;
5656
}
5757
if (displayName == null) {
58-
const id = AST.getFunctionIdentifier(node);
58+
const id = AST.getFunctionId(node);
5959
context.report({
6060
messageId: "noMissingComponentDisplayName",
6161
node: id ?? node,

packages/plugins/eslint-plugin-react-x/src/rules/no-unstable-context-value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
8181
messageId: "unstableContextValue",
8282
node: constructionNode,
8383
data: {
84-
type: AST.toReadableNodeType(constructionNode),
84+
type: AST.toDelimiterCaseType(constructionNode),
8585
suggestion,
8686
},
8787
});

0 commit comments

Comments
 (0)