@wise/wds-codemods 0.0.1-experimental-ccf69a3 → 0.0.1-experimental-cc95209
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/.changeset/better-impalas-drop.md +5 -0
- package/.changeset/config.json +13 -0
- package/.changeset/quick-mails-joke.md +128 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/actions/bootstrap/action.yml +49 -0
- package/.github/actions/commitlint/action.yml +27 -0
- package/.github/actions/test/action.yml +23 -0
- package/.github/workflows/cd-cd.yml +127 -0
- package/.github/workflows/renovate.yml +16 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc.js +5 -0
- package/DEVELOPER.md +783 -0
- package/babel.config.js +28 -0
- package/commitlint.config.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +134 -134
- package/dist/index.js.map +1 -1
- package/dist/transforms/button.d.ts +16 -0
- package/dist/transforms/button.js +583 -491
- package/dist/transforms/button.js.map +1 -1
- package/eslint.config.js +15 -0
- package/jest.config.js +9 -0
- package/mkdocs.yml +4 -0
- package/package.json +21 -27
- package/renovate.json +9 -0
- package/scripts/build.sh +10 -0
- package/src/__tests__/runCodemod.test.ts +96 -0
- package/src/index.ts +4 -0
- package/src/runCodemod.ts +88 -0
- package/src/transforms/button/__tests__/button.test.tsx +153 -0
- package/src/transforms/button/button.ts +447 -0
- package/src/transforms/helpers/__tests__/createTestTransform.test.ts +27 -0
- package/src/transforms/helpers/__tests__/hasImport.test.ts +52 -0
- package/src/transforms/helpers/__tests__/iconUtils.test.ts +207 -0
- package/src/transforms/helpers/__tests__/jsxElementUtils.test.ts +130 -0
- package/src/transforms/helpers/__tests__/jsxReportingUtils.test.ts +265 -0
- package/src/transforms/helpers/createTestTransform.ts +18 -0
- package/src/transforms/helpers/hasImport.ts +60 -0
- package/src/transforms/helpers/iconUtils.ts +87 -0
- package/src/transforms/helpers/index.ts +5 -0
- package/src/transforms/helpers/jsxElementUtils.ts +67 -0
- package/src/transforms/helpers/jsxReportingUtils.ts +224 -0
- package/src/utils/__tests__/getOptions.test.ts +170 -0
- package/src/utils/__tests__/handleError.test.ts +18 -0
- package/src/utils/__tests__/loadTransformModules.test.ts +51 -0
- package/src/utils/__tests__/reportManualReview.test.ts +42 -0
- package/src/utils/getOptions.ts +63 -0
- package/src/utils/handleError.ts +6 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/loadTransformModules.ts +28 -0
- package/src/utils/reportManualReview.ts +17 -0
- package/test-button.tsx +230 -0
- package/test-file.js +2 -0
- package/tsconfig.json +14 -0
- package/tsup.config.js +13 -0
- package/dist/reportManualReview-_cdvHN4m.js +0 -16
- package/dist/reportManualReview-_cdvHN4m.js.map +0 -1
|
@@ -1,514 +1,606 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/reportManualReview.ts
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
var REPORT_PATH = path.resolve(process.cwd(), "codemod-report.txt");
|
|
5
|
+
var reportManualReview = async (filePath, message) => {
|
|
6
|
+
const lineMatch = /at line (\d+)/u.exec(message);
|
|
7
|
+
const lineNumber = lineMatch?.[1];
|
|
8
|
+
const cleanMessage = message.replace(/ at line \d+/u, "");
|
|
9
|
+
const lineInfo = lineNumber ? `:${lineNumber}` : "";
|
|
10
|
+
await fs.appendFile(REPORT_PATH, `[${filePath}${lineInfo}] ${cleanMessage}
|
|
11
|
+
`, "utf8");
|
|
12
|
+
};
|
|
13
|
+
var reportManualReview_default = reportManualReview;
|
|
14
|
+
|
|
15
|
+
// src/transforms/helpers/createTestTransform.ts
|
|
16
|
+
import { applyTransform } from "jscodeshift/src/testUtils";
|
|
2
17
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Checks if a specific import exists in the given root collection and provides
|
|
6
|
-
* a method to remove it if found.
|
|
7
|
-
*/
|
|
18
|
+
// src/transforms/helpers/hasImport.ts
|
|
8
19
|
function hasImport(root, sourceValue, importName, j) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
const importDeclarations = root.find(j.ImportDeclaration, {
|
|
21
|
+
source: { value: sourceValue }
|
|
22
|
+
});
|
|
23
|
+
if (importDeclarations.size() === 0) {
|
|
24
|
+
return {
|
|
25
|
+
exists: false,
|
|
26
|
+
remove: () => {
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const namedImport = importDeclarations.find(j.ImportSpecifier, {
|
|
31
|
+
imported: { name: importName }
|
|
32
|
+
});
|
|
33
|
+
const defaultImport = importDeclarations.find(j.ImportDefaultSpecifier, {
|
|
34
|
+
local: { name: importName }
|
|
35
|
+
});
|
|
36
|
+
const exists = namedImport.size() > 0 || defaultImport.size() > 0;
|
|
37
|
+
const remove = () => {
|
|
38
|
+
importDeclarations.forEach((path2) => {
|
|
39
|
+
const filteredSpecifiers = path2.node.specifiers?.filter((specifier) => {
|
|
40
|
+
if (specifier.type === "ImportSpecifier" && specifier.imported.name === importName) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (specifier.type === "ImportDefaultSpecifier" && specifier.local?.name === importName) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}) ?? [];
|
|
48
|
+
if (filteredSpecifiers.length === 0) {
|
|
49
|
+
path2.prune();
|
|
50
|
+
} else {
|
|
51
|
+
j(path2).replaceWith(
|
|
52
|
+
j.importDeclaration(filteredSpecifiers, path2.node.source, path2.node.importKind)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return { exists, remove };
|
|
32
58
|
}
|
|
59
|
+
var hasImport_default = hasImport;
|
|
33
60
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
// src/transforms/helpers/iconUtils.ts
|
|
62
|
+
var processIconChildren = (j, children, iconImports, openingElement) => {
|
|
63
|
+
if (!children || !openingElement.attributes) return;
|
|
64
|
+
const unwrapJsxElement = (node) => {
|
|
65
|
+
if (typeof node === "object" && node !== null && "type" in node && node.type === "JSXExpressionContainer" && j.JSXElement.check(node.expression)) {
|
|
66
|
+
return node.expression;
|
|
67
|
+
}
|
|
68
|
+
return node;
|
|
69
|
+
};
|
|
70
|
+
const totalChildren = children.length;
|
|
71
|
+
const iconChildIndex = children.findIndex((child) => {
|
|
72
|
+
const unwrapped = unwrapJsxElement(child);
|
|
73
|
+
return j.JSXElement.check(unwrapped) && unwrapped.openingElement.name.type === "JSXIdentifier" && iconImports.has(unwrapped.openingElement.name.name);
|
|
74
|
+
});
|
|
75
|
+
if (iconChildIndex === -1) return;
|
|
76
|
+
const iconChild = unwrapJsxElement(children[iconChildIndex]);
|
|
77
|
+
if (!iconChild || iconChild.openingElement.name.type !== "JSXIdentifier") return;
|
|
78
|
+
const iconName = iconChild.openingElement.name.name;
|
|
79
|
+
const distanceToStart = iconChildIndex;
|
|
80
|
+
const distanceToEnd = totalChildren - 1 - iconChildIndex;
|
|
81
|
+
const iconPropName = distanceToStart <= distanceToEnd ? "addonStart" : "addonEnd";
|
|
82
|
+
const iconObject = j.objectExpression([
|
|
83
|
+
j.property("init", j.identifier("type"), j.literal("icon")),
|
|
84
|
+
j.property("init", j.identifier("value"), iconChild)
|
|
85
|
+
]);
|
|
86
|
+
const iconProp = j.jsxAttribute(
|
|
87
|
+
j.jsxIdentifier(iconPropName),
|
|
88
|
+
j.jsxExpressionContainer(iconObject)
|
|
89
|
+
);
|
|
90
|
+
openingElement.attributes.push(iconProp);
|
|
91
|
+
children.splice(iconChildIndex, 1);
|
|
92
|
+
const isWhitespaceJsxText = (node) => {
|
|
93
|
+
return typeof node === "object" && node !== null && node.type === "JSXText" && typeof node.value === "string" && node.value.trim() === "";
|
|
94
|
+
};
|
|
95
|
+
if (iconChildIndex - 1 >= 0 && isWhitespaceJsxText(children[iconChildIndex - 1])) {
|
|
96
|
+
children.splice(iconChildIndex - 1, 1);
|
|
97
|
+
} else if (isWhitespaceJsxText(children[iconChildIndex])) {
|
|
98
|
+
children.splice(iconChildIndex, 1);
|
|
99
|
+
}
|
|
67
100
|
};
|
|
101
|
+
var iconUtils_default = processIconChildren;
|
|
68
102
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (elementName && elementName.type === "JSXIdentifier") return {
|
|
76
|
-
...elementName,
|
|
77
|
-
name: newName
|
|
78
|
-
};
|
|
79
|
-
return elementName;
|
|
103
|
+
// src/transforms/helpers/jsxElementUtils.ts
|
|
104
|
+
var setNameIfJSXIdentifier = (elementName, newName) => {
|
|
105
|
+
if (elementName && elementName.type === "JSXIdentifier") {
|
|
106
|
+
return { ...elementName, name: newName };
|
|
107
|
+
}
|
|
108
|
+
return elementName;
|
|
80
109
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return Array.isArray(attributes) && attributes.some((attr) => attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === attributeName);
|
|
110
|
+
var hasAttribute = (attributes, attributeName) => {
|
|
111
|
+
return Array.isArray(attributes) && attributes.some(
|
|
112
|
+
(attr) => attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === attributeName
|
|
113
|
+
);
|
|
86
114
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*/
|
|
90
|
-
const hasAttributeOnElement = (element, attributeName) => {
|
|
91
|
-
return hasAttribute(element.attributes, attributeName);
|
|
115
|
+
var hasAttributeOnElement = (element, attributeName) => {
|
|
116
|
+
return hasAttribute(element.attributes, attributeName);
|
|
92
117
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
118
|
+
var addAttributesIfMissing = (j, openingElement, attributesToAdd) => {
|
|
119
|
+
if (!Array.isArray(openingElement.attributes)) return;
|
|
120
|
+
const attrs = openingElement.attributes;
|
|
121
|
+
attributesToAdd.forEach(({ attribute, name }) => {
|
|
122
|
+
if (!hasAttributeOnElement(openingElement, name)) {
|
|
123
|
+
attrs.push(attribute);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
102
126
|
};
|
|
103
127
|
|
|
104
|
-
|
|
105
|
-
//#region src/transforms/helpers/jsxReportingUtils.ts
|
|
106
|
-
/**
|
|
107
|
-
* CodemodReporter is a utility class for reporting issues found during codemod transformations.
|
|
108
|
-
* It provides methods to report issues related to JSX elements, props, and attributes.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* const issues: string[] = [];
|
|
113
|
-
* const reporter = createReporter(j, issues);
|
|
114
|
-
*
|
|
115
|
-
* // Report a deprecated prop
|
|
116
|
-
* reporter.reportDeprecatedProp(buttonElement, 'flat', 'variant="text"');
|
|
117
|
-
*
|
|
118
|
-
* // Report complex expression that needs review
|
|
119
|
-
* reporter.reportAmbiguousExpression(element, 'size');
|
|
120
|
-
*
|
|
121
|
-
* // Auto-detect common issues
|
|
122
|
-
* reporter.reportAttributeIssues(element);
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
128
|
+
// src/transforms/helpers/jsxReportingUtils.ts
|
|
125
129
|
var CodemodReporter = class {
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
130
|
+
j;
|
|
131
|
+
issues;
|
|
132
|
+
constructor(options) {
|
|
133
|
+
this.j = options.jscodeshift;
|
|
134
|
+
this.issues = options.issues;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Reports an issue with a JSX element
|
|
138
|
+
*/
|
|
139
|
+
reportElement(element, reason) {
|
|
140
|
+
const node = this.getNode(element);
|
|
141
|
+
const componentName = this.getComponentName(node);
|
|
142
|
+
const line = this.getLineNumber(node);
|
|
143
|
+
this.addIssue(`Manual review required: <${componentName}> at line ${line} ${reason}.`);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Reports an issue with a specific prop
|
|
147
|
+
*/
|
|
148
|
+
reportProp(element, propName, reason) {
|
|
149
|
+
const node = this.getNode(element);
|
|
150
|
+
const componentName = this.getComponentName(node);
|
|
151
|
+
const line = this.getLineNumber(node);
|
|
152
|
+
this.addIssue(
|
|
153
|
+
`Manual review required: prop "${propName}" on <${componentName}> at line ${line} ${reason}.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Reports an issue with a JSX attribute directly
|
|
158
|
+
*/
|
|
159
|
+
reportAttribute(attr, element, reason) {
|
|
160
|
+
const node = this.getNode(element);
|
|
161
|
+
const componentName = this.getComponentName(node);
|
|
162
|
+
const propName = this.getAttributeName(attr);
|
|
163
|
+
const line = this.getLineNumber(attr) || this.getLineNumber(node);
|
|
164
|
+
const defaultReason = this.getAttributeReason(attr);
|
|
165
|
+
const finalReason = reason || defaultReason;
|
|
166
|
+
this.addIssue(
|
|
167
|
+
`Manual review required: prop "${propName}" on <${componentName}> at line ${line} ${finalReason}.`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reports spread props on an element
|
|
172
|
+
*/
|
|
173
|
+
reportSpreadProps(element) {
|
|
174
|
+
this.reportElement(element, "contains spread props that need manual review");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Reports conflicting prop and children
|
|
178
|
+
*/
|
|
179
|
+
reportPropWithChildren(element, propName) {
|
|
180
|
+
this.reportProp(
|
|
181
|
+
element,
|
|
182
|
+
propName,
|
|
183
|
+
`conflicts with children - both "${propName}" prop and children are present`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Reports unsupported prop value
|
|
188
|
+
*/
|
|
189
|
+
reportUnsupportedValue(element, propName, value) {
|
|
190
|
+
this.reportProp(element, propName, `has unsupported value "${value}"`);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Reports ambiguous expression in prop
|
|
194
|
+
*/
|
|
195
|
+
reportAmbiguousExpression(element, propName) {
|
|
196
|
+
this.reportProp(element, propName, "contains a complex expression that needs manual review");
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Reports ambiguous children (like dynamic icons)
|
|
200
|
+
*/
|
|
201
|
+
reportAmbiguousChildren(element, childType = "content") {
|
|
202
|
+
this.reportElement(element, `contains ambiguous ${childType} that needs manual review`);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Reports deprecated prop usage
|
|
206
|
+
*/
|
|
207
|
+
reportDeprecatedProp(element, propName, alternative) {
|
|
208
|
+
const suggestion = alternative ? ` Use ${alternative} instead` : "";
|
|
209
|
+
this.reportProp(element, propName, `is deprecated${suggestion}`);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Reports missing required prop
|
|
213
|
+
*/
|
|
214
|
+
reportMissingRequiredProp(element, propName) {
|
|
215
|
+
this.reportProp(element, propName, "is required but missing");
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Reports conflicting props
|
|
219
|
+
*/
|
|
220
|
+
reportConflictingProps(element, propNames) {
|
|
221
|
+
const propList = propNames.map((name) => `"${name}"`).join(", ");
|
|
222
|
+
this.reportElement(element, `has conflicting props: ${propList} cannot be used together`);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Auto-detects and reports common attribute issues
|
|
226
|
+
*/
|
|
227
|
+
reportAttributeIssues(element) {
|
|
228
|
+
const node = this.getNode(element);
|
|
229
|
+
const { attributes } = node.openingElement;
|
|
230
|
+
if (!attributes) return;
|
|
231
|
+
if (attributes.some((attr) => attr.type === "JSXSpreadAttribute")) {
|
|
232
|
+
this.reportSpreadProps(element);
|
|
233
|
+
}
|
|
234
|
+
attributes.forEach((attr) => {
|
|
235
|
+
if (attr.type === "JSXAttribute" && attr.value?.type === "JSXExpressionContainer") {
|
|
236
|
+
this.reportAttribute(attr, element);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// Private helper methods
|
|
241
|
+
getNode(element) {
|
|
242
|
+
return "node" in element ? element.node : element;
|
|
243
|
+
}
|
|
244
|
+
getComponentName(node) {
|
|
245
|
+
const { name } = node.openingElement;
|
|
246
|
+
if (name.type === "JSXIdentifier") {
|
|
247
|
+
return name.name;
|
|
248
|
+
}
|
|
249
|
+
return this.j(name).toSource();
|
|
250
|
+
}
|
|
251
|
+
getLineNumber(node) {
|
|
252
|
+
return node.loc?.start.line?.toString() || "unknown";
|
|
253
|
+
}
|
|
254
|
+
getAttributeName(attr) {
|
|
255
|
+
if (attr.name.type === "JSXIdentifier") {
|
|
256
|
+
return attr.name.name;
|
|
257
|
+
}
|
|
258
|
+
return this.j(attr.name).toSource();
|
|
259
|
+
}
|
|
260
|
+
getAttributeReason(attr) {
|
|
261
|
+
if (!attr.value) return "has no value";
|
|
262
|
+
if (attr.value.type === "JSXExpressionContainer") {
|
|
263
|
+
const expr = attr.value.expression;
|
|
264
|
+
const expressionType = expr.type.replace("Expression", "").toLowerCase();
|
|
265
|
+
if (expr.type === "Identifier" || expr.type === "MemberExpression") {
|
|
266
|
+
const valueText = this.j(expr).toSource();
|
|
267
|
+
return `contains a ${expressionType} (${valueText})`;
|
|
268
|
+
}
|
|
269
|
+
return `contains a complex ${expressionType} expression`;
|
|
270
|
+
}
|
|
271
|
+
return "needs manual review";
|
|
272
|
+
}
|
|
273
|
+
addIssue(message) {
|
|
274
|
+
this.issues.push(message);
|
|
275
|
+
}
|
|
255
276
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
jscodeshift: j,
|
|
259
|
-
issues
|
|
260
|
-
});
|
|
277
|
+
var createReporter = (j, issues) => {
|
|
278
|
+
return new CodemodReporter({ jscodeshift: j, issues });
|
|
261
279
|
};
|
|
262
280
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
281
|
+
// src/transforms/button/button.ts
|
|
282
|
+
var parser = "tsx";
|
|
283
|
+
var priorityMapping = {
|
|
284
|
+
accent: {
|
|
285
|
+
primary: "primary",
|
|
286
|
+
secondary: "secondary-neutral",
|
|
287
|
+
tertiary: "tertiary"
|
|
288
|
+
},
|
|
289
|
+
positive: {
|
|
290
|
+
primary: "primary",
|
|
291
|
+
secondary: "secondary-neutral",
|
|
292
|
+
tertiary: "secondary-neutral"
|
|
293
|
+
},
|
|
294
|
+
negative: {
|
|
295
|
+
primary: "primary",
|
|
296
|
+
secondary: "secondary",
|
|
297
|
+
tertiary: "secondary"
|
|
298
|
+
}
|
|
282
299
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
300
|
+
var sizeMap = {
|
|
301
|
+
EXTRA_SMALL: "xs",
|
|
302
|
+
SMALL: "sm",
|
|
303
|
+
MEDIUM: "md",
|
|
304
|
+
LARGE: "lg",
|
|
305
|
+
EXTRA_LARGE: "xl",
|
|
306
|
+
xs: "sm",
|
|
307
|
+
sm: "sm",
|
|
308
|
+
md: "md",
|
|
309
|
+
lg: "lg",
|
|
310
|
+
xl: "xl"
|
|
294
311
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
312
|
+
var resolveSize = (size) => {
|
|
313
|
+
if (!size) return size;
|
|
314
|
+
const match = /^Size\.(EXTRA_SMALL|SMALL|MEDIUM|LARGE|EXTRA_LARGE)$/u.exec(size);
|
|
315
|
+
if (match) {
|
|
316
|
+
return sizeMap[match[1]];
|
|
317
|
+
}
|
|
318
|
+
return sizeMap[size] || size;
|
|
300
319
|
};
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
320
|
+
var resolvePriority = (type, priority) => {
|
|
321
|
+
if (type && priority) {
|
|
322
|
+
return priorityMapping[type]?.[priority] || priority;
|
|
323
|
+
}
|
|
324
|
+
return priority;
|
|
304
325
|
};
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
326
|
+
var resolveType = (type, htmlType) => {
|
|
327
|
+
if (htmlType) {
|
|
328
|
+
return htmlType;
|
|
329
|
+
}
|
|
330
|
+
const legacyButtonTypes = [
|
|
331
|
+
"accent",
|
|
332
|
+
"negative",
|
|
333
|
+
"positive",
|
|
334
|
+
"primary",
|
|
335
|
+
"pay",
|
|
336
|
+
"secondary",
|
|
337
|
+
"danger",
|
|
338
|
+
"link",
|
|
339
|
+
"button",
|
|
340
|
+
"reset",
|
|
341
|
+
"submit"
|
|
342
|
+
];
|
|
343
|
+
return type && legacyButtonTypes.includes(type) ? type : null;
|
|
318
344
|
};
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
345
|
+
var convertEnumValue = (value) => {
|
|
346
|
+
if (!value) return { converted: value, wasEnum: false };
|
|
347
|
+
const strippedValue = value.replace(/^['"]|['"]$/gu, "");
|
|
348
|
+
const enumMapping = {
|
|
349
|
+
"Priority.SECONDARY": "secondary",
|
|
350
|
+
"Priority.PRIMARY": "primary",
|
|
351
|
+
"Priority.TERTIARY": "tertiary",
|
|
352
|
+
"ControlType.NEGATIVE": "negative",
|
|
353
|
+
"ControlType.POSITIVE": "positive",
|
|
354
|
+
"ControlType.ACCENT": "accent",
|
|
355
|
+
"ControlType.BUTTON": "button",
|
|
356
|
+
"ControlType.RESET": "reset",
|
|
357
|
+
"HtmlType.SUBMIT": "submit",
|
|
358
|
+
"HtmlType.BUTTON": "button",
|
|
359
|
+
"HtmlType.RESET": "reset",
|
|
360
|
+
"Sentiment.NEGATIVE": "negative"
|
|
361
|
+
};
|
|
362
|
+
const wasEnum = strippedValue in enumMapping;
|
|
363
|
+
const converted = enumMapping[strippedValue] || strippedValue;
|
|
364
|
+
return { converted, wasEnum };
|
|
331
365
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
366
|
+
var transformer = (file, api, options) => {
|
|
367
|
+
const j = api.jscodeshift;
|
|
368
|
+
const root = j(file.source);
|
|
369
|
+
const manualReviewIssues = [];
|
|
370
|
+
const reporter = createReporter(j, manualReviewIssues);
|
|
371
|
+
const { exists: hasButtonImport } = hasImport_default(root, "@transferwise/components", "Button", j);
|
|
372
|
+
const { exists: hasActionButtonImport, remove: removeActionButtonImport } = hasImport_default(
|
|
373
|
+
root,
|
|
374
|
+
"@transferwise/components",
|
|
375
|
+
"ActionButton",
|
|
376
|
+
j
|
|
377
|
+
);
|
|
378
|
+
const iconImports = /* @__PURE__ */ new Set();
|
|
379
|
+
root.find(j.ImportDeclaration, { source: { value: "@transferwise/icons" } }).forEach((path2) => {
|
|
380
|
+
path2.node.specifiers?.forEach((specifier) => {
|
|
381
|
+
if ((specifier.type === "ImportDefaultSpecifier" || specifier.type === "ImportSpecifier") && specifier.local) {
|
|
382
|
+
const localName = specifier.local.name;
|
|
383
|
+
iconImports.add(localName);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
if (hasActionButtonImport) {
|
|
388
|
+
root.findJSXElements("ActionButton").forEach((path2) => {
|
|
389
|
+
const { openingElement, closingElement } = path2.node;
|
|
390
|
+
openingElement.name = setNameIfJSXIdentifier(openingElement.name, "Button");
|
|
391
|
+
if (closingElement) {
|
|
392
|
+
closingElement.name = setNameIfJSXIdentifier(closingElement.name, "Button");
|
|
393
|
+
}
|
|
394
|
+
addAttributesIfMissing(j, openingElement, [
|
|
395
|
+
{ attribute: j.jsxAttribute(j.jsxIdentifier("v2")), name: "v2" },
|
|
396
|
+
{ attribute: j.jsxAttribute(j.jsxIdentifier("size"), j.literal("sm")), name: "size" }
|
|
397
|
+
]);
|
|
398
|
+
iconUtils_default(j, path2.node.children, iconImports, openingElement);
|
|
399
|
+
if ((openingElement.attributes ?? []).some((attr) => attr.type === "JSXSpreadAttribute")) {
|
|
400
|
+
reporter.reportSpreadProps(path2);
|
|
401
|
+
}
|
|
402
|
+
const legacyPropNames = ["priority", "text"];
|
|
403
|
+
const legacyProps = {};
|
|
404
|
+
openingElement.attributes?.forEach((attr) => {
|
|
405
|
+
if (attr.type === "JSXAttribute" && attr.name && attr.name.type === "JSXIdentifier") {
|
|
406
|
+
const { name } = attr.name;
|
|
407
|
+
if (legacyPropNames.includes(name)) {
|
|
408
|
+
if (attr.value) {
|
|
409
|
+
if (attr.value.type === "StringLiteral") {
|
|
410
|
+
legacyProps[name] = attr.value.value;
|
|
411
|
+
} else if (attr.value.type === "JSXExpressionContainer") {
|
|
412
|
+
reporter.reportAttribute(attr, path2);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
const hasTextProp = openingElement.attributes?.some(
|
|
419
|
+
(attr) => attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "text"
|
|
420
|
+
);
|
|
421
|
+
const hasChildren = path2.node.children?.some(
|
|
422
|
+
(child) => child.type === "JSXText" && child.value.trim() !== "" || child.type === "JSXElement" || child.type === "JSXExpressionContainer"
|
|
423
|
+
);
|
|
424
|
+
if (hasTextProp && hasChildren) {
|
|
425
|
+
reporter.reportPropWithChildren(path2, "text");
|
|
426
|
+
}
|
|
427
|
+
(path2.node.children || []).forEach((child) => {
|
|
428
|
+
if (child.type === "JSXExpressionContainer") {
|
|
429
|
+
const expr = child.expression;
|
|
430
|
+
if (expr.type === "ConditionalExpression" || expr.type === "CallExpression" || expr.type === "Identifier" || expr.type === "MemberExpression") {
|
|
431
|
+
reporter.reportAmbiguousChildren(path2, "icon");
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
removeActionButtonImport();
|
|
437
|
+
}
|
|
438
|
+
if (hasButtonImport) {
|
|
439
|
+
root.findJSXElements("Button").forEach((path2) => {
|
|
440
|
+
const { openingElement } = path2.node;
|
|
441
|
+
if (hasAttributeOnElement(openingElement, "v2")) return;
|
|
442
|
+
addAttributesIfMissing(j, openingElement, [
|
|
443
|
+
{ attribute: j.jsxAttribute(j.jsxIdentifier("v2")), name: "v2" }
|
|
444
|
+
]);
|
|
445
|
+
iconUtils_default(j, path2.node.children, iconImports, openingElement);
|
|
446
|
+
const legacyProps = {};
|
|
447
|
+
const legacyPropNames = ["priority", "size", "type", "htmlType", "sentiment"];
|
|
448
|
+
const keepAttributes = [];
|
|
449
|
+
(openingElement.attributes ?? []).forEach((attr) => {
|
|
450
|
+
if (attr.type === "JSXAttribute" && attr.name && attr.name.type === "JSXIdentifier" && legacyPropNames.includes(attr.name.name)) {
|
|
451
|
+
const { name } = attr.name;
|
|
452
|
+
let migrated = false;
|
|
453
|
+
let rawStringValue;
|
|
454
|
+
if (attr.value) {
|
|
455
|
+
if (attr.value.type === "StringLiteral") {
|
|
456
|
+
rawStringValue = attr.value.value;
|
|
457
|
+
legacyProps[name] = attr.value.value;
|
|
458
|
+
} else if (attr.value.type === "JSXExpressionContainer") {
|
|
459
|
+
rawStringValue = String(j(attr.value.expression).toSource());
|
|
460
|
+
const { converted } = convertEnumValue(rawStringValue);
|
|
461
|
+
legacyProps[name] = converted;
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
legacyProps[name] = void 0;
|
|
465
|
+
}
|
|
466
|
+
const { wasEnum } = convertEnumValue(rawStringValue);
|
|
467
|
+
if (rawStringValue && wasEnum) {
|
|
468
|
+
migrated = true;
|
|
469
|
+
} else if (name === "size") {
|
|
470
|
+
const rawValue = legacyProps.size;
|
|
471
|
+
const resolved2 = resolveSize(rawValue);
|
|
472
|
+
const supportedSizes = ["xs", "sm", "md", "lg", "xl"];
|
|
473
|
+
if (typeof rawValue === "string" && typeof resolved2 === "string" && supportedSizes.includes(resolved2)) {
|
|
474
|
+
migrated = true;
|
|
475
|
+
} else if (typeof rawValue === "string") {
|
|
476
|
+
reporter.reportUnsupportedValue(path2, "size", rawValue);
|
|
477
|
+
} else if (rawValue !== void 0) {
|
|
478
|
+
reporter.reportAmbiguousExpression(path2, "size");
|
|
479
|
+
}
|
|
480
|
+
} else if (name === "priority") {
|
|
481
|
+
const rawValue = legacyProps.priority;
|
|
482
|
+
const { converted } = convertEnumValue(rawValue);
|
|
483
|
+
const mapped = resolvePriority(legacyProps.type, converted);
|
|
484
|
+
const supportedPriorities = ["primary", "secondary", "tertiary", "secondary-neutral"];
|
|
485
|
+
if (typeof rawValue === "string" && typeof mapped === "string" && supportedPriorities.includes(mapped)) {
|
|
486
|
+
migrated = true;
|
|
487
|
+
} else if (typeof rawValue === "string") {
|
|
488
|
+
reporter.reportUnsupportedValue(path2, "priority", rawValue);
|
|
489
|
+
} else if (rawValue !== void 0) {
|
|
490
|
+
reporter.reportAmbiguousExpression(path2, "priority");
|
|
491
|
+
}
|
|
492
|
+
} else if (name === "type" || name === "htmlType") {
|
|
493
|
+
const rawType2 = legacyProps.type;
|
|
494
|
+
const rawHtmlType2 = legacyProps.htmlType;
|
|
495
|
+
const resolvedType2 = typeof rawType2 === "string" ? rawType2 : rawType2 && typeof rawType2 === "object" ? convertEnumValue(j(rawType2).toSource()).converted : void 0;
|
|
496
|
+
const resolved2 = resolveType(resolvedType2, rawHtmlType2);
|
|
497
|
+
const supportedTypes2 = ["button", "reset", "submit"];
|
|
498
|
+
if (typeof resolved2 === "string" && supportedTypes2.includes(resolved2)) {
|
|
499
|
+
migrated = true;
|
|
500
|
+
} else if (typeof rawType2 === "string" || typeof rawHtmlType2 === "string") {
|
|
501
|
+
reporter.reportUnsupportedValue(path2, "type", rawType2 ?? rawHtmlType2 ?? "");
|
|
502
|
+
} else if (rawType2 !== void 0 || rawHtmlType2 !== void 0) {
|
|
503
|
+
reporter.reportAmbiguousExpression(path2, "type");
|
|
504
|
+
}
|
|
505
|
+
} else if (name === "sentiment") {
|
|
506
|
+
const rawValue = legacyProps.sentiment;
|
|
507
|
+
if (rawValue === "negative") {
|
|
508
|
+
migrated = true;
|
|
509
|
+
} else if (typeof rawValue === "string") {
|
|
510
|
+
reporter.reportUnsupportedValue(path2, "sentiment", rawValue);
|
|
511
|
+
} else if (rawValue !== void 0) {
|
|
512
|
+
reporter.reportAmbiguousExpression(path2, "sentiment");
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (!migrated) keepAttributes.push(attr);
|
|
516
|
+
} else {
|
|
517
|
+
keepAttributes.push(attr);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
const newAttributes = [];
|
|
521
|
+
const rawSize = legacyProps.size;
|
|
522
|
+
const resolvedSize = resolveSize(rawSize);
|
|
523
|
+
if (typeof rawSize === "string" && typeof resolvedSize === "string" && ["xs", "sm", "md", "lg", "xl"].includes(resolvedSize)) {
|
|
524
|
+
newAttributes.push(j.jsxAttribute(j.jsxIdentifier("size"), j.literal(resolvedSize)));
|
|
525
|
+
}
|
|
526
|
+
const rawPriority = legacyProps.priority;
|
|
527
|
+
const { converted: convertedPriority } = convertEnumValue(rawPriority);
|
|
528
|
+
const mappedPriority = resolvePriority(legacyProps.type, convertedPriority);
|
|
529
|
+
if (typeof rawPriority === "string" && typeof mappedPriority === "string" && ["primary", "secondary", "tertiary", "secondary-neutral"].includes(mappedPriority)) {
|
|
530
|
+
newAttributes.push(j.jsxAttribute(j.jsxIdentifier("priority"), j.literal(mappedPriority)));
|
|
531
|
+
}
|
|
532
|
+
const rawType = legacyProps.type;
|
|
533
|
+
const rawHtmlType = legacyProps.htmlType;
|
|
534
|
+
const resolvedType = typeof rawType === "string" ? rawType : rawType && typeof rawType === "object" ? convertEnumValue(j(rawType).toSource()).converted : void 0;
|
|
535
|
+
const resolved = resolveType(resolvedType, rawHtmlType);
|
|
536
|
+
const supportedTypes = ["button", "reset", "submit", "negative"];
|
|
537
|
+
if (typeof resolved === "string" && supportedTypes.includes(resolved)) {
|
|
538
|
+
if (resolved !== "negative") {
|
|
539
|
+
newAttributes.push(j.jsxAttribute(j.jsxIdentifier("type"), j.literal(resolved)));
|
|
540
|
+
}
|
|
541
|
+
if (resolved === "negative") {
|
|
542
|
+
newAttributes.push(j.jsxAttribute(j.jsxIdentifier("sentiment"), j.literal("negative")));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const rawSentiment = legacyProps.sentiment;
|
|
546
|
+
if (rawSentiment === "negative") {
|
|
547
|
+
newAttributes.push(j.jsxAttribute(j.jsxIdentifier("sentiment"), j.literal("negative")));
|
|
548
|
+
}
|
|
549
|
+
Array.prototype.push.apply(newAttributes, keepAttributes);
|
|
550
|
+
let asIndex = -1;
|
|
551
|
+
let asValue = null;
|
|
552
|
+
let hrefExists = false;
|
|
553
|
+
let asAmbiguous = false;
|
|
554
|
+
let hrefAmbiguous = false;
|
|
555
|
+
newAttributes.forEach((attr, index) => {
|
|
556
|
+
if (attr.type === "JSXAttribute" && attr.name) {
|
|
557
|
+
if (attr.name.name === "as") {
|
|
558
|
+
if (attr.value) {
|
|
559
|
+
if (attr.value.type === "StringLiteral") {
|
|
560
|
+
asValue = attr.value.value;
|
|
561
|
+
} else if (attr.value.type === "JSXExpressionContainer") {
|
|
562
|
+
asAmbiguous = true;
|
|
563
|
+
reporter.reportAttribute(attr, path2);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
asIndex = index;
|
|
567
|
+
}
|
|
568
|
+
if (attr.name.name === "href") {
|
|
569
|
+
hrefExists = true;
|
|
570
|
+
if (attr.value && attr.value.type !== "StringLiteral") {
|
|
571
|
+
hrefAmbiguous = true;
|
|
572
|
+
reporter.reportAttribute(attr, path2);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
if (asValue && asValue !== "a") {
|
|
578
|
+
reporter.reportUnsupportedValue(path2, "as", asValue);
|
|
579
|
+
}
|
|
580
|
+
if (asValue === "a") {
|
|
581
|
+
if (asIndex !== -1) {
|
|
582
|
+
newAttributes.splice(asIndex, 1);
|
|
583
|
+
}
|
|
584
|
+
if (!hrefExists) {
|
|
585
|
+
newAttributes.push(j.jsxAttribute(j.jsxIdentifier("href"), j.literal("#")));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
openingElement.attributes = newAttributes;
|
|
589
|
+
if ((openingElement.attributes ?? []).some((attr) => attr.type === "JSXSpreadAttribute")) {
|
|
590
|
+
reporter.reportSpreadProps(path2);
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
if (manualReviewIssues.length > 0) {
|
|
595
|
+
manualReviewIssues.forEach(async (issue) => {
|
|
596
|
+
await reportManualReview_default(file.path, issue);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
return root.toSource();
|
|
600
|
+
};
|
|
601
|
+
var button_default = transformer;
|
|
602
|
+
export {
|
|
603
|
+
button_default as default,
|
|
604
|
+
parser
|
|
510
605
|
};
|
|
511
|
-
|
|
512
|
-
//#endregion
|
|
513
|
-
export { transformer as default, parser };
|
|
514
606
|
//# sourceMappingURL=button.js.map
|