@mui/internal-babel-plugin-display-name 1.0.4-canary.0 → 1.0.4-canary.1
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/package.json +2 -2
- package/src/index.js +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-babel-plugin-display-name",
|
|
3
|
-
"version": "1.0.4-canary.
|
|
3
|
+
"version": "1.0.4-canary.1",
|
|
4
4
|
"description": "Babel plugin for automatic React display name generation with tree-shaking and prefix support, forked from @zendesk/babel-plugin-react-displayname.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"babel-plugin"
|
|
37
37
|
],
|
|
38
38
|
"homepage": "https://github.com/mui/mui-public",
|
|
39
|
-
"gitSha": "
|
|
39
|
+
"gitSha": "89c91764b62f0af7ce6ee4ec52c8e45b47e3c8aa",
|
|
40
40
|
"scripts": {
|
|
41
41
|
"test": "jest"
|
|
42
42
|
}
|
package/src/index.js
CHANGED
|
@@ -239,6 +239,19 @@ function addDisplayNamesToFunctionComponent(t, path) {
|
|
|
239
239
|
|
|
240
240
|
// const componentIdentifier = <Element />
|
|
241
241
|
if (parentPath.isVariableDeclarator()) {
|
|
242
|
+
// Ternary expression
|
|
243
|
+
if (t.isConditionalExpression(parentPath.node.init)) {
|
|
244
|
+
const { consequent, alternate } = parentPath.node.init;
|
|
245
|
+
const isConsequentFunction =
|
|
246
|
+
t.isArrowFunctionExpression(consequent) || t.isFunctionExpression(consequent);
|
|
247
|
+
const isAlternateFunction =
|
|
248
|
+
t.isArrowFunctionExpression(alternate) || t.isFunctionExpression(alternate);
|
|
249
|
+
|
|
250
|
+
// Only add display name if variable is a function
|
|
251
|
+
if (!isConsequentFunction || !isAlternateFunction) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
242
255
|
assignmentPath = parentPath.parentPath;
|
|
243
256
|
componentIdentifiers.unshift({
|
|
244
257
|
id: /** @type {babel.types.Expression} */ (parentPath.node.id),
|