@atlaskit/menu 2.4.0 → 2.5.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 +20 -1
- package/__perf__/button.tsx +7 -9
- package/__perf__/custom.tsx +13 -17
- package/__perf__/link.tsx +6 -6
- package/__perf__/utils/example-runner.tsx +36 -41
- package/__perf__/utils/interaction-tasks.tsx +63 -86
- package/codemods/0.7.0-change-css-fn-prop.tsx +128 -156
- package/codemods/2.1.0-invalid-link-item-to-button-item.tsx +121 -145
- package/codemods/__tests__/0.7.0-change-css-fn-prop.tsx +77 -77
- package/codemods/__tests__/next-invalid-link-item-to-button-item.tsx +117 -117
- package/codemods/helpers/generic.tsx +528 -564
- package/dist/cjs/internal/components/menu-item-primitive.js +13 -2
- package/dist/cjs/internal/components/skeleton-shimmer.js +6 -0
- package/dist/cjs/menu-item/button-item.js +4 -0
- package/dist/cjs/menu-item/custom-item.js +8 -2
- package/dist/cjs/menu-item/heading-item.js +12 -2
- package/dist/cjs/menu-item/link-item.js +4 -0
- package/dist/cjs/menu-item/skeleton-heading-item.js +12 -1
- package/dist/cjs/menu-item/skeleton-item.js +25 -1
- package/dist/cjs/menu-section/menu-group.js +4 -0
- package/dist/cjs/menu-section/popup-menu-group.js +4 -0
- package/dist/cjs/menu-section/section.js +19 -4
- package/dist/es2019/internal/components/menu-item-primitive.js +13 -2
- package/dist/es2019/internal/components/skeleton-shimmer.js +5 -0
- package/dist/es2019/menu-item/button-item.js +5 -0
- package/dist/es2019/menu-item/custom-item.js +9 -2
- package/dist/es2019/menu-item/heading-item.js +13 -2
- package/dist/es2019/menu-item/link-item.js +5 -0
- package/dist/es2019/menu-item/skeleton-heading-item.js +11 -1
- package/dist/es2019/menu-item/skeleton-item.js +24 -1
- package/dist/es2019/menu-section/menu-group.js +4 -0
- package/dist/es2019/menu-section/popup-menu-group.js +4 -0
- package/dist/es2019/menu-section/section.js +20 -4
- package/dist/esm/internal/components/menu-item-primitive.js +13 -2
- package/dist/esm/internal/components/skeleton-shimmer.js +5 -0
- package/dist/esm/menu-item/button-item.js +5 -0
- package/dist/esm/menu-item/custom-item.js +9 -2
- package/dist/esm/menu-item/heading-item.js +13 -2
- package/dist/esm/menu-item/link-item.js +5 -0
- package/dist/esm/menu-item/skeleton-heading-item.js +11 -1
- package/dist/esm/menu-item/skeleton-item.js +24 -1
- package/dist/esm/menu-section/menu-group.js +4 -0
- package/dist/esm/menu-section/popup-menu-group.js +4 -0
- package/dist/esm/menu-section/section.js +20 -4
- package/dist/types/internal/components/skeleton-shimmer.d.ts +4 -1
- package/dist/types/menu-item/custom-item.d.ts +3 -0
- package/dist/types/menu-section/menu-group.d.ts +3 -0
- package/dist/types/menu-section/popup-menu-group.d.ts +3 -0
- package/dist/types-ts4.5/internal/components/skeleton-shimmer.d.ts +4 -1
- package/dist/types-ts4.5/menu-item/custom-item.d.ts +3 -0
- package/dist/types-ts4.5/menu-section/menu-group.d.ts +3 -0
- package/dist/types-ts4.5/menu-section/popup-menu-group.d.ts +3 -0
- package/package.json +133 -133
- package/report.api.md +130 -138
|
@@ -1,177 +1,149 @@
|
|
|
1
1
|
import { type NodePath } from 'ast-types/lib/node-path';
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
API,
|
|
4
|
+
ASTPath,
|
|
5
|
+
default as core,
|
|
6
|
+
FileInfo,
|
|
7
|
+
ImportDeclaration,
|
|
8
|
+
ImportSpecifier,
|
|
9
|
+
Options,
|
|
10
10
|
} from 'jscodeshift';
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.find(j.JSXAttribute)
|
|
25
|
-
.filter((attribute) => {
|
|
26
|
-
const matches = j(attribute)
|
|
27
|
-
.find(j.JSXIdentifier)
|
|
28
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
29
|
-
return Boolean(matches.length);
|
|
30
|
-
});
|
|
12
|
+
import { addCommentBeforeJSX, getDefaultSpecifierName } from './helpers/generic';
|
|
13
|
+
|
|
14
|
+
function getJSXAttributesByName(j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) {
|
|
15
|
+
return j(element)
|
|
16
|
+
.find(j.JSXOpeningElement)
|
|
17
|
+
.find(j.JSXAttribute)
|
|
18
|
+
.filter((attribute) => {
|
|
19
|
+
const matches = j(attribute)
|
|
20
|
+
.find(j.JSXIdentifier)
|
|
21
|
+
.filter((identifier) => identifier.value.name === attributeName);
|
|
22
|
+
return Boolean(matches.length);
|
|
23
|
+
});
|
|
31
24
|
}
|
|
32
25
|
|
|
33
26
|
function getImportSpecifier(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
j: core.JSCodeshift,
|
|
28
|
+
source: ReturnType<typeof j>,
|
|
29
|
+
specifier: string,
|
|
30
|
+
imported: string,
|
|
38
31
|
) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!specifiers.length) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
32
|
+
const specifiers = source
|
|
33
|
+
.find(j.ImportDeclaration)
|
|
34
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
35
|
+
.find(j.ImportSpecifier)
|
|
36
|
+
.filter((path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported);
|
|
37
|
+
|
|
38
|
+
if (!specifiers.length) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
55
43
|
}
|
|
56
44
|
|
|
57
|
-
function updateCssFnProp(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
cssFnExpression!.value.params.shift();
|
|
102
|
-
} catch (e) {
|
|
103
|
-
addCommentBeforeJSX(
|
|
104
|
-
j,
|
|
105
|
-
cssFnProp,
|
|
106
|
-
`
|
|
45
|
+
function updateCssFnProp(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
|
|
46
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
47
|
+
const cssFnPropCollection = getJSXAttributesByName(j, element, 'cssFn');
|
|
48
|
+
|
|
49
|
+
// no cssProp usage for this element
|
|
50
|
+
if (!cssFnPropCollection.length) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cssFnProp = cssFnPropCollection.get();
|
|
55
|
+
|
|
56
|
+
const cssFnExpression: NodePath = j(cssFnProp)
|
|
57
|
+
.find(j.JSXExpressionContainer)
|
|
58
|
+
.find(j.Expression)
|
|
59
|
+
.get();
|
|
60
|
+
|
|
61
|
+
if (cssFnExpression) {
|
|
62
|
+
// just remove the state styles param
|
|
63
|
+
try {
|
|
64
|
+
const [stylePropName] = cssFnExpression!.value.params;
|
|
65
|
+
j(cssFnExpression)
|
|
66
|
+
.find(j.SpreadElement)
|
|
67
|
+
.forEach((n) => {
|
|
68
|
+
// discerns whether there are multiple identifiers here
|
|
69
|
+
const isComplexIdentifier = j(n).find(j.Identifier).length > 1;
|
|
70
|
+
|
|
71
|
+
if (isComplexIdentifier) {
|
|
72
|
+
throw new Error('CSSFn Prop codemod: Unable to parse spread element');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hasStyleProp = !!j(n)
|
|
76
|
+
.find(j.Identifier)
|
|
77
|
+
.filter((node) => node.value.name === stylePropName.name).length;
|
|
78
|
+
if (hasStyleProp) {
|
|
79
|
+
j(n).remove();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
cssFnExpression!.value.params.shift();
|
|
84
|
+
} catch (e) {
|
|
85
|
+
addCommentBeforeJSX(
|
|
86
|
+
j,
|
|
87
|
+
cssFnProp,
|
|
88
|
+
`
|
|
107
89
|
The usage of the 'cssFn' prop in this component could not be transformed and requires manual intervention.
|
|
108
90
|
The 'cssFn' prop has been simplified so that users no longer need to merge the inherited styles with their own overrides.
|
|
109
91
|
For more info please reach out to #help-design-system-code.
|
|
110
92
|
`,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
115
97
|
}
|
|
116
98
|
|
|
117
99
|
function hasImportDeclaration(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
100
|
+
j: core.JSCodeshift,
|
|
101
|
+
source: ReturnType<typeof j>,
|
|
102
|
+
importPath: string,
|
|
121
103
|
) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.filter((path) => path.node.source.value === importPath).length;
|
|
104
|
+
return !!source.find(j.ImportDeclaration).filter((path) => path.node.source.value === importPath)
|
|
105
|
+
.length;
|
|
125
106
|
}
|
|
126
107
|
|
|
127
|
-
export default function transformer(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return source.toSource(
|
|
169
|
-
options.printOptions || {
|
|
170
|
-
quote: 'single',
|
|
171
|
-
trailingComma: true,
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return fileInfo.source;
|
|
108
|
+
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
109
|
+
const source = j(fileInfo.source);
|
|
110
|
+
|
|
111
|
+
if (hasImportDeclaration(j, source, '@atlaskit/menu')) {
|
|
112
|
+
const defaultSpecifier = getDefaultSpecifierName({
|
|
113
|
+
j,
|
|
114
|
+
base: source,
|
|
115
|
+
packageName: '@atlaskit/menu',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (defaultSpecifier != null) {
|
|
119
|
+
updateCssFnProp(j, source, defaultSpecifier);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
[
|
|
123
|
+
'ButtonItem',
|
|
124
|
+
'LinkItem',
|
|
125
|
+
'CustomItem',
|
|
126
|
+
'HeadingItem',
|
|
127
|
+
'SkeletonItem',
|
|
128
|
+
'SkeletonHeadingItem',
|
|
129
|
+
'MenuGroup',
|
|
130
|
+
'PopupMenuGroup',
|
|
131
|
+
'Section',
|
|
132
|
+
].forEach((pkg) => {
|
|
133
|
+
const importSpecifier = getImportSpecifier(j, source, '@atlaskit/menu', pkg);
|
|
134
|
+
|
|
135
|
+
if (importSpecifier != null) {
|
|
136
|
+
updateCssFnProp(j, source, importSpecifier);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return source.toSource(
|
|
141
|
+
options.printOptions || {
|
|
142
|
+
quote: 'single',
|
|
143
|
+
trailingComma: true,
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return fileInfo.source;
|
|
177
149
|
}
|
|
@@ -1,170 +1,146 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
API,
|
|
3
|
+
ASTPath,
|
|
4
|
+
default as core,
|
|
5
|
+
FileInfo,
|
|
6
|
+
ImportDeclaration,
|
|
7
|
+
ImportSpecifier,
|
|
8
|
+
Options,
|
|
9
9
|
} from 'jscodeshift';
|
|
10
10
|
|
|
11
11
|
const invalidHrefValues = ['', '#'];
|
|
12
12
|
const pkg = '@atlaskit/menu';
|
|
13
13
|
|
|
14
|
-
function getJSXAttributesByName(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.find(j.JSXIdentifier)
|
|
25
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
26
|
-
return Boolean(matches.length);
|
|
27
|
-
});
|
|
14
|
+
function getJSXAttributesByName(j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) {
|
|
15
|
+
return j(element)
|
|
16
|
+
.find(j.JSXOpeningElement)
|
|
17
|
+
.find(j.JSXAttribute)
|
|
18
|
+
.filter((attribute) => {
|
|
19
|
+
const matches = j(attribute)
|
|
20
|
+
.find(j.JSXIdentifier)
|
|
21
|
+
.filter((identifier) => identifier.value.name === attributeName);
|
|
22
|
+
return Boolean(matches.length);
|
|
23
|
+
});
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
function getImportSpecifier(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
j: core.JSCodeshift,
|
|
28
|
+
source: ReturnType<typeof j>,
|
|
29
|
+
specifier: string,
|
|
30
|
+
imported: string,
|
|
35
31
|
) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!specifiers.length) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
32
|
+
const specifiers = source
|
|
33
|
+
.find(j.ImportDeclaration)
|
|
34
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
35
|
+
.find(j.ImportSpecifier)
|
|
36
|
+
.filter((path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported);
|
|
37
|
+
|
|
38
|
+
if (!specifiers.length) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
function convertInvalidLinkItemsToButtonItems(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
j: core.JSCodeshift,
|
|
47
|
+
source: ReturnType<typeof j>,
|
|
48
|
+
specifier: string,
|
|
58
49
|
) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
element.value.openingElement.name.name = 'ButtonItem';
|
|
126
|
-
if (
|
|
127
|
-
element.value.closingElement &&
|
|
128
|
-
element.value.closingElement.name.type === 'JSXIdentifier'
|
|
129
|
-
) {
|
|
130
|
-
element.value.closingElement.name.name = 'ButtonItem';
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
50
|
+
// For each instance of LinkItem
|
|
51
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
52
|
+
const hrefPropCollection = getJSXAttributesByName(j, element, 'href');
|
|
53
|
+
|
|
54
|
+
// base case: no `href` prop exists, it is invalid
|
|
55
|
+
let validHref = false;
|
|
56
|
+
|
|
57
|
+
// if `href` exists
|
|
58
|
+
if (hrefPropCollection.length > 0) {
|
|
59
|
+
const hrefProp = hrefPropCollection.get();
|
|
60
|
+
|
|
61
|
+
const hrefStringLiteral = j(hrefProp).find(j.StringLiteral);
|
|
62
|
+
const hrefExpressionContainer = j(hrefProp).find(j.JSXExpressionContainer).find(j.Expression);
|
|
63
|
+
|
|
64
|
+
// This is tin foil hattery. Can something be neither a string literal
|
|
65
|
+
// nor an expression container? Don't know but gonna cover that
|
|
66
|
+
if (hrefStringLiteral.length === 0 && hrefExpressionContainer.length === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (hrefStringLiteral.length > 0) {
|
|
71
|
+
const hrefValue = hrefStringLiteral.get().value.value;
|
|
72
|
+
if (invalidHrefValues.includes(hrefValue)) {
|
|
73
|
+
j(hrefProp).forEach((el) => j(el).remove());
|
|
74
|
+
} else {
|
|
75
|
+
validHref = true;
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
// It seems foolish to try and resolve variables, so we will assume it
|
|
79
|
+
// is valid
|
|
80
|
+
validHref = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!validHref) {
|
|
85
|
+
const pkgImport = source
|
|
86
|
+
.find(j.ImportDeclaration)
|
|
87
|
+
.filter((path) => path.node.source.value === pkg);
|
|
88
|
+
const buttonItemIsImported =
|
|
89
|
+
pkgImport
|
|
90
|
+
.find(j.ImportSpecifier)
|
|
91
|
+
.nodes()
|
|
92
|
+
.filter((node) => node.imported.name === 'ButtonItem').length > 0;
|
|
93
|
+
if (!buttonItemIsImported) {
|
|
94
|
+
// Add ButtonItem to imports
|
|
95
|
+
const newSpecifier = j.importSpecifier(j.identifier('ButtonItem'));
|
|
96
|
+
pkgImport.forEach((moduleImport) => {
|
|
97
|
+
const specifiers = moduleImport.node.specifiers ? [...moduleImport.node.specifiers] : [];
|
|
98
|
+
j(moduleImport).replaceWith(
|
|
99
|
+
j.importDeclaration(specifiers.concat([newSpecifier]), moduleImport.node.source),
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Replace existing LinkItem with ButtonItem, while maintaining the same props
|
|
105
|
+
if (element.value.openingElement.name.type === 'JSXIdentifier') {
|
|
106
|
+
element.value.openingElement.name.name = 'ButtonItem';
|
|
107
|
+
if (
|
|
108
|
+
element.value.closingElement &&
|
|
109
|
+
element.value.closingElement.name.type === 'JSXIdentifier'
|
|
110
|
+
) {
|
|
111
|
+
element.value.closingElement.name.name = 'ButtonItem';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
135
116
|
}
|
|
136
117
|
|
|
137
118
|
function hasImportDeclaration(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
119
|
+
j: core.JSCodeshift,
|
|
120
|
+
source: ReturnType<typeof j>,
|
|
121
|
+
importPath: string,
|
|
141
122
|
) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
.filter((path) => path.node.source.value === importPath).length;
|
|
123
|
+
return !!source.find(j.ImportDeclaration).filter((path) => path.node.source.value === importPath)
|
|
124
|
+
.length;
|
|
145
125
|
}
|
|
146
126
|
|
|
147
|
-
export default function transformer(
|
|
148
|
-
|
|
149
|
-
{ jscodeshift: j }: API,
|
|
150
|
-
options: Options,
|
|
151
|
-
) {
|
|
152
|
-
const source = j(fileInfo.source);
|
|
127
|
+
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
128
|
+
const source = j(fileInfo.source);
|
|
153
129
|
|
|
154
|
-
|
|
155
|
-
|
|
130
|
+
if (hasImportDeclaration(j, source, pkg)) {
|
|
131
|
+
const importSpecifier = getImportSpecifier(j, source, pkg, 'LinkItem');
|
|
156
132
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
133
|
+
if (importSpecifier != null) {
|
|
134
|
+
convertInvalidLinkItemsToButtonItems(j, source, importSpecifier);
|
|
135
|
+
}
|
|
160
136
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
137
|
+
return source.toSource(
|
|
138
|
+
options.printOptions || {
|
|
139
|
+
quote: 'single',
|
|
140
|
+
trailingComma: true,
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
}
|
|
168
144
|
|
|
169
|
-
|
|
145
|
+
return fileInfo.source;
|
|
170
146
|
}
|