@react-spectrum/codemods 1.2.1 → 1.2.3

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 (29) hide show
  1. package/dist/index.js +12 -10
  2. package/dist/s1-to-s2/src/codemods/codemod.js +33 -17
  3. package/dist/s1-to-s2/src/codemods/components/ActionGroup/transform.js +34 -11
  4. package/dist/s1-to-s2/src/codemods/components/Avatar/transform.js +5 -1
  5. package/dist/s1-to-s2/src/codemods/components/ContextualHelpTrigger/transform.js +1 -1
  6. package/dist/s1-to-s2/src/codemods/components/DialogContainer/transform.js +3 -4
  7. package/dist/s1-to-s2/src/codemods/components/DialogTrigger/transform.js +33 -11
  8. package/dist/s1-to-s2/src/codemods/components/Item/transform.js +28 -7
  9. package/dist/s1-to-s2/src/codemods/components/Link/transform.js +6 -4
  10. package/dist/s1-to-s2/src/codemods/components/Row/transform.js +12 -5
  11. package/dist/s1-to-s2/src/codemods/components/Section/transform.js +12 -3
  12. package/dist/s1-to-s2/src/codemods/components/TableView/transform.js +36 -19
  13. package/dist/s1-to-s2/src/codemods/components/Tabs/transform.js +25 -9
  14. package/dist/s1-to-s2/src/codemods/icons/iconMap.js +319 -1276
  15. package/dist/s1-to-s2/src/codemods/shared/dimensions.js +5 -32
  16. package/dist/s1-to-s2/src/codemods/shared/styleProps.js +55 -19
  17. package/dist/s1-to-s2/src/codemods/shared/transforms.js +130 -67
  18. package/dist/s1-to-s2/src/codemods/shared/unsafeStyle.js +102 -48
  19. package/dist/s1-to-s2/src/codemods/shared/utils.js +31 -28
  20. package/dist/s1-to-s2/src/getComponents.js +8 -8
  21. package/dist/s1-to-s2/src/index.js +10 -6
  22. package/dist/s1-to-s2/src/utils/installPackage.js +5 -1
  23. package/dist/s1-to-s2/src/utils/waitForKeypress.js +1 -1
  24. package/dist/test-utils-rc-update/src/codemod.js +236 -0
  25. package/dist/test-utils-rc-update/src/index.js +13 -0
  26. package/dist/use-monopackages/src/codemod.js +25 -27
  27. package/dist/use-subpaths/src/codemod.js +11 -5
  28. package/dist/use-subpaths/src/specifiers.js +3 -1
  29. package/package.json +24 -22
@@ -41,7 +41,9 @@ const t = __importStar(require("@babel/types"));
41
41
  * Copies the columns prop from the TableHeader to the Row component.
42
42
  */
43
43
  function addColumnsPropToRow(path) {
44
- const tableHeaderPath = path.get('children').find((child) => t.isJSXElement(child.node) &&
44
+ const tableHeaderPath = path
45
+ .get('children')
46
+ .find(child => t.isJSXElement(child.node) &&
45
47
  t.isJSXIdentifier(child.node.openingElement.name) &&
46
48
  (0, utils_1.getName)(child, child.node.openingElement.name) === 'TableHeader');
47
49
  if (!tableHeaderPath) {
@@ -51,7 +53,7 @@ function addColumnsPropToRow(path) {
51
53
  const columnsProp = tableHeaderPath
52
54
  .get('openingElement')
53
55
  .get('attributes')
54
- .find((attr) => t.isJSXAttribute(attr.node) && attr.node.name.name === 'columns');
56
+ .find(attr => t.isJSXAttribute(attr.node) && attr.node.name.name === 'columns');
55
57
  if (columnsProp) {
56
58
  path.traverse({
57
59
  JSXElement(innerPath) {
@@ -61,9 +63,12 @@ function addColumnsPropToRow(path) {
61
63
  let rowPath = innerPath;
62
64
  rowPath.node.openingElement.attributes.push(columnsProp.node);
63
65
  // If Row doesn't contain id prop, leave a comment for the user to check manually
64
- let idProp = rowPath.get('openingElement').get('attributes').find((attr) => t.isJSXAttribute(attr.node) && attr.node.name.name === 'id');
66
+ let idProp = rowPath
67
+ .get('openingElement')
68
+ .get('attributes')
69
+ .find(attr => t.isJSXAttribute(attr.node) && attr.node.name.name === 'id');
65
70
  if (!idProp) {
66
- (0, utils_1.addComment)(rowPath.node, ' TODO(S2-upgrade): If the items do not have id properties, you\'ll need to add an id prop to the Row.');
71
+ (0, utils_1.addComment)(rowPath.node, " TODO(S2-upgrade): If the items do not have id properties, you'll need to add an id prop to the Row.");
67
72
  }
68
73
  }
69
74
  }
@@ -71,7 +76,9 @@ function addColumnsPropToRow(path) {
71
76
  }
72
77
  }
73
78
  function commentIfNestedColumns(path) {
74
- const headerPath = path.get('children').find((child) => t.isJSXElement(child.node) &&
79
+ const headerPath = path
80
+ .get('children')
81
+ .find(child => t.isJSXElement(child.node) &&
75
82
  t.isJSXIdentifier(child.node.openingElement.name) &&
76
83
  (0, utils_1.getName)(child, child.node.openingElement.name) === 'TableHeader');
77
84
  const columns = headerPath?.get('children') || [];
@@ -90,19 +97,24 @@ function commentIfNestedColumns(path) {
90
97
  }
91
98
  /**
92
99
  * Adds isRowHeader to the first Column in a table if there isn't already a row header.
100
+ *
93
101
  * @param path
94
102
  */
95
103
  function addRowHeader(path) {
96
- let tableHeaderPath = path.get('children').find((child) => t.isJSXElement(child.node) &&
104
+ let tableHeaderPath = path
105
+ .get('children')
106
+ .find(child => t.isJSXElement(child.node) &&
97
107
  t.isJSXIdentifier(child.node.openingElement.name) &&
98
108
  (0, utils_1.getName)(child, child.node.openingElement.name) === 'TableHeader');
99
109
  // Check if isRowHeader is already set on a Column
100
110
  let hasRowHeader = false;
101
- tableHeaderPath?.get('children').forEach((child) => {
111
+ tableHeaderPath?.get('children').forEach(child => {
102
112
  if (t.isJSXElement(child.node) &&
103
113
  t.isJSXIdentifier(child.node.openingElement.name) &&
104
114
  (0, utils_1.getName)(child, child.node.openingElement.name) === 'Column') {
105
- let isRowHeaderProp = child.get('openingElement').get('attributes').find((attr) => t.isJSXAttribute(attr.node) && attr.node.name.name === 'isRowHeader');
115
+ let isRowHeaderProp = child.get('openingElement')
116
+ .get('attributes')
117
+ .find(attr => t.isJSXAttribute(attr.node) && attr.node.name.name === 'isRowHeader');
106
118
  if (isRowHeaderProp) {
107
119
  hasRowHeader = true;
108
120
  }
@@ -110,7 +122,7 @@ function addRowHeader(path) {
110
122
  });
111
123
  // If there isn't already a row header, add one to the first Column if possible
112
124
  if (!hasRowHeader) {
113
- tableHeaderPath?.get('children').forEach((child) => {
125
+ tableHeaderPath?.get('children').forEach(child => {
114
126
  // Add to first Column if static
115
127
  if (!hasRowHeader &&
116
128
  t.isJSXElement(child.node) &&
@@ -122,7 +134,7 @@ function addRowHeader(path) {
122
134
  // If render function is used, leave a comment to update manually
123
135
  if (t.isJSXExpressionContainer(child.node) &&
124
136
  t.isArrowFunctionExpression(child.node.expression)) {
125
- (0, utils_1.addComment)(child.node, ' TODO(S2-upgrade): You\'ll need to add isRowHeader to one of the columns manually.');
137
+ (0, utils_1.addComment)(child.node, " TODO(S2-upgrade): You'll need to add isRowHeader to one of the columns manually.");
126
138
  }
127
139
  // If array.map is used, leave a comment to update manually
128
140
  if (t.isJSXExpressionContainer(child.node) &&
@@ -130,17 +142,20 @@ function addRowHeader(path) {
130
142
  t.isMemberExpression(child.node.expression.callee) &&
131
143
  t.isIdentifier(child.node.expression.callee.property) &&
132
144
  child.node.expression.callee.property.name === 'map') {
133
- (0, utils_1.addComment)(child.node, ' TODO(S2-upgrade): You\'ll need to add isRowHeader to one of the columns manually.');
145
+ (0, utils_1.addComment)(child.node, " TODO(S2-upgrade): You'll need to add isRowHeader to one of the columns manually.");
134
146
  }
135
147
  });
136
148
  }
137
149
  }
138
150
  /**
139
151
  * Moves loadingState and onLoadMore from TableBody to TableView.
152
+ *
140
153
  * @param path
141
154
  */
142
155
  function movePropsFromTableBodyToTableView(path) {
143
- const tableBodyPath = path.get('children').find((child) => t.isJSXElement(child.node) &&
156
+ const tableBodyPath = path
157
+ .get('children')
158
+ .find(child => t.isJSXElement(child.node) &&
144
159
  t.isJSXIdentifier(child.node.openingElement.name) &&
145
160
  (0, utils_1.getName)(child, child.node.openingElement.name) === 'TableBody');
146
161
  if (!tableBodyPath) {
@@ -148,19 +163,21 @@ function movePropsFromTableBodyToTableView(path) {
148
163
  }
149
164
  const propsToMove = ['loadingState', 'onLoadMore'];
150
165
  const newAttributes = [];
151
- tableBodyPath.node.openingElement.attributes = tableBodyPath.node.openingElement.attributes.filter(attribute => {
152
- if (t.isJSXAttribute(attribute) && propsToMove.includes(attribute.name.name)) {
153
- newAttributes.push(attribute);
154
- return false; // Remove from TableBody
155
- }
156
- return true; // Keep in TableBody
157
- });
166
+ tableBodyPath.node.openingElement.attributes =
167
+ tableBodyPath.node.openingElement.attributes.filter(attribute => {
168
+ if (t.isJSXAttribute(attribute) && propsToMove.includes(attribute.name.name)) {
169
+ newAttributes.push(attribute);
170
+ return false; // Remove from TableBody
171
+ }
172
+ return true; // Keep in TableBody
173
+ });
158
174
  if (newAttributes.length > 0) {
159
175
  path.node.openingElement.attributes.push(...newAttributes);
160
176
  }
161
177
  }
162
178
  /**
163
179
  * Transforms TableView:
180
+ *
164
181
  * - For Column and Row: Update key to be id (and keep key if rendered inside array.map).
165
182
  * - For dynamic tables, pass a columns prop into Row.
166
183
  * - For Row: Update dynamic render function to pass in column instead of columnKey.
@@ -42,7 +42,10 @@ function transformTabList(tabListPath) {
42
42
  JSXElement(itemPath) {
43
43
  if (t.isJSXIdentifier(itemPath.node.openingElement.name) &&
44
44
  (0, utils_1.getName)(itemPath, itemPath.node.openingElement.name) === 'Item') {
45
- (0, transforms_1.updateComponentWithinCollection)(itemPath, { parentComponentName: 'TabList', newComponentName: 'Tab' });
45
+ (0, transforms_1.updateComponentWithinCollection)(itemPath, {
46
+ parentComponentName: 'TabList',
47
+ newComponentName: 'Tab'
48
+ });
46
49
  }
47
50
  }
48
51
  });
@@ -50,26 +53,37 @@ function transformTabList(tabListPath) {
50
53
  }
51
54
  function transformTabPanels(tabPanelsPath, itemsProp) {
52
55
  // Dynamic case
53
- let dynamicRender = tabPanelsPath.get('children').find(path => t.isJSXExpressionContainer(path.node));
56
+ let dynamicRender = tabPanelsPath
57
+ .get('children')
58
+ .find(path => t.isJSXExpressionContainer(path.node));
54
59
  if (dynamicRender) {
55
60
  (0, transforms_1.updateToNewComponentName)(tabPanelsPath, { newComponentName: 'Collection' });
56
61
  let itemPath = dynamicRender.get('expression').get('body');
57
- (0, transforms_1.updateComponentWithinCollection)(itemPath, { parentComponentName: 'Collection', newComponentName: 'TabPanel' });
62
+ (0, transforms_1.updateComponentWithinCollection)(itemPath, {
63
+ parentComponentName: 'Collection',
64
+ newComponentName: 'TabPanel'
65
+ });
58
66
  if (itemsProp) {
59
67
  tabPanelsPath.node.openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('items'), itemsProp.value));
60
68
  }
61
69
  return [tabPanelsPath.node];
62
70
  }
63
71
  // Static case
64
- return tabPanelsPath.get('children').map(itemPath => {
72
+ return tabPanelsPath
73
+ .get('children')
74
+ .map(itemPath => {
65
75
  if (t.isJSXElement(itemPath.node) &&
66
76
  t.isJSXIdentifier(itemPath.node.openingElement.name) &&
67
77
  (0, utils_1.getName)(itemPath, itemPath.node.openingElement.name) === 'Item') {
68
- (0, transforms_1.updateComponentWithinCollection)(itemPath, { parentComponentName: 'TabPanels', newComponentName: 'TabPanel' });
78
+ (0, transforms_1.updateComponentWithinCollection)(itemPath, {
79
+ parentComponentName: 'TabPanels',
80
+ newComponentName: 'TabPanel'
81
+ });
69
82
  return itemPath.node;
70
83
  }
71
84
  return null;
72
- }).filter(Boolean);
85
+ })
86
+ .filter(Boolean);
73
87
  }
74
88
  /**
75
89
  * Transforms Tabs props and structure:
@@ -80,7 +94,7 @@ function transformTabPanels(tabPanelsPath, itemsProp) {
80
94
  * - Remove isQuiet (it is no longer supported in Spectrum 2).
81
95
  */
82
96
  function transformTabs(path) {
83
- let program = path.findParent((p) => t.isProgram(p.node));
97
+ let program = path.findParent(p => t.isProgram(p.node));
84
98
  (0, utils_1.removeComponentImport)(program, 'TabPanels');
85
99
  let tabListNode = null;
86
100
  let tabPanelsNodes = [];
@@ -95,14 +109,16 @@ function transformTabs(path) {
95
109
  path.get('children').forEach(childPath => {
96
110
  if (t.isJSXElement(childPath.node)) {
97
111
  if (t.isJSXIdentifier(childPath.node.openingElement.name) &&
98
- (0, utils_1.getName)(childPath, childPath.node.openingElement.name) === 'TabList') {
112
+ (0, utils_1.getName)(childPath, childPath.node.openingElement.name) ===
113
+ 'TabList') {
99
114
  tabListNode = transformTabList(childPath);
100
115
  if (itemsProp) {
101
116
  tabListNode.openingElement.attributes.push(itemsProp);
102
117
  }
103
118
  }
104
119
  else if (t.isJSXIdentifier(childPath.node.openingElement.name) &&
105
- (0, utils_1.getName)(childPath, childPath.node.openingElement.name) === 'TabPanels') {
120
+ (0, utils_1.getName)(childPath, childPath.node.openingElement.name) ===
121
+ 'TabPanels') {
106
122
  tabPanelsNodes = transformTabPanels(childPath, itemsProp);
107
123
  }
108
124
  }