@openrewrite/rewrite 8.69.0-20251207-160255 → 8.69.0-20251207-214914
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/cli/cli-utils.d.ts.map +1 -1
- package/dist/cli/cli-utils.js +3 -2
- package/dist/cli/cli-utils.js.map +1 -1
- package/dist/cli/rewrite.js +2 -1
- package/dist/cli/rewrite.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +99 -56
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +48 -8
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/recipes/async-callback-in-sync-array-method.d.ts +40 -0
- package/dist/javascript/recipes/async-callback-in-sync-array-method.d.ts.map +1 -0
- package/dist/javascript/recipes/async-callback-in-sync-array-method.js +232 -0
- package/dist/javascript/recipes/async-callback-in-sync-array-method.js.map +1 -0
- package/dist/javascript/recipes/change-import.d.ts +51 -0
- package/dist/javascript/recipes/change-import.d.ts.map +1 -0
- package/dist/javascript/recipes/change-import.js +658 -0
- package/dist/javascript/recipes/change-import.js.map +1 -0
- package/dist/javascript/recipes/index.d.ts +3 -0
- package/dist/javascript/recipes/index.d.ts.map +1 -1
- package/dist/javascript/recipes/index.js +3 -0
- package/dist/javascript/recipes/index.js.map +1 -1
- package/dist/javascript/recipes/order-imports.d.ts +10 -0
- package/dist/javascript/recipes/order-imports.d.ts.map +1 -0
- package/dist/javascript/recipes/order-imports.js +240 -0
- package/dist/javascript/recipes/order-imports.js.map +1 -0
- package/dist/javascript/templating/index.d.ts +1 -1
- package/dist/javascript/templating/index.d.ts.map +1 -1
- package/dist/javascript/templating/index.js +2 -1
- package/dist/javascript/templating/index.js.map +1 -1
- package/dist/javascript/templating/rewrite.d.ts +36 -2
- package/dist/javascript/templating/rewrite.d.ts.map +1 -1
- package/dist/javascript/templating/rewrite.js +76 -0
- package/dist/javascript/templating/rewrite.js.map +1 -1
- package/dist/json/parser.js +78 -30
- package/dist/json/parser.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +7 -4
- package/dist/run.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/cli/cli-utils.ts +3 -2
- package/src/cli/rewrite.ts +2 -1
- package/src/index.ts +3 -2
- package/src/javascript/add-import.ts +125 -69
- package/src/javascript/parser.ts +49 -8
- package/src/javascript/recipes/async-callback-in-sync-array-method.ts +237 -0
- package/src/javascript/recipes/change-import.ts +700 -0
- package/src/javascript/recipes/index.ts +3 -0
- package/src/javascript/recipes/order-imports.ts +242 -0
- package/src/javascript/templating/index.ts +2 -1
- package/src/javascript/templating/rewrite.ts +89 -4
- package/src/json/parser.ts +69 -24
- package/src/run.ts +5 -4
- package/dist/recipe/index.d.ts +0 -2
- package/dist/recipe/index.d.ts.map +0 -1
- package/dist/recipe/index.js +0 -21
- package/dist/recipe/index.js.map +0 -1
- package/dist/recipe/order-imports.d.ts +0 -10
- package/dist/recipe/order-imports.d.ts.map +0 -1
- package/dist/recipe/order-imports.js +0 -213
- package/dist/recipe/order-imports.js.map +0 -1
- package/src/recipe/index.ts +0 -17
- package/src/recipe/order-imports.ts +0 -195
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Recipe } from "../../recipe";
|
|
2
|
+
import { ExecutionContext } from "../../execution";
|
|
3
|
+
import { TreeVisitor } from "../../visitor";
|
|
4
|
+
/**
|
|
5
|
+
* Detects async callbacks passed to synchronous array methods.
|
|
6
|
+
*
|
|
7
|
+
* This is a common bug pattern in JavaScript/TypeScript where async functions
|
|
8
|
+
* are passed to array methods like `.some()`, `.every()`, `.find()`, etc.
|
|
9
|
+
* These methods don't await the promises returned by async callbacks, leading
|
|
10
|
+
* to bugs where Promise objects are treated as truthy values.
|
|
11
|
+
*
|
|
12
|
+
* Example of buggy code:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // BUG: .some() doesn't await, so any Promise is truthy
|
|
15
|
+
* const hasAdmin = users.some(async user => {
|
|
16
|
+
* return await checkPermission(user, 'admin');
|
|
17
|
+
* });
|
|
18
|
+
* // hasAdmin is ALWAYS true because Promise objects are truthy!
|
|
19
|
+
*
|
|
20
|
+
* // CORRECT: Use a for loop with await
|
|
21
|
+
* let hasAdmin = false;
|
|
22
|
+
* for (const user of users) {
|
|
23
|
+
* if (await checkPermission(user, 'admin')) {
|
|
24
|
+
* hasAdmin = true;
|
|
25
|
+
* break;
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* This recipe reports occurrences but doesn't auto-fix because the correct
|
|
31
|
+
* fix depends on the context (could use for...of loop, Promise.all, etc.).
|
|
32
|
+
*/
|
|
33
|
+
export declare class AsyncCallbackInSyncArrayMethod extends Recipe {
|
|
34
|
+
readonly name = "org.openrewrite.javascript.cleanup.async-callback-in-sync-array-method";
|
|
35
|
+
readonly displayName: string;
|
|
36
|
+
readonly description: string;
|
|
37
|
+
readonly tags: string[];
|
|
38
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=async-callback-in-sync-array-method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-callback-in-sync-array-method.d.ts","sourceRoot":"","sources":["../../../src/javascript/recipes/async-callback-in-sync-array-method.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AA0J1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,8BAA+B,SAAQ,MAAM;IACtD,QAAQ,CAAC,IAAI,4EAA4E;IACzF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAyD;IACrF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAiL;IAC7M,QAAQ,CAAC,IAAI,WAA2D;IAElE,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA6B9D"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 the original author or authors.
|
|
4
|
+
* <p>
|
|
5
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
* <p>
|
|
9
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
10
|
+
* <p>
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.AsyncCallbackInSyncArrayMethod = void 0;
|
|
28
|
+
const recipe_1 = require("../../recipe");
|
|
29
|
+
const visitor_1 = require("../visitor");
|
|
30
|
+
const java_1 = require("../../java");
|
|
31
|
+
const tree_1 = require("../tree");
|
|
32
|
+
const java_2 = require("../../java");
|
|
33
|
+
const markers_1 = require("../../markers");
|
|
34
|
+
/**
|
|
35
|
+
* Array methods that don't await async callbacks.
|
|
36
|
+
* When an async function is passed as a callback to these methods,
|
|
37
|
+
* the returned Promise is not awaited, leading to bugs.
|
|
38
|
+
*/
|
|
39
|
+
const SYNC_ARRAY_METHODS = new Set([
|
|
40
|
+
'some', // Returns first truthy value, but Promise is always truthy
|
|
41
|
+
'every', // Returns first falsy value, but Promise is always truthy
|
|
42
|
+
'find', // Returns first truthy value, but Promise is always truthy
|
|
43
|
+
'findIndex', // Returns first truthy value, but Promise is always truthy
|
|
44
|
+
'filter', // Filters based on truthy values, but Promise is always truthy
|
|
45
|
+
'forEach', // Ignores return values entirely, async callbacks won't be awaited
|
|
46
|
+
]);
|
|
47
|
+
/**
|
|
48
|
+
* Check if a type is a Promise type.
|
|
49
|
+
* Looks for types like Promise<T>, PromiseLike<T>, or the Promise class itself.
|
|
50
|
+
*/
|
|
51
|
+
function isPromiseType(type) {
|
|
52
|
+
if (!type)
|
|
53
|
+
return false;
|
|
54
|
+
// Check for Class type with Promise name
|
|
55
|
+
if (java_2.Type.isClass(type)) {
|
|
56
|
+
const fqn = type.fullyQualifiedName;
|
|
57
|
+
return fqn === 'Promise' ||
|
|
58
|
+
fqn === 'PromiseLike' ||
|
|
59
|
+
fqn.endsWith('.Promise') ||
|
|
60
|
+
fqn.endsWith('.PromiseLike');
|
|
61
|
+
}
|
|
62
|
+
// Check for Parameterized type (e.g., Promise<boolean>)
|
|
63
|
+
if (java_2.Type.isParameterized(type)) {
|
|
64
|
+
return isPromiseType(type.type);
|
|
65
|
+
}
|
|
66
|
+
// Check for Union type (e.g., Promise<T> | undefined)
|
|
67
|
+
if (java_2.Type.isUnion(type)) {
|
|
68
|
+
return type.bounds.some(b => isPromiseType(b));
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if an arrow function has an async modifier.
|
|
74
|
+
* In JavaScript, async is represented as a LanguageExtension modifier with keyword="async"
|
|
75
|
+
*/
|
|
76
|
+
function hasAsyncModifier(arrowFunc) {
|
|
77
|
+
return arrowFunc.modifiers.some(m => m.type === java_1.J.ModifierType.Async ||
|
|
78
|
+
(m.type === java_1.J.ModifierType.LanguageExtension && m.keyword === 'async'));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check if a function type returns a Promise.
|
|
82
|
+
*/
|
|
83
|
+
function functionTypeReturnsPromise(funcType) {
|
|
84
|
+
if (!java_2.Type.isFunctionType(funcType))
|
|
85
|
+
return false;
|
|
86
|
+
const clazz = funcType;
|
|
87
|
+
if (clazz.typeParameters && clazz.typeParameters.length > 0) {
|
|
88
|
+
// First type parameter is typically R (return type) in TypeScript function types
|
|
89
|
+
// It's a GenericTypeVariable with bounds containing the actual type
|
|
90
|
+
const returnTypeParam = clazz.typeParameters[0];
|
|
91
|
+
// Check if it's directly a Promise type
|
|
92
|
+
if (isPromiseType(returnTypeParam)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
// Check if it's a GenericTypeVariable with bounds
|
|
96
|
+
if (java_2.Type.isGenericTypeVariable(returnTypeParam)) {
|
|
97
|
+
const bounds = returnTypeParam.bounds;
|
|
98
|
+
if (bounds && bounds.some(b => isPromiseType(b))) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if a callback argument returns a Promise.
|
|
107
|
+
* This checks:
|
|
108
|
+
* 1. Explicit async modifier on arrow functions
|
|
109
|
+
* 2. Type annotation indicating Promise return type
|
|
110
|
+
* 3. Function references whose type indicates Promise return
|
|
111
|
+
*/
|
|
112
|
+
function callbackReturnsPromise(arg) {
|
|
113
|
+
var _a;
|
|
114
|
+
// Handle RightPadded wrapper
|
|
115
|
+
const element = (_a = arg === null || arg === void 0 ? void 0 : arg.element) !== null && _a !== void 0 ? _a : arg;
|
|
116
|
+
if (!element)
|
|
117
|
+
return false;
|
|
118
|
+
// Check if it's an arrow function
|
|
119
|
+
if (element.kind === tree_1.JS.Kind.ArrowFunction) {
|
|
120
|
+
const arrowFunc = element;
|
|
121
|
+
// Check for async modifier
|
|
122
|
+
if (hasAsyncModifier(arrowFunc)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
// Check if return type expression indicates Promise
|
|
126
|
+
const returnType = arrowFunc.returnTypeExpression;
|
|
127
|
+
if (returnType) {
|
|
128
|
+
// Check if the return type expression is an identifier named Promise
|
|
129
|
+
if (returnType.kind === java_1.J.Kind.Identifier) {
|
|
130
|
+
const id = returnType;
|
|
131
|
+
if (id.simpleName === 'Promise' || id.simpleName === 'PromiseLike') {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Check if it's a parameterized type like Promise<boolean>
|
|
136
|
+
if (returnType.kind === java_1.J.Kind.ParameterizedType) {
|
|
137
|
+
const pt = returnType;
|
|
138
|
+
// ParameterizedType has 'clazz' property which is the base type
|
|
139
|
+
const baseType = pt.clazz;
|
|
140
|
+
if ((baseType === null || baseType === void 0 ? void 0 : baseType.kind) === java_1.J.Kind.Identifier) {
|
|
141
|
+
const clazz = baseType;
|
|
142
|
+
if (clazz.simpleName === 'Promise' || clazz.simpleName === 'PromiseLike') {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Check type attribution if available
|
|
149
|
+
const funcType = arrowFunc.type;
|
|
150
|
+
if (funcType && functionTypeReturnsPromise(funcType)) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Check if it's a function reference (Identifier) with type attribution
|
|
155
|
+
if (element.kind === java_1.J.Kind.Identifier) {
|
|
156
|
+
const identifier = element;
|
|
157
|
+
const funcType = identifier.type;
|
|
158
|
+
if (funcType && functionTypeReturnsPromise(funcType)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Detects async callbacks passed to synchronous array methods.
|
|
166
|
+
*
|
|
167
|
+
* This is a common bug pattern in JavaScript/TypeScript where async functions
|
|
168
|
+
* are passed to array methods like `.some()`, `.every()`, `.find()`, etc.
|
|
169
|
+
* These methods don't await the promises returned by async callbacks, leading
|
|
170
|
+
* to bugs where Promise objects are treated as truthy values.
|
|
171
|
+
*
|
|
172
|
+
* Example of buggy code:
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // BUG: .some() doesn't await, so any Promise is truthy
|
|
175
|
+
* const hasAdmin = users.some(async user => {
|
|
176
|
+
* return await checkPermission(user, 'admin');
|
|
177
|
+
* });
|
|
178
|
+
* // hasAdmin is ALWAYS true because Promise objects are truthy!
|
|
179
|
+
*
|
|
180
|
+
* // CORRECT: Use a for loop with await
|
|
181
|
+
* let hasAdmin = false;
|
|
182
|
+
* for (const user of users) {
|
|
183
|
+
* if (await checkPermission(user, 'admin')) {
|
|
184
|
+
* hasAdmin = true;
|
|
185
|
+
* break;
|
|
186
|
+
* }
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* This recipe reports occurrences but doesn't auto-fix because the correct
|
|
191
|
+
* fix depends on the context (could use for...of loop, Promise.all, etc.).
|
|
192
|
+
*/
|
|
193
|
+
class AsyncCallbackInSyncArrayMethod extends recipe_1.Recipe {
|
|
194
|
+
constructor() {
|
|
195
|
+
super(...arguments);
|
|
196
|
+
this.name = "org.openrewrite.javascript.cleanup.async-callback-in-sync-array-method";
|
|
197
|
+
this.displayName = "Detect async callbacks in synchronous array methods";
|
|
198
|
+
this.description = "Detects async callbacks passed to array methods like .some(), .every(), .filter() which don't await promises. This is a common bug where Promise objects are always truthy.";
|
|
199
|
+
this.tags = ["javascript", "typescript", "async", "bug", "cleanup"];
|
|
200
|
+
}
|
|
201
|
+
editor() {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
return new class extends visitor_1.JavaScriptVisitor {
|
|
204
|
+
visitMethodInvocation(method, ctx) {
|
|
205
|
+
const _super = Object.create(null, {
|
|
206
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
207
|
+
});
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
var _a, _b;
|
|
210
|
+
let m = yield _super.visitMethodInvocation.call(this, method, ctx);
|
|
211
|
+
const methodName = (_a = m.name) === null || _a === void 0 ? void 0 : _a.simpleName;
|
|
212
|
+
if (!methodName || !SYNC_ARRAY_METHODS.has(methodName)) {
|
|
213
|
+
return m;
|
|
214
|
+
}
|
|
215
|
+
// Check the arguments for async callbacks
|
|
216
|
+
const args = (_b = m.arguments) === null || _b === void 0 ? void 0 : _b.elements;
|
|
217
|
+
if (!args || args.length === 0) {
|
|
218
|
+
return m;
|
|
219
|
+
}
|
|
220
|
+
const firstArg = args[0];
|
|
221
|
+
if (callbackReturnsPromise(firstArg)) {
|
|
222
|
+
return (0, markers_1.markupWarn)(m, `Async callback passed to .${methodName}()`, `Array methods like .${methodName}() don't await async callbacks, so Promises are treated as truthy values. Consider using a for...of loop with await instead.`);
|
|
223
|
+
}
|
|
224
|
+
return m;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.AsyncCallbackInSyncArrayMethod = AsyncCallbackInSyncArrayMethod;
|
|
232
|
+
//# sourceMappingURL=async-callback-in-sync-array-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-callback-in-sync-array-method.js","sourceRoot":"","sources":["../../../src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AC,CAAC;wBACb,CAAC;wBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;wBACzB,IAAI,sBAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC;4BACnC,OAAO,IAAA,oBAAU,EACb,CAAC,EACD,6BAA6B,UAAU,IAAI,EAC3C,uBAAuB,UAAU,8HAA8H,CAClK,CAAC;wBACN,CAAC;wBAED,OAAO,CAAC,CAAC;oBACb,CAAC;iBAAA;aACJ,EAAE,CAAC;QACR,CAAC;KAAA;CACJ;AAnCD,wEAmCC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Recipe } from "../../recipe";
|
|
2
|
+
import { TreeVisitor } from "../../visitor";
|
|
3
|
+
import { ExecutionContext } from "../../execution";
|
|
4
|
+
/**
|
|
5
|
+
* Changes an import from one module to another, updating all type attributions.
|
|
6
|
+
*
|
|
7
|
+
* This recipe is useful for:
|
|
8
|
+
* - Library migrations (e.g., moving `act` from `react-dom/test-utils` to `react`)
|
|
9
|
+
* - Module restructuring (e.g., split packages)
|
|
10
|
+
* - Renaming exported members
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Migrate act import from react-dom/test-utils to react
|
|
14
|
+
* const recipe = new ChangeImport({
|
|
15
|
+
* oldModule: "react-dom/test-utils",
|
|
16
|
+
* oldMember: "act",
|
|
17
|
+
* newModule: "react"
|
|
18
|
+
* });
|
|
19
|
+
* // Before: import { act } from 'react-dom/test-utils';
|
|
20
|
+
* // After: import { act } from 'react';
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Change a named import to a different name
|
|
24
|
+
* const recipe = new ChangeImport({
|
|
25
|
+
* oldModule: "lodash",
|
|
26
|
+
* oldMember: "extend",
|
|
27
|
+
* newModule: "lodash",
|
|
28
|
+
* newMember: "assign"
|
|
29
|
+
* });
|
|
30
|
+
* // Before: import { extend } from 'lodash';
|
|
31
|
+
* // After: import { assign } from 'lodash';
|
|
32
|
+
*/
|
|
33
|
+
export declare class ChangeImport extends Recipe {
|
|
34
|
+
readonly name = "org.openrewrite.javascript.change-import";
|
|
35
|
+
readonly displayName = "Change import";
|
|
36
|
+
readonly description = "Changes an import from one module/member to another, updating all type attributions.";
|
|
37
|
+
oldModule: string;
|
|
38
|
+
oldMember: string;
|
|
39
|
+
newModule: string;
|
|
40
|
+
newMember?: string;
|
|
41
|
+
newAlias?: string;
|
|
42
|
+
constructor(options?: {
|
|
43
|
+
oldModule?: string;
|
|
44
|
+
oldMember?: string;
|
|
45
|
+
newModule?: string;
|
|
46
|
+
newMember?: string;
|
|
47
|
+
newAlias?: string;
|
|
48
|
+
});
|
|
49
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=change-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-import.d.ts","sourceRoot":"","sources":["../../../src/javascript/recipes/change-import.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAS,MAAM,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAMjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACpC,QAAQ,CAAC,IAAI,8CAA8C;IAC3D,QAAQ,CAAC,WAAW,mBAAmB;IACvC,QAAQ,CAAC,WAAW,0FAA0F;IAO9G,SAAS,EAAG,MAAM,CAAC;IAOnB,SAAS,EAAG,MAAM,CAAC;IAOnB,SAAS,EAAG,MAAM,CAAC;IAQnB,SAAS,CAAC,EAAE,MAAM,CAAC;IAOnB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEN,OAAO,CAAC,EAAE;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB;IAIK,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAmlB9D"}
|