@vkontakte/vkui-codemods 1.1.0-beta.2 → 1.1.0

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 (132) hide show
  1. package/dist/autoDetectVKUIVersion.js +16 -24
  2. package/dist/cli.js +97 -160
  3. package/dist/codemod-helpers.js +41 -43
  4. package/dist/getAvailableCodemods.js +13 -14
  5. package/dist/helpers/logger.js +17 -17
  6. package/dist/index.js +76 -147
  7. package/dist/report.js +4 -4
  8. package/dist/testHelpers/testHelper.js +17 -88
  9. package/dist/transforms/v6/accordion.js +10 -10
  10. package/dist/transforms/v6/action-sheet-item.js +5 -5
  11. package/dist/transforms/v6/action-sheet.js +15 -15
  12. package/dist/transforms/v6/alert.js +14 -14
  13. package/dist/transforms/v6/appearance-provider.js +8 -10
  14. package/dist/transforms/v6/banner.js +10 -10
  15. package/dist/transforms/v6/calendar-range.js +6 -6
  16. package/dist/transforms/v6/calendar.js +6 -6
  17. package/dist/transforms/v6/card-scroll.js +5 -5
  18. package/dist/transforms/v6/chip.js +6 -6
  19. package/dist/transforms/v6/chips-input.js +6 -6
  20. package/dist/transforms/v6/config-provider.js +20 -20
  21. package/dist/transforms/v6/content-card.js +7 -7
  22. package/dist/transforms/v6/custom-scroll-view.js +11 -13
  23. package/dist/transforms/v6/date-input.js +6 -6
  24. package/dist/transforms/v6/date-range-input.js +6 -6
  25. package/dist/transforms/v6/fixed-layout.js +11 -11
  26. package/dist/transforms/v6/forbid-imports.js +8 -8
  27. package/dist/transforms/v6/form-item.js +9 -9
  28. package/dist/transforms/v6/form-layout.js +10 -10
  29. package/dist/transforms/v6/gallery.js +5 -5
  30. package/dist/transforms/v6/gradient-prop-change.js +12 -12
  31. package/dist/transforms/v6/horizontal-cell-show-more.js +7 -11
  32. package/dist/transforms/v6/image-base.js +7 -7
  33. package/dist/transforms/v6/modal-card.js +16 -18
  34. package/dist/transforms/v6/modal-page-header.js +11 -11
  35. package/dist/transforms/v6/pagination.js +12 -12
  36. package/dist/transforms/v6/panel-header-content.js +10 -10
  37. package/dist/transforms/v6/panel-header.js +11 -11
  38. package/dist/transforms/v6/placeholder.js +5 -5
  39. package/dist/transforms/v6/popout-wrapper.js +9 -9
  40. package/dist/transforms/v6/popover.js +45 -54
  41. package/dist/transforms/v6/popper.js +35 -44
  42. package/dist/transforms/v6/range-slider.js +14 -25
  43. package/dist/transforms/v6/rich-tooltip.js +10 -10
  44. package/dist/transforms/v6/search.js +6 -6
  45. package/dist/transforms/v6/select.js +7 -7
  46. package/dist/transforms/v6/simple-cell.js +13 -15
  47. package/dist/transforms/v6/split-col.js +9 -9
  48. package/dist/transforms/v6/tabbar.js +5 -5
  49. package/dist/transforms/v6/tappable.js +13 -15
  50. package/dist/transforms/v6/text-tooltip.js +47 -58
  51. package/dist/transforms/v6/tooltip-container.js +14 -14
  52. package/dist/transforms/v6/tooltip.js +63 -72
  53. package/dist/transforms/v6/typography.js +19 -21
  54. package/dist/transforms/v6/users-stack.js +13 -13
  55. package/dist/transforms/v6/visually-hidden-input.js +13 -24
  56. package/dist/transforms/v7/action-sheet.js +5 -5
  57. package/dist/transforms/v7/alert.js +5 -5
  58. package/dist/transforms/v7/appearance-provider.js +12 -12
  59. package/dist/transforms/v7/appearance.js +16 -16
  60. package/dist/transforms/v7/banner.js +13 -14
  61. package/dist/transforms/v7/calendar.js +5 -5
  62. package/dist/transforms/v7/card-grid.js +5 -5
  63. package/dist/transforms/v7/card-scroll.js +17 -18
  64. package/dist/transforms/v7/cell-button.js +13 -13
  65. package/dist/transforms/v7/cell.js +5 -5
  66. package/dist/transforms/v7/chips-select.js +8 -8
  67. package/dist/transforms/v7/common/moveFromChildrenToLabel.js +19 -21
  68. package/dist/transforms/v7/common/remapSizePropValue.js +14 -16
  69. package/dist/transforms/v7/common/removeChildrenFromComponent.js +6 -6
  70. package/dist/transforms/v7/common/swapGapPropElements.js +7 -7
  71. package/dist/transforms/v7/config-provider.js +32 -36
  72. package/dist/transforms/v7/content-card.js +5 -5
  73. package/dist/transforms/v7/counter.js +12 -12
  74. package/dist/transforms/v7/custom-scroll-view.js +8 -8
  75. package/dist/transforms/v7/custom-select.js +8 -8
  76. package/dist/transforms/v7/date-picker.js +8 -8
  77. package/dist/transforms/v7/flex.js +6 -6
  78. package/dist/transforms/v7/form-item.js +29 -35
  79. package/dist/transforms/v7/form-status.js +5 -5
  80. package/dist/transforms/v7/header.js +21 -21
  81. package/dist/transforms/v7/horizontal-cell-show-more.js +16 -19
  82. package/dist/transforms/v7/horizontal-cell.js +5 -5
  83. package/dist/transforms/v7/horizontal-scroll.js +12 -12
  84. package/dist/transforms/v7/image-overlay.js +30 -32
  85. package/dist/transforms/v7/mini-info-cell.js +5 -5
  86. package/dist/transforms/v7/modal-card.js +7 -7
  87. package/dist/transforms/v7/onboarding-tooltip.js +5 -5
  88. package/dist/transforms/v7/panel-header-back.js +6 -6
  89. package/dist/transforms/v7/panel-header-close.js +6 -6
  90. package/dist/transforms/v7/panel-header-content.js +5 -5
  91. package/dist/transforms/v7/panel-header-edit.js +6 -6
  92. package/dist/transforms/v7/panel-header-submit.js +6 -6
  93. package/dist/transforms/v7/panel-spinner.js +10 -10
  94. package/dist/transforms/v7/placeholder.js +5 -5
  95. package/dist/transforms/v7/rich-cell.js +5 -5
  96. package/dist/transforms/v7/screen-spinner.js +7 -7
  97. package/dist/transforms/v7/scroll-arrow.js +20 -23
  98. package/dist/transforms/v7/select.js +8 -8
  99. package/dist/transforms/v7/separator.js +6 -6
  100. package/dist/transforms/v7/simple-cell.js +5 -5
  101. package/dist/transforms/v7/simple-grid.js +6 -6
  102. package/dist/transforms/v7/spacing.js +9 -9
  103. package/dist/transforms/v7/spinner.js +9 -9
  104. package/dist/transforms/v7/subnavigation-bar.js +10 -10
  105. package/dist/transforms/v7/subnavigation-button.js +5 -5
  106. package/dist/transforms/v7/tabbar-item.js +5 -5
  107. package/dist/transforms/v7/tooltip.js +5 -5
  108. package/dist/transforms/v7/typography.js +16 -17
  109. package/dist/transforms/v7/users-stack.js +13 -13
  110. package/dist/transforms/v8/action-sheet.js +6 -6
  111. package/dist/transforms/v8/alert.js +5 -5
  112. package/dist/transforms/v8/checkbox.js +12 -12
  113. package/dist/transforms/v8/chips-input.js +7 -7
  114. package/dist/transforms/v8/chips-select.js +7 -7
  115. package/dist/transforms/v8/common/moveAllPropsIntoSlotProp.js +6 -16
  116. package/dist/transforms/v8/common/moveInputPropsIntoSlotProps.js +8 -8
  117. package/dist/transforms/v8/common/movePropIntoSlotProps.js +44 -63
  118. package/dist/transforms/v8/custom-select.js +7 -7
  119. package/dist/transforms/v8/file.js +7 -7
  120. package/dist/transforms/v8/input.js +8 -7
  121. package/dist/transforms/v8/native-select.js +7 -7
  122. package/dist/transforms/v8/popout-wrapper.js +12 -12
  123. package/dist/transforms/v8/radio.js +12 -12
  124. package/dist/transforms/v8/rich-cell.js +11 -11
  125. package/dist/transforms/v8/search.js +8 -7
  126. package/dist/transforms/v8/select.js +7 -7
  127. package/dist/transforms/v8/snackbar.js +6 -6
  128. package/dist/transforms/v8/split-layout.js +7 -7
  129. package/dist/transforms/v8/switch.js +7 -7
  130. package/dist/transforms/v8/text-area.js +7 -7
  131. package/dist/transforms/v8/write-bar.js +7 -7
  132. package/package.json +6 -5
@@ -5,23 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parser = void 0;
7
7
  exports.default = transformer;
8
- var chalk_1 = __importDefault(require("chalk"));
9
- var codemod_helpers_1 = require("../../codemod-helpers");
10
- var report_1 = require("../../report");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const codemod_helpers_1 = require("../../codemod-helpers");
10
+ const report_1 = require("../../report");
11
11
  exports.parser = 'tsx';
12
12
  function transformer(file, api, options) {
13
- var alias = options.alias;
14
- var j = api.jscodeshift;
15
- var source = j(file.source);
16
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'RichTooltip', alias).localName;
13
+ const { alias } = options;
14
+ const j = api.jscodeshift;
15
+ const source = j(file.source);
16
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'RichTooltip', alias);
17
17
  if (!localName) {
18
18
  return source.toSource();
19
19
  }
20
- var richTooltipComponents = source
20
+ const richTooltipComponents = source
21
21
  .find(j.JSXOpeningElement)
22
- .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; });
22
+ .filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName);
23
23
  if (richTooltipComponents.size() > 0) {
24
- (0, report_1.report)(api, ": ".concat(chalk_1.default.white.bgBlue('RichTooltip'), " component does not exist anymore. Use Tooltip."));
24
+ (0, report_1.report)(api, `: ${chalk_1.default.white.bgBlue('RichTooltip')} component does not exist anymore. Use Tooltip.`);
25
25
  }
26
26
  return source.toSource();
27
27
  }
@@ -2,17 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parser = void 0;
4
4
  exports.default = transformer;
5
- var codemod_helpers_1 = require("../../codemod-helpers");
5
+ const codemod_helpers_1 = require("../../codemod-helpers");
6
6
  exports.parser = 'tsx';
7
- var RENAME_MAP = {
7
+ const RENAME_MAP = {
8
8
  iconAriaLabel: 'iconLabel',
9
9
  clearAriaLabel: 'clearLabel',
10
10
  };
11
11
  function transformer(file, api, options) {
12
- var alias = options.alias;
13
- var j = api.jscodeshift;
14
- var source = j(file.source);
15
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Search', alias).localName;
12
+ const { alias } = options;
13
+ const j = api.jscodeshift;
14
+ const source = j(file.source);
15
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Search', alias);
16
16
  if (localName) {
17
17
  (0, codemod_helpers_1.renameProp)(j, source, localName, RENAME_MAP);
18
18
  }
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parser = void 0;
4
4
  exports.default = transformer;
5
- var codemod_helpers_1 = require("../../codemod-helpers");
5
+ const codemod_helpers_1 = require("../../codemod-helpers");
6
6
  exports.parser = 'tsx';
7
7
  function transformer(file, api, options) {
8
- var alias = options.alias;
9
- var j = api.jscodeshift;
10
- var source = j(file.source);
11
- var selectLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Select', alias).localName;
12
- var customSelectLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, 'CustomSelect', alias).localName;
13
- var chipsSelectLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ChipsSelect', alias).localName;
8
+ const { alias } = options;
9
+ const j = api.jscodeshift;
10
+ const source = j(file.source);
11
+ const { localName: selectLocalName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Select', alias);
12
+ const { localName: customSelectLocalName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'CustomSelect', alias);
13
+ const { localName: chipsSelectLocalName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'ChipsSelect', alias);
14
14
  if (selectLocalName) {
15
15
  (0, codemod_helpers_1.swapBooleanValue)(api, source, selectLocalName, 'fixDropdownWidth', 'dropdownAutoWidth');
16
16
  }
@@ -5,30 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parser = void 0;
7
7
  exports.default = transformer;
8
- var chalk_1 = __importDefault(require("chalk"));
9
- var codemod_helpers_1 = require("../../codemod-helpers");
10
- var report_1 = require("../../report");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const codemod_helpers_1 = require("../../codemod-helpers");
10
+ const report_1 = require("../../report");
11
11
  exports.parser = 'tsx';
12
12
  function transformer(file, api, options) {
13
- var alias = options.alias;
14
- var j = api.jscodeshift;
15
- var source = j(file.source);
16
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'SimpleCell', alias).localName;
13
+ const { alias } = options;
14
+ const j = api.jscodeshift;
15
+ const source = j(file.source);
16
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'SimpleCell', alias);
17
17
  if (!localName) {
18
18
  return source.toSource();
19
19
  }
20
20
  source
21
21
  .find(j.JSXOpeningElement)
22
- .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
22
+ .filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
23
23
  .find(j.JSXAttribute)
24
- .filter(function (attribute) {
25
- return attribute.node.name.name === 'expandable' || attribute.node.name.name === 'disabled';
26
- })
27
- .forEach(function (attribute) {
24
+ .filter((attribute) => attribute.node.name.name === 'expandable' || attribute.node.name.name === 'disabled')
25
+ .forEach((attribute) => {
28
26
  if (attribute.node.name.name === 'expandable') {
29
- var attributeValue = attribute.node.value;
27
+ const attributeValue = attribute.node.value;
30
28
  if (attributeValue && attributeValue.type === 'JSXExpressionContainer') {
31
- var expression = attributeValue.expression;
29
+ const expression = attributeValue.expression;
32
30
  if (expression.type === 'BooleanLiteral') {
33
31
  if (expression.value) {
34
32
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier('expandable'), j.stringLiteral('auto')));
@@ -43,7 +41,7 @@ function transformer(file, api, options) {
43
41
  }
44
42
  }
45
43
  if (attribute.node.name.name === 'disabled') {
46
- (0, report_1.report)(api, ": ".concat(chalk_1.default.white.bgBlue('disabled'), " prop in ").concat(chalk_1.default.white.bgBlue('SimpleCell'), " may be no longer needed."));
44
+ (0, report_1.report)(api, `: ${chalk_1.default.white.bgBlue('disabled')} prop in ${chalk_1.default.white.bgBlue('SimpleCell')} may be no longer needed.`);
47
45
  }
48
46
  });
49
47
  return source.toSource();
@@ -2,23 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parser = void 0;
4
4
  exports.default = transformer;
5
- var codemod_helpers_1 = require("../../codemod-helpers");
5
+ const codemod_helpers_1 = require("../../codemod-helpers");
6
6
  exports.parser = 'tsx';
7
7
  function transformer(file, api, options) {
8
- var alias = options.alias;
9
- var j = api.jscodeshift;
10
- var source = j(file.source);
11
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'SplitCol', alias).localName;
8
+ const { alias } = options;
9
+ const j = api.jscodeshift;
10
+ const source = j(file.source);
11
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'SplitCol', alias);
12
12
  if (!localName) {
13
13
  return source.toSource();
14
14
  }
15
15
  source
16
16
  .find(j.JSXOpeningElement)
17
- .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
17
+ .filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
18
18
  .find(j.JSXAttribute)
19
- .filter(function (attribute) { return attribute.node.name.name === 'spaced'; })
20
- .forEach(function (attribute) {
21
- var node = attribute.node;
19
+ .filter((attribute) => attribute.node.name.name === 'spaced')
20
+ .forEach((attribute) => {
21
+ const node = attribute.node;
22
22
  if (!node.value) {
23
23
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier('autoSpaced')));
24
24
  }
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parser = void 0;
4
4
  exports.default = transformer;
5
- var codemod_helpers_1 = require("../../codemod-helpers");
5
+ const codemod_helpers_1 = require("../../codemod-helpers");
6
6
  exports.parser = 'tsx';
7
7
  function transformer(file, api, options) {
8
- var alias = options.alias;
9
- var j = api.jscodeshift;
10
- var source = j(file.source);
11
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Tabbar', alias).localName;
8
+ const { alias } = options;
9
+ const j = api.jscodeshift;
10
+ const source = j(file.source);
11
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Tabbar', alias);
12
12
  if (localName) {
13
13
  (0, codemod_helpers_1.swapBooleanValue)(api, source, localName, 'shadow', 'plain');
14
14
  }
@@ -5,29 +5,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parser = void 0;
7
7
  exports.default = transformer;
8
- var chalk_1 = __importDefault(require("chalk"));
9
- var codemod_helpers_1 = require("../../codemod-helpers");
10
- var report_1 = require("../../report");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const codemod_helpers_1 = require("../../codemod-helpers");
10
+ const report_1 = require("../../report");
11
11
  exports.parser = 'tsx';
12
- var REMOVED_PROPS = ['onEnter', 'onLeave', 'onStart', 'onEnd', 'onMove', 'stopPropagation'];
12
+ const REMOVED_PROPS = ['onEnter', 'onLeave', 'onStart', 'onEnd', 'onMove', 'stopPropagation'];
13
13
  function transformer(file, api, options) {
14
- var alias = options.alias;
15
- var j = api.jscodeshift;
16
- var source = j(file.source);
17
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Tappable', alias).localName;
14
+ const { alias } = options;
15
+ const j = api.jscodeshift;
16
+ const source = j(file.source);
17
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Tappable', alias);
18
18
  if (!localName) {
19
19
  return source.toSource();
20
20
  }
21
21
  source
22
22
  .find(j.JSXOpeningElement)
23
- .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
23
+ .filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
24
24
  .find(j.JSXAttribute)
25
- .filter(function (attribute) {
26
- return typeof attribute.node.name.name === 'string' &&
27
- REMOVED_PROPS.includes(attribute.node.name.name);
28
- })
29
- .forEach(function (attribute) {
30
- (0, report_1.report)(api, ": ".concat(chalk_1.default.white.bgBlue(attribute.node.name.name), " prop in ").concat(chalk_1.default.white.bgBlue('Tappable'), " component is no longer available. Manual changes required."));
25
+ .filter((attribute) => typeof attribute.node.name.name === 'string' &&
26
+ REMOVED_PROPS.includes(attribute.node.name.name))
27
+ .forEach((attribute) => {
28
+ (0, report_1.report)(api, `: ${chalk_1.default.white.bgBlue(attribute.node.name.name)} prop in ${chalk_1.default.white.bgBlue('Tappable')} component is no longer available. Manual changes required.`);
31
29
  });
32
30
  return source.toSource();
33
31
  }
@@ -2,15 +2,14 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.parser = void 0;
8
7
  exports.default = transformer;
9
- var chalk_1 = __importDefault(require("chalk"));
10
- var codemod_helpers_1 = require("../../codemod-helpers");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const codemod_helpers_1 = require("../../codemod-helpers");
11
10
  exports.parser = 'tsx';
12
- var componentName = 'unstable_TextTooltip';
13
- var ATTRIBUTE_MANIPULATOR = {
11
+ const componentName = 'unstable_TextTooltip';
12
+ const ATTRIBUTE_MANIPULATOR = {
14
13
  offsetSkidding: {
15
14
  keyTo: 'offsetByCrossAxis',
16
15
  },
@@ -25,115 +24,105 @@ var ATTRIBUTE_MANIPULATOR = {
25
24
  },
26
25
  renderContent: {
27
26
  keyTo: 'children',
28
- reportText: function () {
29
- return ": ".concat(chalk_1.default.white.bgBlue('children'), " prop in ").concat(chalk_1.default.white.bgBlue('TextTooltip'), ". You should unwraps function manually");
30
- },
27
+ reportText: () => `: ${chalk_1.default.white.bgBlue('children')} prop in ${chalk_1.default.white.bgBlue('TextTooltip')}. You should unwraps function manually`,
31
28
  },
32
29
  customMiddlewares: {
33
30
  keyTo: 'unknown',
34
- reportText: function () {
35
- return ": ".concat(chalk_1.default.white.bgBlue('customMiddlewares'), " prop in ").concat(chalk_1.default.white.bgBlue('TextTooltip'), ". You should unwraps function manually");
36
- },
31
+ reportText: () => `: ${chalk_1.default.white.bgBlue('customMiddlewares')} prop in ${chalk_1.default.white.bgBlue('TextTooltip')}. You should unwraps function manually`,
37
32
  },
38
33
  };
39
- var FORCE_PORTAL = 'forcePortal';
40
- var COMPLEX_ATTRIBUTE_MANIPULATOR = (_a = {},
41
- _a[FORCE_PORTAL] = {
34
+ const FORCE_PORTAL = 'forcePortal';
35
+ const COMPLEX_ATTRIBUTE_MANIPULATOR = {
36
+ [FORCE_PORTAL]: {
42
37
  keyTo: 'usePortal',
43
38
  },
44
- _a.portalRoot = {
39
+ portalRoot: {
45
40
  keyTo: 'usePortal',
46
41
  },
47
- _a);
48
- var LEGACY_SHOWN_DELAY_PROP = 'shownDelay';
49
- var LEGACY_HIDE_DELAY_PROP = 'hideDelay';
50
- var NEW_HOVER_DELAY_PROP = 'hoverDelay';
42
+ };
43
+ const LEGACY_SHOWN_DELAY_PROP = 'shownDelay';
44
+ const LEGACY_HIDE_DELAY_PROP = 'hideDelay';
45
+ const NEW_HOVER_DELAY_PROP = 'hoverDelay';
51
46
  function transformer(file, api, options) {
52
- var alias = options.alias;
53
- var j = api.jscodeshift;
54
- var source = j(file.source);
55
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
56
- var attributeReplacer = (0, codemod_helpers_1.createAttributeManipulator)(ATTRIBUTE_MANIPULATOR, api);
47
+ const { alias } = options;
48
+ const j = api.jscodeshift;
49
+ const source = j(file.source);
50
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias);
51
+ const attributeReplacer = (0, codemod_helpers_1.createAttributeManipulator)(ATTRIBUTE_MANIPULATOR, api);
57
52
  if (!localName) {
58
53
  return source.toSource();
59
54
  }
60
55
  source
61
56
  .find(j.ImportDeclaration)
62
- .filter(function (path) { return path.node.source.value === alias; })
57
+ .filter((path) => path.node.source.value === alias)
63
58
  .find(j.ImportSpecifier, { imported: { name: componentName } })
64
- .forEach(function (path) {
65
- return j(path).replaceWith(function (path) { return j.importSpecifier(j.identifier('Tooltip'), path.node.local); });
66
- });
59
+ .forEach((path) => j(path).replaceWith((path) => j.importSpecifier(j.identifier('Tooltip'), path.node.local)));
67
60
  source
68
61
  .find(j.JSXOpeningElement)
69
- .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
70
- .find(j.JSXAttribute, function (attribute) {
71
- return typeof attribute.name.name === 'string' ? attributeReplacer.has(attribute.name.name) : false;
72
- })
73
- .forEach(function (attribute) {
74
- var attributeName = attribute.node.name.name;
75
- var foundFix = attributeReplacer.getReplacers(attributeName);
62
+ .filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
63
+ .find(j.JSXAttribute, (attribute) => typeof attribute.name.name === 'string' ? attributeReplacer.has(attribute.name.name) : false)
64
+ .forEach((attribute) => {
65
+ const attributeName = attribute.node.name.name;
66
+ const foundFix = attributeReplacer.getReplacers(attributeName);
76
67
  if (foundFix) {
77
68
  if (foundFix.action === 'remove') {
78
69
  j(attribute).remove();
79
70
  }
80
71
  else {
81
- var value = attribute.node.value;
72
+ const value = attribute.node.value;
82
73
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(foundFix.keyTo()), foundFix.valueTo(value)));
83
74
  }
84
75
  }
85
76
  });
86
- var complexAttributeReplacer = (0, codemod_helpers_1.createAttributeManipulator)(COMPLEX_ATTRIBUTE_MANIPULATOR, api);
87
- source.findJSXElements(localName).forEach(function (element) {
77
+ const complexAttributeReplacer = (0, codemod_helpers_1.createAttributeManipulator)(COMPLEX_ATTRIBUTE_MANIPULATOR, api);
78
+ source.findJSXElements(localName).forEach((element) => {
88
79
  j(element)
89
- .find(j.JSXAttribute, function (attribute) {
90
- return typeof attribute.name.name === 'string'
91
- ? complexAttributeReplacer.has(attribute.name.name)
92
- : false;
93
- })
94
- .forEach(function (attribute, _, attributes) {
95
- var attributeName = attribute.node.name.name;
80
+ .find(j.JSXAttribute, (attribute) => typeof attribute.name.name === 'string'
81
+ ? complexAttributeReplacer.has(attribute.name.name)
82
+ : false)
83
+ .forEach((attribute, _, attributes) => {
84
+ const attributeName = attribute.node.name.name;
96
85
  if (attributes.length === 2 && attributeName === FORCE_PORTAL) {
97
86
  j(attribute).remove();
98
87
  }
99
88
  else {
100
- var foundFix = complexAttributeReplacer.getReplacers(attributeName);
89
+ const foundFix = complexAttributeReplacer.getReplacers(attributeName);
101
90
  if (foundFix && foundFix.action !== 'remove') {
102
- var value = attribute.node.value;
91
+ const value = attribute.node.value;
103
92
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(foundFix.keyTo()), foundFix.valueTo(value)));
104
93
  }
105
94
  }
106
95
  });
107
96
  // разрешаем hoverDelay
108
- var _a = [
109
- j(element).find(j.JSXAttribute, function (attribute) { return attribute.name.name === LEGACY_SHOWN_DELAY_PROP; }),
110
- j(element).find(j.JSXAttribute, function (attribute) { return attribute.name.name === LEGACY_HIDE_DELAY_PROP; }),
111
- ], shownDelayAttr = _a[0], hideDelayAttr = _a[1];
112
- var getNumericLiteral = function (attributeCollection) {
113
- var val;
114
- attributeCollection.find(j.NumericLiteral).forEach(function (attribute) {
97
+ const [shownDelayAttr, hideDelayAttr] = [
98
+ j(element).find(j.JSXAttribute, (attribute) => attribute.name.name === LEGACY_SHOWN_DELAY_PROP),
99
+ j(element).find(j.JSXAttribute, (attribute) => attribute.name.name === LEGACY_HIDE_DELAY_PROP),
100
+ ];
101
+ const getNumericLiteral = (attributeCollection) => {
102
+ let val;
103
+ attributeCollection.find(j.NumericLiteral).forEach((attribute) => {
115
104
  val = attribute.node;
116
105
  });
117
106
  return val ? val : j.numericLiteral(0);
118
107
  };
119
108
  if (shownDelayAttr.length === 1 && hideDelayAttr.length === 0) {
120
- shownDelayAttr.forEach(function (attribute) {
109
+ shownDelayAttr.forEach((attribute) => {
121
110
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(NEW_HOVER_DELAY_PROP), j.jsxExpressionContainer(getNumericLiteral(shownDelayAttr))));
122
111
  });
123
112
  }
124
113
  else if (shownDelayAttr.length === 0 && hideDelayAttr.length === 1) {
125
- hideDelayAttr.forEach(function (attribute) {
114
+ hideDelayAttr.forEach((attribute) => {
126
115
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(NEW_HOVER_DELAY_PROP), j.jsxExpressionContainer(j.arrayExpression([j.numericLiteral(0), getNumericLiteral(hideDelayAttr)]))));
127
116
  });
128
117
  }
129
118
  else if (shownDelayAttr.length === 1 && hideDelayAttr.length === 1) {
130
- shownDelayAttr.forEach(function (attribute) {
119
+ shownDelayAttr.forEach((attribute) => {
131
120
  j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(NEW_HOVER_DELAY_PROP), j.jsxExpressionContainer(j.arrayExpression([
132
121
  getNumericLiteral(shownDelayAttr),
133
122
  getNumericLiteral(hideDelayAttr),
134
123
  ]))));
135
124
  });
136
- hideDelayAttr.forEach(function (attribute) {
125
+ hideDelayAttr.forEach((attribute) => {
137
126
  j(attribute).remove();
138
127
  });
139
128
  }
@@ -2,36 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parser = void 0;
4
4
  exports.default = transformer;
5
- var codemod_helpers_1 = require("../../codemod-helpers");
5
+ const codemod_helpers_1 = require("../../codemod-helpers");
6
6
  exports.parser = 'tsx';
7
- var componentName = 'TooltipContainer';
8
- var componentNameTo = 'OnboardingTooltipContainer';
7
+ const componentName = 'TooltipContainer';
8
+ const componentNameTo = 'OnboardingTooltipContainer';
9
9
  function transformer(file, api, options) {
10
- var alias = options.alias;
11
- var j = api.jscodeshift;
12
- var source = j(file.source);
13
- var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
14
- var needRename = true;
10
+ const { alias } = options;
11
+ const j = api.jscodeshift;
12
+ const source = j(file.source);
13
+ const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias);
14
+ let needRename = true;
15
15
  if (!localName) {
16
16
  return source.toSource();
17
17
  }
18
18
  // подменяем импорт
19
19
  source
20
20
  .find(j.ImportDeclaration)
21
- .filter(function (path) { return path.node.source.value === alias; })
21
+ .filter((path) => path.node.source.value === alias)
22
22
  .find(j.ImportSpecifier, { imported: { name: componentName } })
23
- .forEach(function (path) {
24
- j(path).replaceWith(function (path) {
23
+ .forEach((path) => {
24
+ j(path).replaceWith((path) => {
25
25
  if (path.node.local && path.node.local.name !== path.node.imported.name) {
26
26
  needRename = false;
27
27
  }
28
28
  return j.importSpecifier(j.jsxIdentifier(componentNameTo), needRename ? null : path.node.local);
29
29
  });
30
30
  });
31
- source.findJSXElements(localName).forEach(function (element) {
31
+ source.findJSXElements(localName).forEach((element) => {
32
32
  // меняем название компонента в JSX на переименованный в импорте (если нужно)
33
- j(element).replaceWith(function (path) {
34
- var renamedLocalName = needRename ? componentNameTo : localName;
33
+ j(element).replaceWith((path) => {
34
+ const renamedLocalName = needRename ? componentNameTo : localName;
35
35
  return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(renamedLocalName), path.node.openingElement.attributes, path.node.closingElement ? false : true), path.node.closingElement ? j.jsxClosingElement(j.jsxIdentifier(renamedLocalName)) : null, path.node.children);
36
36
  });
37
37
  });