@mui/x-codemod 9.0.0-alpha.3 → 9.0.0-rc.0
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/CHANGELOG.md +384 -1
- package/README.md +248 -1
- package/package.json +3 -3
- package/util/renameClasses.js +93 -0
- package/v9.0.0/charts/preset-safe/index.js +5 -1
- package/v9.0.0/charts/remove-deprecated-series-types/index.js +206 -0
- package/v9.0.0/charts/remove-is-bar-series-helpers/index.js +98 -0
- package/v9.0.0/charts/remove-stabilized-experimentalFeatures/index.js +41 -0
- package/v9.0.0/charts/rename-classes/index.js +148 -0
- package/v9.0.0/charts/rename-voronoi-max-radius/index.js +38 -0
- package/v9.0.0/data-grid/remove-stabilized-experimentalFeatures/index.js +41 -0
- package/v9.0.0/pickers/preset-safe/index.js +29 -0
- package/v9.0.0/pickers/remove-disable-margin/index.js +134 -0
- package/v9.0.0/pickers/remove-enable-accessible-field-dom-structure/index.js +72 -0
- package/v9.0.0/pickers/remove-picker-day-2/index.js +155 -0
- package/v9.0.0/pickers/rename-field-ref/index.js +94 -0
- package/v9.0.0/pickers/rename-picker-classes/index.js +126 -0
- package/v9.0.0/pickers/rename-picker-day-2/index.js +105 -0
- package/v9.0.0/pickers/rename-pickers-day/index.js +90 -0
- package/v9.0.0/preset-safe/index.js +2 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.renameClasses = renameClasses;
|
|
7
|
+
/**
|
|
8
|
+
* Renames classes objects and their properties.
|
|
9
|
+
*
|
|
10
|
+
* Handles:
|
|
11
|
+
* - Root imports: `import { lineElementClasses } from '@mui/x-charts'`
|
|
12
|
+
* - Nested imports: `import { lineElementClasses } from '@mui/x-charts/LineChart'`
|
|
13
|
+
* - Aliases: `import { lineElementClasses as lec } from '@mui/x-charts'`
|
|
14
|
+
* (renames imported name but keeps alias, still renames properties on aliased usage)
|
|
15
|
+
* - Member expression property renaming: `lineElementClasses.root` → `lineClasses.elementRoot`
|
|
16
|
+
*/
|
|
17
|
+
function renameClasses(parameters) {
|
|
18
|
+
const {
|
|
19
|
+
j,
|
|
20
|
+
root,
|
|
21
|
+
packageNames
|
|
22
|
+
} = parameters;
|
|
23
|
+
const packageRegExp = new RegExp(`^(${packageNames.join('|')})(/.*)?$`);
|
|
24
|
+
|
|
25
|
+
// Track local names → old class name, so we can rename properties on aliased usages
|
|
26
|
+
const localNameToOldClassName = {};
|
|
27
|
+
// Track non-aliased identifiers that need renaming
|
|
28
|
+
const renamedIdentifiersMap = {};
|
|
29
|
+
// Track name already added to the file
|
|
30
|
+
const alreadyAvailableIdentifiersMap = new Set();
|
|
31
|
+
const importDeclarations = root.find(j.ImportDeclaration).filter(path => {
|
|
32
|
+
const pathStr = path.node.source.value?.toString() ?? '';
|
|
33
|
+
return !!pathStr.match(packageRegExp);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Rename import specifiers and collect local names for property renaming
|
|
37
|
+
importDeclarations.find(j.ImportSpecifier).filter(path => parameters.classes.hasOwnProperty(path.node.imported.name)).forEach(path => {
|
|
38
|
+
const oldName = path.node.imported.name;
|
|
39
|
+
const config = parameters.classes[oldName];
|
|
40
|
+
const localName = path.node.local?.name;
|
|
41
|
+
const hasAlias = localName !== oldName;
|
|
42
|
+
|
|
43
|
+
// Track the local name for property renaming
|
|
44
|
+
localNameToOldClassName[hasAlias ? localName : oldName] = oldName;
|
|
45
|
+
renamedIdentifiersMap[oldName] = config.newClassName;
|
|
46
|
+
if (!hasAlias && alreadyAvailableIdentifiersMap.has(config.newClassName)) {
|
|
47
|
+
const importDeclarationCollection = j(path).closest(j.ImportDeclaration);
|
|
48
|
+
path.prune();
|
|
49
|
+
if (importDeclarationCollection.length > 0) {
|
|
50
|
+
const importDeclaration = importDeclarationCollection.nodes()[0];
|
|
51
|
+
if (importDeclaration.specifiers?.length === 0) {
|
|
52
|
+
importDeclarationCollection.remove();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
alreadyAvailableIdentifiersMap.add(config.newClassName);
|
|
58
|
+
if (hasAlias) {
|
|
59
|
+
// Keep the alias, only rename the imported name
|
|
60
|
+
path.replace(j.importSpecifier(j.identifier(config.newClassName), j.identifier(localName)));
|
|
61
|
+
} else {
|
|
62
|
+
path.replace(j.importSpecifier(j.identifier(config.newClassName)));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Rename member expression properties (e.g., lineElementClasses.root → lineClasses.elementRoot)
|
|
67
|
+
root.find(j.MemberExpression).filter(path => {
|
|
68
|
+
if (path.node.object.type !== 'Identifier') {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const objectName = path.node.object.name;
|
|
72
|
+
if (!localNameToOldClassName.hasOwnProperty(objectName)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (path.node.property.type !== 'Identifier') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const oldClassName = localNameToOldClassName[objectName];
|
|
79
|
+
return parameters.classes[oldClassName].properties.hasOwnProperty(path.node.property.name);
|
|
80
|
+
}).replaceWith(path => {
|
|
81
|
+
const objectName = path.node.object.name;
|
|
82
|
+
const oldPropertyName = path.node.property.name;
|
|
83
|
+
const oldClassName = localNameToOldClassName[objectName];
|
|
84
|
+
const newPropertyName = parameters.classes[oldClassName].properties[oldPropertyName];
|
|
85
|
+
return j.memberExpression(path.node.object, j.identifier(newPropertyName));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Rename identifier usages (non-aliased)
|
|
89
|
+
root.find(j.Identifier).filter(path => renamedIdentifiersMap.hasOwnProperty(path.node.name)).replaceWith(path => {
|
|
90
|
+
return j.identifier(renamedIdentifiersMap[path.node.name]);
|
|
91
|
+
});
|
|
92
|
+
return root;
|
|
93
|
+
}
|
|
@@ -15,9 +15,13 @@ var replaceHeatmapHideLegend = _interopRequireWildcard(require("../replace-heatm
|
|
|
15
15
|
var renameSankeyChart = _interopRequireWildcard(require("../rename-sankey-chart"));
|
|
16
16
|
var replaceShowMarkDefault = _interopRequireWildcard(require("../replace-show-mark-default"));
|
|
17
17
|
var removeEnableKeyboardNavigation = _interopRequireWildcard(require("../remove-enable-keyboard-navigation"));
|
|
18
|
+
var removeStabilizedExperimentalFeatures = _interopRequireWildcard(require("../remove-stabilized-experimentalFeatures"));
|
|
19
|
+
var renameVoronoiMaxRadius = _interopRequireWildcard(require("../rename-voronoi-max-radius"));
|
|
20
|
+
var removeDeprecatedSeriesTypes = _interopRequireWildcard(require("../remove-deprecated-series-types"));
|
|
21
|
+
var removeIsBarSeriesHelpers = _interopRequireWildcard(require("../remove-is-bar-series-helpers"));
|
|
18
22
|
const allModules = [
|
|
19
23
|
// Add other transforms here as they are created
|
|
20
|
-
replaceHeatmapHideLegend, replaceShowMarkDefault, removeEnableKeyboardNavigation, renameIdToSeriesId, renameChartApiImport, renameSankeyChart, renameChartContainer, renameChartDataProvider, renameChartZoomSlider];
|
|
24
|
+
replaceHeatmapHideLegend, replaceShowMarkDefault, removeEnableKeyboardNavigation, removeStabilizedExperimentalFeatures, renameIdToSeriesId, renameChartApiImport, renameSankeyChart, renameChartContainer, renameChartDataProvider, renameChartZoomSlider, renameVoronoiMaxRadius, removeDeprecatedSeriesTypes, removeIsBarSeriesHelpers];
|
|
21
25
|
function transformer(file, api, options) {
|
|
22
26
|
allModules.forEach(module => {
|
|
23
27
|
file.source = module.default(file, api, options);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
11
|
+
// Maps from removed type to the replacement info
|
|
12
|
+
const REMOVED_TYPES = {
|
|
13
|
+
CartesianSeriesType: {
|
|
14
|
+
baseType: 'AllSeriesType',
|
|
15
|
+
genericType: 'CartesianChartSeriesType'
|
|
16
|
+
},
|
|
17
|
+
DefaultizedCartesianSeriesType: {
|
|
18
|
+
baseType: 'DefaultizedSeriesType',
|
|
19
|
+
genericType: 'CartesianChartSeriesType'
|
|
20
|
+
},
|
|
21
|
+
StackableSeriesType: {
|
|
22
|
+
baseType: 'DefaultizedSeriesType',
|
|
23
|
+
genericType: 'StackableChartSeriesType'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const REMOVED_TYPE_NAMES = Object.keys(REMOVED_TYPES);
|
|
27
|
+
function transformer(file, api, options) {
|
|
28
|
+
const j = api.jscodeshift;
|
|
29
|
+
const root = j(file.source);
|
|
30
|
+
const printOptions = options.printOptions || {
|
|
31
|
+
quote: 'single',
|
|
32
|
+
trailingComma: true,
|
|
33
|
+
wrapColumn: 40
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Track local names for removed types and the source they came from
|
|
37
|
+
const removedTypeLocalNames = {};
|
|
38
|
+
let originalImportSource = null;
|
|
39
|
+
|
|
40
|
+
// Find and remove imports of deprecated types
|
|
41
|
+
const packageRegex = /^@mui\/x-charts(-pro|-premium)?(\/(models|internals))?$/;
|
|
42
|
+
root.find(j.ImportDeclaration).forEach(astPath => {
|
|
43
|
+
const source = astPath.node.source.value?.toString() ?? '';
|
|
44
|
+
if (!packageRegex.test(source)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const specifiers = astPath.node.specifiers || [];
|
|
48
|
+
const remainingSpecifiers = [];
|
|
49
|
+
specifiers.forEach(specifier => {
|
|
50
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
51
|
+
const importedName = specifier.imported.name.toString();
|
|
52
|
+
if (REMOVED_TYPE_NAMES.includes(importedName)) {
|
|
53
|
+
// Track the local name used for this import
|
|
54
|
+
const localName = specifier.local?.name.toString() || importedName;
|
|
55
|
+
removedTypeLocalNames[localName] = importedName;
|
|
56
|
+
// Track the original import source (use the first one found)
|
|
57
|
+
if (!originalImportSource) {
|
|
58
|
+
originalImportSource = source;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
remainingSpecifiers.push(specifier);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
remainingSpecifiers.push(specifier);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (remainingSpecifiers.length === 0) {
|
|
68
|
+
// Remove the entire import declaration if no specifiers remain
|
|
69
|
+
j(astPath).remove();
|
|
70
|
+
} else if (remainingSpecifiers.length !== specifiers.length) {
|
|
71
|
+
// Update the import declaration with remaining specifiers
|
|
72
|
+
astPath.node.specifiers = remainingSpecifiers;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// If no relevant imports were found, return the source unchanged to avoid reformatting
|
|
77
|
+
if (Object.keys(removedTypeLocalNames).length === 0) {
|
|
78
|
+
return file.source;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Replace type references with the new types
|
|
82
|
+
// We need to add the necessary imports if they're not already present
|
|
83
|
+
const typesToImport = new Set();
|
|
84
|
+
const genericTypesToImport = new Set();
|
|
85
|
+
Object.entries(removedTypeLocalNames).forEach(([localName, originalName]) => {
|
|
86
|
+
const replacementInfo = REMOVED_TYPES[originalName];
|
|
87
|
+
if (!replacementInfo) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Find all usages of the type as a type reference
|
|
92
|
+
root.find(j.TSTypeReference).forEach(astPath => {
|
|
93
|
+
if (astPath.node.typeName.type === 'Identifier' && astPath.node.typeName.name === localName) {
|
|
94
|
+
typesToImport.add(replacementInfo.baseType);
|
|
95
|
+
genericTypesToImport.add(replacementInfo.genericType);
|
|
96
|
+
|
|
97
|
+
// Replace with the generic type: e.g., AllSeriesType<CartesianChartSeriesType>
|
|
98
|
+
const newTypeReference = j.tsTypeReference(j.identifier(replacementInfo.baseType), j.tsTypeParameterInstantiation([j.tsTypeReference(j.identifier(replacementInfo.genericType))]));
|
|
99
|
+
j(astPath).replaceWith(newTypeReference);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Helper to check if a type is already imported from a given package pattern
|
|
105
|
+
const isAlreadyImported = (typeName, sourcePattern) => {
|
|
106
|
+
return root.find(j.ImportSpecifier, {
|
|
107
|
+
imported: {
|
|
108
|
+
name: typeName
|
|
109
|
+
}
|
|
110
|
+
}).filter(specPath => {
|
|
111
|
+
const importDecl = specPath.parentPath.parentPath;
|
|
112
|
+
const source = importDecl.node.source.value?.toString() ?? '';
|
|
113
|
+
return sourcePattern.test(source);
|
|
114
|
+
}).size() > 0;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Collect all types that need to be added to imports
|
|
118
|
+
const allTypesToAdd = new Set([...typesToImport, ...genericTypesToImport]);
|
|
119
|
+
const typesToAdd = Array.from(allTypesToAdd).filter(typeName => !isAlreadyImported(typeName, packageRegex));
|
|
120
|
+
|
|
121
|
+
// Determine where to add types - use original source or default to same pattern
|
|
122
|
+
// If original was '@mui/x-charts', add to '@mui/x-charts'
|
|
123
|
+
// If original was '@mui/x-charts/models', add to '@mui/x-charts/models'
|
|
124
|
+
const importSource = originalImportSource || '@mui/x-charts/models';
|
|
125
|
+
|
|
126
|
+
// Merge duplicate import declarations from the same source before adding new types.
|
|
127
|
+
// Previous codemods may have split imports, leaving multiple declarations from the same source.
|
|
128
|
+
const importsBySource = new Map();
|
|
129
|
+
root.find(j.ImportDeclaration).forEach(astPath => {
|
|
130
|
+
const source = astPath.node.source.value?.toString() ?? '';
|
|
131
|
+
if (!packageRegex.test(source)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!importsBySource.has(source)) {
|
|
135
|
+
importsBySource.set(source, []);
|
|
136
|
+
}
|
|
137
|
+
importsBySource.get(source).push(astPath);
|
|
138
|
+
});
|
|
139
|
+
importsBySource.forEach(paths => {
|
|
140
|
+
if (paths.length <= 1) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Collect all specifiers from all declarations, deduplicating by name
|
|
145
|
+
const allSpecifiers = [];
|
|
146
|
+
const seenNames = new Set();
|
|
147
|
+
paths.forEach(importPath => {
|
|
148
|
+
(importPath.node.specifiers || []).forEach(specifier => {
|
|
149
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
150
|
+
const name = specifier.imported.name.toString();
|
|
151
|
+
if (!seenNames.has(name)) {
|
|
152
|
+
seenNames.add(name);
|
|
153
|
+
allSpecifiers.push(specifier);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
allSpecifiers.push(specifier);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Keep the first declaration with all specifiers, remove the rest
|
|
162
|
+
paths[0].node.specifiers = allSpecifiers;
|
|
163
|
+
for (let i = 1; i < paths.length; i += 1) {
|
|
164
|
+
j(paths[i]).remove();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Add all replacement types to the same import source as the original
|
|
169
|
+
if (typesToAdd.length > 0) {
|
|
170
|
+
const existingImport = root.find(j.ImportDeclaration, {
|
|
171
|
+
source: {
|
|
172
|
+
value: importSource
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
if (existingImport.size() > 0) {
|
|
176
|
+
// Add to the existing import
|
|
177
|
+
const specifiers = existingImport.at(0).get().node.specifiers || [];
|
|
178
|
+
typesToAdd.forEach(typeName => {
|
|
179
|
+
specifiers.push(j.importSpecifier(j.identifier(typeName)));
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
// Create new import
|
|
183
|
+
const newImport = j.importDeclaration(typesToAdd.map(typeName => j.importSpecifier(j.identifier(typeName))), j.stringLiteral(importSource));
|
|
184
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
185
|
+
if (firstImport.size() > 0) {
|
|
186
|
+
firstImport.insertBefore(newImport);
|
|
187
|
+
} else {
|
|
188
|
+
root.get().node.program.body.unshift(newImport);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return root.toSource(printOptions);
|
|
193
|
+
}
|
|
194
|
+
const testConfig = () => ({
|
|
195
|
+
name: 'remove-deprecated-series-types',
|
|
196
|
+
specFiles: [{
|
|
197
|
+
name: 'root-imports',
|
|
198
|
+
actual: (0, _readFile.default)(_nodePath.default.join(__dirname, 'actual-root-imports.spec.tsx')),
|
|
199
|
+
expected: (0, _readFile.default)(_nodePath.default.join(__dirname, 'expected-root-imports.spec.tsx'))
|
|
200
|
+
}, {
|
|
201
|
+
name: 'nested-imports',
|
|
202
|
+
actual: (0, _readFile.default)(_nodePath.default.join(__dirname, 'actual-nested-imports.spec.tsx')),
|
|
203
|
+
expected: (0, _readFile.default)(_nodePath.default.join(__dirname, 'expected-nested-imports.spec.tsx'))
|
|
204
|
+
}]
|
|
205
|
+
});
|
|
206
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
11
|
+
const REMOVED_FUNCTIONS = ['isBarSeries', 'isDefaultizedBarSeries'];
|
|
12
|
+
function transformer(file, api, options) {
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const printOptions = options.printOptions || {
|
|
16
|
+
quote: 'single',
|
|
17
|
+
trailingComma: true,
|
|
18
|
+
wrapColumn: 40
|
|
19
|
+
};
|
|
20
|
+
const importedFunctions = {};
|
|
21
|
+
|
|
22
|
+
// Find and remove imports of isBarSeries and isDefaultizedBarSeries
|
|
23
|
+
const packageRegex = /^@mui\/x-charts(-pro|-premium)?(\/(models|internals))?$/;
|
|
24
|
+
root.find(j.ImportDeclaration).forEach(astPath => {
|
|
25
|
+
const source = astPath.node.source.value?.toString() ?? '';
|
|
26
|
+
if (!packageRegex.test(source)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const specifiers = astPath.node.specifiers || [];
|
|
30
|
+
const remainingSpecifiers = [];
|
|
31
|
+
specifiers.forEach(specifier => {
|
|
32
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
33
|
+
const importedName = specifier.imported.name.toString();
|
|
34
|
+
if (REMOVED_FUNCTIONS.includes(importedName)) {
|
|
35
|
+
// Track the local name used for this import
|
|
36
|
+
const localName = specifier.local?.name.toString() || importedName;
|
|
37
|
+
importedFunctions[localName] = importedName;
|
|
38
|
+
} else {
|
|
39
|
+
remainingSpecifiers.push(specifier);
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
remainingSpecifiers.push(specifier);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (remainingSpecifiers.length === 0) {
|
|
46
|
+
// Remove the entire import declaration if no specifiers remain
|
|
47
|
+
j(astPath).remove();
|
|
48
|
+
} else if (remainingSpecifiers.length !== specifiers.length) {
|
|
49
|
+
// Update the import declaration with remaining specifiers
|
|
50
|
+
astPath.node.specifiers = remainingSpecifiers;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// If no relevant imports were found, return the source unchanged to avoid reformatting
|
|
55
|
+
if (Object.keys(importedFunctions).length === 0) {
|
|
56
|
+
return file.source;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Replace function calls with series.type === 'bar'
|
|
60
|
+
// isBarSeries(series) -> series.type === 'bar'
|
|
61
|
+
// isDefaultizedBarSeries(series) -> series.type === 'bar'
|
|
62
|
+
Object.keys(importedFunctions).forEach(localName => {
|
|
63
|
+
root.find(j.CallExpression, {
|
|
64
|
+
callee: {
|
|
65
|
+
type: 'Identifier',
|
|
66
|
+
name: localName
|
|
67
|
+
}
|
|
68
|
+
}).replaceWith(astPath => {
|
|
69
|
+
const args = astPath.node.arguments;
|
|
70
|
+
if (args.length !== 1) {
|
|
71
|
+
// If not exactly 1 argument, keep as-is (shouldn't happen)
|
|
72
|
+
return astPath.node;
|
|
73
|
+
}
|
|
74
|
+
const arg = args[0];
|
|
75
|
+
if (arg.type === 'SpreadElement') {
|
|
76
|
+
// Can't handle spread elements
|
|
77
|
+
return astPath.node;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Create: arg.type === 'bar'
|
|
81
|
+
return j.binaryExpression('===', j.memberExpression(arg, j.identifier('type')), j.stringLiteral('bar'));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return root.toSource(printOptions);
|
|
85
|
+
}
|
|
86
|
+
const testConfig = () => ({
|
|
87
|
+
name: 'remove-is-bar-series-helpers',
|
|
88
|
+
specFiles: [{
|
|
89
|
+
name: 'root-imports',
|
|
90
|
+
actual: (0, _readFile.default)(_nodePath.default.join(__dirname, 'actual-root-imports.spec.tsx')),
|
|
91
|
+
expected: (0, _readFile.default)(_nodePath.default.join(__dirname, 'expected-root-imports.spec.tsx'))
|
|
92
|
+
}, {
|
|
93
|
+
name: 'nested-imports',
|
|
94
|
+
actual: (0, _readFile.default)(_nodePath.default.join(__dirname, 'actual-nested-imports.spec.tsx')),
|
|
95
|
+
expected: (0, _readFile.default)(_nodePath.default.join(__dirname, 'expected-nested-imports.spec.tsx'))
|
|
96
|
+
}]
|
|
97
|
+
});
|
|
98
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _removeObjectProperty = _interopRequireDefault(require("../../../util/removeObjectProperty"));
|
|
11
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
12
|
+
const componentsNames = ['BarChart', 'LineChart', 'PieChart', 'ScatterChart', 'SparkLineChart', 'RadarChart', 'ChartsContainer', 'ChartsDataProvider', 'BarChartPro', 'LineChartPro', 'PieChartPro', 'ScatterChartPro', 'RadarChartPro', 'FunnelChart', 'Heatmap', 'SankeyChart', 'BarChartPremium', 'HeatmapPremium', 'ChartDataProvider', 'ChartDataProviderPro', 'ChartDataProviderPremium', 'ChartsDataProviderPro', 'ChartsDataProviderPremium'];
|
|
13
|
+
const propName = 'experimentalFeatures';
|
|
14
|
+
const propKeys = ['preferStrictDomainInLineCharts'];
|
|
15
|
+
function transformer(file, api, options) {
|
|
16
|
+
const j = api.jscodeshift;
|
|
17
|
+
const root = j(file.source);
|
|
18
|
+
const printOptions = options.printOptions || {
|
|
19
|
+
quote: 'single',
|
|
20
|
+
trailingComma: true
|
|
21
|
+
};
|
|
22
|
+
propKeys.forEach(propKey => {
|
|
23
|
+
(0, _removeObjectProperty.default)({
|
|
24
|
+
root,
|
|
25
|
+
j,
|
|
26
|
+
propName,
|
|
27
|
+
componentsNames,
|
|
28
|
+
propKey
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return root.toSource(printOptions);
|
|
32
|
+
}
|
|
33
|
+
const testConfig = () => ({
|
|
34
|
+
name: 'remove-stabilized-experimentalFeatures',
|
|
35
|
+
specFiles: [{
|
|
36
|
+
name: 'remove preferStrictDomainInLineCharts from experimentalFeatures',
|
|
37
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual.spec.tsx')),
|
|
38
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected.spec.tsx'))
|
|
39
|
+
}]
|
|
40
|
+
});
|
|
41
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
11
|
+
var _renameClasses = require("../../../util/renameClasses");
|
|
12
|
+
function transformer(file, api, options) {
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const printOptions = options.printOptions || {
|
|
16
|
+
quote: 'single',
|
|
17
|
+
trailingComma: true
|
|
18
|
+
};
|
|
19
|
+
(0, _renameClasses.renameClasses)({
|
|
20
|
+
j,
|
|
21
|
+
root,
|
|
22
|
+
packageNames: ['@mui/x-charts', '@mui/x-charts-pro', '@mui/x-charts-premium'],
|
|
23
|
+
classes: {
|
|
24
|
+
barElementClasses: {
|
|
25
|
+
newClassName: 'barClasses',
|
|
26
|
+
properties: {
|
|
27
|
+
root: 'element'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
barLabelClasses: {
|
|
31
|
+
newClassName: 'barClasses',
|
|
32
|
+
properties: {
|
|
33
|
+
root: 'label',
|
|
34
|
+
animate: 'labelAnimate'
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
pieArcClasses: {
|
|
38
|
+
newClassName: 'pieClasses',
|
|
39
|
+
properties: {
|
|
40
|
+
root: 'arc'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
pieArcLabelClasses: {
|
|
44
|
+
newClassName: 'pieClasses',
|
|
45
|
+
properties: {
|
|
46
|
+
root: 'arcLabel'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
radarSeriesPlotClasses: {
|
|
50
|
+
newClassName: 'radarClasses',
|
|
51
|
+
properties: {
|
|
52
|
+
root: 'seriesRoot',
|
|
53
|
+
area: 'seriesArea',
|
|
54
|
+
mark: 'seriesMark'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
areaElementClasses: {
|
|
58
|
+
newClassName: 'lineClasses',
|
|
59
|
+
properties: {
|
|
60
|
+
root: 'area'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
lineElementClasses: {
|
|
64
|
+
newClassName: 'lineClasses',
|
|
65
|
+
properties: {
|
|
66
|
+
root: 'line'
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
markElementClasses: {
|
|
70
|
+
newClassName: 'lineClasses',
|
|
71
|
+
properties: {
|
|
72
|
+
root: 'mark',
|
|
73
|
+
animate: 'markAnimate'
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
lineHighlightElementClasses: {
|
|
77
|
+
newClassName: 'lineClasses',
|
|
78
|
+
properties: {
|
|
79
|
+
root: 'highlight'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
funnelSectionClasses: {
|
|
83
|
+
newClassName: 'funnelClasses',
|
|
84
|
+
properties: {
|
|
85
|
+
root: 'section',
|
|
86
|
+
filled: 'sectionFilled',
|
|
87
|
+
outlined: 'sectionOutlined',
|
|
88
|
+
label: 'sectionLabel'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
sankeyPlotClasses: {
|
|
92
|
+
newClassName: 'sankeyClasses',
|
|
93
|
+
properties: {}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Classes that had same name as cartesian classes but only for radar charts.
|
|
99
|
+
(0, _renameClasses.renameClasses)({
|
|
100
|
+
j,
|
|
101
|
+
root,
|
|
102
|
+
packageNames: ['@mui/x-charts/RadarChart', '@mui/x-charts-pro/RadarChart', '@mui/x-charts-premium/RadarChart'],
|
|
103
|
+
classes: {
|
|
104
|
+
chartsAxisHighlightClasses: {
|
|
105
|
+
newClassName: 'radarClasses',
|
|
106
|
+
properties: {
|
|
107
|
+
root: 'axisHighlightRoot',
|
|
108
|
+
line: 'axisHighlightLine',
|
|
109
|
+
dot: 'axisHighlightDot'
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
chartsAxisClasses: {
|
|
113
|
+
newClassName: 'radarClasses',
|
|
114
|
+
properties: {
|
|
115
|
+
root: 'axisRoot',
|
|
116
|
+
line: 'axisLine',
|
|
117
|
+
label: 'axisLabel'
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
chartsGridClasses: {
|
|
121
|
+
newClassName: 'radarClasses',
|
|
122
|
+
properties: {
|
|
123
|
+
radial: 'gridRadial',
|
|
124
|
+
divider: 'gridDivider',
|
|
125
|
+
stripe: 'gridStripe'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return root.toSource(printOptions);
|
|
131
|
+
}
|
|
132
|
+
const testConfig = () => ({
|
|
133
|
+
name: 'rename-classes',
|
|
134
|
+
specFiles: [{
|
|
135
|
+
name: 'rename barElementClasses to barClasses',
|
|
136
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual-imports.spec.tsx')),
|
|
137
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected-imports.spec.tsx'))
|
|
138
|
+
}, {
|
|
139
|
+
name: 'rename radar-specific classes only when imported from RadarChart',
|
|
140
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual-radar-imports.spec.tsx')),
|
|
141
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected-radar-imports.spec.tsx'))
|
|
142
|
+
}, {
|
|
143
|
+
name: 'do not rename radar-specific classes when imported from root package',
|
|
144
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual-not-radar-imports.spec.tsx')),
|
|
145
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected-not-radar-imports.spec.tsx'))
|
|
146
|
+
}]
|
|
147
|
+
});
|
|
148
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
11
|
+
var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
12
|
+
function transformer(file, api, options) {
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const printOptions = options.printOptions || {
|
|
16
|
+
quote: 'single',
|
|
17
|
+
trailingComma: true
|
|
18
|
+
};
|
|
19
|
+
(0, _renameProps.default)({
|
|
20
|
+
j,
|
|
21
|
+
root,
|
|
22
|
+
componentNames: ['ScatterChart', 'ScatterChartPro', 'SparkLineChart', 'ChartsContainer', 'ChartContainer', 'ChartDataProvider', 'ChartsDataProvider', 'ChartDataProviderPro', 'ChartsDataProviderPro', 'ChartDataProviderPremium', 'ChartsDataProviderPremium'],
|
|
23
|
+
props: {
|
|
24
|
+
voronoiMaxRadius: 'hitAreaRadius',
|
|
25
|
+
disableVoronoi: 'disableHitArea'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return root.toSource(printOptions);
|
|
29
|
+
}
|
|
30
|
+
const testConfig = () => ({
|
|
31
|
+
name: 'rename-voronoi-max-radius',
|
|
32
|
+
specFiles: [{
|
|
33
|
+
name: 'rename voronoiMaxRadius to hitAreaRadius and disableVoronoi to disableHitArea',
|
|
34
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual-imports.spec.tsx')),
|
|
35
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected-imports.spec.tsx'))
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
exports.testConfig = testConfig;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
exports.testConfig = void 0;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _removeObjectProperty = _interopRequireDefault(require("../../../util/removeObjectProperty"));
|
|
11
|
+
var _readFile = _interopRequireDefault(require("../../../util/readFile"));
|
|
12
|
+
const componentsNames = ['DataGridPremium'];
|
|
13
|
+
const propName = 'experimentalFeatures';
|
|
14
|
+
const propKeys = ['charts'];
|
|
15
|
+
function transformer(file, api, options) {
|
|
16
|
+
const j = api.jscodeshift;
|
|
17
|
+
const root = j(file.source);
|
|
18
|
+
const printOptions = options.printOptions || {
|
|
19
|
+
quote: 'single',
|
|
20
|
+
trailingComma: true
|
|
21
|
+
};
|
|
22
|
+
propKeys.forEach(propKey => {
|
|
23
|
+
(0, _removeObjectProperty.default)({
|
|
24
|
+
root,
|
|
25
|
+
j,
|
|
26
|
+
propName,
|
|
27
|
+
componentsNames,
|
|
28
|
+
propKey
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return root.toSource(printOptions);
|
|
32
|
+
}
|
|
33
|
+
const testConfig = () => ({
|
|
34
|
+
name: 'remove-stabilized-experimentalFeatures',
|
|
35
|
+
specFiles: [{
|
|
36
|
+
name: 'remove charts from experimentalFeatures',
|
|
37
|
+
actual: (0, _readFile.default)(_path.default.join(__dirname, 'actual.spec.tsx')),
|
|
38
|
+
expected: (0, _readFile.default)(_path.default.join(__dirname, 'expected.spec.tsx'))
|
|
39
|
+
}]
|
|
40
|
+
});
|
|
41
|
+
exports.testConfig = testConfig;
|