@atlaskit/textfield 6.3.1 → 6.4.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 +593 -582
- package/__perf__/examples.tsx +34 -37
- package/codemods/5.0.0-lite-mode.tsx +5 -8
- package/codemods/__tests__/5.0.0-lite-mode.tsx +14 -14
- package/codemods/__tests__/remove-imports.tsx +29 -31
- package/codemods/__tests__/remove-prop.tsx +28 -28
- package/codemods/__tests__/rename-disabled-to-isdisabled.tsx +28 -28
- package/codemods/__tests__/rename-imports.tsx +45 -48
- package/codemods/migrations/remove-imports.tsx +3 -3
- package/codemods/migrations/rename-disabled-to-isdisabled.tsx +1 -5
- package/codemods/migrations/rename-imports.tsx +8 -8
- package/codemods/migrations/utils.tsx +279 -320
- package/dist/cjs/text-field.js +8 -2
- package/dist/es2019/text-field.js +9 -2
- package/dist/esm/text-field.js +9 -2
- package/dist/types/text-field.d.ts +4 -1
- package/dist/types/types.d.ts +1 -1
- package/dist/types-ts4.5/text-field.d.ts +4 -1
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/package.json +92 -94
- package/report.api.md +21 -23
|
@@ -1,376 +1,335 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
type API,
|
|
3
|
+
type ASTPath,
|
|
4
|
+
type default as core,
|
|
5
|
+
type FileInfo,
|
|
6
|
+
type Identifier,
|
|
7
|
+
type ImportDeclaration,
|
|
8
|
+
type ImportSpecifier,
|
|
9
|
+
type JSXAttribute,
|
|
10
|
+
type Options,
|
|
11
|
+
type Program,
|
|
11
12
|
} from 'jscodeshift';
|
|
12
|
-
import { Collection } from 'jscodeshift/src/Collection';
|
|
13
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
13
14
|
|
|
14
15
|
export type Nullable<T> = T | null;
|
|
15
16
|
|
|
16
|
-
export function getDefaultSpecifier(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
.find(j.ImportDefaultSpecifier);
|
|
28
|
-
|
|
29
|
-
if (!specifiers.length) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
17
|
+
export function getDefaultSpecifier(j: core.JSCodeshift, source: any, specifier: string) {
|
|
18
|
+
const specifiers = source
|
|
19
|
+
.find(j.ImportDeclaration)
|
|
20
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
21
|
+
.find(j.ImportDefaultSpecifier);
|
|
22
|
+
|
|
23
|
+
if (!specifiers.length) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
33
27
|
}
|
|
34
28
|
export function getNamedSpecifier(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
j: core.JSCodeshift,
|
|
30
|
+
source: any,
|
|
31
|
+
specifier: string,
|
|
32
|
+
importName: string,
|
|
39
33
|
) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
if (!specifiers.length) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
34
|
+
const specifiers = source
|
|
35
|
+
.find(j.ImportDeclaration)
|
|
36
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
37
|
+
.find(j.ImportSpecifier)
|
|
38
|
+
.filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
|
|
39
|
+
|
|
40
|
+
if (!specifiers.length) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
56
44
|
}
|
|
57
45
|
|
|
58
46
|
export function getJSXAttributesByName(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
j: core.JSCodeshift,
|
|
48
|
+
element: ASTPath<any>,
|
|
49
|
+
attributeName: string,
|
|
62
50
|
): Collection<JSXAttribute> {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
return j(element)
|
|
52
|
+
.find(j.JSXOpeningElement)
|
|
53
|
+
.find(j.JSXAttribute)
|
|
54
|
+
.filter((attribute) => {
|
|
55
|
+
const matches = j(attribute)
|
|
56
|
+
.find(j.JSXIdentifier)
|
|
57
|
+
.filter((identifier) => identifier.value.name === attributeName);
|
|
58
|
+
return Boolean(matches.length);
|
|
59
|
+
});
|
|
72
60
|
}
|
|
73
61
|
|
|
74
|
-
export function hasImportDeclaration(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
typeof path.node.source.value === 'string' &&
|
|
84
|
-
path.node.source.value.startsWith(importPath),
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return Boolean(imports.length);
|
|
62
|
+
export function hasImportDeclaration(j: core.JSCodeshift, source: any, importPath: string) {
|
|
63
|
+
const imports = source
|
|
64
|
+
.find(j.ImportDeclaration)
|
|
65
|
+
.filter(
|
|
66
|
+
(path: ASTPath<ImportDeclaration>) =>
|
|
67
|
+
typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return Boolean(imports.length);
|
|
88
71
|
}
|
|
89
72
|
// not replacing newlines (which \s does)
|
|
90
73
|
const spacesAndTabs: RegExp = /[ \t]{2,}/g;
|
|
91
74
|
const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
|
|
92
75
|
|
|
93
76
|
function clean(value: string): string {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
77
|
+
return (
|
|
78
|
+
value
|
|
79
|
+
.replace(spacesAndTabs, ' ')
|
|
80
|
+
.replace(lineStartWithSpaces, '')
|
|
81
|
+
// using .trim() to clear the any newlines before the first text and after last text
|
|
82
|
+
.trim()
|
|
83
|
+
);
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
export function addCommentToStartOfFile({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
87
|
+
j,
|
|
88
|
+
base,
|
|
89
|
+
message,
|
|
107
90
|
}: {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
91
|
+
j: core.JSCodeshift;
|
|
92
|
+
base: Collection<Node>;
|
|
93
|
+
message: string;
|
|
111
94
|
}) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
addCommentBefore({
|
|
96
|
+
j,
|
|
97
|
+
target: base.find(j.Program),
|
|
98
|
+
message,
|
|
99
|
+
});
|
|
117
100
|
}
|
|
118
101
|
|
|
119
102
|
export function addCommentBefore({
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
j,
|
|
104
|
+
target,
|
|
105
|
+
message,
|
|
123
106
|
}: {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
107
|
+
j: core.JSCodeshift;
|
|
108
|
+
target: Collection<Program> | Collection<ImportDeclaration>;
|
|
109
|
+
message: string;
|
|
127
110
|
}) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
const content: string = ` TODO: (from codemod) ${clean(message)} `;
|
|
112
|
+
target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
|
|
113
|
+
path.value.comments = path.value.comments || [];
|
|
131
114
|
|
|
132
|
-
|
|
133
|
-
(comment) => comment.value === content,
|
|
134
|
-
);
|
|
115
|
+
const exists = path.value.comments.find((comment) => comment.value === content);
|
|
135
116
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
// avoiding duplicates of the same comment
|
|
118
|
+
if (exists) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
140
121
|
|
|
141
|
-
|
|
142
|
-
|
|
122
|
+
path.value.comments.push(j.commentBlock(content));
|
|
123
|
+
});
|
|
143
124
|
}
|
|
144
125
|
|
|
145
126
|
export function doesIdentifierExist({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
127
|
+
j,
|
|
128
|
+
base,
|
|
129
|
+
name,
|
|
149
130
|
}: {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
131
|
+
j: core.JSCodeshift;
|
|
132
|
+
base: Collection<any>;
|
|
133
|
+
name: string;
|
|
153
134
|
}): boolean {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
);
|
|
135
|
+
return (
|
|
136
|
+
base
|
|
137
|
+
.find(j.Identifier)
|
|
138
|
+
.filter((identifer: ASTPath<Identifier>) => identifer.value.name === name).length > 0
|
|
139
|
+
);
|
|
160
140
|
}
|
|
161
141
|
|
|
162
142
|
export function getSafeImportName({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
143
|
+
j,
|
|
144
|
+
base,
|
|
145
|
+
currentDefaultSpecifierName,
|
|
146
|
+
desiredName,
|
|
147
|
+
fallbackName,
|
|
168
148
|
}: {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
149
|
+
j: core.JSCodeshift;
|
|
150
|
+
base: Collection<any>;
|
|
151
|
+
currentDefaultSpecifierName: string;
|
|
152
|
+
desiredName: string;
|
|
153
|
+
fallbackName: string;
|
|
174
154
|
}) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
155
|
+
if (currentDefaultSpecifierName === desiredName) {
|
|
156
|
+
return desiredName;
|
|
157
|
+
}
|
|
178
158
|
|
|
179
|
-
|
|
159
|
+
const isUsed: boolean = doesIdentifierExist({ j, base, name: desiredName });
|
|
180
160
|
|
|
181
|
-
|
|
161
|
+
return isUsed ? fallbackName : desiredName;
|
|
182
162
|
}
|
|
183
163
|
|
|
184
164
|
export const createRemoveFuncFor =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
165
|
+
(component: string, prop: string, comment?: string) =>
|
|
166
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
167
|
+
const defaultSpecifier = getDefaultSpecifier(j, source, component);
|
|
168
|
+
|
|
169
|
+
if (!defaultSpecifier) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
source.findJSXElements(defaultSpecifier).forEach((element) => {
|
|
174
|
+
getJSXAttributesByName(j, element, prop).forEach((attribute) => {
|
|
175
|
+
j(attribute).remove();
|
|
176
|
+
if (comment) {
|
|
177
|
+
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
};
|
|
202
182
|
|
|
203
183
|
export const createRemoveImportsFor =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
.find(j.ImportSpecifier)
|
|
287
|
-
.remove();
|
|
288
|
-
}
|
|
289
|
-
};
|
|
184
|
+
({
|
|
185
|
+
importsToRemove,
|
|
186
|
+
packagePath,
|
|
187
|
+
comment,
|
|
188
|
+
}: {
|
|
189
|
+
importsToRemove: string[];
|
|
190
|
+
packagePath: string;
|
|
191
|
+
comment: string;
|
|
192
|
+
}) =>
|
|
193
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
194
|
+
const isUsingName: boolean =
|
|
195
|
+
source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
|
|
196
|
+
.length > 0;
|
|
197
|
+
if (!isUsingName) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const existingAliases: Nullable<string>[] =
|
|
202
|
+
source
|
|
203
|
+
.find(j.ImportDeclaration)
|
|
204
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
205
|
+
.find(j.ImportSpecifier)
|
|
206
|
+
.nodes()
|
|
207
|
+
.map((specifier): Nullable<string> => {
|
|
208
|
+
if (!importsToRemove.includes(specifier.imported.name)) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
// If aliased: return the alias
|
|
212
|
+
if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
|
|
213
|
+
return specifier.local.name;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return null;
|
|
217
|
+
})
|
|
218
|
+
.filter(Boolean) || null;
|
|
219
|
+
|
|
220
|
+
// Add comments
|
|
221
|
+
source
|
|
222
|
+
.find(j.ImportDeclaration)
|
|
223
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
224
|
+
.find(j.ImportSpecifier)
|
|
225
|
+
.filter((importSpecifier) => {
|
|
226
|
+
const identifier = j(importSpecifier).find(j.Identifier).get();
|
|
227
|
+
if (
|
|
228
|
+
importsToRemove.includes(identifier.value.name) ||
|
|
229
|
+
existingAliases.includes(identifier.value.name)
|
|
230
|
+
) {
|
|
231
|
+
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
})
|
|
236
|
+
.remove();
|
|
237
|
+
|
|
238
|
+
// Remove entire import if it is empty
|
|
239
|
+
const isEmptyNamedImport =
|
|
240
|
+
source
|
|
241
|
+
.find(j.ImportDeclaration)
|
|
242
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
243
|
+
.find(j.ImportSpecifier)
|
|
244
|
+
.find(j.Identifier).length === 0;
|
|
245
|
+
|
|
246
|
+
if (isEmptyNamedImport) {
|
|
247
|
+
const isEmptyDefaultImport =
|
|
248
|
+
source
|
|
249
|
+
.find(j.ImportDeclaration)
|
|
250
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
251
|
+
.find(j.ImportDefaultSpecifier)
|
|
252
|
+
.find(j.Identifier).length === 0;
|
|
253
|
+
|
|
254
|
+
isEmptyDefaultImport
|
|
255
|
+
? source
|
|
256
|
+
.find(j.ImportDeclaration)
|
|
257
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
258
|
+
.remove()
|
|
259
|
+
: source
|
|
260
|
+
.find(j.ImportDeclaration)
|
|
261
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
262
|
+
.find(j.ImportSpecifier)
|
|
263
|
+
.remove();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
290
266
|
|
|
291
267
|
export const createRenameJSXFunc =
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return true;
|
|
347
|
-
}
|
|
348
|
-
return false;
|
|
349
|
-
})
|
|
350
|
-
.replaceWith(
|
|
351
|
-
[
|
|
352
|
-
j.importSpecifier(
|
|
353
|
-
j.identifier(toName),
|
|
354
|
-
existingAlias ? j.identifier(existingAlias) : null,
|
|
355
|
-
),
|
|
356
|
-
],
|
|
357
|
-
j.literal(packagePath),
|
|
358
|
-
);
|
|
359
|
-
};
|
|
268
|
+
(packagePath: string, from: string, to: string, fallback: string | undefined = undefined) =>
|
|
269
|
+
(j: core.JSCodeshift, source: any) => {
|
|
270
|
+
const namedSpecifier = getNamedSpecifier(j, source, packagePath, from);
|
|
271
|
+
|
|
272
|
+
const toName = fallback
|
|
273
|
+
? getSafeImportName({
|
|
274
|
+
j,
|
|
275
|
+
base: source,
|
|
276
|
+
currentDefaultSpecifierName: namedSpecifier,
|
|
277
|
+
desiredName: to,
|
|
278
|
+
fallbackName: fallback,
|
|
279
|
+
})
|
|
280
|
+
: to;
|
|
281
|
+
|
|
282
|
+
const existingAlias: Nullable<string> =
|
|
283
|
+
source
|
|
284
|
+
.find(j.ImportDeclaration)
|
|
285
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === packagePath)
|
|
286
|
+
.find(j.ImportSpecifier)
|
|
287
|
+
.nodes()
|
|
288
|
+
.map((specifier: ImportSpecifier): Nullable<string> => {
|
|
289
|
+
if (from !== specifier.imported.name) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
// If aliased: return the alias
|
|
293
|
+
if (specifier.local && from !== specifier.local.name) {
|
|
294
|
+
return specifier.local.name;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return null;
|
|
298
|
+
})
|
|
299
|
+
.filter(Boolean)[0] || null;
|
|
300
|
+
|
|
301
|
+
source
|
|
302
|
+
.find(j.ImportDeclaration)
|
|
303
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === packagePath)
|
|
304
|
+
.find(j.ImportSpecifier)
|
|
305
|
+
.filter((importSpecifier: ImportSpecifier) => {
|
|
306
|
+
const identifier = j(importSpecifier).find(j.Identifier).get();
|
|
307
|
+
if (from === identifier.value.name || existingAlias === identifier.value.name) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
})
|
|
312
|
+
.replaceWith(
|
|
313
|
+
[
|
|
314
|
+
j.importSpecifier(
|
|
315
|
+
j.identifier(toName),
|
|
316
|
+
existingAlias ? j.identifier(existingAlias) : null,
|
|
317
|
+
),
|
|
318
|
+
],
|
|
319
|
+
j.literal(packagePath),
|
|
320
|
+
);
|
|
321
|
+
};
|
|
360
322
|
|
|
361
323
|
export const createTransformer =
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
) =>
|
|
366
|
-
(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
|
|
367
|
-
const source: Collection<Node> = j(fileInfo.source);
|
|
324
|
+
(component: string, migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[]) =>
|
|
325
|
+
(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
|
|
326
|
+
const source: Collection<Node> = j(fileInfo.source);
|
|
368
327
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
328
|
+
if (!hasImportDeclaration(j, source, component)) {
|
|
329
|
+
return fileInfo.source;
|
|
330
|
+
}
|
|
372
331
|
|
|
373
|
-
|
|
332
|
+
migrates.forEach((tf) => tf(j, source));
|
|
374
333
|
|
|
375
|
-
|
|
376
|
-
|
|
334
|
+
return source.toSource(options.printOptions || { quote: 'single' });
|
|
335
|
+
};
|