@mui/internal-babel-plugin-display-name 1.0.4-canary.0 → 1.0.4-canary.2

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.
Files changed (2) hide show
  1. package/package.json +7 -8
  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.0",
3
+ "version": "1.0.4-canary.2",
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",
@@ -13,20 +13,19 @@
13
13
  "src/index.js"
14
14
  ],
15
15
  "dependencies": {
16
- "@babel/helper-module-imports": "^7.18.6",
16
+ "@babel/helper-module-imports": "^7.27.1",
17
17
  "@babel/helper-plugin-utils": "^7.20.2"
18
18
  },
19
19
  "devDependencies": {
20
- "@babel/core": "^7.20.2",
20
+ "@babel/core": "^7.27.4",
21
21
  "@babel/preset-env": "^7.20.2",
22
22
  "@babel/preset-react": "^7.18.6",
23
23
  "@types/babel__core": "^7.20.5",
24
- "@types/babel__helper-plugin-utils": "^7.10.3",
25
- "prettier": "^2.7.1"
24
+ "@types/babel__helper-plugin-utils": "^7.10.3"
26
25
  },
27
26
  "peerDependencies": {
28
- "@babel/core": "^7.0.0",
29
- "@babel/preset-react": "^7.0.0"
27
+ "@babel/core": "7",
28
+ "@babel/preset-react": "7"
30
29
  },
31
30
  "license": "Apache-2.0",
32
31
  "keywords": [
@@ -36,7 +35,7 @@
36
35
  "babel-plugin"
37
36
  ],
38
37
  "homepage": "https://github.com/mui/mui-public",
39
- "gitSha": "1c2b2282d97b7e09cf2d01ccc23046544f4e36ba",
38
+ "gitSha": "d07b12b0d9e2420d77cb9b7212b836e588b03e1d",
40
39
  "scripts": {
41
40
  "test": "jest"
42
41
  }
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),