@mui/codemod 5.2.0 → 5.2.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/codemod.js
CHANGED
|
File without changes
|
|
@@ -9,6 +9,7 @@ function propsToObject({
|
|
|
9
9
|
j,
|
|
10
10
|
root,
|
|
11
11
|
componentName,
|
|
12
|
+
aliasName,
|
|
12
13
|
propName,
|
|
13
14
|
props
|
|
14
15
|
}) {
|
|
@@ -20,30 +21,41 @@ function propsToObject({
|
|
|
20
21
|
return value;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
propValue = buildObject(node, propValue);
|
|
30
|
-
delete attributes[index];
|
|
24
|
+
const result = aliasName ? root.find(j.JSXElement, {
|
|
25
|
+
openingElement: {
|
|
26
|
+
name: {
|
|
27
|
+
property: {
|
|
28
|
+
name: componentName
|
|
29
|
+
}
|
|
31
30
|
}
|
|
32
|
-
}
|
|
31
|
+
}
|
|
32
|
+
}) : root.findJSXElements(componentName);
|
|
33
|
+
return result.forEach(path => {
|
|
34
|
+
if (!aliasName || aliasName && path.node.openingElement.name.object.name === aliasName) {
|
|
35
|
+
let propValue = [];
|
|
36
|
+
const attributes = path.node.openingElement.attributes;
|
|
37
|
+
attributes.forEach((node, index) => {
|
|
38
|
+
// Only transform whitelisted props
|
|
39
|
+
if (node.type === 'JSXAttribute' && props.includes(node.name.name)) {
|
|
40
|
+
propValue = buildObject(node, propValue);
|
|
41
|
+
delete attributes[index];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
if (propValue.length > 0) {
|
|
46
|
+
const propNameAttr = attributes.find(attr => {
|
|
47
|
+
var _attr$name;
|
|
37
48
|
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
return (attr == null ? void 0 : (_attr$name = attr.name) == null ? void 0 : _attr$name.name) === propName;
|
|
50
|
+
});
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
if (propNameAttr) {
|
|
53
|
+
var _propNameAttr$value$e;
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
(((_propNameAttr$value$e = propNameAttr.value.expression) == null ? void 0 : _propNameAttr$value$e.properties) || []).push(...j.objectExpression(propValue).properties);
|
|
56
|
+
} else {
|
|
57
|
+
attributes.push(j.jsxAttribute(j.jsxIdentifier(propName), j.jsxExpressionContainer(j.objectExpression(propValue))));
|
|
58
|
+
}
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
});
|
|
@@ -21,9 +21,20 @@ function transformer(file, api, options) {
|
|
|
21
21
|
const printOptions = options.printOptions || {
|
|
22
22
|
quote: 'single'
|
|
23
23
|
};
|
|
24
|
+
let aliasName;
|
|
25
|
+
root.find(j.ImportDeclaration).forEach(path => {
|
|
26
|
+
if (path.node.source.value.match(/^(@mui\/material|@material-ui\/core)$/)) {
|
|
27
|
+
var _path$node$specifiers;
|
|
28
|
+
|
|
29
|
+
if (((_path$node$specifiers = path.node.specifiers[0]) == null ? void 0 : _path$node$specifiers.type) === 'ImportNamespaceSpecifier') {
|
|
30
|
+
aliasName = path.node.specifiers[0].local.name;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
24
34
|
return (0, _propsToObject.default)({
|
|
25
35
|
j,
|
|
26
36
|
root,
|
|
37
|
+
aliasName,
|
|
27
38
|
componentName: 'Box',
|
|
28
39
|
propName: 'sx',
|
|
29
40
|
props
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var UI = _interopRequireWildcard(require("@material-ui/core"));
|
|
4
|
+
|
|
5
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
var _UI$Box;
|
|
8
|
+
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
+
|
|
13
|
+
const Foo = () => _UI$Box || (_UI$Box = /*#__PURE__*/(0, _jsxRuntime.jsx)(UI.Box, {
|
|
14
|
+
px: 2
|
|
15
|
+
}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var UI = _interopRequireWildcard(require("@material-ui/core"));
|
|
4
|
+
|
|
5
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
+
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
|
|
11
|
+
const Foo = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(UI.Box, {
|
|
12
|
+
sx: {
|
|
13
|
+
px: 2
|
|
14
|
+
}
|
|
15
|
+
});
|