@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.
- package/dist/autoDetectVKUIVersion.js +16 -24
- package/dist/cli.js +97 -160
- package/dist/codemod-helpers.js +41 -43
- package/dist/getAvailableCodemods.js +13 -14
- package/dist/helpers/logger.js +17 -17
- package/dist/index.js +76 -147
- package/dist/report.js +4 -4
- package/dist/testHelpers/testHelper.js +17 -88
- package/dist/transforms/v6/accordion.js +10 -10
- package/dist/transforms/v6/action-sheet-item.js +5 -5
- package/dist/transforms/v6/action-sheet.js +15 -15
- package/dist/transforms/v6/alert.js +14 -14
- package/dist/transforms/v6/appearance-provider.js +8 -10
- package/dist/transforms/v6/banner.js +10 -10
- package/dist/transforms/v6/calendar-range.js +6 -6
- package/dist/transforms/v6/calendar.js +6 -6
- package/dist/transforms/v6/card-scroll.js +5 -5
- package/dist/transforms/v6/chip.js +6 -6
- package/dist/transforms/v6/chips-input.js +6 -6
- package/dist/transforms/v6/config-provider.js +20 -20
- package/dist/transforms/v6/content-card.js +7 -7
- package/dist/transforms/v6/custom-scroll-view.js +11 -13
- package/dist/transforms/v6/date-input.js +6 -6
- package/dist/transforms/v6/date-range-input.js +6 -6
- package/dist/transforms/v6/fixed-layout.js +11 -11
- package/dist/transforms/v6/forbid-imports.js +8 -8
- package/dist/transforms/v6/form-item.js +9 -9
- package/dist/transforms/v6/form-layout.js +10 -10
- package/dist/transforms/v6/gallery.js +5 -5
- package/dist/transforms/v6/gradient-prop-change.js +12 -12
- package/dist/transforms/v6/horizontal-cell-show-more.js +7 -11
- package/dist/transforms/v6/image-base.js +7 -7
- package/dist/transforms/v6/modal-card.js +16 -18
- package/dist/transforms/v6/modal-page-header.js +11 -11
- package/dist/transforms/v6/pagination.js +12 -12
- package/dist/transforms/v6/panel-header-content.js +10 -10
- package/dist/transforms/v6/panel-header.js +11 -11
- package/dist/transforms/v6/placeholder.js +5 -5
- package/dist/transforms/v6/popout-wrapper.js +9 -9
- package/dist/transforms/v6/popover.js +45 -54
- package/dist/transforms/v6/popper.js +35 -44
- package/dist/transforms/v6/range-slider.js +14 -25
- package/dist/transforms/v6/rich-tooltip.js +10 -10
- package/dist/transforms/v6/search.js +6 -6
- package/dist/transforms/v6/select.js +7 -7
- package/dist/transforms/v6/simple-cell.js +13 -15
- package/dist/transforms/v6/split-col.js +9 -9
- package/dist/transforms/v6/tabbar.js +5 -5
- package/dist/transforms/v6/tappable.js +13 -15
- package/dist/transforms/v6/text-tooltip.js +47 -58
- package/dist/transforms/v6/tooltip-container.js +14 -14
- package/dist/transforms/v6/tooltip.js +63 -72
- package/dist/transforms/v6/typography.js +19 -21
- package/dist/transforms/v6/users-stack.js +13 -13
- package/dist/transforms/v6/visually-hidden-input.js +13 -24
- package/dist/transforms/v7/action-sheet.js +5 -5
- package/dist/transforms/v7/alert.js +5 -5
- package/dist/transforms/v7/appearance-provider.js +12 -12
- package/dist/transforms/v7/appearance.js +16 -16
- package/dist/transforms/v7/banner.js +13 -14
- package/dist/transforms/v7/calendar.js +5 -5
- package/dist/transforms/v7/card-grid.js +5 -5
- package/dist/transforms/v7/card-scroll.js +17 -18
- package/dist/transforms/v7/cell-button.js +13 -13
- package/dist/transforms/v7/cell.js +5 -5
- package/dist/transforms/v7/chips-select.js +8 -8
- package/dist/transforms/v7/common/moveFromChildrenToLabel.js +19 -21
- package/dist/transforms/v7/common/remapSizePropValue.js +14 -16
- package/dist/transforms/v7/common/removeChildrenFromComponent.js +6 -6
- package/dist/transforms/v7/common/swapGapPropElements.js +7 -7
- package/dist/transforms/v7/config-provider.js +32 -36
- package/dist/transforms/v7/content-card.js +5 -5
- package/dist/transforms/v7/counter.js +12 -12
- package/dist/transforms/v7/custom-scroll-view.js +8 -8
- package/dist/transforms/v7/custom-select.js +8 -8
- package/dist/transforms/v7/date-picker.js +8 -8
- package/dist/transforms/v7/flex.js +6 -6
- package/dist/transforms/v7/form-item.js +29 -35
- package/dist/transforms/v7/form-status.js +5 -5
- package/dist/transforms/v7/header.js +21 -21
- package/dist/transforms/v7/horizontal-cell-show-more.js +16 -19
- package/dist/transforms/v7/horizontal-cell.js +5 -5
- package/dist/transforms/v7/horizontal-scroll.js +12 -12
- package/dist/transforms/v7/image-overlay.js +30 -32
- package/dist/transforms/v7/mini-info-cell.js +5 -5
- package/dist/transforms/v7/modal-card.js +7 -7
- package/dist/transforms/v7/onboarding-tooltip.js +5 -5
- package/dist/transforms/v7/panel-header-back.js +6 -6
- package/dist/transforms/v7/panel-header-close.js +6 -6
- package/dist/transforms/v7/panel-header-content.js +5 -5
- package/dist/transforms/v7/panel-header-edit.js +6 -6
- package/dist/transforms/v7/panel-header-submit.js +6 -6
- package/dist/transforms/v7/panel-spinner.js +10 -10
- package/dist/transforms/v7/placeholder.js +5 -5
- package/dist/transforms/v7/rich-cell.js +5 -5
- package/dist/transforms/v7/screen-spinner.js +7 -7
- package/dist/transforms/v7/scroll-arrow.js +20 -23
- package/dist/transforms/v7/select.js +8 -8
- package/dist/transforms/v7/separator.js +6 -6
- package/dist/transforms/v7/simple-cell.js +5 -5
- package/dist/transforms/v7/simple-grid.js +6 -6
- package/dist/transforms/v7/spacing.js +9 -9
- package/dist/transforms/v7/spinner.js +9 -9
- package/dist/transforms/v7/subnavigation-bar.js +10 -10
- package/dist/transforms/v7/subnavigation-button.js +5 -5
- package/dist/transforms/v7/tabbar-item.js +5 -5
- package/dist/transforms/v7/tooltip.js +5 -5
- package/dist/transforms/v7/typography.js +16 -17
- package/dist/transforms/v7/users-stack.js +13 -13
- package/dist/transforms/v8/action-sheet.js +6 -6
- package/dist/transforms/v8/alert.js +5 -5
- package/dist/transforms/v8/checkbox.js +12 -12
- package/dist/transforms/v8/chips-input.js +7 -7
- package/dist/transforms/v8/chips-select.js +7 -7
- package/dist/transforms/v8/common/moveAllPropsIntoSlotProp.js +6 -16
- package/dist/transforms/v8/common/moveInputPropsIntoSlotProps.js +8 -8
- package/dist/transforms/v8/common/movePropIntoSlotProps.js +44 -63
- package/dist/transforms/v8/custom-select.js +7 -7
- package/dist/transforms/v8/file.js +7 -7
- package/dist/transforms/v8/input.js +8 -7
- package/dist/transforms/v8/native-select.js +7 -7
- package/dist/transforms/v8/popout-wrapper.js +12 -12
- package/dist/transforms/v8/radio.js +12 -12
- package/dist/transforms/v8/rich-cell.js +11 -11
- package/dist/transforms/v8/search.js +8 -7
- package/dist/transforms/v8/select.js +7 -7
- package/dist/transforms/v8/snackbar.js +6 -6
- package/dist/transforms/v8/split-layout.js +7 -7
- package/dist/transforms/v8/switch.js +7 -7
- package/dist/transforms/v8/text-area.js +7 -7
- package/dist/transforms/v8/write-bar.js +7 -7
- 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
+
const richTooltipComponents = source
|
|
21
21
|
.find(j.JSXOpeningElement)
|
|
22
|
-
.filter(
|
|
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,
|
|
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
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
|
-
|
|
7
|
+
const RENAME_MAP = {
|
|
8
8
|
iconAriaLabel: 'iconLabel',
|
|
9
9
|
clearAriaLabel: 'clearLabel',
|
|
10
10
|
};
|
|
11
11
|
function transformer(file, api, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
7
|
function transformer(file, api, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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(
|
|
22
|
+
.filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
|
|
23
23
|
.find(j.JSXAttribute)
|
|
24
|
-
.filter(
|
|
25
|
-
|
|
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
|
-
|
|
27
|
+
const attributeValue = attribute.node.value;
|
|
30
28
|
if (attributeValue && attributeValue.type === 'JSXExpressionContainer') {
|
|
31
|
-
|
|
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,
|
|
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
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
7
|
function transformer(file, api, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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(
|
|
17
|
+
.filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
|
|
18
18
|
.find(j.JSXAttribute)
|
|
19
|
-
.filter(
|
|
20
|
-
.forEach(
|
|
21
|
-
|
|
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
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
7
|
function transformer(file, api, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
const REMOVED_PROPS = ['onEnter', 'onLeave', 'onStart', 'onEnd', 'onMove', 'stopPropagation'];
|
|
13
13
|
function transformer(file, api, options) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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(
|
|
23
|
+
.filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
|
|
24
24
|
.find(j.JSXAttribute)
|
|
25
|
-
.filter(
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
10
|
-
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
11
10
|
exports.parser = 'tsx';
|
|
12
|
-
|
|
13
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
const FORCE_PORTAL = 'forcePortal';
|
|
35
|
+
const COMPLEX_ATTRIBUTE_MANIPULATOR = {
|
|
36
|
+
[FORCE_PORTAL]: {
|
|
42
37
|
keyTo: 'usePortal',
|
|
43
38
|
},
|
|
44
|
-
|
|
39
|
+
portalRoot: {
|
|
45
40
|
keyTo: 'usePortal',
|
|
46
41
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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(
|
|
57
|
+
.filter((path) => path.node.source.value === alias)
|
|
63
58
|
.find(j.ImportSpecifier, { imported: { name: componentName } })
|
|
64
|
-
.forEach(
|
|
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(
|
|
70
|
-
.find(j.JSXAttribute,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.
|
|
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
|
-
|
|
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
|
-
|
|
87
|
-
source.findJSXElements(localName).forEach(
|
|
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,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
89
|
+
const foundFix = complexAttributeReplacer.getReplacers(attributeName);
|
|
101
90
|
if (foundFix && foundFix.action !== 'remove') {
|
|
102
|
-
|
|
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
|
-
|
|
109
|
-
j(element).find(j.JSXAttribute,
|
|
110
|
-
j(element).find(j.JSXAttribute,
|
|
111
|
-
]
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
attributeCollection.find(j.NumericLiteral).forEach(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const componentName = 'TooltipContainer';
|
|
8
|
+
const componentNameTo = 'OnboardingTooltipContainer';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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(
|
|
21
|
+
.filter((path) => path.node.source.value === alias)
|
|
22
22
|
.find(j.ImportSpecifier, { imported: { name: componentName } })
|
|
23
|
-
.forEach(
|
|
24
|
-
j(path).replaceWith(
|
|
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(
|
|
31
|
+
source.findJSXElements(localName).forEach((element) => {
|
|
32
32
|
// меняем название компонента в JSX на переименованный в импорте (если нужно)
|
|
33
|
-
j(element).replaceWith(
|
|
34
|
-
|
|
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
|
});
|