@sanity/ui-codemod 1.0.0-alpha.1

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.
Files changed (157) hide show
  1. package/bin/run.js +5 -0
  2. package/dist/_chunks-es/addAttribute.js +11 -0
  3. package/dist/_chunks-es/addAttribute.js.map +1 -0
  4. package/dist/_chunks-es/box.mods.js +186 -0
  5. package/dist/_chunks-es/box.mods.js.map +1 -0
  6. package/dist/_chunks-es/flex.mods.js +74 -0
  7. package/dist/_chunks-es/flex.mods.js.map +1 -0
  8. package/dist/_chunks-es/getTransformPath.js +75 -0
  9. package/dist/_chunks-es/getTransformPath.js.map +1 -0
  10. package/dist/_chunks-es/grid.mods.js +110 -0
  11. package/dist/_chunks-es/grid.mods.js.map +1 -0
  12. package/dist/_chunks-es/layout-mods.js +424 -0
  13. package/dist/_chunks-es/layout-mods.js.map +1 -0
  14. package/dist/_chunks-es/transformComponent.js +359 -0
  15. package/dist/_chunks-es/transformComponent.js.map +1 -0
  16. package/dist/commands/latest/box.d.ts +47 -0
  17. package/dist/commands/latest/box.js +17 -0
  18. package/dist/commands/latest/box.js.map +1 -0
  19. package/dist/commands/latest/card.d.ts +47 -0
  20. package/dist/commands/latest/card.js +17 -0
  21. package/dist/commands/latest/card.js.map +1 -0
  22. package/dist/commands/latest/code.d.ts +47 -0
  23. package/dist/commands/latest/code.js +17 -0
  24. package/dist/commands/latest/code.js.map +1 -0
  25. package/dist/commands/latest/container.d.ts +47 -0
  26. package/dist/commands/latest/container.js +17 -0
  27. package/dist/commands/latest/container.js.map +1 -0
  28. package/dist/commands/latest/flex.d.ts +47 -0
  29. package/dist/commands/latest/flex.js +17 -0
  30. package/dist/commands/latest/flex.js.map +1 -0
  31. package/dist/commands/latest/grid.d.ts +47 -0
  32. package/dist/commands/latest/grid.js +17 -0
  33. package/dist/commands/latest/grid.js.map +1 -0
  34. package/dist/commands/latest/heading.d.ts +47 -0
  35. package/dist/commands/latest/heading.js +17 -0
  36. package/dist/commands/latest/heading.js.map +1 -0
  37. package/dist/commands/latest/text.d.ts +47 -0
  38. package/dist/commands/latest/text.js +17 -0
  39. package/dist/commands/latest/text.js.map +1 -0
  40. package/dist/transforms/latest/box/box.d.ts +18 -0
  41. package/dist/transforms/latest/box/box.js +101 -0
  42. package/dist/transforms/latest/box/box.js.map +1 -0
  43. package/dist/transforms/latest/card/card.d.ts +18 -0
  44. package/dist/transforms/latest/card/card.js +618 -0
  45. package/dist/transforms/latest/card/card.js.map +1 -0
  46. package/dist/transforms/latest/code/code.d.ts +18 -0
  47. package/dist/transforms/latest/code/code.js +73 -0
  48. package/dist/transforms/latest/code/code.js.map +1 -0
  49. package/dist/transforms/latest/container/container.d.ts +18 -0
  50. package/dist/transforms/latest/container/container.js +91 -0
  51. package/dist/transforms/latest/container/container.js.map +1 -0
  52. package/dist/transforms/latest/flex/flex.d.ts +18 -0
  53. package/dist/transforms/latest/flex/flex.js +19 -0
  54. package/dist/transforms/latest/flex/flex.js.map +1 -0
  55. package/dist/transforms/latest/grid/grid.d.ts +18 -0
  56. package/dist/transforms/latest/grid/grid.js +19 -0
  57. package/dist/transforms/latest/grid/grid.js.map +1 -0
  58. package/dist/transforms/latest/heading/heading.d.ts +18 -0
  59. package/dist/transforms/latest/heading/heading.js +85 -0
  60. package/dist/transforms/latest/heading/heading.js.map +1 -0
  61. package/dist/transforms/latest/text/text.d.ts +18 -0
  62. package/dist/transforms/latest/text/text.js +88 -0
  63. package/dist/transforms/latest/text/text.js.map +1 -0
  64. package/package.json +68 -0
  65. package/src/baseCommand.ts +74 -0
  66. package/src/commands/latest/box.ts +21 -0
  67. package/src/commands/latest/card.ts +21 -0
  68. package/src/commands/latest/code.ts +21 -0
  69. package/src/commands/latest/container.ts +21 -0
  70. package/src/commands/latest/flex.ts +21 -0
  71. package/src/commands/latest/grid.ts +21 -0
  72. package/src/commands/latest/heading.ts +21 -0
  73. package/src/commands/latest/inline.ts +21 -0
  74. package/src/commands/latest/label.ts +21 -0
  75. package/src/commands/latest/stack.ts +21 -0
  76. package/src/commands/latest/text.ts +21 -0
  77. package/src/constants/latest/layout-mods.ts +422 -0
  78. package/src/transforms/latest/box/box.mods.ts +88 -0
  79. package/src/transforms/latest/box/box.test.ts +204 -0
  80. package/src/transforms/latest/box/box.ts +104 -0
  81. package/src/transforms/latest/card/card.mods.ts +592 -0
  82. package/src/transforms/latest/card/card.test.ts +207 -0
  83. package/src/transforms/latest/card/card.ts +71 -0
  84. package/src/transforms/latest/code/code.mods.ts +57 -0
  85. package/src/transforms/latest/code/code.test.ts +61 -0
  86. package/src/transforms/latest/code/code.ts +53 -0
  87. package/src/transforms/latest/container/container.mods.ts +77 -0
  88. package/src/transforms/latest/container/container.test.ts +105 -0
  89. package/src/transforms/latest/container/container.ts +42 -0
  90. package/src/transforms/latest/flex/flex.mods.ts +73 -0
  91. package/src/transforms/latest/flex/flex.test.ts +80 -0
  92. package/src/transforms/latest/flex/flex.ts +42 -0
  93. package/src/transforms/latest/grid/grid.mods.ts +109 -0
  94. package/src/transforms/latest/grid/grid.test.ts +97 -0
  95. package/src/transforms/latest/grid/grid.ts +42 -0
  96. package/src/transforms/latest/heading/heading.mods.ts +70 -0
  97. package/src/transforms/latest/heading/heading.test.ts +87 -0
  98. package/src/transforms/latest/heading/heading.ts +53 -0
  99. package/src/transforms/latest/inline/inline.mods.ts +65 -0
  100. package/src/transforms/latest/inline/inline.test.ts +57 -0
  101. package/src/transforms/latest/inline/inline.ts +42 -0
  102. package/src/transforms/latest/label/label.mods.ts +72 -0
  103. package/src/transforms/latest/label/label.test.ts +113 -0
  104. package/src/transforms/latest/label/label.ts +67 -0
  105. package/src/transforms/latest/stack/stack.mods.ts +12 -0
  106. package/src/transforms/latest/stack/stack.test.ts +160 -0
  107. package/src/transforms/latest/stack/stack.ts +102 -0
  108. package/src/transforms/latest/text/text.mods.ts +72 -0
  109. package/src/transforms/latest/text/text.test.ts +113 -0
  110. package/src/transforms/latest/text/text.ts +57 -0
  111. package/src/types/AnyExpression.ts +9 -0
  112. package/src/types/AttributeMods.ts +16 -0
  113. package/src/types/BaseOptions.ts +6 -0
  114. package/src/utils/addAttribute.test.ts +43 -0
  115. package/src/utils/addAttribute.ts +26 -0
  116. package/src/utils/addImportSpecifier.test.ts +36 -0
  117. package/src/utils/addImportSpecifier.ts +42 -0
  118. package/src/utils/getAttribute.ts +22 -0
  119. package/src/utils/getAttributeExpression.ts +22 -0
  120. package/src/utils/getAttributeValue.ts +20 -0
  121. package/src/utils/getClonedImportSpecifiers.ts +29 -0
  122. package/src/utils/getComponentJsxNames.ts +17 -0
  123. package/src/utils/getComponentLocalNames.ts +69 -0
  124. package/src/utils/getCompositeAttrValue.ts +39 -0
  125. package/src/utils/getMappingArray.ts +36 -0
  126. package/src/utils/getMappingExpression.ts +22 -0
  127. package/src/utils/getMappingValue.ts +52 -0
  128. package/src/utils/getShorthandAttributes.ts +54 -0
  129. package/src/utils/getSplitImportSpecifiers.ts +40 -0
  130. package/src/utils/getStaticAttributeExpression.ts +35 -0
  131. package/src/utils/getStyleExpression.ts +37 -0
  132. package/src/utils/getStyledComponentAliases.ts +28 -0
  133. package/src/utils/getStyledComponentName.ts +52 -0
  134. package/src/utils/getTransformPath.ts +17 -0
  135. package/src/utils/insertTodoWarning.ts +48 -0
  136. package/src/utils/isImportBindingUsed.ts +53 -0
  137. package/src/utils/isValidStyleType.ts +21 -0
  138. package/src/utils/mergeStyle.ts +64 -0
  139. package/src/utils/removeUnusedImport.test.ts +77 -0
  140. package/src/utils/removeUnusedImport.ts +57 -0
  141. package/src/utils/replaceElement.test.ts +181 -0
  142. package/src/utils/replaceElement.ts +106 -0
  143. package/src/utils/replaceStyledComponent.test.ts +57 -0
  144. package/src/utils/replaceStyledComponent.ts +60 -0
  145. package/src/utils/shouldTransformComponent.test.ts +61 -0
  146. package/src/utils/shouldTransformComponent.ts +40 -0
  147. package/src/utils/testUtils.ts +54 -0
  148. package/src/utils/transformAttributes.test.ts +544 -0
  149. package/src/utils/transformAttributes.ts +248 -0
  150. package/src/utils/transformComponent.test.ts +45 -0
  151. package/src/utils/transformComponent.ts +31 -0
  152. package/src/utils/transformImport.test.ts +175 -0
  153. package/src/utils/transformImport.ts +55 -0
  154. package/src/utils/transformImportAlias.test.ts +40 -0
  155. package/src/utils/transformImportAlias.ts +49 -0
  156. package/src/utils/transformStyledComponents.test.ts +172 -0
  157. package/src/utils/transformStyledComponents.ts +58 -0
@@ -0,0 +1,359 @@
1
+ import "jscodeshift";
2
+ function getClonedImportSpecifiers(j, specifiers = []) {
3
+ return specifiers.map((spec) => {
4
+ if (spec.type === "ImportSpecifier") {
5
+ if (spec.imported.type !== "Identifier" || spec.local?.type !== "Identifier")
6
+ return spec;
7
+ const clone = j.importSpecifier(
8
+ j.identifier(spec.imported.name),
9
+ j.identifier(spec.local.name)
10
+ );
11
+ return "importKind" in spec && spec.importKind === "type" && Object.assign(clone, { importKind: "type" }), clone;
12
+ } else
13
+ return j.importDefaultSpecifier(
14
+ j.identifier(spec.local?.name)
15
+ );
16
+ });
17
+ }
18
+ function getSplitImportSpecifiers(specifiers = [], componentName) {
19
+ const componentNames = /* @__PURE__ */ new Set([componentName, `${componentName}Props`]), specs = {
20
+ componentSpecs: [],
21
+ restSpecs: []
22
+ };
23
+ for (const spec of specifiers) {
24
+ if (spec.type === "ImportNamespaceSpecifier") {
25
+ specs.restSpecs.push(spec);
26
+ continue;
27
+ }
28
+ if (spec.type === "ImportSpecifier" || spec.type === "ImportDefaultSpecifier") {
29
+ let local;
30
+ if (spec.type === "ImportSpecifier") {
31
+ const loc = spec.local ?? spec.imported;
32
+ local = loc.type === "Identifier" ? loc.name : null;
33
+ }
34
+ spec.type === "ImportDefaultSpecifier" && (local = spec.local?.type === "Identifier" ? spec.local.name : null), local && componentNames.has(local) ? specs.componentSpecs.push(spec) : specs.restSpecs.push(spec);
35
+ }
36
+ }
37
+ return specs;
38
+ }
39
+ const DEFAULT_UI_PACKAGE = "@sanity/ui";
40
+ function transformImport(j, root, componentName, fromPackage = DEFAULT_UI_PACKAGE, toPackage = DEFAULT_UI_PACKAGE) {
41
+ if (fromPackage === toPackage)
42
+ return !1;
43
+ let hasChanges = !1;
44
+ return root.find(j.ImportDeclaration).forEach((path) => {
45
+ const node = path.node;
46
+ if (node.source.value !== fromPackage)
47
+ return;
48
+ const { componentSpecs, restSpecs } = getSplitImportSpecifiers(node.specifiers, componentName);
49
+ if (componentSpecs.length === 0)
50
+ return;
51
+ if (restSpecs.length === 0) {
52
+ if (node.source && typeof node.source == "object" && "value" in node.source) {
53
+ const sourceLiteral = node.source;
54
+ sourceLiteral.value = toPackage;
55
+ }
56
+ hasChanges = !0;
57
+ return;
58
+ }
59
+ path.node.specifiers = restSpecs;
60
+ const clonedImportSpecifiers = getClonedImportSpecifiers(j, componentSpecs);
61
+ path.insertAfter(j.importDeclaration(clonedImportSpecifiers, j.stringLiteral(toPackage))), hasChanges = !0;
62
+ }), hasChanges;
63
+ }
64
+ function getComponentLocalNames(j, root, componentName, options) {
65
+ const importedNames = /* @__PURE__ */ new Set(), packages = /* @__PURE__ */ new Set([
66
+ options?.fromPackage ?? DEFAULT_UI_PACKAGE,
67
+ options?.toPackage ?? DEFAULT_UI_PACKAGE
68
+ ]);
69
+ let hasOtherPackageImport = !1;
70
+ return root.find(j.ImportDeclaration).forEach((path) => {
71
+ const node = path.node;
72
+ if ("importKind" in node && node.importKind === "type")
73
+ return;
74
+ const matchesPackage = packages.has(node.source.value);
75
+ for (const spec of node.specifiers ?? []) {
76
+ if (spec.type !== "ImportSpecifier" || "importKind" in spec && spec.importKind === "type" || spec.imported.type !== "Identifier" || spec.imported.name !== componentName)
77
+ continue;
78
+ const local = spec.local?.type === "Identifier" ? spec.local.name : spec.imported.name;
79
+ if (!matchesPackage) {
80
+ hasOtherPackageImport = !0;
81
+ continue;
82
+ }
83
+ importedNames.add(local);
84
+ }
85
+ }), importedNames.size > 0 ? importedNames : hasOtherPackageImport ? /* @__PURE__ */ new Set() : root.find(j.JSXOpeningElement).some(({ node }) => node.name.type === "JSXIdentifier" && node.name.name === componentName) ? /* @__PURE__ */ new Set([componentName]) : /* @__PURE__ */ new Set();
86
+ }
87
+ function getAttribute(attrs, name) {
88
+ if (attrs) {
89
+ for (const attr of attrs)
90
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === name)
91
+ return attr;
92
+ }
93
+ }
94
+ function getAttributeExpression(attr, j) {
95
+ return attr.value ? attr.value.type === "StringLiteral" || attr.value.type === "Literal" ? attr.value : attr.value.type === "JSXExpressionContainer" ? attr.value.expression : null : j.booleanLiteral(!0);
96
+ }
97
+ function getStaticAttributeExpression(j, attrs, name) {
98
+ const attr = getAttribute(attrs, name);
99
+ if (!attr)
100
+ return null;
101
+ const expr = getAttributeExpression(attr, j);
102
+ return expr && (expr.type === "StringLiteral" || expr.type === "NumericLiteral" || expr.type === "BooleanLiteral" || expr.type === "Literal") ? expr.value : null;
103
+ }
104
+ function insertTodoWarning(j, path, warning) {
105
+ let target = null;
106
+ if (path.node.type === "ImportDeclaration")
107
+ target = path.node;
108
+ else if (path.node.type === "VariableDeclarator") {
109
+ const parent = path.parent;
110
+ parent?.node.type === "VariableDeclaration" && (target = parent.node);
111
+ } else path.parent?.node.type === "JSXElement" && (target = path.parent.node);
112
+ return !target || (target.comments ??= [], target.comments.some((comment) => comment.value.includes(warning))) ? !1 : (target.comments.unshift(j.commentLine(` UI-CODEMOD TODO: ${warning}`, !0)), !0);
113
+ }
114
+ function shouldTransformComponent(j, root, componentName, localNames, options) {
115
+ if (localNames.size > 0)
116
+ return !0;
117
+ const fromPackage = options?.fromPackage ?? DEFAULT_UI_PACKAGE, toPackage = options?.toPackage ?? DEFAULT_UI_PACKAGE;
118
+ return fromPackage === toPackage ? !1 : root.find(j.ImportDeclaration).some((path) => {
119
+ const node = path.node;
120
+ if (node.source.value !== fromPackage)
121
+ return !1;
122
+ const { componentSpecs } = getSplitImportSpecifiers(node.specifiers, componentName);
123
+ return componentSpecs.length > 0;
124
+ });
125
+ }
126
+ function getCompositeAttrValue(j, attrs, mapping) {
127
+ let compositeAttrValue = null;
128
+ for (const compositeKey of Object.keys(mapping)) {
129
+ const compositeMapping = mapping[compositeKey];
130
+ if (!compositeMapping)
131
+ continue;
132
+ let hasMatchingValues = !0;
133
+ for (const propName of Object.keys(compositeMapping)) {
134
+ const mappingValue = compositeMapping[propName], attrValue = getStaticAttributeExpression(j, attrs, propName);
135
+ if (mappingValue === void 0 || attrValue !== mappingValue) {
136
+ hasMatchingValues = !1;
137
+ break;
138
+ }
139
+ }
140
+ if (hasMatchingValues) {
141
+ compositeAttrValue = compositeKey;
142
+ break;
143
+ }
144
+ }
145
+ return compositeAttrValue;
146
+ }
147
+ function getMappingExpression(j, val) {
148
+ return val === void 0 ? j.identifier("undefined") : typeof val == "boolean" ? j.booleanLiteral(val) : typeof val == "number" ? j.numericLiteral(val) : j.stringLiteral(val);
149
+ }
150
+ function getMappingValue(mapping, expr) {
151
+ let matchedVal;
152
+ for (const val in mapping)
153
+ expr.value === mapping[val] && (matchedVal = mapping[val]);
154
+ if (matchedVal)
155
+ return matchedVal;
156
+ let key;
157
+ if ((expr.type === "NumericLiteral" || expr.type === "BooleanLiteral" || expr.type === "StringLiteral" || expr.type === "Literal") && (key = String(expr.value)), expr.type === "TemplateLiteral") {
158
+ const expressions = expr.expressions, quasis = expr.quasis;
159
+ expressions.length === 0 && quasis.length === 1 && (key = quasis[0]?.value.cooked ?? null);
160
+ }
161
+ if (!key)
162
+ return;
163
+ if (Object.prototype.hasOwnProperty.call(mapping, key))
164
+ return mapping[key];
165
+ const number = Number(key);
166
+ if (!Number.isNaN(number) && Object.prototype.hasOwnProperty.call(mapping, number))
167
+ return mapping[number];
168
+ }
169
+ function getMappingArray(j, arr, mapping, allowUndefined) {
170
+ if (arr.type !== "ArrayExpression")
171
+ return null;
172
+ const elements = arr.elements, output = [];
173
+ for (const el of elements) {
174
+ if (el == null || el.type === "SpreadElement")
175
+ return null;
176
+ const mappingValue = getMappingValue(mapping, el);
177
+ if (!mappingValue && !allowUndefined)
178
+ return null;
179
+ output.push(getMappingExpression(j, mappingValue));
180
+ }
181
+ return j.arrayExpression(output);
182
+ }
183
+ function getShorthandAttributes(j, expr, mod) {
184
+ const attributes = [];
185
+ if (!("props" in mod))
186
+ return [];
187
+ if (expr.type === "ArrayExpression")
188
+ for (const prop of mod.props) {
189
+ const styleArray = getMappingArray(j, expr, prop.mapping, !0);
190
+ styleArray && attributes.push(
191
+ j.jsxAttribute(j.jsxIdentifier(prop.name), j.jsxExpressionContainer(styleArray))
192
+ );
193
+ }
194
+ for (const prop of mod.props) {
195
+ const styleValue = getMappingValue(prop.mapping, expr);
196
+ styleValue !== void 0 && (typeof styleValue == "string" ? attributes.push(j.jsxAttribute(j.jsxIdentifier(prop.name), j.stringLiteral(styleValue))) : attributes.push(
197
+ j.jsxAttribute(
198
+ j.jsxIdentifier(prop.name),
199
+ j.jsxExpressionContainer(getMappingExpression(j, styleValue))
200
+ )
201
+ ));
202
+ }
203
+ return attributes;
204
+ }
205
+ function getStyleExpression(j, expr) {
206
+ if (expr.type === "Literal") {
207
+ if (expr.value === null)
208
+ return j.literal(null);
209
+ if (typeof expr.value == "boolean")
210
+ return j.booleanLiteral(expr.value);
211
+ if (typeof expr.value == "number")
212
+ return j.numericLiteral(expr.value);
213
+ if (typeof expr.value == "string")
214
+ return j.stringLiteral(expr.value);
215
+ }
216
+ return expr.type === "BooleanLiteral" ? j.booleanLiteral(expr.value) : expr.type === "NumericLiteral" ? j.numericLiteral(expr.value) : expr.type === "StringLiteral" ? j.stringLiteral(expr.value) : expr;
217
+ }
218
+ function isValidStyleType(expr) {
219
+ if (expr.type === "TemplateLiteral") {
220
+ const expressions = expr.expressions, quasis = expr.quasis;
221
+ return expressions.length === 0 && quasis.length === 1;
222
+ }
223
+ return expr.type === "StringLiteral" || expr.type === "Literal" || expr.type === "NumericLiteral" || expr.type === "BooleanLiteral" || expr.type === "NullLiteral";
224
+ }
225
+ function mergeStyle(j, attrs, styleKey, styleExpression) {
226
+ const styleProp = j.objectProperty(j.identifier(styleKey), styleExpression), styleIndex = attrs.findIndex(
227
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "style"
228
+ );
229
+ if (styleIndex === -1)
230
+ return attrs.push(
231
+ j.jsxAttribute(
232
+ j.jsxIdentifier("style"),
233
+ j.jsxExpressionContainer(j.objectExpression([styleProp]))
234
+ )
235
+ ), !0;
236
+ const styleAttr = attrs[styleIndex];
237
+ if (styleAttr.value?.type !== "JSXExpressionContainer")
238
+ return !1;
239
+ const expr = styleAttr.value.expression;
240
+ return expr.type === "ObjectExpression" ? (expr.properties = expr.properties.filter((prop) => {
241
+ if (prop.type !== "ObjectProperty" && prop.type !== "Property")
242
+ return !0;
243
+ const key = prop.key;
244
+ return (key.type === "Identifier" ? key.name : key.type === "StringLiteral" || key.type === "Literal" ? String(key.value) : null) !== styleKey;
245
+ }), expr.properties.push(styleProp), !0) : (styleAttr.value = j.jsxExpressionContainer(
246
+ j.objectExpression([j.spreadElement(expr), styleProp])
247
+ ), !0);
248
+ }
249
+ function transformAttributes(j, path, mods, todoWarning) {
250
+ if (!path.node.attributes)
251
+ return !1;
252
+ let hasChanges = !1;
253
+ const attrs = path.node.attributes, removeIdxs = [];
254
+ for (const [attrName, mod] of Object.entries(mods))
255
+ mod?.type === "warn-missing" && (getAttribute(attrs, attrName) || insertTodoWarning(j, path, mod.warning || todoWarning) && (hasChanges = !0));
256
+ for (let i = 0; i < attrs.length; i++) {
257
+ const attr = attrs[i];
258
+ if (!attr || attr.type !== "JSXAttribute" || attr.name.type !== "JSXIdentifier")
259
+ continue;
260
+ const mod = mods[attr.name.name], expr = getAttributeExpression(attr, j);
261
+ if (!(!mod || !expr)) {
262
+ if (mod.type === "remove" && removeIdxs.push(i), mod.type === "warn-only" && insertTodoWarning(j, path, mod.warning || todoWarning) && (hasChanges = !0), mod.type === "rename-only" && attr.name.type === "JSXIdentifier" && (attr.name.name = mod.name, hasChanges = !0), mod.type === "style-only") {
263
+ if (!expr || !isValidStyleType(expr)) {
264
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
265
+ continue;
266
+ }
267
+ mergeStyle(j, attrs, mod.style, getStyleExpression(j, expr)) ? removeIdxs.push(i) : insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
268
+ }
269
+ if (mod.type === "style-mapped") {
270
+ if (!expr || !isValidStyleType(expr)) {
271
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
272
+ continue;
273
+ }
274
+ const styleValue = getMappingValue(mod.mapping, expr);
275
+ if (styleValue === void 0) {
276
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
277
+ continue;
278
+ }
279
+ mergeStyle(j, attrs, mod.style, getMappingExpression(j, styleValue)) ? removeIdxs.push(i) : insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
280
+ }
281
+ if (mod.type === "shorthand-mapped") {
282
+ if (expr.type === "ConditionalExpression" || expr.type === "Identifier") {
283
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
284
+ continue;
285
+ }
286
+ const shorthandAttrs = getShorthandAttributes(j, expr, mod);
287
+ shorthandAttrs.length ? (attrs.splice(i + 1, 0, ...shorthandAttrs), removeIdxs.push(i)) : insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
288
+ }
289
+ if (mod.type === "composite") {
290
+ const triggerName = attr.name.name, compositeValue = getCompositeAttrValue(j, attrs, mod.mapping);
291
+ if (!compositeValue) {
292
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
293
+ continue;
294
+ }
295
+ attr.name.type === "JSXIdentifier" && (attr.name.name = mod.name), attr.value = j.stringLiteral(compositeValue);
296
+ for (const attrName of Object.keys(mod.mapping[compositeValue] || {})) {
297
+ if (attrName === triggerName)
298
+ continue;
299
+ const otherAttr = getAttribute(attrs, attrName);
300
+ if (otherAttr) {
301
+ const k = attrs.indexOf(otherAttr);
302
+ k !== -1 && removeIdxs.push(k);
303
+ }
304
+ }
305
+ hasChanges = !0;
306
+ }
307
+ if (mod.type === "mapped-only" || mod.type === "rename-mapped") {
308
+ if (mod.type === "rename-mapped" && attr.name.type === "JSXIdentifier" && (attr.name.name = mod.name), expr.type === "ConditionalExpression" || expr.type === "Identifier") {
309
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
310
+ continue;
311
+ }
312
+ if (expr.type === "ArrayExpression") {
313
+ const styleArray = getMappingArray(j, expr, mod.mapping);
314
+ if (!styleArray) {
315
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
316
+ continue;
317
+ }
318
+ attr.value?.type === "JSXExpressionContainer" ? attr.value.expression = styleArray : attr.value = j.jsxExpressionContainer(styleArray), hasChanges = !0;
319
+ continue;
320
+ }
321
+ const styleValue = getMappingValue(mod.mapping, expr);
322
+ if (styleValue === void 0) {
323
+ insertTodoWarning(j, path, todoWarning) && (hasChanges = !0);
324
+ continue;
325
+ }
326
+ typeof styleValue == "string" ? attr.value = j.stringLiteral(styleValue) : attr.value = j.jsxExpressionContainer(getMappingExpression(j, styleValue)), hasChanges = !0;
327
+ }
328
+ }
329
+ }
330
+ const idxsToRemove = [...new Set(removeIdxs)].sort((a, b) => b - a);
331
+ if (idxsToRemove.length > 0) {
332
+ hasChanges = !0;
333
+ for (const i of idxsToRemove)
334
+ attrs.splice(i, 1);
335
+ }
336
+ return hasChanges;
337
+ }
338
+ function transformComponent(fileInfo, api, fn) {
339
+ const j = api.jscodeshift, root = j(fileInfo.source);
340
+ let hasChanges = !1;
341
+ return fn({
342
+ j,
343
+ root,
344
+ markChanged: () => {
345
+ hasChanges = !0;
346
+ }
347
+ }), hasChanges ? root.toSource() : void 0;
348
+ }
349
+ export {
350
+ getAttribute,
351
+ getComponentLocalNames,
352
+ getStaticAttributeExpression,
353
+ insertTodoWarning,
354
+ shouldTransformComponent,
355
+ transformAttributes,
356
+ transformComponent,
357
+ transformImport
358
+ };
359
+ //# sourceMappingURL=transformComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformComponent.js","sources":["../../src/utils/getClonedImportSpecifiers.ts","../../src/utils/getSplitImportSpecifiers.ts","../../src/utils/transformImport.ts","../../src/utils/getComponentLocalNames.ts","../../src/utils/getAttribute.ts","../../src/utils/getAttributeExpression.ts","../../src/utils/getStaticAttributeExpression.ts","../../src/utils/insertTodoWarning.ts","../../src/utils/shouldTransformComponent.ts","../../src/utils/getCompositeAttrValue.ts","../../src/utils/getMappingExpression.ts","../../src/utils/getMappingValue.ts","../../src/utils/getMappingArray.ts","../../src/utils/getShorthandAttributes.ts","../../src/utils/getStyleExpression.ts","../../src/utils/isValidStyleType.ts","../../src/utils/mergeStyle.ts","../../src/utils/transformAttributes.ts","../../src/utils/transformComponent.ts"],"sourcesContent":["import type {API, ImportDefaultSpecifier, ImportSpecifier} from 'jscodeshift'\n\nexport function getClonedImportSpecifiers(\n j: API['jscodeshift'],\n specifiers: (ImportSpecifier | ImportDefaultSpecifier)[] = [],\n) {\n return specifiers.map((spec) => {\n if (spec.type === 'ImportSpecifier') {\n if (spec.imported.type !== 'Identifier' || spec.local?.type !== 'Identifier') {\n return spec\n }\n\n const clone = j.importSpecifier(\n j.identifier(spec.imported.name),\n j.identifier(spec.local.name),\n )\n\n if ('importKind' in spec && spec.importKind === 'type') {\n Object.assign(clone, {importKind: 'type'})\n }\n\n return clone\n } else {\n return j.importDefaultSpecifier(\n j.identifier((spec as ImportDefaultSpecifier).local?.name as string),\n )\n }\n })\n}\n","import type {ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier} from 'jscodeshift'\n\nexport function getSplitImportSpecifiers(\n specifiers: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[] = [],\n componentName: string,\n) {\n const componentNames = new Set([componentName, `${componentName}Props`])\n const specs = {\n componentSpecs: [] as (ImportSpecifier | ImportDefaultSpecifier)[],\n restSpecs: [] as (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[],\n }\n\n for (const spec of specifiers) {\n if (spec.type === 'ImportNamespaceSpecifier') {\n specs.restSpecs.push(spec)\n continue\n }\n\n if (spec.type === 'ImportSpecifier' || spec.type === 'ImportDefaultSpecifier') {\n let local\n\n if (spec.type === 'ImportSpecifier') {\n const loc = spec.local ?? spec.imported\n local = loc.type === 'Identifier' ? loc.name : null\n }\n\n if (spec.type === 'ImportDefaultSpecifier') {\n local = spec.local?.type === 'Identifier' ? spec.local.name : null\n }\n\n if (local && componentNames.has(local)) {\n specs.componentSpecs.push(spec)\n } else {\n specs.restSpecs.push(spec)\n }\n }\n }\n\n return specs\n}\n","import type {API, Collection} from 'jscodeshift'\n\nimport {getClonedImportSpecifiers} from './getClonedImportSpecifiers'\nimport {getSplitImportSpecifiers} from './getSplitImportSpecifiers'\n\nexport const DEFAULT_UI_PACKAGE = '@sanity/ui'\n\n/**\n * Rewrites imports from `fromPackage` to `toPackage`, splitting imports if needed.\n * Returns whether the AST was updated.\n */\nexport function transformImport(\n j: API['jscodeshift'],\n root: Collection,\n componentName: string,\n fromPackage: string = DEFAULT_UI_PACKAGE,\n toPackage: string = DEFAULT_UI_PACKAGE,\n): boolean {\n if (fromPackage === toPackage) {\n return false\n }\n\n let hasChanges = false\n\n root.find(j.ImportDeclaration).forEach((path) => {\n const node = path.node\n\n if (node.source.value !== fromPackage) {\n return\n }\n\n const {componentSpecs, restSpecs} = getSplitImportSpecifiers(node.specifiers, componentName)\n\n if (componentSpecs.length === 0) {\n return\n }\n\n if (restSpecs.length === 0) {\n if (node.source && typeof node.source === 'object' && 'value' in node.source) {\n const sourceLiteral = node.source as {value: string}\n sourceLiteral.value = toPackage\n }\n\n hasChanges = true\n return\n }\n\n path.node.specifiers = restSpecs\n const clonedImportSpecifiers = getClonedImportSpecifiers(j, componentSpecs)\n path.insertAfter(j.importDeclaration(clonedImportSpecifiers, j.stringLiteral(toPackage)))\n hasChanges = true\n })\n\n return hasChanges\n}\n","import type {API, Collection} from 'jscodeshift'\n\nimport type {BaseOptions} from '../types/BaseOptions'\nimport {DEFAULT_UI_PACKAGE} from './transformImport'\n\nexport function getComponentLocalNames(\n j: API['jscodeshift'],\n root: Collection,\n componentName: string,\n options?: BaseOptions,\n): Set<string> {\n const importedNames = new Set<string>()\n const packages = new Set([\n options?.fromPackage ?? DEFAULT_UI_PACKAGE,\n options?.toPackage ?? DEFAULT_UI_PACKAGE,\n ])\n let hasOtherPackageImport = false\n\n root.find(j.ImportDeclaration).forEach((path) => {\n const node = path.node\n\n if ('importKind' in node && node.importKind === 'type') {\n return\n }\n\n const matchesPackage = packages.has(node.source.value as string)\n\n for (const spec of node.specifiers ?? []) {\n if (spec.type !== 'ImportSpecifier') {\n continue\n }\n\n if ('importKind' in spec && spec.importKind === 'type') {\n continue\n }\n\n if (spec.imported.type !== 'Identifier' || spec.imported.name !== componentName) {\n continue\n }\n\n const local = spec.local?.type === 'Identifier' ? spec.local.name : spec.imported.name\n\n if (!matchesPackage) {\n hasOtherPackageImport = true\n continue\n }\n\n importedNames.add(local)\n }\n })\n\n if (importedNames.size > 0) {\n return importedNames\n }\n\n if (hasOtherPackageImport) {\n return new Set()\n }\n\n const usesComponentInJsx = root.find(j.JSXOpeningElement).some(({node}) => {\n return node.name.type === 'JSXIdentifier' && node.name.name === componentName\n })\n\n if (usesComponentInJsx) {\n return new Set([componentName])\n }\n\n return new Set()\n}\n","import type {JSXAttribute, JSXElement} from 'jscodeshift'\n\nexport function getAttribute(\n attrs: JSXElement['openingElement']['attributes'],\n name: string,\n): JSXAttribute | undefined {\n if (!attrs) {\n return undefined\n }\n\n for (const attr of attrs) {\n if (\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === name\n ) {\n return attr\n }\n }\n\n return undefined\n}\n","import {type API, type JSXAttribute} from 'jscodeshift'\n\nimport {type AnyExpression} from '../types/AnyExpression'\n\nexport function getAttributeExpression(\n attr: JSXAttribute,\n j: API['jscodeshift'],\n): AnyExpression | null {\n if (!attr.value) {\n return j.booleanLiteral(true)\n }\n\n if (attr.value.type === 'StringLiteral' || attr.value.type === 'Literal') {\n return attr.value\n }\n\n if (attr.value.type === 'JSXExpressionContainer') {\n return attr.value.expression\n }\n\n return null\n}\n","import type {API, JSXAttribute, JSXSpreadAttribute} from 'jscodeshift'\n\nimport {getAttribute} from './getAttribute'\nimport {getAttributeExpression} from './getAttributeExpression'\n\nexport type CompositePrimitive = string | number | boolean\n\nexport function getStaticAttributeExpression(\n j: API['jscodeshift'],\n attrs: (JSXAttribute | JSXSpreadAttribute)[],\n name: string,\n): CompositePrimitive | null {\n const attr = getAttribute(attrs, name)\n\n if (!attr) {\n return null\n }\n\n const expr = getAttributeExpression(attr, j)\n\n if (!expr) {\n return null\n }\n\n if (\n expr.type === 'StringLiteral' ||\n expr.type === 'NumericLiteral' ||\n expr.type === 'BooleanLiteral' ||\n expr.type === 'Literal'\n ) {\n return expr.value as string | number | boolean\n }\n\n return null\n}\n","import {\n type API,\n type ASTPath,\n type ImportDeclaration,\n type JSXOpeningElement,\n type VariableDeclarator,\n} from 'jscodeshift'\n\ntype CommentableNode = {\n comments?: {type: string; value: string; leading?: boolean}[] | null\n}\n\n/**\n * Inserts a `UI-CODEMOD TODO` comment.\n * Returns whether the AST was updated.\n */\nexport function insertTodoWarning(\n j: API['jscodeshift'],\n path: ASTPath<JSXOpeningElement | ImportDeclaration | VariableDeclarator>,\n warning: string,\n): boolean {\n let target: CommentableNode | null = null\n\n if (path.node.type === 'ImportDeclaration') {\n target = path.node\n } else if (path.node.type === 'VariableDeclarator') {\n const parent = path.parent\n\n if (parent?.node.type === 'VariableDeclaration') {\n target = parent.node\n }\n } else if (path.parent?.node.type === 'JSXElement') {\n target = path.parent.node\n }\n\n if (!target) {\n return false\n }\n\n target.comments ??= []\n\n if (target.comments.some((comment) => comment.value.includes(warning))) {\n return false\n }\n\n target.comments.unshift(j.commentLine(` UI-CODEMOD TODO: ${warning}`, true))\n return true\n}\n","import type {API, Collection} from 'jscodeshift'\n\nimport type {BaseOptions} from '../types/BaseOptions'\nimport {getSplitImportSpecifiers} from './getSplitImportSpecifiers'\nimport {DEFAULT_UI_PACKAGE} from './transformImport'\n\n/**\n * Returns whether a component transform should run on this file, based on local\n * usage or a pending import rewrite.\n */\nexport function shouldTransformComponent(\n j: API['jscodeshift'],\n root: Collection,\n componentName: string,\n localNames: Set<string>,\n options?: BaseOptions,\n): boolean {\n if (localNames.size > 0) {\n return true\n }\n\n const fromPackage = options?.fromPackage ?? DEFAULT_UI_PACKAGE\n const toPackage = options?.toPackage ?? DEFAULT_UI_PACKAGE\n\n if (fromPackage === toPackage) {\n return false\n }\n\n return root.find(j.ImportDeclaration).some((path) => {\n const node = path.node\n\n if (node.source.value !== fromPackage) {\n return false\n }\n\n const {componentSpecs} = getSplitImportSpecifiers(node.specifiers, componentName)\n\n return componentSpecs.length > 0\n })\n}\n","import type {API, JSXAttribute, JSXSpreadAttribute} from 'jscodeshift'\n\nimport type {CompositeAttributeMapping} from '../types/AttributeMods'\nimport {getStaticAttributeExpression} from './getStaticAttributeExpression'\n\nexport function getCompositeAttrValue(\n j: API['jscodeshift'],\n attrs: (JSXAttribute | JSXSpreadAttribute)[],\n mapping: CompositeAttributeMapping,\n) {\n let compositeAttrValue: string | null = null\n\n for (const compositeKey of Object.keys(mapping)) {\n const compositeMapping = mapping[compositeKey]\n\n if (!compositeMapping) {\n continue\n }\n\n let hasMatchingValues = true\n\n for (const propName of Object.keys(compositeMapping)) {\n const mappingValue = compositeMapping[propName]\n const attrValue = getStaticAttributeExpression(j, attrs, propName)\n\n if (mappingValue === undefined || attrValue !== mappingValue) {\n hasMatchingValues = false\n break\n }\n }\n\n if (hasMatchingValues) {\n compositeAttrValue = compositeKey\n break\n }\n }\n\n return compositeAttrValue\n}\n","import {type API} from 'jscodeshift'\n\nimport type {AnyExpression} from '../types/AnyExpression'\n\nexport function getMappingExpression(\n j: API['jscodeshift'],\n val: string | boolean | number | undefined,\n): AnyExpression {\n if (val === undefined) {\n return j.identifier('undefined')\n }\n\n if (typeof val === 'boolean') {\n return j.booleanLiteral(val)\n }\n\n if (typeof val === 'number') {\n return j.numericLiteral(val)\n }\n\n return j.stringLiteral(val)\n}\n","import type {AnyExpression} from '../types/AnyExpression'\nimport type {AttributeMapping} from '../types/AttributeMods'\n\nexport function getMappingValue(mapping: AttributeMapping, expr: AnyExpression) {\n let matchedVal\n\n for (const val in mapping) {\n if (expr.value === mapping[val]) {\n matchedVal = mapping[val]\n }\n }\n\n if (matchedVal) {\n return matchedVal\n }\n\n let key\n\n if (\n expr.type === 'NumericLiteral' ||\n expr.type === 'BooleanLiteral' ||\n expr.type === 'StringLiteral' ||\n expr.type === 'Literal'\n ) {\n key = String(expr.value)\n }\n\n if (expr.type === 'TemplateLiteral') {\n const expressions = expr.expressions as unknown[]\n const quasis = expr.quasis as {value: {cooked: string | null}}[]\n\n if (expressions.length === 0 && quasis.length === 1) {\n key = quasis[0]?.value.cooked ?? null\n }\n }\n\n if (!key) {\n return\n }\n\n if (Object.prototype.hasOwnProperty.call(mapping, key)) {\n return mapping[key]\n }\n\n const number = Number(key)\n\n if (!Number.isNaN(number) && Object.prototype.hasOwnProperty.call(mapping, number)) {\n return mapping[number]\n }\n\n return\n}\n","import {type API, type ArrayExpression} from 'jscodeshift'\n\nimport type {AnyExpression} from '../types/AnyExpression'\nimport type {AttributeMapping} from '../types/AttributeMods'\nimport {getMappingExpression} from './getMappingExpression'\nimport {getMappingValue} from './getMappingValue'\n\nexport function getMappingArray(\n j: API['jscodeshift'],\n arr: AnyExpression,\n mapping: AttributeMapping,\n allowUndefined?: boolean,\n): ArrayExpression | null {\n if (arr.type !== 'ArrayExpression') {\n return null\n }\n\n const elements = arr.elements as (AnyExpression | null)[]\n const output: AnyExpression[] = []\n\n for (const el of elements) {\n if (el == null || el.type === 'SpreadElement') {\n return null\n }\n\n const mappingValue = getMappingValue(mapping, el)\n\n if (!mappingValue && !allowUndefined) {\n return null\n }\n\n output.push(getMappingExpression(j, mappingValue))\n }\n\n return j.arrayExpression(output as never[])\n}\n","import type {API, JSXAttribute} from 'jscodeshift'\n\nimport type {AnyExpression} from '../types/AnyExpression'\nimport type {AttributeMod} from '../types/AttributeMods'\nimport {getMappingArray} from './getMappingArray'\nimport {getMappingExpression} from './getMappingExpression'\nimport {getMappingValue} from './getMappingValue'\n\nexport function getShorthandAttributes(\n j: API['jscodeshift'],\n expr: AnyExpression,\n mod: AttributeMod,\n) {\n const attributes: JSXAttribute[] = []\n\n if (!('props' in mod)) {\n return []\n }\n\n if (expr.type === 'ArrayExpression') {\n for (const prop of mod.props) {\n const styleArray = getMappingArray(j, expr, prop.mapping, true)\n\n if (!styleArray) {\n continue\n }\n\n attributes.push(\n j.jsxAttribute(j.jsxIdentifier(prop.name), j.jsxExpressionContainer(styleArray)),\n )\n }\n }\n\n for (const prop of mod.props) {\n const styleValue = getMappingValue(prop.mapping, expr)\n\n if (styleValue === undefined) {\n continue\n }\n\n if (typeof styleValue === 'string') {\n attributes.push(j.jsxAttribute(j.jsxIdentifier(prop.name), j.stringLiteral(styleValue)))\n } else {\n attributes.push(\n j.jsxAttribute(\n j.jsxIdentifier(prop.name),\n j.jsxExpressionContainer(getMappingExpression(j, styleValue) as never),\n ),\n )\n }\n }\n\n return attributes\n}\n","import {type API} from 'jscodeshift'\n\nimport {type AnyExpression} from '../types/AnyExpression'\n\nexport function getStyleExpression(j: API['jscodeshift'], expr: AnyExpression): AnyExpression {\n if (expr.type === 'Literal') {\n if (expr.value === null) {\n return j.literal(null)\n }\n\n if (typeof expr.value === 'boolean') {\n return j.booleanLiteral(expr.value)\n }\n\n if (typeof expr.value === 'number') {\n return j.numericLiteral(expr.value)\n }\n\n if (typeof expr.value === 'string') {\n return j.stringLiteral(expr.value)\n }\n }\n\n if (expr.type === 'BooleanLiteral') {\n return j.booleanLiteral(expr.value as boolean)\n }\n\n if (expr.type === 'NumericLiteral') {\n return j.numericLiteral(expr.value as number)\n }\n\n if (expr.type === 'StringLiteral') {\n return j.stringLiteral(expr.value as string)\n }\n\n return expr\n}\n","import {type AnyExpression} from '../types/AnyExpression'\n\nexport function isValidStyleType(expr: AnyExpression) {\n if (expr.type === 'TemplateLiteral') {\n const expressions = expr.expressions as unknown[]\n const quasis = expr.quasis as {value: {cooked: string | null}}[]\n return expressions.length === 0 && quasis.length === 1\n }\n\n if (\n expr.type === 'StringLiteral' ||\n expr.type === 'Literal' ||\n expr.type === 'NumericLiteral' ||\n expr.type === 'BooleanLiteral' ||\n expr.type === 'NullLiteral'\n ) {\n return true\n }\n\n return false\n}\n","import {type API, type JSXAttribute, type JSXSpreadAttribute} from 'jscodeshift'\n\nimport {type AnyExpression} from '../types/AnyExpression'\n\nexport function mergeStyle(\n j: API['jscodeshift'],\n attrs: (JSXAttribute | JSXSpreadAttribute)[],\n styleKey: string,\n styleExpression: AnyExpression,\n) {\n const styleProp = j.objectProperty(j.identifier(styleKey), styleExpression as never)\n\n const styleIndex = attrs.findIndex(\n (a): a is JSXAttribute =>\n a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === 'style',\n )\n\n if (styleIndex === -1) {\n attrs.push(\n j.jsxAttribute(\n j.jsxIdentifier('style'),\n j.jsxExpressionContainer(j.objectExpression([styleProp])),\n ),\n )\n\n return true\n }\n\n const styleAttr = attrs[styleIndex] as JSXAttribute\n\n if (styleAttr.value?.type !== 'JSXExpressionContainer') {\n return false\n }\n\n const expr = styleAttr.value.expression\n\n if (expr.type === 'ObjectExpression') {\n expr.properties = expr.properties.filter((prop) => {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property') {\n return true\n }\n\n const key = prop.key\n\n const name =\n key.type === 'Identifier'\n ? key.name\n : key.type === 'StringLiteral' || key.type === 'Literal'\n ? String(key.value)\n : null\n\n return name !== styleKey\n })\n\n expr.properties.push(styleProp)\n return true\n }\n\n styleAttr.value = j.jsxExpressionContainer(\n j.objectExpression([j.spreadElement(expr as never), styleProp]),\n )\n\n return true\n}\n","import {type API, type ASTPath, type JSXOpeningElement} from 'jscodeshift'\n\nimport {type AttributeMods} from '../types/AttributeMods'\nimport {getAttribute} from './getAttribute'\nimport {getAttributeExpression} from './getAttributeExpression'\nimport {getCompositeAttrValue} from './getCompositeAttrValue'\nimport {getMappingArray} from './getMappingArray'\nimport {getMappingExpression} from './getMappingExpression'\nimport {getMappingValue} from './getMappingValue'\nimport {getShorthandAttributes} from './getShorthandAttributes'\nimport {getStyleExpression} from './getStyleExpression'\nimport {insertTodoWarning} from './insertTodoWarning'\nimport {isValidStyleType} from './isValidStyleType'\nimport {mergeStyle} from './mergeStyle'\n\n/**\n * Applies attribute migration rules to a JSX opening element.\n * Returns whether the AST was updated.\n */\nexport function transformAttributes(\n j: API['jscodeshift'],\n path: ASTPath<JSXOpeningElement>,\n mods: AttributeMods,\n todoWarning: string,\n): boolean {\n if (!path.node.attributes) {\n return false\n }\n\n let hasChanges = false\n const attrs = path.node.attributes\n const removeIdxs: number[] = []\n\n for (const [attrName, mod] of Object.entries(mods)) {\n if (mod?.type !== 'warn-missing') {\n continue\n }\n\n if (getAttribute(attrs, attrName)) {\n continue\n }\n\n if (insertTodoWarning(j, path, mod.warning || todoWarning)) {\n hasChanges = true\n }\n }\n\n for (let i = 0; i < attrs.length; i++) {\n const attr = attrs[i]\n\n if (!attr || attr.type !== 'JSXAttribute' || attr.name.type !== 'JSXIdentifier') {\n continue\n }\n\n const mod = mods[attr.name.name]\n const expr = getAttributeExpression(attr, j)\n\n if (!mod || !expr) {\n continue\n }\n\n if (mod.type === 'remove') {\n removeIdxs.push(i)\n }\n\n if (mod.type === 'warn-only') {\n if (insertTodoWarning(j, path, mod.warning || todoWarning)) {\n hasChanges = true\n }\n }\n\n if (mod.type === 'rename-only') {\n if (attr.name.type === 'JSXIdentifier') {\n attr.name.name = mod.name\n hasChanges = true\n }\n }\n\n if (mod.type === 'style-only') {\n if (!expr || !isValidStyleType(expr)) {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n const merged = mergeStyle(j, attrs, mod.style, getStyleExpression(j, expr))\n\n if (merged) {\n removeIdxs.push(i)\n } else if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n }\n\n if (mod.type === 'style-mapped') {\n if (!expr || !isValidStyleType(expr)) {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n const styleValue = getMappingValue(mod.mapping, expr)\n\n if (styleValue === undefined) {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n const merged = mergeStyle(j, attrs, mod.style, getMappingExpression(j, styleValue))\n\n if (merged) {\n removeIdxs.push(i)\n } else if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n }\n\n if (mod.type === 'shorthand-mapped') {\n if (expr.type === 'ConditionalExpression' || expr.type === 'Identifier') {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n const shorthandAttrs = getShorthandAttributes(j, expr, mod)\n\n if (shorthandAttrs.length) {\n attrs.splice(i + 1, 0, ...shorthandAttrs)\n removeIdxs.push(i)\n } else if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n }\n\n if (mod.type === 'composite') {\n const triggerName = attr.name.name\n const compositeValue = getCompositeAttrValue(j, attrs, mod.mapping)\n\n if (!compositeValue) {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n if (attr.name.type === 'JSXIdentifier') {\n attr.name.name = mod.name\n }\n\n attr.value = j.stringLiteral(compositeValue)\n\n for (const attrName of Object.keys(mod.mapping[compositeValue] || {})) {\n if (attrName === triggerName) {\n continue\n }\n\n const otherAttr = getAttribute(attrs, attrName)\n\n if (otherAttr) {\n const k = attrs.indexOf(otherAttr)\n\n if (k !== -1) {\n removeIdxs.push(k)\n }\n }\n }\n\n hasChanges = true\n }\n\n if (mod.type === 'mapped-only' || mod.type === 'rename-mapped') {\n if (mod.type === 'rename-mapped') {\n if (attr.name.type === 'JSXIdentifier') {\n attr.name.name = mod.name\n }\n }\n\n if (expr.type === 'ConditionalExpression' || expr.type === 'Identifier') {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n if (expr.type === 'ArrayExpression') {\n const styleArray = getMappingArray(j, expr, mod.mapping)\n\n if (!styleArray) {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n if (attr.value?.type === 'JSXExpressionContainer') {\n attr.value.expression = styleArray\n } else {\n attr.value = j.jsxExpressionContainer(styleArray)\n }\n\n hasChanges = true\n continue\n }\n\n const styleValue = getMappingValue(mod.mapping, expr)\n\n if (styleValue === undefined) {\n if (insertTodoWarning(j, path, todoWarning)) {\n hasChanges = true\n }\n\n continue\n }\n\n if (typeof styleValue === 'string') {\n attr.value = j.stringLiteral(styleValue)\n } else {\n attr.value = j.jsxExpressionContainer(getMappingExpression(j, styleValue) as never)\n }\n\n hasChanges = true\n }\n }\n\n const idxsToRemove = [...new Set(removeIdxs)].sort((a, b) => b - a)\n\n if (idxsToRemove.length > 0) {\n hasChanges = true\n\n for (const i of idxsToRemove) {\n attrs.splice(i, 1)\n }\n }\n\n return hasChanges\n}\n","import type {API, Collection, FileInfo} from 'jscodeshift'\n\nexport type TransformContext = {\n j: API['jscodeshift']\n root: Collection\n markChanged: () => void\n}\n\n/**\n * Runs a component transform on a file and only calls `toSource()` when\n * `markChanged()` was invoked. Returns `undefined` for no-op files.\n */\nexport function transformComponent(\n fileInfo: FileInfo,\n api: API,\n fn: (ctx: TransformContext) => void,\n): string | undefined {\n const j = api.jscodeshift\n const root = j(fileInfo.source)\n let hasChanges = false\n\n fn({\n j,\n root,\n markChanged: () => {\n hasChanges = true\n },\n })\n\n return hasChanges ? root.toSource() : undefined\n}\n"],"names":[],"mappings":";AAEO,SAAS,0BACd,GACA,aAA2D,IAC3D;AACA,SAAO,WAAW,IAA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CAAC,YAAY;AACX,8BAAkB,GAAG,MAAM,WAAW,MACxC,aAAa;AAGf;AAAA,UACF;AAEI,eAAK,OAAO,SAAS,2BACvB,KAAK,MAAM,aAAa,aAExB,KAAK,QAAQ,EAAE,uBAAuB,UAAU,GAGlD,aAAa;AACb;AAAA,QACF;AAEA,cAAM,aAAa,gBAAgB,IAAI,SAAS,IAAI;AAEpD,YAAI,eAAe,QAAW;AACxB,4BAAkB,GAAG,MAAM,WAAW,MACxC,aAAa;AAGf;AAAA,QACF;AAEI,eAAO,cAAe,WACxB,KAAK,QAAQ,EAAE,cAAc,UAAU,IAEvC,KAAK,QAAQ,EAAE,uBAAuB,qBAAqB,GAAG,UAAU,CAAU,GAGpF,aAAa;AAAA,MACf;AAAA,IAAA;AAAA,EACF;AAEA,QAAM,eAAe,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAElE,MAAI,aAAa,SAAS,GAAG;AAC3B,iBAAa;AAEb,eAAW,KAAK;AACd,YAAM,OAAO,GAAG,CAAC;AAAA,EAErB;AAEA,SAAO;AACT;AC3OO,SAAS,mBACd,UACA,KACA,IACoB;AACpB,QAAM,IAAI,IAAI,aACR,OAAO,EAAE,SAAS,MAAM;AAC9B,MAAI,aAAa;AAEjB,SAAA,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,aAAa,MAAM;AACjB,mBAAa;AAAA,IACf;AAAA,EAAA,CACD,GAEM,aAAa,KAAK,aAAa;AACxC;"}
@@ -0,0 +1,47 @@
1
+ import { Command } from "@oclif/core";
2
+ import { Interfaces } from "@oclif/core";
3
+
4
+ declare type Args<T extends typeof Command> = Interfaces.InferredArgs<
5
+ T["args"]
6
+ >;
7
+
8
+ declare abstract class BaseCommand<T extends typeof Command> extends Command {
9
+ static baseFlags: {
10
+ paths: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
11
+ fromPackage: Interfaces.OptionFlag<
12
+ string | undefined,
13
+ Interfaces.CustomOptions
14
+ >;
15
+ toPackage: Interfaces.OptionFlag<
16
+ string | undefined,
17
+ Interfaces.CustomOptions
18
+ >;
19
+ extensions: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
20
+ dry: Interfaces.BooleanFlag<boolean>;
21
+ print: Interfaces.BooleanFlag<boolean>;
22
+ verbose: Interfaces.OptionFlag<number, Interfaces.CustomOptions>;
23
+ };
24
+ protected flags: Flags<T>;
25
+ protected args: Args<T>;
26
+ static examples: string[];
27
+ init(): Promise<void>;
28
+ protected catch(
29
+ err: Error & {
30
+ exitCode?: number;
31
+ },
32
+ ): Promise<unknown>;
33
+ protected finally(_: Error | undefined): Promise<unknown>;
34
+ }
35
+
36
+ /** @public */
37
+ declare class Box extends BaseCommand<typeof Box> {
38
+ static description: string;
39
+ run(): Promise<void>;
40
+ }
41
+ export default Box;
42
+
43
+ declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
44
+ (typeof BaseCommand)["baseFlags"] & T["flags"]
45
+ >;
46
+
47
+ export {};
@@ -0,0 +1,17 @@
1
+ import { run } from "jscodeshift/src/Runner.js";
2
+ import { BaseCommand, getTransformPath } from "../../_chunks-es/getTransformPath.js";
3
+ class Box extends BaseCommand {
4
+ static description = "Transform Box component";
5
+ async run() {
6
+ const { flags } = await this.parse(Box), { paths, ...restFlags } = flags, transformPath = getTransformPath(this.config.root, "latest", "box");
7
+ await run(transformPath, paths, {
8
+ babel: !0,
9
+ parser: "tsx",
10
+ ...restFlags
11
+ });
12
+ }
13
+ }
14
+ export {
15
+ Box as default
16
+ };
17
+ //# sourceMappingURL=box.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box.js","sources":["../../../src/commands/latest/box.ts"],"sourcesContent":["import {run} from 'jscodeshift/src/Runner.js'\n\nimport {BaseCommand} from '../../baseCommand'\nimport {getTransformPath} from '../../utils/getTransformPath'\n\n/** @public */\nexport default class Box extends BaseCommand<typeof Box> {\n static override description = 'Transform Box component'\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(Box)\n const {paths, ...restFlags} = flags\n const transformPath = getTransformPath(this.config.root, 'latest', 'box')\n\n await run(transformPath, paths, {\n babel: true,\n parser: 'tsx',\n ...restFlags,\n })\n }\n}\n"],"names":[],"mappings":";;AAMA,MAAqB,YAAY,YAAwB;AAAA,EACvD,OAAgB,cAAc;AAAA,EAE9B,MAAa,MAAqB;AAChC,UAAM,EAAC,UAAS,MAAM,KAAK,MAAM,GAAG,GAC9B,EAAC,OAAO,GAAG,UAAA,IAAa,OACxB,gBAAgB,iBAAiB,KAAK,OAAO,MAAM,UAAU,KAAK;AAExE,UAAM,IAAI,eAAe,OAAO;AAAA,MAC9B,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;"}
@@ -0,0 +1,47 @@
1
+ import { Command } from "@oclif/core";
2
+ import { Interfaces } from "@oclif/core";
3
+
4
+ declare type Args<T extends typeof Command> = Interfaces.InferredArgs<
5
+ T["args"]
6
+ >;
7
+
8
+ declare abstract class BaseCommand<T extends typeof Command> extends Command {
9
+ static baseFlags: {
10
+ paths: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
11
+ fromPackage: Interfaces.OptionFlag<
12
+ string | undefined,
13
+ Interfaces.CustomOptions
14
+ >;
15
+ toPackage: Interfaces.OptionFlag<
16
+ string | undefined,
17
+ Interfaces.CustomOptions
18
+ >;
19
+ extensions: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
20
+ dry: Interfaces.BooleanFlag<boolean>;
21
+ print: Interfaces.BooleanFlag<boolean>;
22
+ verbose: Interfaces.OptionFlag<number, Interfaces.CustomOptions>;
23
+ };
24
+ protected flags: Flags<T>;
25
+ protected args: Args<T>;
26
+ static examples: string[];
27
+ init(): Promise<void>;
28
+ protected catch(
29
+ err: Error & {
30
+ exitCode?: number;
31
+ },
32
+ ): Promise<unknown>;
33
+ protected finally(_: Error | undefined): Promise<unknown>;
34
+ }
35
+
36
+ /** @public */
37
+ declare class Card extends BaseCommand<typeof Card> {
38
+ static description: string;
39
+ run(): Promise<void>;
40
+ }
41
+ export default Card;
42
+
43
+ declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
44
+ (typeof BaseCommand)["baseFlags"] & T["flags"]
45
+ >;
46
+
47
+ export {};
@@ -0,0 +1,17 @@
1
+ import { run } from "jscodeshift/src/Runner.js";
2
+ import { BaseCommand, getTransformPath } from "../../_chunks-es/getTransformPath.js";
3
+ class Card extends BaseCommand {
4
+ static description = "Transform Card component";
5
+ async run() {
6
+ const { flags } = await this.parse(Card), { paths, ...restFlags } = flags, transformPath = getTransformPath(this.config.root, "latest", "card");
7
+ await run(transformPath, paths, {
8
+ babel: !0,
9
+ parser: "tsx",
10
+ ...restFlags
11
+ });
12
+ }
13
+ }
14
+ export {
15
+ Card as default
16
+ };
17
+ //# sourceMappingURL=card.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.js","sources":["../../../src/commands/latest/card.ts"],"sourcesContent":["import {run} from 'jscodeshift/src/Runner.js'\n\nimport {BaseCommand} from '../../baseCommand'\nimport {getTransformPath} from '../../utils/getTransformPath'\n\n/** @public */\nexport default class Card extends BaseCommand<typeof Card> {\n static override description = 'Transform Card component'\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(Card)\n const {paths, ...restFlags} = flags\n const transformPath = getTransformPath(this.config.root, 'latest', 'card')\n\n await run(transformPath, paths, {\n babel: true,\n parser: 'tsx',\n ...restFlags,\n })\n }\n}\n"],"names":[],"mappings":";;AAMA,MAAqB,aAAa,YAAyB;AAAA,EACzD,OAAgB,cAAc;AAAA,EAE9B,MAAa,MAAqB;AAChC,UAAM,EAAC,UAAS,MAAM,KAAK,MAAM,IAAI,GAC/B,EAAC,OAAO,GAAG,UAAA,IAAa,OACxB,gBAAgB,iBAAiB,KAAK,OAAO,MAAM,UAAU,MAAM;AAEzE,UAAM,IAAI,eAAe,OAAO;AAAA,MAC9B,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;"}
@@ -0,0 +1,47 @@
1
+ import { Command } from "@oclif/core";
2
+ import { Interfaces } from "@oclif/core";
3
+
4
+ declare type Args<T extends typeof Command> = Interfaces.InferredArgs<
5
+ T["args"]
6
+ >;
7
+
8
+ declare abstract class BaseCommand<T extends typeof Command> extends Command {
9
+ static baseFlags: {
10
+ paths: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
11
+ fromPackage: Interfaces.OptionFlag<
12
+ string | undefined,
13
+ Interfaces.CustomOptions
14
+ >;
15
+ toPackage: Interfaces.OptionFlag<
16
+ string | undefined,
17
+ Interfaces.CustomOptions
18
+ >;
19
+ extensions: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
20
+ dry: Interfaces.BooleanFlag<boolean>;
21
+ print: Interfaces.BooleanFlag<boolean>;
22
+ verbose: Interfaces.OptionFlag<number, Interfaces.CustomOptions>;
23
+ };
24
+ protected flags: Flags<T>;
25
+ protected args: Args<T>;
26
+ static examples: string[];
27
+ init(): Promise<void>;
28
+ protected catch(
29
+ err: Error & {
30
+ exitCode?: number;
31
+ },
32
+ ): Promise<unknown>;
33
+ protected finally(_: Error | undefined): Promise<unknown>;
34
+ }
35
+
36
+ /** @public */
37
+ declare class Code extends BaseCommand<typeof Code> {
38
+ static description: string;
39
+ run(): Promise<void>;
40
+ }
41
+ export default Code;
42
+
43
+ declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
44
+ (typeof BaseCommand)["baseFlags"] & T["flags"]
45
+ >;
46
+
47
+ export {};
@@ -0,0 +1,17 @@
1
+ import { run } from "jscodeshift/src/Runner.js";
2
+ import { BaseCommand, getTransformPath } from "../../_chunks-es/getTransformPath.js";
3
+ class Code extends BaseCommand {
4
+ static description = "Transform Code component";
5
+ async run() {
6
+ const { flags } = await this.parse(Code), { paths, ...restFlags } = flags, transformPath = getTransformPath(this.config.root, "latest", "code");
7
+ await run(transformPath, paths, {
8
+ babel: !0,
9
+ parser: "tsx",
10
+ ...restFlags
11
+ });
12
+ }
13
+ }
14
+ export {
15
+ Code as default
16
+ };
17
+ //# sourceMappingURL=code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.js","sources":["../../../src/commands/latest/code.ts"],"sourcesContent":["import {run} from 'jscodeshift/src/Runner.js'\n\nimport {BaseCommand} from '../../baseCommand'\nimport {getTransformPath} from '../../utils/getTransformPath'\n\n/** @public */\nexport default class Code extends BaseCommand<typeof Code> {\n static override description = 'Transform Code component'\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(Code)\n const {paths, ...restFlags} = flags\n const transformPath = getTransformPath(this.config.root, 'latest', 'code')\n\n await run(transformPath, paths, {\n babel: true,\n parser: 'tsx',\n ...restFlags,\n })\n }\n}\n"],"names":[],"mappings":";;AAMA,MAAqB,aAAa,YAAyB;AAAA,EACzD,OAAgB,cAAc;AAAA,EAE9B,MAAa,MAAqB;AAChC,UAAM,EAAC,UAAS,MAAM,KAAK,MAAM,IAAI,GAC/B,EAAC,OAAO,GAAG,UAAA,IAAa,OACxB,gBAAgB,iBAAiB,KAAK,OAAO,MAAM,UAAU,MAAM;AAEzE,UAAM,IAAI,eAAe,OAAO;AAAA,MAC9B,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;"}