Skip to content

Commit ea68863

Browse files
committed
Simplify componentName null/undefined handling
1 parent 314f7bc commit ea68863

File tree

1 file changed

+4
-4
lines changed
  • packages/babel-plugin-component-annotate/src

1 file changed

+4
-4
lines changed

packages/babel-plugin-component-annotate/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ function functionBodyPushAttributes(
251251
function processJSX(
252252
context: JSXProcessingContext,
253253
jsxNode: Babel.NodePath,
254-
componentName?: string | null
254+
componentName?: string
255255
): void {
256256
if (!jsxNode) {
257257
return;
258258
}
259259

260260
// Use provided componentName or fall back to context componentName
261-
const currentComponentName = componentName !== undefined ? componentName : context.componentName;
261+
const currentComponentName = componentName ?? context.componentName;
262262

263263
// NOTE: I don't know of a case where `openingElement` would have more than one item,
264264
// but it's safer to always iterate
@@ -300,7 +300,7 @@ function processJSX(
300300
shouldSetComponentName = false;
301301
processJSX(context, child, currentComponentName);
302302
} else {
303-
processJSX(context, child, null);
303+
processJSX(context, child, "");
304304
}
305305
});
306306
}
@@ -313,7 +313,7 @@ function processJSX(
313313
function applyAttributes(
314314
context: JSXProcessingContext,
315315
openingElement: Babel.NodePath<Babel.types.JSXOpeningElement>,
316-
componentName: string | null
316+
componentName: string
317317
): void {
318318
const { t, attributeNames, ignoredComponents, fragmentContext, sourceFileName } = context;
319319
const [componentAttributeName, elementAttributeName, sourceFileAttributeName] = attributeNames;

0 commit comments

Comments
 (0)