Skip to content

Commit 41ee491

Browse files
committed
refactor: minor improvements
1 parent 1a40c15 commit 41ee491

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

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

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ export function useComponentCollector(
9393
const onFunctionExit = () => {
9494
const entry = functionEntries.at(-1);
9595
if (entry == null) return;
96-
if (!entry.isComponent) {
97-
return functionEntries.pop();
98-
}
96+
if (!entry.isComponent) return functionEntries.pop();
9997
const shouldDrop = AST.getNestedReturnStatements(entry.node.body)
10098
.slice()
10199
.reverse()
@@ -126,16 +124,12 @@ export function useComponentCollector(
126124
":function[type]:exit": onFunctionExit,
127125
"ArrowFunctionExpression[type][body.type!='BlockStatement']"() {
128126
const entry = getCurrentEntry();
129-
if (entry == null) {
130-
return;
131-
}
127+
if (entry == null) return;
132128
const { body } = entry.node;
133129
const isComponent = hasNoneOrValidComponentName(entry.node, context)
134130
&& JSX.isJSXValue(body, jsxCtx, hint)
135131
&& hasValidHierarchy(entry.node, context, hint);
136-
if (!isComponent) {
137-
return;
138-
}
132+
if (!isComponent) return;
139133
const initPath = AST.getFunctionInitPath(entry.node);
140134
const id = getFunctionComponentIdentifier(entry.node, context);
141135
const name = getComponentNameFromIdentifier(id);
@@ -163,40 +157,29 @@ export function useComponentCollector(
163157
: _;
164158
const component = [...components.values()]
165159
.findLast(({ name }) => name != null && name === componentName);
166-
if (component == null) {
167-
return;
168-
}
160+
if (component == null) return;
169161
component.displayName = right;
170162
},
171163
}
172164
: {},
173165
...collectHookCalls
174166
? {
175167
"CallExpression[type]:exit"(node: TSESTree.CallExpression) {
176-
if (!isReactHookCall(node)) {
177-
return;
178-
}
168+
if (!isReactHookCall(node)) return;
179169
const entry = getCurrentEntry();
180-
if (entry == null) {
181-
return;
182-
}
170+
if (entry == null) return;
183171
entry.hookCalls.push(node);
184172
},
185173
}
186174
: {},
187175
"ReturnStatement[type]"(node: TSESTree.ReturnStatement) {
188176
const entry = getCurrentEntry();
189-
if (entry == null) {
190-
return;
191-
}
177+
if (entry == null) return;
192178
const isComponent = hasNoneOrValidComponentName(entry.node, context)
193179
&& JSX.isJSXValue(node.argument, jsxCtx, hint)
194180
&& hasValidHierarchy(entry.node, context, hint);
195-
if (!isComponent) {
196-
return;
197-
}
198-
functionEntries.pop();
199-
functionEntries.push({ ...entry, isComponent });
181+
if (!isComponent) return;
182+
entry.isComponent = true;
200183
const initPath = AST.getFunctionInitPath(entry.node);
201184
const id = getFunctionComponentIdentifier(entry.node, context);
202185
const name = getComponentNameFromIdentifier(id);

0 commit comments

Comments
 (0)