@atlaskit/codemod-utils 4.1.3 → 4.2.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 +6 -0
- package/dist/cjs/index.js +29 -31
- package/dist/cjs/utils/index.js +185 -279
- package/dist/cjs/utils/support.js +113 -209
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/utils/index.js +12 -44
- package/dist/es2019/utils/support.js +26 -68
- package/dist/es2019/version.json +1 -1
- package/dist/esm/utils/index.js +12 -44
- package/dist/esm/utils/support.js +32 -77
- package/dist/esm/version.json +1 -1
- package/package.json +5 -9
- package/report.api.md +31 -13
- package/dist/types-ts4.0/index.d.ts +0 -2
- package/dist/types-ts4.0/utils/index.d.ts +0 -15
- package/dist/types-ts4.0/utils/support.d.ts +0 -47
package/dist/cjs/utils/index.js
CHANGED
|
@@ -4,325 +4,231 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.replaceImportStatementFor = exports.renameNamedImportWithAliasName = exports.flattenCertainChildPropsAsProp = exports.elevateComponentToNewEntryPoint = exports.createTransformer = exports.createRenameJSXFunc = exports.createRenameImportFor = exports.createRenameFuncFor = exports.createRemoveFuncFor = exports.createRemoveFuncAddCommentFor = exports.createConvertFuncFor = exports.changeImportEntryPoint = void 0;
|
|
7
|
-
|
|
8
7
|
var _support = require("./support");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
const createRemoveFuncFor = (component, importName, prop, predicate = () => true, comment) => (j, source) => {
|
|
9
|
+
const specifier = (0, _support.getNamedSpecifier)(j, source, component, importName);
|
|
10
|
+
if (!specifier) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
source.findJSXElements(specifier).forEach(element => {
|
|
14
|
+
if (predicate(j, element) && comment) {
|
|
15
|
+
(0, _support.addCommentToStartOfFile)({
|
|
16
|
+
j,
|
|
17
|
+
base: source,
|
|
18
|
+
message: comment
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
(0, _support.getJSXAttributesByName)(j, element, prop).forEach(attribute => {
|
|
22
|
+
j(attribute).remove();
|
|
23
|
+
});
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
source.findJSXElements(specifier).forEach(function (element) {
|
|
23
|
-
if (predicate(j, element) && comment) {
|
|
24
|
-
(0, _support.addCommentToStartOfFile)({
|
|
25
|
-
j: j,
|
|
26
|
-
base: source,
|
|
27
|
-
message: comment
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
(0, _support.getJSXAttributesByName)(j, element, prop).forEach(function (attribute) {
|
|
31
|
-
j(attribute).remove();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
25
|
+
});
|
|
36
26
|
};
|
|
37
|
-
|
|
38
27
|
exports.createRemoveFuncFor = createRemoveFuncFor;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
source.findJSXElements(defaultSpecifier).forEach(function (element) {
|
|
49
|
-
(0, _support.getJSXAttributesByName)(j, element, from).forEach(function (attribute) {
|
|
50
|
-
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
|
|
51
|
-
});
|
|
28
|
+
const createRenameFuncFor = (component, from, to) => (j, source) => {
|
|
29
|
+
const defaultSpecifier = (0, _support.getDefaultSpecifier)(j, source, component);
|
|
30
|
+
if (!defaultSpecifier) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
source.findJSXElements(defaultSpecifier).forEach(element => {
|
|
34
|
+
(0, _support.getJSXAttributesByName)(j, element, from).forEach(attribute => {
|
|
35
|
+
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
|
|
52
36
|
});
|
|
53
|
-
};
|
|
37
|
+
});
|
|
54
38
|
};
|
|
55
|
-
|
|
56
39
|
exports.createRenameFuncFor = createRenameFuncFor;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var node = j.jsxAttribute(j.jsxIdentifier(to));
|
|
70
|
-
|
|
71
|
-
if (shouldConvert) {
|
|
72
|
-
j(attribute).insertBefore(node);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
40
|
+
const createConvertFuncFor = (component, from, to, predicate) => (j, source) => {
|
|
41
|
+
const defaultSpecifier = (0, _support.getDefaultSpecifier)(j, source, component);
|
|
42
|
+
if (!defaultSpecifier) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
source.findJSXElements(defaultSpecifier).forEach(element => {
|
|
46
|
+
(0, _support.getJSXAttributesByName)(j, element, from).forEach(attribute => {
|
|
47
|
+
const shouldConvert = predicate && predicate(attribute.node.value) || false;
|
|
48
|
+
const node = j.jsxAttribute(j.jsxIdentifier(to));
|
|
49
|
+
if (shouldConvert) {
|
|
50
|
+
j(attribute).insertBefore(node);
|
|
51
|
+
}
|
|
75
52
|
});
|
|
76
|
-
};
|
|
53
|
+
});
|
|
77
54
|
};
|
|
78
|
-
|
|
79
55
|
exports.createConvertFuncFor = createConvertFuncFor;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
j(path).replaceWith(defaultDeclarations);
|
|
96
|
-
var otherDeclarations = otherSpecifier.map(function (s) {
|
|
97
|
-
var localName = s.local.name;
|
|
98
|
-
|
|
99
|
-
if (convertMap[localName]) {
|
|
100
|
-
return j.importDeclaration([j.importDefaultSpecifier(j.identifier(localName))], j.literal(convertMap[localName]));
|
|
101
|
-
} else {
|
|
102
|
-
return j.importDeclaration([j.importDefaultSpecifier(j.identifier(localName))], j.literal(convertMap['*']));
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
j(path).insertAfter(otherDeclarations);
|
|
56
|
+
const replaceImportStatementFor = (pkg, convertMap) => (j, root) => {
|
|
57
|
+
root.find(j.ImportDeclaration).filter(path => path.node.source.value === pkg).forEach(path => {
|
|
58
|
+
const defaultSpecifier = (path.value.specifiers || []).filter(specifier => specifier.type === 'ImportDefaultSpecifier');
|
|
59
|
+
const defaultDeclarations = defaultSpecifier.map(s => {
|
|
60
|
+
return j.importDeclaration([s], j.literal(convertMap['default']));
|
|
61
|
+
});
|
|
62
|
+
const otherSpecifier = (path.value.specifiers || []).filter(specifier => specifier.type === 'ImportSpecifier');
|
|
63
|
+
j(path).replaceWith(defaultDeclarations);
|
|
64
|
+
const otherDeclarations = otherSpecifier.map(s => {
|
|
65
|
+
const localName = s.local.name;
|
|
66
|
+
if (convertMap[localName]) {
|
|
67
|
+
return j.importDeclaration([j.importDefaultSpecifier(j.identifier(localName))], j.literal(convertMap[localName]));
|
|
68
|
+
} else {
|
|
69
|
+
return j.importDeclaration([j.importDefaultSpecifier(j.identifier(localName))], j.literal(convertMap['*']));
|
|
70
|
+
}
|
|
106
71
|
});
|
|
107
|
-
|
|
72
|
+
j(path).insertAfter(otherDeclarations);
|
|
73
|
+
});
|
|
108
74
|
};
|
|
109
|
-
|
|
110
75
|
exports.replaceImportStatementFor = replaceImportStatementFor;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return path.node.source.value === component;
|
|
116
|
-
}).forEach(function (path) {
|
|
117
|
-
j(path).replaceWith(j.importDeclaration(path.value.specifiers, j.literal(to)));
|
|
118
|
-
});
|
|
119
|
-
};
|
|
76
|
+
const createRenameImportFor = (component, from, to) => (j, source) => {
|
|
77
|
+
source.find(j.ImportDeclaration).filter(path => path.node.source.value === component).forEach(path => {
|
|
78
|
+
j(path).replaceWith(j.importDeclaration(path.value.specifiers, j.literal(to)));
|
|
79
|
+
});
|
|
120
80
|
};
|
|
121
|
-
|
|
122
81
|
exports.createRenameImportFor = createRenameImportFor;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return fileInfo.source;
|
|
137
|
-
};
|
|
82
|
+
const createTransformer = (migrates, shouldApplyTransform) => (fileInfo, {
|
|
83
|
+
jscodeshift: j
|
|
84
|
+
}, options) => {
|
|
85
|
+
const source = j(fileInfo.source);
|
|
86
|
+
|
|
87
|
+
// If shouldApplyTransform not provided then perform old behaviour
|
|
88
|
+
if (!shouldApplyTransform || shouldApplyTransform(j, source)) {
|
|
89
|
+
migrates.forEach(tf => tf(j, source));
|
|
90
|
+
return source.toSource(options.printOptions);
|
|
91
|
+
}
|
|
92
|
+
return fileInfo.source;
|
|
138
93
|
};
|
|
139
|
-
|
|
140
94
|
exports.createTransformer = createTransformer;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
importDeclarations.forEach(function (path) {
|
|
160
|
-
j(path).replaceWith(newDefaultSpecifier);
|
|
161
|
-
j(path).insertBefore(newOtherSpecifiers);
|
|
162
|
-
});
|
|
163
|
-
};
|
|
95
|
+
const elevateComponentToNewEntryPoint = (pkg, toPkg, innerElementName) => (j, root) => {
|
|
96
|
+
const importDeclarations = root.find(j.ImportDeclaration).filter(path => path.node.source.value === pkg);
|
|
97
|
+
const defaultSpecifier = importDeclarations.find(j.ImportDefaultSpecifier).nodes();
|
|
98
|
+
const otherSpecifier = importDeclarations.find(j.ImportSpecifier).nodes();
|
|
99
|
+
const newDefaultSpecifier = defaultSpecifier.map(s => {
|
|
100
|
+
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(pkg));
|
|
101
|
+
});
|
|
102
|
+
const newOtherSpecifiers = otherSpecifier.map(s => {
|
|
103
|
+
if (s.imported.name === innerElementName) {
|
|
104
|
+
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(toPkg));
|
|
105
|
+
} else {
|
|
106
|
+
return j.importDeclaration([s], j.literal(pkg));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
importDeclarations.forEach(path => {
|
|
110
|
+
j(path).replaceWith(newDefaultSpecifier);
|
|
111
|
+
j(path).insertBefore(newOtherSpecifiers);
|
|
112
|
+
});
|
|
164
113
|
};
|
|
165
|
-
|
|
166
114
|
exports.elevateComponentToNewEntryPoint = elevateComponentToNewEntryPoint;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if ((property.type === 'Property' || property.type === 'ObjectProperty') && property.key.type === 'Identifier' && property.key.name === childProp) {
|
|
182
|
-
var _element$node$opening;
|
|
183
|
-
|
|
184
|
-
(_element$node$opening = element.node.openingElement.attributes) === null || _element$node$opening === void 0 ? void 0 : _element$node$opening.push(j.jsxAttribute(j.jsxIdentifier(childProp), j.jsxExpressionContainer(property.value)));
|
|
185
|
-
}
|
|
186
|
-
});
|
|
115
|
+
const flattenCertainChildPropsAsProp = (component, propName, childProps) => (j, source) => {
|
|
116
|
+
const defaultSpecifier = (0, _support.getDefaultSpecifier)(j, source, component);
|
|
117
|
+
if (!defaultSpecifier) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
source.findJSXElements(defaultSpecifier).forEach(element => {
|
|
121
|
+
(0, _support.getJSXAttributesByName)(j, element, propName).forEach(attribute => {
|
|
122
|
+
j(attribute).find(j.JSXExpressionContainer).find(j.ObjectExpression).forEach(objectExpression => {
|
|
123
|
+
objectExpression.node.properties.forEach(property => {
|
|
124
|
+
childProps.forEach(childProp => {
|
|
125
|
+
if ((property.type === 'Property' || property.type === 'ObjectProperty') && property.key.type === 'Identifier' && property.key.name === childProp) {
|
|
126
|
+
var _element$node$opening;
|
|
127
|
+
(_element$node$opening = element.node.openingElement.attributes) === null || _element$node$opening === void 0 ? void 0 : _element$node$opening.push(j.jsxAttribute(j.jsxIdentifier(childProp), j.jsxExpressionContainer(property.value)));
|
|
128
|
+
}
|
|
187
129
|
});
|
|
188
130
|
});
|
|
189
131
|
});
|
|
190
132
|
});
|
|
191
|
-
};
|
|
133
|
+
});
|
|
192
134
|
};
|
|
193
|
-
|
|
194
135
|
exports.flattenCertainChildPropsAsProp = flattenCertainChildPropsAsProp;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}) : to;
|
|
207
|
-
var existingAlias = source.find(j.ImportDeclaration).filter(function (path) {
|
|
208
|
-
return path.node.source.value === packagePath;
|
|
209
|
-
}).find(j.ImportSpecifier).nodes().map(function (specifier) {
|
|
210
|
-
if (from !== specifier.imported.name) {
|
|
211
|
-
return null;
|
|
212
|
-
} // If aliased: return the alias
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (specifier.local && from !== specifier.local.name) {
|
|
216
|
-
return specifier.local.name;
|
|
217
|
-
}
|
|
218
|
-
|
|
136
|
+
const createRenameJSXFunc = (packagePath, from, to, fallback = undefined) => (j, source) => {
|
|
137
|
+
const namedSpecifier = (0, _support.getNamedSpecifier)(j, source, packagePath, from);
|
|
138
|
+
const toName = fallback ? (0, _support.getSafeImportName)({
|
|
139
|
+
j,
|
|
140
|
+
base: source,
|
|
141
|
+
currentDefaultSpecifierName: namedSpecifier,
|
|
142
|
+
desiredName: to,
|
|
143
|
+
fallbackName: fallback
|
|
144
|
+
}) : to;
|
|
145
|
+
const existingAlias = source.find(j.ImportDeclaration).filter(path => path.node.source.value === packagePath).find(j.ImportSpecifier).nodes().map(specifier => {
|
|
146
|
+
if (from !== specifier.imported.name) {
|
|
219
147
|
return null;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return
|
|
231
|
-
}
|
|
232
|
-
|
|
148
|
+
}
|
|
149
|
+
// If aliased: return the alias
|
|
150
|
+
if (specifier.local && from !== specifier.local.name) {
|
|
151
|
+
return specifier.local.name;
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}).filter(Boolean)[0] || null;
|
|
155
|
+
source.find(j.ImportDeclaration).filter(path => path.node.source.value === packagePath).find(j.ImportSpecifier).filter(importSpecifier => {
|
|
156
|
+
const identifier = j(importSpecifier).find(j.Identifier).get();
|
|
157
|
+
if (from === identifier.value.name || existingAlias === identifier.value.name) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}).replaceWith([j.importSpecifier(j.identifier(toName), existingAlias ? j.identifier(existingAlias) : null)], j.literal(packagePath));
|
|
233
162
|
};
|
|
234
|
-
|
|
235
163
|
exports.createRenameJSXFunc = createRenameJSXFunc;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
j: j,
|
|
252
|
-
base: source,
|
|
253
|
-
message: comment
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
});
|
|
164
|
+
const createRemoveFuncAddCommentFor = (component, prop, comment) => (j, source) => {
|
|
165
|
+
const defaultSpecifier = (0, _support.getDefaultSpecifier)(j, source, component);
|
|
166
|
+
if (!defaultSpecifier) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
source.findJSXElements(defaultSpecifier).forEach(element => {
|
|
170
|
+
(0, _support.getJSXAttributesByName)(j, element, prop).forEach(attribute => {
|
|
171
|
+
j(attribute).remove();
|
|
172
|
+
if (comment) {
|
|
173
|
+
(0, _support.addCommentToStartOfFile)({
|
|
174
|
+
j,
|
|
175
|
+
base: source,
|
|
176
|
+
message: comment
|
|
177
|
+
});
|
|
178
|
+
}
|
|
257
179
|
});
|
|
258
|
-
};
|
|
180
|
+
});
|
|
259
181
|
};
|
|
260
|
-
|
|
261
182
|
exports.createRemoveFuncAddCommentFor = createRemoveFuncAddCommentFor;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}).find(j.ImportSpecifier).filter(function (path) {
|
|
268
|
-
return path.node.imported.name === from;
|
|
269
|
-
}).forEach(function (path) {
|
|
270
|
-
var localName = path.node.local.name;
|
|
271
|
-
j(path).replaceWith(j.importSpecifier(j.identifier(to), j.identifier(localName)));
|
|
272
|
-
});
|
|
273
|
-
};
|
|
183
|
+
const renameNamedImportWithAliasName = (component, from, to) => (j, source) => {
|
|
184
|
+
source.find(j.ImportDeclaration).filter(path => path.node.source.value === component).find(j.ImportSpecifier).filter(path => path.node.imported.name === from).forEach(path => {
|
|
185
|
+
const localName = path.node.local.name;
|
|
186
|
+
j(path).replaceWith(j.importSpecifier(j.identifier(to), j.identifier(localName)));
|
|
187
|
+
});
|
|
274
188
|
};
|
|
275
|
-
|
|
276
189
|
exports.renameNamedImportWithAliasName = renameNamedImportWithAliasName;
|
|
190
|
+
const changeImportEntryPoint = (oldPackageName, importToConvert, newPackageName, shouldBeTypeImport) => (j, root) => {
|
|
191
|
+
root.find(j.ImportDeclaration, {
|
|
192
|
+
source: {
|
|
193
|
+
value: oldPackageName
|
|
194
|
+
}
|
|
195
|
+
}).forEach(path => {
|
|
196
|
+
var _currentImportSpecifi;
|
|
197
|
+
const currentImportSpecifier = (path.value.specifiers || []).find(specifier => {
|
|
198
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
199
|
+
return specifier.imported.name === importToConvert;
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
});
|
|
203
|
+
if (!currentImportSpecifier) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const importedSpecifierName = currentImportSpecifier.imported.name;
|
|
207
|
+
const localSpecifierName = (_currentImportSpecifi = currentImportSpecifier.local) === null || _currentImportSpecifi === void 0 ? void 0 : _currentImportSpecifi.name;
|
|
208
|
+
const newIdentifier = j.importSpecifier(j.identifier(importedSpecifierName), localSpecifierName ? j.identifier(localSpecifierName) : undefined);
|
|
277
209
|
|
|
278
|
-
|
|
279
|
-
|
|
210
|
+
// check if new import exists, if not create it
|
|
211
|
+
(0, _support.tryCreateImport)(j, root, oldPackageName, newPackageName, shouldBeTypeImport);
|
|
212
|
+
|
|
213
|
+
// remove the old import specifier, but NOT the whole package
|
|
280
214
|
root.find(j.ImportDeclaration, {
|
|
281
215
|
source: {
|
|
282
216
|
value: oldPackageName
|
|
283
217
|
}
|
|
284
|
-
}).
|
|
285
|
-
var _currentImportSpecifi;
|
|
286
|
-
|
|
287
|
-
var currentImportSpecifier = (path.value.specifiers || []).find(function (specifier) {
|
|
288
|
-
if (specifier.type === 'ImportSpecifier') {
|
|
289
|
-
return specifier.imported.name === importToConvert;
|
|
290
|
-
}
|
|
218
|
+
}).find(j.ImportSpecifier).filter(path => path.value.imported.name === importToConvert).remove();
|
|
291
219
|
|
|
292
|
-
|
|
293
|
-
|
|
220
|
+
// adds import specifier to new import
|
|
221
|
+
(0, _support.addToImport)(j, root, newIdentifier, newPackageName);
|
|
294
222
|
|
|
295
|
-
|
|
296
|
-
|
|
223
|
+
// if there are any imports with no specifiers, remove the whole import
|
|
224
|
+
root.find(j.ImportDeclaration, {
|
|
225
|
+
source: {
|
|
226
|
+
value: oldPackageName
|
|
297
227
|
}
|
|
298
|
-
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
(0, _support.tryCreateImport)(j, root, oldPackageName, newPackageName, shouldBeTypeImport); // remove the old import specifier, but NOT the whole package
|
|
304
|
-
|
|
305
|
-
root.find(j.ImportDeclaration, {
|
|
306
|
-
source: {
|
|
307
|
-
value: oldPackageName
|
|
308
|
-
}
|
|
309
|
-
}).find(j.ImportSpecifier).filter(function (path) {
|
|
310
|
-
return path.value.imported.name === importToConvert;
|
|
311
|
-
}).remove(); // adds import specifier to new import
|
|
312
|
-
|
|
313
|
-
(0, _support.addToImport)(j, root, newIdentifier, newPackageName); // if there are any imports with no specifiers, remove the whole import
|
|
314
|
-
|
|
315
|
-
root.find(j.ImportDeclaration, {
|
|
316
|
-
source: {
|
|
317
|
-
value: oldPackageName
|
|
318
|
-
}
|
|
319
|
-
}).filter(function (path) {
|
|
320
|
-
var _path$value$specifier;
|
|
321
|
-
|
|
322
|
-
return !((_path$value$specifier = path.value.specifiers) !== null && _path$value$specifier !== void 0 && _path$value$specifier.length);
|
|
323
|
-
}).remove();
|
|
324
|
-
});
|
|
325
|
-
};
|
|
228
|
+
}).filter(path => {
|
|
229
|
+
var _path$value$specifier;
|
|
230
|
+
return !((_path$value$specifier = path.value.specifiers) !== null && _path$value$specifier !== void 0 && _path$value$specifier.length);
|
|
231
|
+
}).remove();
|
|
232
|
+
});
|
|
326
233
|
};
|
|
327
|
-
|
|
328
234
|
exports.changeImportEntryPoint = changeImportEntryPoint;
|