@atlaskit/codemod-cli 0.24.1 → 0.24.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.24.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#102800](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102800)
8
+ [`868e9aebf5af`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/868e9aebf5af) -
9
+ Fix icon buttons with loading being converted to default buttons
10
+
3
11
  ## 0.24.1
4
12
 
5
13
  ### Patch Changes
package/dist/cjs/main.js CHANGED
@@ -305,7 +305,7 @@ function _main() {
305
305
  case 4:
306
306
  _yield$parseArgs = _context5.sent;
307
307
  packages = _yield$parseArgs.packages;
308
- _process$env$_PACKAGE = "0.24.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.24.2", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
309
309
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
310
310
  if (packages && packages.length > 0) {
311
311
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -34,6 +34,7 @@ var transformer = function transformer(file, api) {
34
34
  var hasLinkIconButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.linkIcon, fileSource, j);
35
35
  var hasLinkButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.link, fileSource, j);
36
36
  var hasIconButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.icon, fileSource, j);
37
+ var hasDefaultLoadingButton = false;
37
38
  var allButtons = fileSource.find(j.JSXElement).filter(function (path) {
38
39
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
39
40
  });
@@ -80,7 +81,8 @@ var transformer = function transformer(file, api) {
80
81
  hasLinkButton = true;
81
82
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
82
83
  }
83
- if (isLoadingButton) {
84
+ if (isLoadingButton && !isIconButton) {
85
+ hasDefaultLoadingButton = true;
84
86
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.default, element.value, j));
85
87
  }
86
88
  var linkAppearanceAttribute = attributes.find(function (node) {
@@ -119,7 +121,11 @@ var transformer = function transformer(file, api) {
119
121
  path.node.name = _constants.NEW_BUTTON_VARIANTS.default;
120
122
  }
121
123
  });
122
- specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
124
+
125
+ // Only add the Button import if we found a default button, not icon only
126
+ if (hasDefaultLoadingButton) {
127
+ specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
128
+ }
123
129
  }
124
130
  if (!specifiers.find(function (specifier) {
125
131
  return specifier.type === 'ImportDefaultSpecifier';
@@ -23,6 +23,8 @@ var transformer = function transformer(file, api) {
23
23
  var _node$node = node.node,
24
24
  specifiers = _node$node.specifiers,
25
25
  source = _node$node.source;
26
+
27
+ // Return early if the import is not a named import
26
28
  if ([].concat((0, _toConsumableArray2.default)(Object.values(_constants.entryPointsMapping)), [_constants.NEW_BUTTON_ENTRY_POINT, '@atlaskit/button/types']).includes(source.value)) {
27
29
  return fileSource.toSource(_constants.PRINT_SETTINGS);
28
30
  }
@@ -33,13 +35,13 @@ var transformer = function transformer(file, api) {
33
35
  var defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(_constants.entryPointsMapping.Button));
34
36
  j(node).insertAfter(defaultButtonImport);
35
37
  }
36
- var valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
38
+ var namedSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
37
39
  return specifier.type === 'ImportSpecifier';
38
40
  });
39
- var newTypeSpecifier = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
41
+ var newTypeSpecifier = namedSpecifiers === null || namedSpecifiers === void 0 ? void 0 : namedSpecifiers.filter(function (specifier) {
40
42
  return specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing');
41
43
  });
42
- var otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
44
+ var otherTypeSpecifiers = namedSpecifiers === null || namedSpecifiers === void 0 ? void 0 : namedSpecifiers.filter(function (specifier) {
43
45
  return _constants.BUTTON_TYPES.includes(specifier.imported.name);
44
46
  });
45
47
  if (newTypeSpecifier !== null && newTypeSpecifier !== void 0 && newTypeSpecifier.length) {
@@ -50,8 +52,8 @@ var transformer = function transformer(file, api) {
50
52
  var _typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
51
53
  j(node).insertAfter(_typeImport);
52
54
  }
53
- if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
54
- valueSpecifiers.forEach(function (specifier) {
55
+ if (namedSpecifiers !== null && namedSpecifiers !== void 0 && namedSpecifiers.length) {
56
+ namedSpecifiers.forEach(function (specifier) {
55
57
  if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && _constants.entryPointsMapping[specifier.imported.name]) {
56
58
  var newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(_constants.entryPointsMapping[specifier.imported.name]));
57
59
  j(node).insertAfter(newImport);
@@ -57,7 +57,10 @@ var handleIconAttributes = exports.handleIconAttributes = function handleIconAtt
57
57
  var buttonAlreadyHasLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(function (buttonAttribute) {
58
58
  return buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'label';
59
59
  });
60
- if (!buttonAlreadyHasLabelProp) {
60
+ var buttonAlreadyHasAriaLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(function (buttonAttribute) {
61
+ return buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'aria-label';
62
+ });
63
+ if (!buttonAlreadyHasLabelProp && !buttonAlreadyHasAriaLabelProp) {
61
64
  var labelAttribute = iconAttributes.find(function (attribute) {
62
65
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
63
66
  });
@@ -123,12 +126,18 @@ var generateNewElement = exports.generateNewElement = function generateNewElemen
123
126
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
124
127
  }));
125
128
  if (hasNoLabelProp && attributes) {
126
- attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
129
+ attributes.unshift(j.jsxAttribute.from({
130
+ name: j.jsxIdentifier('label'),
131
+ value: j.literal(ariaLabelAttr.get().value.value.value)
132
+ }));
127
133
  }
128
134
  ariaLabelAttr.remove();
129
135
  }
130
136
  }
131
- return j.jsxElement(
132
- // self closing if it's an icon button or icon link button
133
- j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon), isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
137
+ return j.jsxElement.from({
138
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon),
139
+ // self closing if it's an icon button or icon link button
140
+ closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
141
+ children: element.children
142
+ });
134
143
  };
@@ -24,6 +24,7 @@ const transformer = (file, api) => {
24
24
  let hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, fileSource, j);
25
25
  let hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, fileSource, j);
26
26
  let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, fileSource, j);
27
+ let hasDefaultLoadingButton = false;
27
28
  const allButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier);
28
29
  const buttonsWithoutUnsupportedProps = allButtons.filter(path => !ifHasUnsupportedProps(path.value.openingElement.attributes));
29
30
  const loadingButtonImportName = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.LoadingButton);
@@ -66,7 +67,8 @@ const transformer = (file, api) => {
66
67
  hasLinkButton = true;
67
68
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
68
69
  }
69
- if (isLoadingButton) {
70
+ if (isLoadingButton && !isIconButton) {
71
+ hasDefaultLoadingButton = true;
70
72
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.default, element.value, j));
71
73
  }
72
74
  const linkAppearanceAttribute = attributes.find(node => {
@@ -97,7 +99,11 @@ const transformer = (file, api) => {
97
99
  path.node.name = NEW_BUTTON_VARIANTS.default;
98
100
  }
99
101
  });
100
- specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
102
+
103
+ // Only add the Button import if we found a default button, not icon only
104
+ if (hasDefaultLoadingButton) {
105
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
106
+ }
101
107
  }
102
108
  if (!specifiers.find(specifier => specifier.type === 'ImportDefaultSpecifier') && remainingDefaultButtons) {
103
109
  specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
@@ -14,6 +14,8 @@ const transformer = (file, api) => {
14
14
  specifiers,
15
15
  source
16
16
  } = node.node;
17
+
18
+ // Return early if the import is not a named import
17
19
  if ([...Object.values(entryPointsMapping), NEW_BUTTON_ENTRY_POINT, '@atlaskit/button/types'].includes(source.value)) {
18
20
  return fileSource.toSource(PRINT_SETTINGS);
19
21
  }
@@ -22,9 +24,9 @@ const transformer = (file, api) => {
22
24
  const defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
23
25
  j(node).insertAfter(defaultButtonImport);
24
26
  }
25
- const valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.type === 'ImportSpecifier');
26
- const newTypeSpecifier = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(specifier => specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing'));
27
- const otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(specifier => BUTTON_TYPES.includes(specifier.imported.name));
27
+ const namedSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.type === 'ImportSpecifier');
28
+ const newTypeSpecifier = namedSpecifiers === null || namedSpecifiers === void 0 ? void 0 : namedSpecifiers.filter(specifier => specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing'));
29
+ const otherTypeSpecifiers = namedSpecifiers === null || namedSpecifiers === void 0 ? void 0 : namedSpecifiers.filter(specifier => BUTTON_TYPES.includes(specifier.imported.name));
28
30
  if (newTypeSpecifier !== null && newTypeSpecifier !== void 0 && newTypeSpecifier.length) {
29
31
  const typeImport = j.importDeclaration(newTypeSpecifier, j.stringLiteral('@atlaskit/button/types'));
30
32
  j(node).insertAfter(typeImport);
@@ -33,8 +35,8 @@ const transformer = (file, api) => {
33
35
  const typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
34
36
  j(node).insertAfter(typeImport);
35
37
  }
36
- if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
37
- valueSpecifiers.forEach(specifier => {
38
+ if (namedSpecifiers !== null && namedSpecifiers !== void 0 && namedSpecifiers.length) {
39
+ namedSpecifiers.forEach(specifier => {
38
40
  if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && entryPointsMapping[specifier.imported.name]) {
39
41
  const newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(entryPointsMapping[specifier.imported.name]));
40
42
  j(node).insertAfter(newImport);
@@ -48,7 +48,8 @@ export const handleIconAttributes = (element, j, iconRenamed = false) => {
48
48
  // takes precedence over icon label.
49
49
 
50
50
  const buttonAlreadyHasLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(buttonAttribute => buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'label');
51
- if (!buttonAlreadyHasLabelProp) {
51
+ const buttonAlreadyHasAriaLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(buttonAttribute => buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'aria-label');
52
+ if (!buttonAlreadyHasLabelProp && !buttonAlreadyHasAriaLabelProp) {
52
53
  const labelAttribute = iconAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label');
53
54
  if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
54
55
  buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.unshift(labelAttribute);
@@ -108,12 +109,18 @@ export const generateNewElement = (variant, element, j) => {
108
109
  if (ariaLabelAttr.length) {
109
110
  const hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label'));
110
111
  if (hasNoLabelProp && attributes) {
111
- attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
112
+ attributes.unshift(j.jsxAttribute.from({
113
+ name: j.jsxIdentifier('label'),
114
+ value: j.literal(ariaLabelAttr.get().value.value.value)
115
+ }));
112
116
  }
113
117
  ariaLabelAttr.remove();
114
118
  }
115
119
  }
116
- return j.jsxElement(
117
- // self closing if it's an icon button or icon link button
118
- j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon), isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
120
+ return j.jsxElement.from({
121
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon),
122
+ // self closing if it's an icon button or icon link button
123
+ closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
124
+ children: element.children
125
+ });
119
126
  };
package/dist/esm/main.js CHANGED
@@ -298,7 +298,7 @@ function _main() {
298
298
  case 4:
299
299
  _yield$parseArgs = _context5.sent;
300
300
  packages = _yield$parseArgs.packages;
301
- _process$env$_PACKAGE = "0.24.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.24.2", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
302
302
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
303
303
  if (packages && packages.length > 0) {
304
304
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -28,6 +28,7 @@ var transformer = function transformer(file, api) {
28
28
  var hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, fileSource, j);
29
29
  var hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, fileSource, j);
30
30
  var hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, fileSource, j);
31
+ var hasDefaultLoadingButton = false;
31
32
  var allButtons = fileSource.find(j.JSXElement).filter(function (path) {
32
33
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
33
34
  });
@@ -74,7 +75,8 @@ var transformer = function transformer(file, api) {
74
75
  hasLinkButton = true;
75
76
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
76
77
  }
77
- if (isLoadingButton) {
78
+ if (isLoadingButton && !isIconButton) {
79
+ hasDefaultLoadingButton = true;
78
80
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.default, element.value, j));
79
81
  }
80
82
  var linkAppearanceAttribute = attributes.find(function (node) {
@@ -113,7 +115,11 @@ var transformer = function transformer(file, api) {
113
115
  path.node.name = NEW_BUTTON_VARIANTS.default;
114
116
  }
115
117
  });
116
- specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
118
+
119
+ // Only add the Button import if we found a default button, not icon only
120
+ if (hasDefaultLoadingButton) {
121
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
122
+ }
117
123
  }
118
124
  if (!specifiers.find(function (specifier) {
119
125
  return specifier.type === 'ImportDefaultSpecifier';
@@ -16,6 +16,8 @@ var transformer = function transformer(file, api) {
16
16
  var _node$node = node.node,
17
17
  specifiers = _node$node.specifiers,
18
18
  source = _node$node.source;
19
+
20
+ // Return early if the import is not a named import
19
21
  if ([].concat(_toConsumableArray(Object.values(entryPointsMapping)), [NEW_BUTTON_ENTRY_POINT, '@atlaskit/button/types']).includes(source.value)) {
20
22
  return fileSource.toSource(PRINT_SETTINGS);
21
23
  }
@@ -26,13 +28,13 @@ var transformer = function transformer(file, api) {
26
28
  var defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
27
29
  j(node).insertAfter(defaultButtonImport);
28
30
  }
29
- var valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
31
+ var namedSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
30
32
  return specifier.type === 'ImportSpecifier';
31
33
  });
32
- var newTypeSpecifier = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
34
+ var newTypeSpecifier = namedSpecifiers === null || namedSpecifiers === void 0 ? void 0 : namedSpecifiers.filter(function (specifier) {
33
35
  return specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing');
34
36
  });
35
- var otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
37
+ var otherTypeSpecifiers = namedSpecifiers === null || namedSpecifiers === void 0 ? void 0 : namedSpecifiers.filter(function (specifier) {
36
38
  return BUTTON_TYPES.includes(specifier.imported.name);
37
39
  });
38
40
  if (newTypeSpecifier !== null && newTypeSpecifier !== void 0 && newTypeSpecifier.length) {
@@ -43,8 +45,8 @@ var transformer = function transformer(file, api) {
43
45
  var _typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
44
46
  j(node).insertAfter(_typeImport);
45
47
  }
46
- if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
47
- valueSpecifiers.forEach(function (specifier) {
48
+ if (namedSpecifiers !== null && namedSpecifiers !== void 0 && namedSpecifiers.length) {
49
+ namedSpecifiers.forEach(function (specifier) {
48
50
  if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && entryPointsMapping[specifier.imported.name]) {
49
51
  var newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(entryPointsMapping[specifier.imported.name]));
50
52
  j(node).insertAfter(newImport);
@@ -51,7 +51,10 @@ export var handleIconAttributes = function handleIconAttributes(element, j) {
51
51
  var buttonAlreadyHasLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(function (buttonAttribute) {
52
52
  return buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'label';
53
53
  });
54
- if (!buttonAlreadyHasLabelProp) {
54
+ var buttonAlreadyHasAriaLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(function (buttonAttribute) {
55
+ return buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'aria-label';
56
+ });
57
+ if (!buttonAlreadyHasLabelProp && !buttonAlreadyHasAriaLabelProp) {
55
58
  var labelAttribute = iconAttributes.find(function (attribute) {
56
59
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
57
60
  });
@@ -117,12 +120,18 @@ export var generateNewElement = function generateNewElement(variant, element, j)
117
120
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
118
121
  }));
119
122
  if (hasNoLabelProp && attributes) {
120
- attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
123
+ attributes.unshift(j.jsxAttribute.from({
124
+ name: j.jsxIdentifier('label'),
125
+ value: j.literal(ariaLabelAttr.get().value.value.value)
126
+ }));
121
127
  }
122
128
  ariaLabelAttr.remove();
123
129
  }
124
130
  }
125
- return j.jsxElement(
126
- // self closing if it's an icon button or icon link button
127
- j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon), isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
131
+ return j.jsxElement.from({
132
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon),
133
+ // self closing if it's an icon button or icon link button
134
+ closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
135
+ children: element.children
136
+ });
128
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -40,7 +40,7 @@
40
40
  "bin": "./bin/codemod-cli.js",
41
41
  "dependencies": {
42
42
  "@atlaskit/codemod-utils": "^4.2.0",
43
- "@atlaskit/tokens": "^1.48.0",
43
+ "@atlaskit/tokens": "^1.49.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codeshift/utils": "^0.2.4",
46
46
  "@hypermod/utils": "^0.4.2",