@openrewrite/recipes-react 0.2.9
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/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +130 -0
- package/dist/index.js.map +1 -0
- package/dist/migration/change-component-prop-value.d.ts +20 -0
- package/dist/migration/change-component-prop-value.d.ts.map +1 -0
- package/dist/migration/change-component-prop-value.js +217 -0
- package/dist/migration/change-component-prop-value.js.map +1 -0
- package/dist/react-native/view-prop-types.d.ts +8 -0
- package/dist/react-native/view-prop-types.d.ts.map +1 -0
- package/dist/react-native/view-prop-types.js +65 -0
- package/dist/react-native/view-prop-types.js.map +1 -0
- package/dist/react16/error-boundaries.d.ts +8 -0
- package/dist/react16/error-boundaries.d.ts.map +1 -0
- package/dist/react16/error-boundaries.js +42 -0
- package/dist/react16/error-boundaries.js.map +1 -0
- package/dist/react16/find-dom-node.d.ts +8 -0
- package/dist/react16/find-dom-node.d.ts.map +1 -0
- package/dist/react16/find-dom-node.js +48 -0
- package/dist/react16/find-dom-node.js.map +1 -0
- package/dist/react16/react-dom-factories.d.ts +8 -0
- package/dist/react16/react-dom-factories.d.ts.map +1 -0
- package/dist/react16/react-dom-factories.js +72 -0
- package/dist/react16/react-dom-factories.js.map +1 -0
- package/dist/react16/react-prop-types.d.ts +8 -0
- package/dist/react16/react-prop-types.d.ts.map +1 -0
- package/dist/react16/react-prop-types.js +69 -0
- package/dist/react16/react-prop-types.js.map +1 -0
- package/dist/react16/react-to-react-dom.d.ts +8 -0
- package/dist/react16/react-to-react-dom.d.ts.map +1 -0
- package/dist/react16/react-to-react-dom.js +97 -0
- package/dist/react16/react-to-react-dom.js.map +1 -0
- package/dist/react16/replace-create-factory.d.ts +8 -0
- package/dist/react16/replace-create-factory.d.ts.map +1 -0
- package/dist/react16/replace-create-factory.js +69 -0
- package/dist/react16/replace-create-factory.js.map +1 -0
- package/dist/react16/upgrade-to-react-16.d.ts +8 -0
- package/dist/react16/upgrade-to-react-16.d.ts.map +1 -0
- package/dist/react16/upgrade-to-react-16.js +41 -0
- package/dist/react16/upgrade-to-react-16.js.map +1 -0
- package/dist/react17/remove-event-persist.d.ts +8 -0
- package/dist/react17/remove-event-persist.d.ts.map +1 -0
- package/dist/react17/remove-event-persist.js +114 -0
- package/dist/react17/remove-event-persist.js.map +1 -0
- package/dist/react17/rename-unsafe-lifecycles.d.ts +8 -0
- package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -0
- package/dist/react17/rename-unsafe-lifecycles.js +48 -0
- package/dist/react17/rename-unsafe-lifecycles.js.map +1 -0
- package/dist/react17/update-react-imports.d.ts +8 -0
- package/dist/react17/update-react-imports.d.ts.map +1 -0
- package/dist/react17/update-react-imports.js +40 -0
- package/dist/react17/update-react-imports.js.map +1 -0
- package/dist/react17/upgrade-to-react-17.d.ts +8 -0
- package/dist/react17/upgrade-to-react-17.d.ts.map +1 -0
- package/dist/react17/upgrade-to-react-17.js +37 -0
- package/dist/react17/upgrade-to-react-17.js.map +1 -0
- package/dist/react18/remove-unstable-batched-updates.d.ts +8 -0
- package/dist/react18/remove-unstable-batched-updates.d.ts.map +1 -0
- package/dist/react18/remove-unstable-batched-updates.js +170 -0
- package/dist/react18/remove-unstable-batched-updates.js.map +1 -0
- package/dist/react18/replace-reactdom-render.d.ts +8 -0
- package/dist/react18/replace-reactdom-render.d.ts.map +1 -0
- package/dist/react18/replace-reactdom-render.js +55 -0
- package/dist/react18/replace-reactdom-render.js.map +1 -0
- package/dist/react18/replace-render-callback.d.ts +8 -0
- package/dist/react18/replace-render-callback.d.ts.map +1 -0
- package/dist/react18/replace-render-callback.js +60 -0
- package/dist/react18/replace-render-callback.js.map +1 -0
- package/dist/react18/replace-unmount-component-at-node.d.ts +8 -0
- package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -0
- package/dist/react18/replace-unmount-component-at-node.js +54 -0
- package/dist/react18/replace-unmount-component-at-node.js.map +1 -0
- package/dist/react18/upgrade-to-react-18.d.ts +8 -0
- package/dist/react18/upgrade-to-react-18.d.ts.map +1 -0
- package/dist/react18/upgrade-to-react-18.js +39 -0
- package/dist/react18/upgrade-to-react-18.js.map +1 -0
- package/dist/react19/deprecated-react-types.d.ts +8 -0
- package/dist/react19/deprecated-react-types.d.ts.map +1 -0
- package/dist/react19/deprecated-react-types.js +135 -0
- package/dist/react19/deprecated-react-types.js.map +1 -0
- package/dist/react19/find-context-consumer.d.ts +9 -0
- package/dist/react19/find-context-consumer.d.ts.map +1 -0
- package/dist/react19/find-context-consumer.js +128 -0
- package/dist/react19/find-context-consumer.js.map +1 -0
- package/dist/react19/find-deprecated-reactdom-apis.d.ts +9 -0
- package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -0
- package/dist/react19/find-deprecated-reactdom-apis.js +132 -0
- package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -0
- package/dist/react19/find-element-ref.d.ts +9 -0
- package/dist/react19/find-element-ref.d.ts.map +1 -0
- package/dist/react19/find-element-ref.js +88 -0
- package/dist/react19/find-element-ref.js.map +1 -0
- package/dist/react19/find-legacy-context-api.d.ts +9 -0
- package/dist/react19/find-legacy-context-api.d.ts.map +1 -0
- package/dist/react19/find-legacy-context-api.js +163 -0
- package/dist/react19/find-legacy-context-api.js.map +1 -0
- package/dist/react19/no-implicit-ref-callback-return.d.ts +8 -0
- package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -0
- package/dist/react19/no-implicit-ref-callback-return.js +107 -0
- package/dist/react19/no-implicit-ref-callback-return.js.map +1 -0
- package/dist/react19/remove-context-provider.d.ts +8 -0
- package/dist/react19/remove-context-provider.d.ts.map +1 -0
- package/dist/react19/remove-context-provider.js +59 -0
- package/dist/react19/remove-context-provider.js.map +1 -0
- package/dist/react19/remove-forward-ref.d.ts +8 -0
- package/dist/react19/remove-forward-ref.d.ts.map +1 -0
- package/dist/react19/remove-forward-ref.js +73 -0
- package/dist/react19/remove-forward-ref.js.map +1 -0
- package/dist/react19/remove-prop-types.d.ts +8 -0
- package/dist/react19/remove-prop-types.d.ts.map +1 -0
- package/dist/react19/remove-prop-types.js +76 -0
- package/dist/react19/remove-prop-types.js.map +1 -0
- package/dist/react19/remove-react-fc.d.ts +8 -0
- package/dist/react19/remove-react-fc.d.ts.map +1 -0
- package/dist/react19/remove-react-fc.js +149 -0
- package/dist/react19/remove-react-fc.js.map +1 -0
- package/dist/react19/replace-act-import.d.ts +9 -0
- package/dist/react19/replace-act-import.d.ts.map +1 -0
- package/dist/react19/replace-act-import.js +34 -0
- package/dist/react19/replace-act-import.js.map +1 -0
- package/dist/react19/replace-default-props.d.ts +8 -0
- package/dist/react19/replace-default-props.d.ts.map +1 -0
- package/dist/react19/replace-default-props.js +195 -0
- package/dist/react19/replace-default-props.js.map +1 -0
- package/dist/react19/replace-react-shallow-renderer.d.ts +8 -0
- package/dist/react19/replace-react-shallow-renderer.d.ts.map +1 -0
- package/dist/react19/replace-react-shallow-renderer.js +69 -0
- package/dist/react19/replace-react-shallow-renderer.js.map +1 -0
- package/dist/react19/replace-reactdom-hydrate.d.ts +8 -0
- package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -0
- package/dist/react19/replace-reactdom-hydrate.js +55 -0
- package/dist/react19/replace-reactdom-hydrate.js.map +1 -0
- package/dist/react19/replace-string-ref.d.ts +8 -0
- package/dist/react19/replace-string-ref.d.ts.map +1 -0
- package/dist/react19/replace-string-ref.js +75 -0
- package/dist/react19/replace-string-ref.js.map +1 -0
- package/dist/react19/replace-use-form-state.d.ts +8 -0
- package/dist/react19/replace-use-form-state.d.ts.map +1 -0
- package/dist/react19/replace-use-form-state.js +54 -0
- package/dist/react19/replace-use-form-state.js.map +1 -0
- package/dist/react19/upgrade-to-react-19.d.ts +8 -0
- package/dist/react19/upgrade-to-react-19.d.ts.map +1 -0
- package/dist/react19/upgrade-to-react-19.js +59 -0
- package/dist/react19/upgrade-to-react-19.js.map +1 -0
- package/dist/react19/use-context-hook.d.ts +8 -0
- package/dist/react19/use-context-hook.d.ts.map +1 -0
- package/dist/react19/use-context-hook.js +54 -0
- package/dist/react19/use-context-hook.js.map +1 -0
- package/dist/react19/use-ref-required-initial.d.ts +8 -0
- package/dist/react19/use-ref-required-initial.d.ts.map +1 -0
- package/dist/react19/use-ref-required-initial.js +74 -0
- package/dist/react19/use-ref-required-initial.js.map +1 -0
- package/dist/refactoring/class-to-functional.d.ts +8 -0
- package/dist/refactoring/class-to-functional.d.ts.map +1 -0
- package/dist/refactoring/class-to-functional.js +205 -0
- package/dist/refactoring/class-to-functional.js.map +1 -0
- package/dist/refactoring/create-class-to-es6.d.ts +8 -0
- package/dist/refactoring/create-class-to-es6.d.ts.map +1 -0
- package/dist/refactoring/create-class-to-es6.js +289 -0
- package/dist/refactoring/create-class-to-es6.js.map +1 -0
- package/dist/refactoring/create-element-to-jsx.d.ts +8 -0
- package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -0
- package/dist/refactoring/create-element-to-jsx.js +167 -0
- package/dist/refactoring/create-element-to-jsx.js.map +1 -0
- package/dist/refactoring/manual-bind-to-arrow.d.ts +8 -0
- package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -0
- package/dist/refactoring/manual-bind-to-arrow.js +134 -0
- package/dist/refactoring/manual-bind-to-arrow.js.map +1 -0
- package/dist/refactoring/pure-render-mixin.d.ts +8 -0
- package/dist/refactoring/pure-render-mixin.d.ts.map +1 -0
- package/dist/refactoring/pure-render-mixin.js +253 -0
- package/dist/refactoring/pure-render-mixin.js.map +1 -0
- package/dist/refactoring/sort-comp.d.ts +8 -0
- package/dist/refactoring/sort-comp.d.ts.map +1 -0
- package/dist/refactoring/sort-comp.js +128 -0
- package/dist/refactoring/sort-comp.js.map +1 -0
- package/dist/search/find-hook-usage.d.ts +9 -0
- package/dist/search/find-hook-usage.d.ts.map +1 -0
- package/dist/search/find-hook-usage.js +262 -0
- package/dist/search/find-hook-usage.js.map +1 -0
- package/dist/search/find-prop-usage.d.ts +15 -0
- package/dist/search/find-prop-usage.d.ts.map +1 -0
- package/dist/search/find-prop-usage.js +177 -0
- package/dist/search/find-prop-usage.js.map +1 -0
- package/dist/search/find-react-component.d.ts +15 -0
- package/dist/search/find-react-component.d.ts.map +1 -0
- package/dist/search/find-react-component.js +260 -0
- package/dist/search/find-react-component.js.map +1 -0
- package/dist/search/find-server-rendering-usage.d.ts +9 -0
- package/dist/search/find-server-rendering-usage.d.ts.map +1 -0
- package/dist/search/find-server-rendering-usage.js +131 -0
- package/dist/search/find-server-rendering-usage.js.map +1 -0
- package/dist/simplify-object-pattern-property.d.ts +8 -0
- package/dist/simplify-object-pattern-property.d.ts.map +1 -0
- package/dist/simplify-object-pattern-property.js +59 -0
- package/dist/simplify-object-pattern-property.js.map +1 -0
- package/dist/simplify-react-imports.d.ts +8 -0
- package/dist/simplify-react-imports.d.ts.map +1 -0
- package/dist/simplify-react-imports.js +199 -0
- package/dist/simplify-react-imports.js.map +1 -0
- package/package.json +39 -0
- package/src/index.ts +149 -0
- package/src/migration/change-component-prop-value.ts +268 -0
- package/src/react-native/view-prop-types.ts +63 -0
- package/src/react16/error-boundaries.ts +46 -0
- package/src/react16/find-dom-node.ts +55 -0
- package/src/react16/react-dom-factories.ts +99 -0
- package/src/react16/react-prop-types.ts +71 -0
- package/src/react16/react-to-react-dom.ts +104 -0
- package/src/react16/replace-create-factory.ts +96 -0
- package/src/react16/upgrade-to-react-16.ts +37 -0
- package/src/react17/remove-event-persist.ts +121 -0
- package/src/react17/rename-unsafe-lifecycles.ts +57 -0
- package/src/react17/update-react-imports.ts +50 -0
- package/src/react17/upgrade-to-react-17.ts +30 -0
- package/src/react18/remove-unstable-batched-updates.ts +192 -0
- package/src/react18/replace-reactdom-render.ts +68 -0
- package/src/react18/replace-render-callback.ts +66 -0
- package/src/react18/replace-unmount-component-at-node.ts +66 -0
- package/src/react18/upgrade-to-react-18.ts +33 -0
- package/src/react19/deprecated-react-types.ts +120 -0
- package/src/react19/find-context-consumer.ts +127 -0
- package/src/react19/find-deprecated-reactdom-apis.ts +125 -0
- package/src/react19/find-element-ref.ts +86 -0
- package/src/react19/find-legacy-context-api.ts +157 -0
- package/src/react19/no-implicit-ref-callback-return.ts +123 -0
- package/src/react19/remove-context-provider.ts +87 -0
- package/src/react19/remove-forward-ref.ts +69 -0
- package/src/react19/remove-prop-types.ts +86 -0
- package/src/react19/remove-react-fc.ts +247 -0
- package/src/react19/replace-act-import.ts +36 -0
- package/src/react19/replace-default-props.ts +220 -0
- package/src/react19/replace-react-shallow-renderer.ts +75 -0
- package/src/react19/replace-reactdom-hydrate.ts +67 -0
- package/src/react19/replace-string-ref.ts +89 -0
- package/src/react19/replace-use-form-state.ts +66 -0
- package/src/react19/upgrade-to-react-19.ts +66 -0
- package/src/react19/use-context-hook.ts +67 -0
- package/src/react19/use-ref-required-initial.ts +75 -0
- package/src/refactoring/class-to-functional.ts +229 -0
- package/src/refactoring/create-class-to-es6.ts +309 -0
- package/src/refactoring/create-element-to-jsx.ts +200 -0
- package/src/refactoring/manual-bind-to-arrow.ts +139 -0
- package/src/refactoring/pure-render-mixin.ts +346 -0
- package/src/refactoring/sort-comp.ts +135 -0
- package/src/search/find-hook-usage.ts +226 -0
- package/src/search/find-prop-usage.ts +176 -0
- package/src/search/find-react-component.ts +254 -0
- package/src/search/find-server-rendering-usage.ts +120 -0
- package/src/simplify-object-pattern-property.ts +71 -0
- package/src/simplify-react-imports.ts +241 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.FindReactComponent = void 0;
|
|
19
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
20
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
21
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
22
|
+
class FindReactComponentRow {
|
|
23
|
+
}
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, rewrite_1.Column)({ displayName: "Component name", description: "The name of the React component" })
|
|
26
|
+
], FindReactComponentRow.prototype, "componentName", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, rewrite_1.Column)({ displayName: "File path", description: "The file path where the component is used" })
|
|
29
|
+
], FindReactComponentRow.prototype, "filePath", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, rewrite_1.Column)({ displayName: "Usage type", description: "How the component is referenced: import, jsx-element, or export" })
|
|
32
|
+
], FindReactComponentRow.prototype, "usageType", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, rewrite_1.Column)({ displayName: "Import path", description: "The module path the component is imported from" })
|
|
35
|
+
], FindReactComponentRow.prototype, "importPath", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, rewrite_1.Column)({ displayName: "Is default import", description: "Whether the component is imported as a default export" })
|
|
38
|
+
], FindReactComponentRow.prototype, "isDefaultImport", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, rewrite_1.Column)({ displayName: "Alias name", description: "Local alias name if the component is imported with a different name" })
|
|
41
|
+
], FindReactComponentRow.prototype, "aliasName", void 0);
|
|
42
|
+
class FindReactComponent extends rewrite_1.Recipe {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
super(options);
|
|
45
|
+
this.name = "org.openrewrite.react.search.find-react-component";
|
|
46
|
+
this.displayName = "Find React component";
|
|
47
|
+
this.description = "Finds all usages of a specific React component including imports, JSX elements, and exports.";
|
|
48
|
+
this.dataTable = new rewrite_1.DataTable("org.openrewrite.react.search.FindReactComponentTable", "React component usages", "Table of all React component usages found in the codebase.", FindReactComponentRow);
|
|
49
|
+
}
|
|
50
|
+
editor() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const componentName = this.componentName;
|
|
53
|
+
const importPathFilter = this.importPath;
|
|
54
|
+
const dataTable = this.dataTable;
|
|
55
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
56
|
+
constructor() {
|
|
57
|
+
super(...arguments);
|
|
58
|
+
this.aliases = new Map();
|
|
59
|
+
this.filePath = "";
|
|
60
|
+
}
|
|
61
|
+
visitJsCompilationUnit(cu, ctx) {
|
|
62
|
+
const _super = Object.create(null, {
|
|
63
|
+
visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
|
|
64
|
+
});
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a;
|
|
67
|
+
this.aliases.clear();
|
|
68
|
+
this.filePath = (_a = cu.sourcePath) !== null && _a !== void 0 ? _a : "";
|
|
69
|
+
return _super.visitJsCompilationUnit.call(this, cu, ctx);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
visitImportSpecifier(spec, ctx) {
|
|
73
|
+
const _super = Object.create(null, {
|
|
74
|
+
visitImportSpecifier: { get: () => super.visitImportSpecifier }
|
|
75
|
+
});
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const specifier = spec.specifier;
|
|
78
|
+
const importDecl = this.findEnclosingImport();
|
|
79
|
+
const modulePath = importDecl ? this.getModuleSpecifier(importDecl) : "";
|
|
80
|
+
if (importPathFilter && modulePath && !this.matchesPath(modulePath, importPathFilter)) {
|
|
81
|
+
return _super.visitImportSpecifier.call(this, spec, ctx);
|
|
82
|
+
}
|
|
83
|
+
if (specifier.kind === javascript_1.JS.Kind.Alias) {
|
|
84
|
+
const alias = specifier;
|
|
85
|
+
const propertyName = alias.propertyName.element;
|
|
86
|
+
if ((0, java_1.isIdentifier)(propertyName) && propertyName.simpleName === componentName) {
|
|
87
|
+
const aliasIdent = alias.alias;
|
|
88
|
+
const aliasName = (0, java_1.isIdentifier)(aliasIdent) ? aliasIdent.simpleName : componentName;
|
|
89
|
+
this.aliases.set(aliasName, { importPath: modulePath, isDefault: false, alias: aliasName });
|
|
90
|
+
dataTable.insertRow(ctx, {
|
|
91
|
+
componentName, filePath: this.filePath, usageType: "import",
|
|
92
|
+
importPath: modulePath, isDefaultImport: false, aliasName
|
|
93
|
+
});
|
|
94
|
+
return (0, rewrite_1.foundSearchResult)(spec, componentName);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if ((0, java_1.isIdentifier)(specifier) && specifier.simpleName === componentName) {
|
|
98
|
+
this.aliases.set(componentName, { importPath: modulePath, isDefault: false, alias: "" });
|
|
99
|
+
dataTable.insertRow(ctx, {
|
|
100
|
+
componentName, filePath: this.filePath, usageType: "import",
|
|
101
|
+
importPath: modulePath, isDefaultImport: false, aliasName: ""
|
|
102
|
+
});
|
|
103
|
+
return (0, rewrite_1.foundSearchResult)(spec, componentName);
|
|
104
|
+
}
|
|
105
|
+
return _super.visitImportSpecifier.call(this, spec, ctx);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
visitImportClause(clause, ctx) {
|
|
109
|
+
const _super = Object.create(null, {
|
|
110
|
+
visitImportClause: { get: () => super.visitImportClause }
|
|
111
|
+
});
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (clause.name) {
|
|
114
|
+
const identifier = clause.name.element;
|
|
115
|
+
if ((0, java_1.isIdentifier)(identifier) && identifier.simpleName === componentName) {
|
|
116
|
+
const importDecl = this.findEnclosingImport();
|
|
117
|
+
const modulePath = importDecl ? this.getModuleSpecifier(importDecl) : "";
|
|
118
|
+
if (!importPathFilter || !modulePath || this.matchesPath(modulePath, importPathFilter)) {
|
|
119
|
+
this.aliases.set(componentName, { importPath: modulePath, isDefault: true, alias: "" });
|
|
120
|
+
dataTable.insertRow(ctx, {
|
|
121
|
+
componentName, filePath: this.filePath, usageType: "import",
|
|
122
|
+
importPath: modulePath, isDefaultImport: true, aliasName: ""
|
|
123
|
+
});
|
|
124
|
+
return (0, rewrite_1.foundSearchResult)(clause, componentName);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return _super.visitImportClause.call(this, clause, ctx);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
visitJsxTag(tag, ctx) {
|
|
132
|
+
const _super = Object.create(null, {
|
|
133
|
+
visitJsxTag: { get: () => super.visitJsxTag }
|
|
134
|
+
});
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
const t = yield _super.visitJsxTag.call(this, tag, ctx);
|
|
138
|
+
const openName = t.openName.element;
|
|
139
|
+
if ((0, java_1.isIdentifier)(openName)) {
|
|
140
|
+
const tagName = openName.simpleName;
|
|
141
|
+
const isTracked = this.aliases.has(tagName);
|
|
142
|
+
const matchesName = tagName === componentName;
|
|
143
|
+
if (isTracked || (!importPathFilter && matchesName)) {
|
|
144
|
+
const info = this.aliases.get(tagName);
|
|
145
|
+
dataTable.insertRow(ctx, {
|
|
146
|
+
componentName, filePath: this.filePath, usageType: "jsx-element",
|
|
147
|
+
importPath: (_a = info === null || info === void 0 ? void 0 : info.importPath) !== null && _a !== void 0 ? _a : "", isDefaultImport: (_b = info === null || info === void 0 ? void 0 : info.isDefault) !== null && _b !== void 0 ? _b : false,
|
|
148
|
+
aliasName: (_c = info === null || info === void 0 ? void 0 : info.alias) !== null && _c !== void 0 ? _c : ""
|
|
149
|
+
});
|
|
150
|
+
return (0, rewrite_1.foundSearchResult)(t, componentName);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (openName.kind === java_1.J.Kind.FieldAccess) {
|
|
154
|
+
const fieldAccess = openName;
|
|
155
|
+
const nameIdent = fieldAccess.name.element;
|
|
156
|
+
if ((0, java_1.isIdentifier)(nameIdent) && nameIdent.simpleName === componentName && !importPathFilter) {
|
|
157
|
+
dataTable.insertRow(ctx, {
|
|
158
|
+
componentName, filePath: this.filePath, usageType: "jsx-element",
|
|
159
|
+
importPath: "", isDefaultImport: false, aliasName: ""
|
|
160
|
+
});
|
|
161
|
+
return (0, rewrite_1.foundSearchResult)(t, componentName);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return t;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
visitExportDeclaration(exportDecl, ctx) {
|
|
168
|
+
const _super = Object.create(null, {
|
|
169
|
+
visitExportDeclaration: { get: () => super.visitExportDeclaration }
|
|
170
|
+
});
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
var _a;
|
|
173
|
+
const e = yield _super.visitExportDeclaration.call(this, exportDecl, ctx);
|
|
174
|
+
const exportClause = e.exportClause;
|
|
175
|
+
if (!exportClause)
|
|
176
|
+
return e;
|
|
177
|
+
if (exportClause.kind === javascript_1.JS.Kind.NamedExports) {
|
|
178
|
+
const namedExports = exportClause;
|
|
179
|
+
for (const elem of namedExports.elements.elements) {
|
|
180
|
+
const el = (_a = elem.element) !== null && _a !== void 0 ? _a : elem;
|
|
181
|
+
if (el.kind === javascript_1.JS.Kind.ExportSpecifier) {
|
|
182
|
+
const spec = el;
|
|
183
|
+
const specifier = spec.specifier;
|
|
184
|
+
if ((0, java_1.isIdentifier)(specifier) && specifier.simpleName === componentName) {
|
|
185
|
+
const modulePath = this.getExportModuleSpecifier(e);
|
|
186
|
+
dataTable.insertRow(ctx, {
|
|
187
|
+
componentName, filePath: this.filePath, usageType: "export",
|
|
188
|
+
importPath: modulePath, isDefaultImport: false, aliasName: ""
|
|
189
|
+
});
|
|
190
|
+
return (0, rewrite_1.foundSearchResult)(e, componentName);
|
|
191
|
+
}
|
|
192
|
+
if (specifier.kind === javascript_1.JS.Kind.Alias) {
|
|
193
|
+
const alias = specifier;
|
|
194
|
+
const propName = alias.propertyName.element;
|
|
195
|
+
if ((0, java_1.isIdentifier)(propName) && propName.simpleName === componentName) {
|
|
196
|
+
const aliasName = (0, java_1.isIdentifier)(alias.alias) ? alias.alias.simpleName : "";
|
|
197
|
+
const modulePath = this.getExportModuleSpecifier(e);
|
|
198
|
+
dataTable.insertRow(ctx, {
|
|
199
|
+
componentName, filePath: this.filePath, usageType: "export",
|
|
200
|
+
importPath: modulePath, isDefaultImport: false, aliasName
|
|
201
|
+
});
|
|
202
|
+
return (0, rewrite_1.foundSearchResult)(e, componentName);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return e;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
findEnclosingImport() {
|
|
212
|
+
return this.cursor.firstEnclosing((t) => t.kind === javascript_1.JS.Kind.Import);
|
|
213
|
+
}
|
|
214
|
+
getModuleSpecifier(importDecl) {
|
|
215
|
+
var _a;
|
|
216
|
+
if (!importDecl.moduleSpecifier)
|
|
217
|
+
return "";
|
|
218
|
+
const spec = importDecl.moduleSpecifier.element;
|
|
219
|
+
if (spec.kind === java_1.J.Kind.Literal) {
|
|
220
|
+
return String((_a = spec.value) !== null && _a !== void 0 ? _a : "");
|
|
221
|
+
}
|
|
222
|
+
return "";
|
|
223
|
+
}
|
|
224
|
+
getExportModuleSpecifier(exportDecl) {
|
|
225
|
+
var _a;
|
|
226
|
+
if (!exportDecl.moduleSpecifier)
|
|
227
|
+
return "";
|
|
228
|
+
const spec = exportDecl.moduleSpecifier.element;
|
|
229
|
+
if (spec.kind === java_1.J.Kind.Literal) {
|
|
230
|
+
return String((_a = spec.value) !== null && _a !== void 0 ? _a : "");
|
|
231
|
+
}
|
|
232
|
+
return "";
|
|
233
|
+
}
|
|
234
|
+
matchesPath(actual, pattern) {
|
|
235
|
+
if (pattern === actual)
|
|
236
|
+
return true;
|
|
237
|
+
const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
|
|
238
|
+
return regex.test(actual);
|
|
239
|
+
}
|
|
240
|
+
}();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
exports.FindReactComponent = FindReactComponent;
|
|
245
|
+
__decorate([
|
|
246
|
+
(0, rewrite_1.Option)({
|
|
247
|
+
displayName: "Component name",
|
|
248
|
+
description: "The name of the React component to find (e.g., 'Button', 'TextField')",
|
|
249
|
+
example: "Button"
|
|
250
|
+
})
|
|
251
|
+
], FindReactComponent.prototype, "componentName", void 0);
|
|
252
|
+
__decorate([
|
|
253
|
+
(0, rewrite_1.Option)({
|
|
254
|
+
displayName: "Import path",
|
|
255
|
+
description: "Optional module path to narrow the search (e.g., '@mui/material'). Supports glob patterns.",
|
|
256
|
+
required: false,
|
|
257
|
+
example: "@mui/material"
|
|
258
|
+
})
|
|
259
|
+
], FindReactComponent.prototype, "importPath", void 0);
|
|
260
|
+
//# sourceMappingURL=find-react-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-react-component.js","sourceRoot":"","sources":["../../src/search/find-react-component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,kDAAyH;AACzH,gEAA2E;AAC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
|
2
|
+
export declare class FindServerRenderingUsage extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.react.search.find-server-rendering-usage";
|
|
4
|
+
readonly displayName = "Find server-side rendering API usage";
|
|
5
|
+
readonly description = "Finds usage of React server-side rendering APIs from `react-dom/server` including `renderToString`, `renderToStaticMarkup`, `renderToNodeStream`, and `renderToStaticNodeStream` to help plan SSR migration.";
|
|
6
|
+
private dataTable;
|
|
7
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=find-server-rendering-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-server-rendering-usage.d.ts","sourceRoot":"","sources":["../../src/search/find-server-rendering-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,gBAAgB,EAAqB,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAiCjH,qBAAa,wBAAyB,SAAQ,MAAM;IAChD,QAAQ,CAAC,IAAI,8DAA8D;IAC3E,QAAQ,CAAC,WAAW,0CAA0C;IAC9D,QAAQ,CAAC,WAAW,kNAAkN;IAEtO,OAAO,CAAC,SAAS,CAKf;IAEI,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0E9D"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.FindServerRenderingUsage = void 0;
|
|
19
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
20
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
21
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
22
|
+
class ServerRenderingRow {
|
|
23
|
+
}
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, rewrite_1.Column)({ displayName: "File path", description: "The file path where the SSR API is used" })
|
|
26
|
+
], ServerRenderingRow.prototype, "filePath", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, rewrite_1.Column)({ displayName: "API name", description: "The name of the server rendering API" })
|
|
29
|
+
], ServerRenderingRow.prototype, "apiName", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, rewrite_1.Column)({ displayName: "Replacement", description: "The recommended replacement API" })
|
|
32
|
+
], ServerRenderingRow.prototype, "replacement", void 0);
|
|
33
|
+
const SSR_APIS = {
|
|
34
|
+
'renderToString': 'Consider using renderToPipeableStream or renderToReadableStream for streaming SSR',
|
|
35
|
+
'renderToStaticMarkup': 'Consider using renderToPipeableStream or renderToReadableStream for streaming SSR',
|
|
36
|
+
'renderToNodeStream': 'Use renderToPipeableStream instead (removed in React 19)',
|
|
37
|
+
'renderToStaticNodeStream': 'Use renderToPipeableStream or renderToReadableStream instead (removed in React 19)',
|
|
38
|
+
};
|
|
39
|
+
class FindServerRenderingUsage extends rewrite_1.Recipe {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.name = "org.openrewrite.react.search.find-server-rendering-usage";
|
|
43
|
+
this.displayName = "Find server-side rendering API usage";
|
|
44
|
+
this.description = "Finds usage of React server-side rendering APIs from `react-dom/server` including `renderToString`, `renderToStaticMarkup`, `renderToNodeStream`, and `renderToStaticNodeStream` to help plan SSR migration.";
|
|
45
|
+
this.dataTable = new rewrite_1.DataTable("org.openrewrite.react.search.ServerRenderingUsageTable", "Server rendering API usages", "Table of all server-side rendering API usages found in the codebase.", ServerRenderingRow);
|
|
46
|
+
}
|
|
47
|
+
editor() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const dataTable = this.dataTable;
|
|
50
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
51
|
+
constructor() {
|
|
52
|
+
super(...arguments);
|
|
53
|
+
this.filePath = "";
|
|
54
|
+
this.importedSsrApis = new Set();
|
|
55
|
+
}
|
|
56
|
+
visitJsCompilationUnit(cu, ctx) {
|
|
57
|
+
const _super = Object.create(null, {
|
|
58
|
+
visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
|
|
59
|
+
});
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
var _a;
|
|
62
|
+
this.filePath = (_a = cu.sourcePath) !== null && _a !== void 0 ? _a : "";
|
|
63
|
+
this.importedSsrApis.clear();
|
|
64
|
+
return _super.visitJsCompilationUnit.call(this, cu, ctx);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
visitImportSpecifier(spec, ctx) {
|
|
68
|
+
const _super = Object.create(null, {
|
|
69
|
+
visitImportSpecifier: { get: () => super.visitImportSpecifier }
|
|
70
|
+
});
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const specifier = spec.specifier;
|
|
73
|
+
let importedName;
|
|
74
|
+
if (specifier.kind === javascript_1.JS.Kind.Alias) {
|
|
75
|
+
const alias = specifier;
|
|
76
|
+
const propName = alias.propertyName.element;
|
|
77
|
+
if ((0, java_1.isIdentifier)(propName)) {
|
|
78
|
+
importedName = propName.simpleName;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if ((0, java_1.isIdentifier)(specifier)) {
|
|
82
|
+
importedName = specifier.simpleName;
|
|
83
|
+
}
|
|
84
|
+
if (importedName && SSR_APIS[importedName]) {
|
|
85
|
+
this.importedSsrApis.add(importedName);
|
|
86
|
+
dataTable.insertRow(ctx, {
|
|
87
|
+
filePath: this.filePath,
|
|
88
|
+
apiName: importedName,
|
|
89
|
+
replacement: SSR_APIS[importedName]
|
|
90
|
+
});
|
|
91
|
+
return (0, rewrite_1.foundSearchResult)(spec, `SSR API: ${importedName}`);
|
|
92
|
+
}
|
|
93
|
+
return _super.visitImportSpecifier.call(this, spec, ctx);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
visitMethodInvocation(method, ctx) {
|
|
97
|
+
const _super = Object.create(null, {
|
|
98
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
99
|
+
});
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
var _a;
|
|
102
|
+
let m = yield _super.visitMethodInvocation.call(this, method, ctx);
|
|
103
|
+
const methodName = m.name.simpleName;
|
|
104
|
+
if (!SSR_APIS[methodName])
|
|
105
|
+
return m;
|
|
106
|
+
if (!m.select && this.importedSsrApis.has(methodName)) {
|
|
107
|
+
return (0, rewrite_1.foundSearchResult)(m, `SSR API: ${methodName}`);
|
|
108
|
+
}
|
|
109
|
+
if (m.select) {
|
|
110
|
+
const select = (_a = m.select.element) !== null && _a !== void 0 ? _a : m.select;
|
|
111
|
+
if ((0, java_1.isIdentifier)(select)) {
|
|
112
|
+
const ns = select.simpleName;
|
|
113
|
+
if (ns === 'ReactDOMServer' || ns === 'ReactDOM') {
|
|
114
|
+
dataTable.insertRow(ctx, {
|
|
115
|
+
filePath: this.filePath,
|
|
116
|
+
apiName: `${ns}.${methodName}`,
|
|
117
|
+
replacement: SSR_APIS[methodName]
|
|
118
|
+
});
|
|
119
|
+
return (0, rewrite_1.foundSearchResult)(m, `SSR API: ${ns}.${methodName}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return m;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.FindServerRenderingUsage = FindServerRenderingUsage;
|
|
131
|
+
//# sourceMappingURL=find-server-rendering-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-server-rendering-usage.js","sourceRoot":"","sources":["../../src/search/find-server-rendering-usage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,kDAAiH;AACjH,gEAAsE;AACtE,oDAA0D;AAE1D,MAAM,kBAAkB;CASvB;AAPG;IADC,IAAA,gBAAM,EAAC,EAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,yCAAyC,EAAC,CAAC;oDACzE;AAGlB;IADC,IAAA,gBAAM,EAAC,EAAC,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,sCAAsC,EAAC,CAAC;mDACtE;AAGjB;IADC,IAAA,gBAAM,EAAC,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,iCAAiC,EAAC,CAAC;uDAChE;AAGzB,MAAM,QAAQ,GAA2B;IACrC,gBAAgB,EAAE,mFAAmF;IACrG,sBAAsB,EAAE,mFAAmF;IAC3G,oBAAoB,EAAE,0DAA0D;IAChF,0BAA0B,EAAE,oFAAoF;CACnH,CAAC;AAaF,MAAa,wBAAyB,SAAQ,gBAAM;IAApD;;QACa,SAAI,GAAG,0DAA0D,CAAC;Q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;wCACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;wCACvB,OAAO,EAAE,GAAG,EAAE,IAAI,UAAU,EAAE;wCAC9B,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC;qCACpC,CAAC,CAAC;oCACH,OAAO,IAAA,2BAAiB,EAAC,CAAC,EAAE,YAAY,EAAE,IAAI,UAAU,EAAE,CAAC,CAAC;gCAChE,CAAC;4BACL,CAAC;wBACL,CAAC;wBAED,OAAO,CAAC,CAAC;oBACb,CAAC;iBAAA;aACJ,EAAE,CAAC;QACR,CAAC;KAAA;CACJ;AAtFD,4DAsFC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class SimplifyObjectPatternProperty extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.javascript.cleanup.simplify-object-pattern-property";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=simplify-object-pattern-property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-object-pattern-property.d.ts","sourceRoot":"","sources":["../src/simplify-object-pattern-property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAa3E,qBAAa,6BAA8B,SAAQ,MAAM;IACrD,QAAQ,CAAC,IAAI,yEAAyE;IACtF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAwC;IACpE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAyI;IAE/J,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAoD9D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SimplifyObjectPatternProperty = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
+
const mutative_1 = require("mutative");
|
|
17
|
+
class SimplifyObjectPatternProperty extends rewrite_1.Recipe {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.name = "org.openrewrite.javascript.cleanup.simplify-object-pattern-property";
|
|
21
|
+
this.displayName = "Simplify object pattern properties";
|
|
22
|
+
this.description = "Simplifies object destructuring patterns where the property name and variable name are the same (e.g., `{ x: x }` becomes `{ x }`).";
|
|
23
|
+
}
|
|
24
|
+
editor() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
27
|
+
visitObjectBindingPattern(pattern, p) {
|
|
28
|
+
const _super = Object.create(null, {
|
|
29
|
+
visitObjectBindingPattern: { get: () => super.visitObjectBindingPattern }
|
|
30
|
+
});
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const visited = yield _super.visitObjectBindingPattern.call(this, pattern, p);
|
|
33
|
+
const simplifiedBindings = visited.bindings.elements.map(right => {
|
|
34
|
+
const element = right.element;
|
|
35
|
+
if (element.kind === javascript_1.JS.Kind.BindingElement) {
|
|
36
|
+
const binding = element;
|
|
37
|
+
if (binding.propertyName && binding.propertyName.element.kind === java_1.J.Kind.Identifier) {
|
|
38
|
+
const propName = binding.propertyName.element.simpleName;
|
|
39
|
+
if (binding.name && binding.name.kind === java_1.J.Kind.Identifier) {
|
|
40
|
+
const assignmentName = binding.name.simpleName;
|
|
41
|
+
if (propName === assignmentName) {
|
|
42
|
+
return Object.assign(Object.assign({}, right), { element: Object.assign(Object.assign({}, binding), { propertyName: undefined, name: Object.assign(Object.assign({}, binding.name), { prefix: binding.propertyName.element.prefix }) }) });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return right;
|
|
48
|
+
});
|
|
49
|
+
return (0, mutative_1.create)(visited, draft => {
|
|
50
|
+
draft.bindings.elements = simplifiedBindings;
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.SimplifyObjectPatternProperty = SimplifyObjectPatternProperty;
|
|
59
|
+
//# sourceMappingURL=simplify-object-pattern-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-object-pattern-property.js","sourceRoot":"","sources":["../src/simplify-object-pattern-property.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA2E;AAC3E,gEAAsE;AACtE,oDAA4C;AAC5C,uCAAgC;AAUhC,MAAa,6BAA8B,SAAQ,gBAAM;IAAzD;;QACa,SAAI,GAAG,qEAAqE,CAAC;QAC7E,gBAAW,GAAW,oCAAoC,CAAC;QAC3D,gBAAW,GAAW,qIAAqI,CAAC;IAsDzK,CAAC;IApDS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACxC,yBAAyB,CAAC,OAAgC,EAAE,C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AC;iBAAA;aACJ,EAAE,CAAC;QACR,CAAC;KAAA;CACJ;AAzDD,sEAyDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class SimplifyReactImports extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.react.simplify-react-imports";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=simplify-react-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-react-imports.d.ts","sourceRoot":"","sources":["../src/simplify-react-imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AA+F3E,qBAAa,oBAAqB,SAAQ,MAAM;IAC5C,QAAQ,CAAC,IAAI,kDAAkD;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA4C;IACxE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA+G;IAErI,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA4I9D"}
|