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

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 +2 -2
  2. package/src/index.js +12 -1
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.2",
3
+ "version": "1.0.4-canary.3",
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",
@@ -35,7 +35,7 @@
35
35
  "babel-plugin"
36
36
  ],
37
37
  "homepage": "https://github.com/mui/mui-public",
38
- "gitSha": "d07b12b0d9e2420d77cb9b7212b836e588b03e1d",
38
+ "gitSha": "01a4b2c7a0dbc772ca3a8d8d458fec5e301ed3d6",
39
39
  "scripts": {
40
40
  "test": "jest"
41
41
  }
package/src/index.js CHANGED
@@ -17,6 +17,10 @@ const DEFAULT_ALLOWED_CALLEES = {
17
17
  const calleeModuleMapping = new Map(); // Mapping of callee name to module name
18
18
  const seenDisplayNames = new Set();
19
19
 
20
+ /**
21
+ * Applies allowed callees mapping to the internal calleeModuleMapping.
22
+ * @param {Record<string, string[]>} mapping - The mapping of module names to method names.
23
+ */
20
24
  function applyAllowedCallees(mapping) {
21
25
  Object.entries(mapping).forEach(([moduleName, methodNames]) => {
22
26
  methodNames.forEach((methodName) => {
@@ -335,6 +339,7 @@ function generateDisplayName(t, componentIdentifiers) {
335
339
  *
336
340
  * @param {babel.types} t content of @babel/types package
337
341
  * @param {babel.Node} node identifier or member expression node
342
+ * @returns {string}
338
343
  */
339
344
  function generateNodeDisplayName(t, node) {
340
345
  if (t.isIdentifier(node)) {
@@ -448,10 +453,15 @@ function createMemberExpression(t, componentIdentifiers) {
448
453
  * `name` will be changed to ensure that it is unique within the scope. e.g. `helper` -> `_helper`
449
454
  *
450
455
  * @param {babel.types} t content of @babel/types package
456
+ * @param {babel.NodePath<babel.types.ArrowFunctionExpression | babel.types.CallExpression | babel.types.FunctionExpression | babel.types.ObjectMethod>} path path to the function node
451
457
  * @param {string} name name of function to follow after
452
458
  */
453
459
  function setInternalFunctionName(t, path, name) {
454
- if (!name || path.node.id != null || path.node.key != null) {
460
+ if (
461
+ !name ||
462
+ ('id' in path.node && path.node.id != null) ||
463
+ ('key' in path.node && path.node.key != null)
464
+ ) {
455
465
  return;
456
466
  }
457
467
 
@@ -459,5 +469,6 @@ function setInternalFunctionName(t, path, name) {
459
469
  if (path.isArrowFunctionExpression()) {
460
470
  path.arrowFunctionToExpression();
461
471
  }
472
+ // @ts-expect-error
462
473
  path.node.id = id;
463
474
  }