Skip to content

Commit a879a9b

Browse files
feat(codemod): transform Text wrapping to maxLines (#6085)
1 parent b3a5aed commit a879a9b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/cli/src/scripts/codemod/transforms/v2/codemodConfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@
481481
},
482482
"removedProps": ["navigated", "selected"]
483483
},
484+
"Text": {
485+
"comment": "wrapping -> maxLines"
486+
},
484487
"TextArea": {
485488
"changedProps": {
486489
"growingMaxLines": "growingMaxRows"

packages/cli/src/scripts/codemod/transforms/v2/main.cts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,29 @@ export default function transform(file: FileInfo, api: API, options?: Options):
405405
});
406406
}
407407

408+
if (componentName === 'Text') {
409+
jsxElements.forEach((el) => {
410+
const wrapping = j(el).find(j.JSXAttribute, { name: { name: 'wrapping' } });
411+
if (wrapping.size() > 0) {
412+
const attr = wrapping.get();
413+
if (
414+
attr.value.value &&
415+
((attr.value.value.type === 'JSXAttribute' && attr.value.value === false) ||
416+
(attr.value.value.type === 'JSXExpressionContainer' && attr.value.value.expression.value === false))
417+
) {
418+
j(el)
419+
.find(j.JSXOpeningElement)
420+
.get()
421+
.value.attributes.push(
422+
j.jsxAttribute(j.jsxIdentifier('maxLines'), j.jsxExpressionContainer(j.numericLiteral(1)))
423+
);
424+
}
425+
wrapping.remove();
426+
isDirty = true;
427+
}
428+
});
429+
}
430+
408431
// before renaming any values, replace hard coded enum values
409432
Object.entries(changes.renamedEnums ?? {}).forEach(([propName, enumRef]) => {
410433
jsxElements.forEach((el) => {

0 commit comments

Comments
 (0)