@mui/internal-babel-plugin-display-name 1.0.4-canary.2 → 1.0.4-canary.4
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 +6 -6
- 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.
|
|
3
|
+
"version": "1.0.4-canary.4",
|
|
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",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/helper-module-imports": "^7.27.1",
|
|
17
|
-
"@babel/helper-plugin-utils": "^7.
|
|
17
|
+
"@babel/helper-plugin-utils": "^7.27.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.
|
|
21
|
-
"@babel/preset-env": "^7.
|
|
22
|
-
"@babel/preset-react": "^7.
|
|
20
|
+
"@babel/core": "^7.28.3",
|
|
21
|
+
"@babel/preset-env": "^7.28.3",
|
|
22
|
+
"@babel/preset-react": "^7.27.1",
|
|
23
23
|
"@types/babel__core": "^7.20.5",
|
|
24
24
|
"@types/babel__helper-plugin-utils": "^7.10.3"
|
|
25
25
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"babel-plugin"
|
|
36
36
|
],
|
|
37
37
|
"homepage": "https://github.com/mui/mui-public",
|
|
38
|
-
"gitSha": "
|
|
38
|
+
"gitSha": "0cb5046984e4e05e1062ae9555e7397b60ea1972",
|
|
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 (
|
|
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
|
}
|