@openrewrite/rewrite 8.72.2 → 8.72.4
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/execution.js +3 -16
- package/dist/execution.js.map +1 -1
- package/dist/index.js +34 -49
- package/dist/index.js.map +1 -1
- package/dist/java/markers.js +12 -29
- package/dist/java/markers.js.map +1 -1
- package/dist/java/print.js +2 -13
- package/dist/java/print.js.map +1 -1
- package/dist/java/rpc.js +1344 -1725
- package/dist/java/rpc.js.map +1 -1
- package/dist/java/type-visitor.js +143 -184
- package/dist/java/type-visitor.js.map +1 -1
- package/dist/java/visitor.js +1072 -1249
- package/dist/java/visitor.js.map +1 -1
- package/dist/javascript/add-import.js +495 -534
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/autodetect.js +116 -159
- package/dist/javascript/autodetect.js.map +1 -1
- package/dist/javascript/cleanup/add-parse-int-radix.js +41 -57
- package/dist/javascript/cleanup/add-parse-int-radix.js.map +1 -1
- package/dist/javascript/cleanup/prefer-optional-chain.js +89 -105
- package/dist/javascript/cleanup/prefer-optional-chain.js.map +1 -1
- package/dist/javascript/cleanup/use-object-property-shorthand.js +74 -95
- package/dist/javascript/cleanup/use-object-property-shorthand.js.map +1 -1
- package/dist/javascript/comparator.js +815 -1167
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/dependency-workspace.js +206 -219
- package/dist/javascript/dependency-workspace.js.map +1 -1
- package/dist/javascript/format/format.js +682 -908
- package/dist/javascript/format/format.js.map +1 -1
- package/dist/javascript/format/minimum-viable-spacing-visitor.js +152 -231
- package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
- package/dist/javascript/format/normalize-whitespace-visitor.js +12 -31
- package/dist/javascript/format/normalize-whitespace-visitor.js.map +1 -1
- package/dist/javascript/format/prettier-config-loader.js +134 -153
- package/dist/javascript/format/prettier-config-loader.js.map +1 -1
- package/dist/javascript/format/prettier-format.js +112 -129
- package/dist/javascript/format/prettier-format.js.map +1 -1
- package/dist/javascript/format/tabs-and-indents-visitor.js +112 -136
- package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
- package/dist/javascript/markers.js +59 -92
- package/dist/javascript/markers.js.map +1 -1
- package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js +39 -52
- package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js.map +1 -1
- package/dist/javascript/migrate/es6/modernize-octal-literals.js +25 -38
- package/dist/javascript/migrate/es6/modernize-octal-literals.js.map +1 -1
- package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js +66 -82
- package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js.map +1 -1
- package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js +10 -23
- package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js.map +1 -1
- package/dist/javascript/node-resolution-result.js +137 -166
- package/dist/javascript/node-resolution-result.js.map +1 -1
- package/dist/javascript/package-json-parser.js +312 -343
- package/dist/javascript/package-json-parser.js.map +1 -1
- package/dist/javascript/package-manager.js +145 -170
- package/dist/javascript/package-manager.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +94 -68
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/print.js +1572 -1835
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/project-parser.js +151 -172
- package/dist/javascript/project-parser.js.map +1 -1
- package/dist/javascript/recipes/add-dependency.js +140 -175
- package/dist/javascript/recipes/add-dependency.js.map +1 -1
- package/dist/javascript/recipes/async-callback-in-sync-array-method.js +20 -36
- package/dist/javascript/recipes/async-callback-in-sync-array-method.js.map +1 -1
- package/dist/javascript/recipes/auto-format.js +3 -14
- package/dist/javascript/recipes/auto-format.js.map +1 -1
- package/dist/javascript/recipes/change-import.js +447 -495
- package/dist/javascript/recipes/change-import.js.map +1 -1
- package/dist/javascript/recipes/order-imports.js +162 -175
- package/dist/javascript/recipes/order-imports.js.map +1 -1
- package/dist/javascript/recipes/upgrade-dependency-version.js +167 -197
- package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -1
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +166 -193
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +1 -1
- package/dist/javascript/remove-import.js +689 -724
- package/dist/javascript/remove-import.js.map +1 -1
- package/dist/javascript/rpc.js +1007 -1332
- package/dist/javascript/rpc.js.map +1 -1
- package/dist/javascript/search/find-dependency.js +84 -110
- package/dist/javascript/search/find-dependency.js.map +1 -1
- package/dist/javascript/search/uses-method.js +5 -19
- package/dist/javascript/search/uses-method.js.map +1 -1
- package/dist/javascript/search/uses-type.js +9 -20
- package/dist/javascript/search/uses-type.js.map +1 -1
- package/dist/javascript/templating/comparator.js +737 -822
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/engine.js +211 -245
- package/dist/javascript/templating/engine.js.map +1 -1
- package/dist/javascript/templating/pattern.js +169 -190
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.js +172 -210
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
- package/dist/javascript/templating/rewrite.js +75 -97
- package/dist/javascript/templating/rewrite.js.map +1 -1
- package/dist/javascript/templating/template.js +69 -82
- package/dist/javascript/templating/template.js.map +1 -1
- package/dist/javascript/tree-debug.js +109 -137
- package/dist/javascript/tree-debug.js.map +1 -1
- package/dist/javascript/visitor.js +1090 -1254
- package/dist/javascript/visitor.js.map +1 -1
- package/dist/json/print.js +72 -103
- package/dist/json/print.js.map +1 -1
- package/dist/json/rpc.js +120 -181
- package/dist/json/rpc.js.map +1 -1
- package/dist/json/visitor.js +69 -100
- package/dist/json/visitor.js.map +1 -1
- package/dist/marketplace.js +20 -33
- package/dist/marketplace.js.map +1 -1
- package/dist/parse-error.js +41 -62
- package/dist/parse-error.js.map +1 -1
- package/dist/parser.js +7 -18
- package/dist/parser.js.map +1 -1
- package/dist/path-utils.js +46 -59
- package/dist/path-utils.js.map +1 -1
- package/dist/preconditions.js +30 -47
- package/dist/preconditions.js.map +1 -1
- package/dist/print.js +6 -19
- package/dist/print.js.map +1 -1
- package/dist/recipe.js +42 -73
- package/dist/recipe.js.map +1 -1
- package/dist/rpc/index.js +74 -115
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/queue.js +71 -90
- package/dist/rpc/queue.js.map +1 -1
- package/dist/rpc/recipe.js +32 -57
- package/dist/rpc/recipe.js.map +1 -1
- package/dist/rpc/request/generate.js +4 -13
- package/dist/rpc/request/generate.js.map +1 -1
- package/dist/rpc/request/get-languages.js +2 -11
- package/dist/rpc/request/get-languages.js.map +1 -1
- package/dist/rpc/request/get-marketplace.js +9 -20
- package/dist/rpc/request/get-marketplace.js.map +1 -1
- package/dist/rpc/request/get-object.js +4 -13
- package/dist/rpc/request/get-object.js.map +1 -1
- package/dist/rpc/request/install-recipes.js +25 -36
- package/dist/rpc/request/install-recipes.js.map +1 -1
- package/dist/rpc/request/metrics.js +8 -17
- package/dist/rpc/request/metrics.js.map +1 -1
- package/dist/rpc/request/parse-project.js +36 -45
- package/dist/rpc/request/parse-project.js.map +1 -1
- package/dist/rpc/request/parse.js +5 -14
- package/dist/rpc/request/parse.js.map +1 -1
- package/dist/rpc/request/prepare-recipe.js +37 -52
- package/dist/rpc/request/prepare-recipe.js.map +1 -1
- package/dist/rpc/request/print.js +5 -14
- package/dist/rpc/request/print.js.map +1 -1
- package/dist/rpc/request/visit.js +56 -71
- package/dist/rpc/request/visit.js.map +1 -1
- package/dist/rpc/rewrite-rpc.js +70 -97
- package/dist/rpc/rewrite-rpc.js.map +1 -1
- package/dist/rpc/server.js +76 -89
- package/dist/rpc/server.js.map +1 -1
- package/dist/run.js +47 -66
- package/dist/run.js.map +1 -1
- package/dist/search/is-source-file.js +8 -19
- package/dist/search/is-source-file.js.map +1 -1
- package/dist/test/rewrite-test.js +154 -188
- package/dist/test/rewrite-test.js.map +1 -1
- package/dist/text/print.js +23 -38
- package/dist/text/print.js.map +1 -1
- package/dist/text/rpc.js +29 -44
- package/dist/text/rpc.js.map +1 -1
- package/dist/text/visitor.js +16 -33
- package/dist/text/visitor.js.map +1 -1
- package/dist/util.js +13 -24
- package/dist/util.js.map +1 -1
- package/dist/version.txt +1 -1
- package/dist/visitor.js +84 -115
- package/dist/visitor.js.map +1 -1
- package/dist/yaml/index.d.ts +2 -0
- package/dist/yaml/index.d.ts.map +1 -1
- package/dist/yaml/index.js +2 -0
- package/dist/yaml/index.js.map +1 -1
- package/dist/yaml/markers.d.ts +21 -0
- package/dist/yaml/markers.d.ts.map +1 -0
- package/dist/yaml/markers.js +37 -0
- package/dist/yaml/markers.js.map +1 -0
- package/dist/yaml/parser.d.ts.map +1 -1
- package/dist/yaml/parser.js +4 -1
- package/dist/yaml/parser.js.map +1 -1
- package/dist/yaml/print.d.ts +1 -1
- package/dist/yaml/print.d.ts.map +1 -1
- package/dist/yaml/print.js +175 -208
- package/dist/yaml/print.js.map +1 -1
- package/dist/yaml/rpc.js +154 -219
- package/dist/yaml/rpc.js.map +1 -1
- package/dist/yaml/visitor.js +78 -113
- package/dist/yaml/visitor.js.map +1 -1
- package/package.json +1 -1
- package/src/javascript/parser.ts +56 -14
- package/src/yaml/index.ts +2 -0
- package/src/yaml/markers.ts +70 -0
- package/src/yaml/parser.ts +5 -1
- package/src/yaml/print.ts +5 -2
|
@@ -20,15 +20,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
20
20
|
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;
|
|
21
21
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
22
|
};
|
|
23
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
24
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
24
|
exports.ChangeImport = void 0;
|
|
34
25
|
const recipe_1 = require("../../recipe");
|
|
@@ -72,550 +63,511 @@ class ChangeImport extends recipe_1.Recipe {
|
|
|
72
63
|
this.displayName = "Change import";
|
|
73
64
|
this.description = "Changes an import from one module/member to another, updating all type attributions.";
|
|
74
65
|
}
|
|
75
|
-
editor() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const aliasInfo = this.checkForOldImport(jsImport);
|
|
112
|
-
if (aliasInfo.found) {
|
|
113
|
-
this.hasOldImport = true;
|
|
114
|
-
this.oldAlias = aliasInfo.alias;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// Visit the compilation unit (this will transform imports via visitJsImport)
|
|
120
|
-
let result = yield _super.visitJsCompilationUnit.call(this, cu, ctx);
|
|
121
|
-
// If we transformed an import but need to add to existing import from new module,
|
|
122
|
-
// or if we only removed a member from a multi-import, use maybeAddImport
|
|
123
|
-
if (this.hasOldImport && !this.transformedImport) {
|
|
124
|
-
const aliasToUse = newAlias !== null && newAlias !== void 0 ? newAlias : this.oldAlias;
|
|
125
|
-
if (newMember === 'default') {
|
|
126
|
-
(0, add_import_1.maybeAddImport)(this, {
|
|
127
|
-
module: newModule,
|
|
128
|
-
member: 'default',
|
|
129
|
-
alias: aliasToUse,
|
|
130
|
-
onlyIfReferenced: false
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
else if (newMember === '*') {
|
|
134
|
-
(0, add_import_1.maybeAddImport)(this, {
|
|
135
|
-
module: newModule,
|
|
136
|
-
member: '*',
|
|
137
|
-
alias: aliasToUse,
|
|
138
|
-
onlyIfReferenced: false
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else if (aliasToUse && aliasToUse !== newMember) {
|
|
142
|
-
(0, add_import_1.maybeAddImport)(this, {
|
|
143
|
-
module: newModule,
|
|
144
|
-
member: newMember,
|
|
145
|
-
alias: aliasToUse,
|
|
146
|
-
onlyIfReferenced: false
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
(0, add_import_1.maybeAddImport)(this, {
|
|
151
|
-
module: newModule,
|
|
152
|
-
member: newMember,
|
|
153
|
-
onlyIfReferenced: false
|
|
154
|
-
});
|
|
155
|
-
}
|
|
66
|
+
async editor() {
|
|
67
|
+
var _a;
|
|
68
|
+
const oldModule = this.oldModule;
|
|
69
|
+
const oldMember = this.oldMember;
|
|
70
|
+
const newModule = this.newModule;
|
|
71
|
+
const newMember = (_a = this.newMember) !== null && _a !== void 0 ? _a : oldMember;
|
|
72
|
+
const newAlias = this.newAlias;
|
|
73
|
+
// Build the old and new FQNs for type attribution updates
|
|
74
|
+
const oldFqn = oldMember === 'default' || oldMember === '*'
|
|
75
|
+
? oldModule
|
|
76
|
+
: `${oldModule}.${oldMember}`;
|
|
77
|
+
const newFqn = newMember === 'default' || newMember === '*'
|
|
78
|
+
? newModule
|
|
79
|
+
: `${newModule}.${newMember}`;
|
|
80
|
+
return new class extends index_1.JavaScriptVisitor {
|
|
81
|
+
constructor() {
|
|
82
|
+
super(...arguments);
|
|
83
|
+
this.hasOldImport = false;
|
|
84
|
+
this.transformedImport = false;
|
|
85
|
+
}
|
|
86
|
+
async visitJsCompilationUnit(cu, ctx) {
|
|
87
|
+
var _a;
|
|
88
|
+
// Reset tracking for each file
|
|
89
|
+
this.hasOldImport = false;
|
|
90
|
+
this.oldAlias = undefined;
|
|
91
|
+
this.transformedImport = false;
|
|
92
|
+
// First pass: check if the old import exists and capture any alias
|
|
93
|
+
for (const statement of cu.statements) {
|
|
94
|
+
const stmt = (_a = statement.element) !== null && _a !== void 0 ? _a : statement;
|
|
95
|
+
if (stmt.kind === index_1.JS.Kind.Import) {
|
|
96
|
+
const jsImport = stmt;
|
|
97
|
+
const aliasInfo = this.checkForOldImport(jsImport);
|
|
98
|
+
if (aliasInfo.found) {
|
|
99
|
+
this.hasOldImport = true;
|
|
100
|
+
this.oldAlias = aliasInfo.alias;
|
|
101
|
+
break;
|
|
156
102
|
}
|
|
157
|
-
|
|
158
|
-
});
|
|
103
|
+
}
|
|
159
104
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
105
|
+
// Visit the compilation unit (this will transform imports via visitJsImport)
|
|
106
|
+
let result = await super.visitJsCompilationUnit(cu, ctx);
|
|
107
|
+
// If we transformed an import but need to add to existing import from new module,
|
|
108
|
+
// or if we only removed a member from a multi-import, use maybeAddImport
|
|
109
|
+
if (this.hasOldImport && !this.transformedImport) {
|
|
110
|
+
const aliasToUse = newAlias !== null && newAlias !== void 0 ? newAlias : this.oldAlias;
|
|
111
|
+
if (newMember === 'default') {
|
|
112
|
+
(0, add_import_1.maybeAddImport)(this, {
|
|
113
|
+
module: newModule,
|
|
114
|
+
member: 'default',
|
|
115
|
+
alias: aliasToUse,
|
|
116
|
+
onlyIfReferenced: false
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else if (newMember === '*') {
|
|
120
|
+
(0, add_import_1.maybeAddImport)(this, {
|
|
121
|
+
module: newModule,
|
|
122
|
+
member: '*',
|
|
123
|
+
alias: aliasToUse,
|
|
124
|
+
onlyIfReferenced: false
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else if (aliasToUse && aliasToUse !== newMember) {
|
|
128
|
+
(0, add_import_1.maybeAddImport)(this, {
|
|
129
|
+
module: newModule,
|
|
130
|
+
member: newMember,
|
|
131
|
+
alias: aliasToUse,
|
|
132
|
+
onlyIfReferenced: false
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
(0, add_import_1.maybeAddImport)(this, {
|
|
137
|
+
module: newModule,
|
|
138
|
+
member: newMember,
|
|
139
|
+
onlyIfReferenced: false
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
async visitImportDeclaration(jsImport, ctx) {
|
|
146
|
+
var _a;
|
|
147
|
+
let imp = await super.visitImportDeclaration(jsImport, ctx);
|
|
148
|
+
if (!this.hasOldImport) {
|
|
149
|
+
return imp;
|
|
150
|
+
}
|
|
151
|
+
const aliasInfo = this.checkForOldImport(imp);
|
|
152
|
+
if (!aliasInfo.found) {
|
|
153
|
+
return imp;
|
|
154
|
+
}
|
|
155
|
+
// Check if this is the only import from the old module
|
|
156
|
+
const namedImports = this.getNamedImports(imp);
|
|
157
|
+
const isOnlyImport = namedImports.length === 1 ||
|
|
158
|
+
(oldMember === 'default' && !((_a = imp.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings)) ||
|
|
159
|
+
(oldMember === '*');
|
|
160
|
+
if (isOnlyImport) {
|
|
161
|
+
// Transform the module specifier in place
|
|
162
|
+
this.transformedImport = true;
|
|
163
|
+
return (0, mutative_1.create)(imp, draft => {
|
|
165
164
|
var _a;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
if (draft.moduleSpecifier) {
|
|
166
|
+
const literal = draft.moduleSpecifier.element;
|
|
167
|
+
literal.value = newModule;
|
|
168
|
+
// Update valueSource to preserve quote style
|
|
169
|
+
const originalSource = literal.valueSource || `"${oldModule}"`;
|
|
170
|
+
const quoteChar = originalSource.startsWith("'") ? "'" : '"';
|
|
171
|
+
literal.valueSource = `${quoteChar}${newModule}${quoteChar}`;
|
|
173
172
|
}
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (draft.moduleSpecifier) {
|
|
185
|
-
const literal = draft.moduleSpecifier.element;
|
|
186
|
-
literal.value = newModule;
|
|
187
|
-
// Update valueSource to preserve quote style
|
|
188
|
-
const originalSource = literal.valueSource || `"${oldModule}"`;
|
|
189
|
-
const quoteChar = originalSource.startsWith("'") ? "'" : '"';
|
|
190
|
-
literal.valueSource = `${quoteChar}${newModule}${quoteChar}`;
|
|
191
|
-
}
|
|
192
|
-
// If we're also renaming the member, update the import specifier
|
|
193
|
-
if (newMember !== oldMember && oldMember !== 'default' && oldMember !== '*') {
|
|
194
|
-
const importClause = draft.importClause;
|
|
195
|
-
if (((_a = importClause === null || importClause === void 0 ? void 0 : importClause.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === index_1.JS.Kind.NamedImports) {
|
|
196
|
-
const namedImports = importClause.namedBindings;
|
|
197
|
-
for (const elem of namedImports.elements.elements) {
|
|
198
|
-
const specifier = elem.element;
|
|
199
|
-
if (specifier.specifier.kind === java_1.J.Kind.Identifier &&
|
|
200
|
-
specifier.specifier.simpleName === oldMember) {
|
|
201
|
-
specifier.specifier.simpleName = newMember;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
173
|
+
// If we're also renaming the member, update the import specifier
|
|
174
|
+
if (newMember !== oldMember && oldMember !== 'default' && oldMember !== '*') {
|
|
175
|
+
const importClause = draft.importClause;
|
|
176
|
+
if (((_a = importClause === null || importClause === void 0 ? void 0 : importClause.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === index_1.JS.Kind.NamedImports) {
|
|
177
|
+
const namedImports = importClause.namedBindings;
|
|
178
|
+
for (const elem of namedImports.elements.elements) {
|
|
179
|
+
const specifier = elem.element;
|
|
180
|
+
if (specifier.specifier.kind === java_1.J.Kind.Identifier &&
|
|
181
|
+
specifier.specifier.simpleName === oldMember) {
|
|
182
|
+
specifier.specifier.simpleName = newMember;
|
|
204
183
|
}
|
|
205
184
|
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
// Remove just the specific member from the import
|
|
210
|
-
// maybeAddImport will add the new import
|
|
211
|
-
return this.removeNamedImportMember(imp, oldMember, ctx);
|
|
185
|
+
}
|
|
212
186
|
}
|
|
213
187
|
});
|
|
214
188
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (!(importClause === null || importClause === void 0 ? void 0 : importClause.namedBindings))
|
|
220
|
-
return;
|
|
221
|
-
if (importClause.namedBindings.kind !== index_1.JS.Kind.NamedImports)
|
|
222
|
-
return;
|
|
223
|
-
const namedImports = importClause.namedBindings;
|
|
224
|
-
const elements = namedImports.elements.elements;
|
|
225
|
-
const filteredElements = elements.filter(elem => {
|
|
226
|
-
const specifier = elem.element;
|
|
227
|
-
const specifierNode = specifier.specifier;
|
|
228
|
-
if (specifierNode.kind === java_1.J.Kind.Identifier) {
|
|
229
|
-
return specifierNode.simpleName !== memberToRemove;
|
|
230
|
-
}
|
|
231
|
-
if (specifierNode.kind === index_1.JS.Kind.Alias) {
|
|
232
|
-
const alias = specifierNode;
|
|
233
|
-
const propertyName = alias.propertyName.element;
|
|
234
|
-
if (propertyName.kind === java_1.J.Kind.Identifier) {
|
|
235
|
-
return propertyName.simpleName !== memberToRemove;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
});
|
|
240
|
-
namedImports.elements.elements = filteredElements;
|
|
241
|
-
});
|
|
242
|
-
});
|
|
189
|
+
else {
|
|
190
|
+
// Remove just the specific member from the import
|
|
191
|
+
// maybeAddImport will add the new import
|
|
192
|
+
return this.removeNamedImportMember(imp, oldMember, ctx);
|
|
243
193
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
return
|
|
252
|
-
const namedImports = namedBindings;
|
|
253
|
-
|
|
194
|
+
}
|
|
195
|
+
async removeNamedImportMember(imp, memberToRemove, _ctx) {
|
|
196
|
+
return (0, mutative_1.create)(imp, draft => {
|
|
197
|
+
const importClause = draft.importClause;
|
|
198
|
+
if (!(importClause === null || importClause === void 0 ? void 0 : importClause.namedBindings))
|
|
199
|
+
return;
|
|
200
|
+
if (importClause.namedBindings.kind !== index_1.JS.Kind.NamedImports)
|
|
201
|
+
return;
|
|
202
|
+
const namedImports = importClause.namedBindings;
|
|
203
|
+
const elements = namedImports.elements.elements;
|
|
204
|
+
const filteredElements = elements.filter(elem => {
|
|
254
205
|
const specifier = elem.element;
|
|
255
206
|
const specifierNode = specifier.specifier;
|
|
256
|
-
if (
|
|
257
|
-
|
|
207
|
+
if (specifierNode.kind === java_1.J.Kind.Identifier) {
|
|
208
|
+
return specifierNode.simpleName !== memberToRemove;
|
|
258
209
|
}
|
|
259
|
-
|
|
210
|
+
if (specifierNode.kind === index_1.JS.Kind.Alias) {
|
|
260
211
|
const alias = specifierNode;
|
|
261
212
|
const propertyName = alias.propertyName.element;
|
|
262
|
-
if (
|
|
263
|
-
|
|
213
|
+
if (propertyName.kind === java_1.J.Kind.Identifier) {
|
|
214
|
+
return propertyName.simpleName !== memberToRemove;
|
|
264
215
|
}
|
|
265
216
|
}
|
|
266
|
-
|
|
267
|
-
return imports;
|
|
268
|
-
}
|
|
269
|
-
visitIdentifier(identifier, ctx) {
|
|
270
|
-
const _super = Object.create(null, {
|
|
271
|
-
visitIdentifier: { get: () => super.visitIdentifier }
|
|
217
|
+
return true;
|
|
272
218
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
219
|
+
namedImports.elements.elements = filteredElements;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
getNamedImports(imp) {
|
|
223
|
+
const imports = [];
|
|
224
|
+
const importClause = imp.importClause;
|
|
225
|
+
if (!importClause)
|
|
226
|
+
return imports;
|
|
227
|
+
const namedBindings = importClause.namedBindings;
|
|
228
|
+
if (!namedBindings || namedBindings.kind !== index_1.JS.Kind.NamedImports)
|
|
229
|
+
return imports;
|
|
230
|
+
const namedImports = namedBindings;
|
|
231
|
+
for (const elem of namedImports.elements.elements) {
|
|
232
|
+
const specifier = elem.element;
|
|
233
|
+
const specifierNode = specifier.specifier;
|
|
234
|
+
if ((0, java_1.isIdentifier)(specifierNode)) {
|
|
235
|
+
imports.push(specifierNode.simpleName);
|
|
236
|
+
}
|
|
237
|
+
else if (specifierNode.kind === index_1.JS.Kind.Alias) {
|
|
238
|
+
const alias = specifierNode;
|
|
239
|
+
const propertyName = alias.propertyName.element;
|
|
240
|
+
if ((0, java_1.isIdentifier)(propertyName)) {
|
|
241
|
+
imports.push(propertyName.simpleName);
|
|
277
242
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return imports;
|
|
246
|
+
}
|
|
247
|
+
async visitIdentifier(identifier, ctx) {
|
|
248
|
+
let ident = await super.visitIdentifier(identifier, ctx);
|
|
249
|
+
if (!this.hasOldImport) {
|
|
250
|
+
return ident;
|
|
251
|
+
}
|
|
252
|
+
// Check and update type attribution
|
|
253
|
+
let changed = false;
|
|
254
|
+
// Update type if it references the old module
|
|
255
|
+
const updatedType = this.updateType(ident.type);
|
|
256
|
+
if (updatedType !== ident.type) {
|
|
257
|
+
changed = true;
|
|
258
|
+
}
|
|
259
|
+
// Update fieldType if it references the old module
|
|
260
|
+
// fieldType is specifically Type.Variable, so we need to handle it specially
|
|
261
|
+
let updatedFieldType = ident.fieldType;
|
|
262
|
+
if (ident.fieldType) {
|
|
263
|
+
const updated = this.updateVariableType(ident.fieldType);
|
|
264
|
+
if (updated !== ident.fieldType) {
|
|
265
|
+
updatedFieldType = updated;
|
|
266
|
+
changed = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (changed) {
|
|
270
|
+
return (0, mutative_1.create)(ident, draft => {
|
|
282
271
|
if (updatedType !== ident.type) {
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
// Update fieldType if it references the old module
|
|
286
|
-
// fieldType is specifically Type.Variable, so we need to handle it specially
|
|
287
|
-
let updatedFieldType = ident.fieldType;
|
|
288
|
-
if (ident.fieldType) {
|
|
289
|
-
const updated = this.updateVariableType(ident.fieldType);
|
|
290
|
-
if (updated !== ident.fieldType) {
|
|
291
|
-
updatedFieldType = updated;
|
|
292
|
-
changed = true;
|
|
293
|
-
}
|
|
272
|
+
draft.type = updatedType;
|
|
294
273
|
}
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
if (updatedType !== ident.type) {
|
|
298
|
-
draft.type = updatedType;
|
|
299
|
-
}
|
|
300
|
-
if (updatedFieldType !== ident.fieldType) {
|
|
301
|
-
draft.fieldType = updatedFieldType;
|
|
302
|
-
}
|
|
303
|
-
});
|
|
274
|
+
if (updatedFieldType !== ident.fieldType) {
|
|
275
|
+
draft.fieldType = updatedFieldType;
|
|
304
276
|
}
|
|
305
|
-
return ident;
|
|
306
277
|
});
|
|
307
278
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (!this.hasOldImport) {
|
|
315
|
-
return m;
|
|
316
|
-
}
|
|
317
|
-
// Update methodType if it references the old module
|
|
318
|
-
const updatedMethodType = this.updateMethodType(m.methodType);
|
|
319
|
-
if (updatedMethodType !== m.methodType) {
|
|
320
|
-
return (0, mutative_1.create)(m, draft => {
|
|
321
|
-
draft.methodType = updatedMethodType;
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
return m;
|
|
325
|
-
});
|
|
279
|
+
return ident;
|
|
280
|
+
}
|
|
281
|
+
async visitMethodInvocation(method, ctx) {
|
|
282
|
+
let m = await super.visitMethodInvocation(method, ctx);
|
|
283
|
+
if (!this.hasOldImport) {
|
|
284
|
+
return m;
|
|
326
285
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
let fa = yield _super.visitFieldAccess.call(this, fieldAccess, ctx);
|
|
333
|
-
if (!this.hasOldImport) {
|
|
334
|
-
return fa;
|
|
335
|
-
}
|
|
336
|
-
// Update type if it references the old module
|
|
337
|
-
const updatedType = this.updateType(fa.type);
|
|
338
|
-
if (updatedType !== fa.type) {
|
|
339
|
-
return (0, mutative_1.create)(fa, draft => {
|
|
340
|
-
draft.type = updatedType;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
return fa;
|
|
286
|
+
// Update methodType if it references the old module
|
|
287
|
+
const updatedMethodType = this.updateMethodType(m.methodType);
|
|
288
|
+
if (updatedMethodType !== m.methodType) {
|
|
289
|
+
return (0, mutative_1.create)(m, draft => {
|
|
290
|
+
draft.methodType = updatedMethodType;
|
|
344
291
|
});
|
|
345
292
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return (0, mutative_1.create)(fc, draft => {
|
|
359
|
-
draft.methodType = updatedMethodType;
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
return fc;
|
|
293
|
+
return m;
|
|
294
|
+
}
|
|
295
|
+
async visitFieldAccess(fieldAccess, ctx) {
|
|
296
|
+
let fa = await super.visitFieldAccess(fieldAccess, ctx);
|
|
297
|
+
if (!this.hasOldImport) {
|
|
298
|
+
return fa;
|
|
299
|
+
}
|
|
300
|
+
// Update type if it references the old module
|
|
301
|
+
const updatedType = this.updateType(fa.type);
|
|
302
|
+
if (updatedType !== fa.type) {
|
|
303
|
+
return (0, mutative_1.create)(fa, draft => {
|
|
304
|
+
draft.type = updatedType;
|
|
363
305
|
});
|
|
364
306
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
307
|
+
return fa;
|
|
308
|
+
}
|
|
309
|
+
async visitFunctionCall(functionCall, ctx) {
|
|
310
|
+
let fc = await super.visitFunctionCall(functionCall, ctx);
|
|
311
|
+
if (!this.hasOldImport) {
|
|
312
|
+
return fc;
|
|
313
|
+
}
|
|
314
|
+
// Update methodType if it references the old module
|
|
315
|
+
const updatedMethodType = this.updateMethodType(fc.methodType);
|
|
316
|
+
if (updatedMethodType !== fc.methodType) {
|
|
317
|
+
return (0, mutative_1.create)(fc, draft => {
|
|
318
|
+
draft.methodType = updatedMethodType;
|
|
368
319
|
});
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
320
|
+
}
|
|
321
|
+
return fc;
|
|
322
|
+
}
|
|
323
|
+
async visitNewClass(newClass, ctx) {
|
|
324
|
+
let nc = await super.visitNewClass(newClass, ctx);
|
|
325
|
+
if (!this.hasOldImport) {
|
|
326
|
+
return nc;
|
|
327
|
+
}
|
|
328
|
+
let changed = false;
|
|
329
|
+
// Update methodType if it references the old module
|
|
330
|
+
const updatedMethodType = this.updateMethodType(nc.methodType);
|
|
331
|
+
if (updatedMethodType !== nc.methodType) {
|
|
332
|
+
changed = true;
|
|
333
|
+
}
|
|
334
|
+
// Update constructorType if it references the old module
|
|
335
|
+
const updatedConstructorType = this.updateMethodType(nc.constructorType);
|
|
336
|
+
if (updatedConstructorType !== nc.constructorType) {
|
|
337
|
+
changed = true;
|
|
338
|
+
}
|
|
339
|
+
// Update type if it references the old module
|
|
340
|
+
const updatedType = this.updateType(nc.type);
|
|
341
|
+
if (updatedType !== nc.type) {
|
|
342
|
+
changed = true;
|
|
343
|
+
}
|
|
344
|
+
if (changed) {
|
|
345
|
+
return (0, mutative_1.create)(nc, draft => {
|
|
377
346
|
if (updatedMethodType !== nc.methodType) {
|
|
378
|
-
|
|
347
|
+
draft.methodType = updatedMethodType;
|
|
379
348
|
}
|
|
380
|
-
// Update constructorType if it references the old module
|
|
381
|
-
const updatedConstructorType = this.updateMethodType(nc.constructorType);
|
|
382
349
|
if (updatedConstructorType !== nc.constructorType) {
|
|
383
|
-
|
|
350
|
+
draft.constructorType = updatedConstructorType;
|
|
384
351
|
}
|
|
385
|
-
// Update type if it references the old module
|
|
386
|
-
const updatedType = this.updateType(nc.type);
|
|
387
352
|
if (updatedType !== nc.type) {
|
|
388
|
-
|
|
353
|
+
draft.type = updatedType;
|
|
389
354
|
}
|
|
390
|
-
if (changed) {
|
|
391
|
-
return (0, mutative_1.create)(nc, draft => {
|
|
392
|
-
if (updatedMethodType !== nc.methodType) {
|
|
393
|
-
draft.methodType = updatedMethodType;
|
|
394
|
-
}
|
|
395
|
-
if (updatedConstructorType !== nc.constructorType) {
|
|
396
|
-
draft.constructorType = updatedConstructorType;
|
|
397
|
-
}
|
|
398
|
-
if (updatedType !== nc.type) {
|
|
399
|
-
draft.type = updatedType;
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
return nc;
|
|
404
355
|
});
|
|
405
356
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
357
|
+
return nc;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Update a type if it references the old module
|
|
361
|
+
*/
|
|
362
|
+
updateType(type) {
|
|
363
|
+
if (!type)
|
|
364
|
+
return type;
|
|
365
|
+
switch (type.kind) {
|
|
366
|
+
case java_1.Type.Kind.Class:
|
|
367
|
+
case java_1.Type.Kind.ShallowClass:
|
|
368
|
+
return this.updateClassType(type);
|
|
369
|
+
case java_1.Type.Kind.Method:
|
|
370
|
+
return this.updateMethodType(type);
|
|
371
|
+
case java_1.Type.Kind.Variable:
|
|
372
|
+
return this.updateVariableType(type);
|
|
373
|
+
case java_1.Type.Kind.Parameterized:
|
|
374
|
+
return this.updateParameterizedType(type);
|
|
375
|
+
case java_1.Type.Kind.Array:
|
|
376
|
+
return this.updateArrayType(type);
|
|
377
|
+
default:
|
|
411
378
|
return type;
|
|
412
|
-
switch (type.kind) {
|
|
413
|
-
case java_1.Type.Kind.Class:
|
|
414
|
-
case java_1.Type.Kind.ShallowClass:
|
|
415
|
-
return this.updateClassType(type);
|
|
416
|
-
case java_1.Type.Kind.Method:
|
|
417
|
-
return this.updateMethodType(type);
|
|
418
|
-
case java_1.Type.Kind.Variable:
|
|
419
|
-
return this.updateVariableType(type);
|
|
420
|
-
case java_1.Type.Kind.Parameterized:
|
|
421
|
-
return this.updateParameterizedType(type);
|
|
422
|
-
case java_1.Type.Kind.Array:
|
|
423
|
-
return this.updateArrayType(type);
|
|
424
|
-
default:
|
|
425
|
-
return type;
|
|
426
|
-
}
|
|
427
379
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Update a Class type if its FQN references the old module
|
|
383
|
+
*/
|
|
384
|
+
updateClassType(classType) {
|
|
385
|
+
let changed = false;
|
|
386
|
+
let newFullyQualifiedName = classType.fullyQualifiedName;
|
|
387
|
+
let newOwningClass = classType.owningClass;
|
|
388
|
+
// Check if the FQN matches or starts with the old module
|
|
389
|
+
if (classType.fullyQualifiedName === oldFqn) {
|
|
390
|
+
newFullyQualifiedName = newFqn;
|
|
391
|
+
changed = true;
|
|
392
|
+
}
|
|
393
|
+
else if (classType.fullyQualifiedName === oldModule) {
|
|
394
|
+
newFullyQualifiedName = newModule;
|
|
395
|
+
changed = true;
|
|
396
|
+
}
|
|
397
|
+
else if (classType.fullyQualifiedName.startsWith(oldModule + '.')) {
|
|
398
|
+
newFullyQualifiedName = newModule + classType.fullyQualifiedName.substring(oldModule.length);
|
|
399
|
+
changed = true;
|
|
400
|
+
}
|
|
401
|
+
// Recursively update owningClass
|
|
402
|
+
if (classType.owningClass) {
|
|
403
|
+
const updatedOwningClass = this.updateClassType(classType.owningClass);
|
|
404
|
+
if (updatedOwningClass !== classType.owningClass) {
|
|
405
|
+
newOwningClass = updatedOwningClass;
|
|
446
406
|
changed = true;
|
|
447
407
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
408
|
+
}
|
|
409
|
+
if (changed) {
|
|
410
|
+
// Type objects are marked as non-draftable, so we manually create new objects
|
|
411
|
+
return Object.assign(Object.assign({}, classType), { fullyQualifiedName: newFullyQualifiedName, owningClass: newOwningClass });
|
|
412
|
+
}
|
|
413
|
+
return classType;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Update a Method type if its declaringType references the old module
|
|
417
|
+
*/
|
|
418
|
+
updateMethodType(methodType) {
|
|
419
|
+
if (!methodType)
|
|
420
|
+
return methodType;
|
|
421
|
+
// Update the declaring type
|
|
422
|
+
if (java_1.Type.isFullyQualified(methodType.declaringType)) {
|
|
423
|
+
const declaringTypeFqn = java_1.Type.FullyQualified.getFullyQualifiedName(methodType.declaringType);
|
|
424
|
+
if (declaringTypeFqn === oldModule ||
|
|
425
|
+
declaringTypeFqn === oldFqn ||
|
|
426
|
+
declaringTypeFqn.startsWith(oldModule + '.')) {
|
|
427
|
+
// Need to update the declaring type
|
|
428
|
+
const updatedDeclaringType = this.updateType(methodType.declaringType);
|
|
429
|
+
// Also update the method name if we're renaming the member
|
|
430
|
+
const updatedName = (oldMember !== 'default' && oldMember !== '*' &&
|
|
431
|
+
methodType.name === oldMember && newMember !== oldMember)
|
|
432
|
+
? newMember
|
|
433
|
+
: methodType.name;
|
|
457
434
|
// Type objects are marked as non-draftable, so we manually create new objects
|
|
458
|
-
return Object.assign(Object.assign({},
|
|
459
|
-
}
|
|
460
|
-
return classType;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Update a Method type if its declaringType references the old module
|
|
464
|
-
*/
|
|
465
|
-
updateMethodType(methodType) {
|
|
466
|
-
if (!methodType)
|
|
467
|
-
return methodType;
|
|
468
|
-
// Update the declaring type
|
|
469
|
-
if (java_1.Type.isFullyQualified(methodType.declaringType)) {
|
|
470
|
-
const declaringTypeFqn = java_1.Type.FullyQualified.getFullyQualifiedName(methodType.declaringType);
|
|
471
|
-
if (declaringTypeFqn === oldModule ||
|
|
472
|
-
declaringTypeFqn === oldFqn ||
|
|
473
|
-
declaringTypeFqn.startsWith(oldModule + '.')) {
|
|
474
|
-
// Need to update the declaring type
|
|
475
|
-
const updatedDeclaringType = this.updateType(methodType.declaringType);
|
|
476
|
-
// Also update the method name if we're renaming the member
|
|
477
|
-
const updatedName = (oldMember !== 'default' && oldMember !== '*' &&
|
|
478
|
-
methodType.name === oldMember && newMember !== oldMember)
|
|
479
|
-
? newMember
|
|
480
|
-
: methodType.name;
|
|
481
|
-
// Type objects are marked as non-draftable, so we manually create new objects
|
|
482
|
-
return Object.assign(Object.assign({}, methodType), { declaringType: updatedDeclaringType, name: updatedName });
|
|
483
|
-
}
|
|
435
|
+
return Object.assign(Object.assign({}, methodType), { declaringType: updatedDeclaringType, name: updatedName });
|
|
484
436
|
}
|
|
485
|
-
return methodType;
|
|
486
437
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
// Update inner type if it references the old module
|
|
503
|
-
const updatedInnerType = this.updateType(variableType.type);
|
|
504
|
-
if (updatedInnerType !== variableType.type) {
|
|
505
|
-
newInnerType = updatedInnerType;
|
|
438
|
+
return methodType;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Update a Variable type if its owner references the old module
|
|
442
|
+
*/
|
|
443
|
+
updateVariableType(variableType) {
|
|
444
|
+
let changed = false;
|
|
445
|
+
let newOwner = variableType.owner;
|
|
446
|
+
let newInnerType = variableType.type;
|
|
447
|
+
// Update owner if it references the old module
|
|
448
|
+
if (variableType.owner) {
|
|
449
|
+
const updatedOwner = this.updateType(variableType.owner);
|
|
450
|
+
if (updatedOwner !== variableType.owner) {
|
|
451
|
+
newOwner = updatedOwner;
|
|
506
452
|
changed = true;
|
|
507
453
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
const
|
|
531
|
-
if (
|
|
532
|
-
|
|
454
|
+
}
|
|
455
|
+
// Update inner type if it references the old module
|
|
456
|
+
const updatedInnerType = this.updateType(variableType.type);
|
|
457
|
+
if (updatedInnerType !== variableType.type) {
|
|
458
|
+
newInnerType = updatedInnerType;
|
|
459
|
+
changed = true;
|
|
460
|
+
}
|
|
461
|
+
if (changed) {
|
|
462
|
+
// Type objects are marked as non-draftable, so we manually create new objects
|
|
463
|
+
return Object.assign(Object.assign({}, variableType), { owner: newOwner, type: newInnerType });
|
|
464
|
+
}
|
|
465
|
+
return variableType;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Update a Parameterized type if its base type references the old module
|
|
469
|
+
*/
|
|
470
|
+
updateParameterizedType(paramType) {
|
|
471
|
+
let changed = false;
|
|
472
|
+
let newBaseType = paramType.type;
|
|
473
|
+
let newTypeParams = paramType.typeParameters;
|
|
474
|
+
// Update base type
|
|
475
|
+
if (java_1.Type.isFullyQualified(paramType.type)) {
|
|
476
|
+
const updatedType = this.updateType(paramType.type);
|
|
477
|
+
if (updatedType !== paramType.type) {
|
|
478
|
+
newBaseType = updatedType;
|
|
533
479
|
changed = true;
|
|
534
480
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
481
|
+
}
|
|
482
|
+
// Update type parameters
|
|
483
|
+
const updatedParams = paramType.typeParameters.map(tp => this.updateType(tp));
|
|
484
|
+
if (updatedParams.some((p, i) => p !== paramType.typeParameters[i])) {
|
|
485
|
+
newTypeParams = updatedParams;
|
|
486
|
+
changed = true;
|
|
487
|
+
}
|
|
488
|
+
if (changed) {
|
|
489
|
+
// Type objects are marked as non-draftable, so we manually create new objects
|
|
490
|
+
return Object.assign(Object.assign({}, paramType), { type: newBaseType, typeParameters: newTypeParams });
|
|
491
|
+
}
|
|
492
|
+
return paramType;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Update an Array type if its element type references the old module
|
|
496
|
+
*/
|
|
497
|
+
updateArrayType(arrayType) {
|
|
498
|
+
const updatedElemType = this.updateType(arrayType.elemType);
|
|
499
|
+
if (updatedElemType !== arrayType.elemType) {
|
|
500
|
+
// Type objects are marked as non-draftable, so we manually create new objects
|
|
501
|
+
return Object.assign(Object.assign({}, arrayType), { elemType: updatedElemType });
|
|
502
|
+
}
|
|
503
|
+
return arrayType;
|
|
504
|
+
}
|
|
505
|
+
checkForOldImport(jsImport) {
|
|
506
|
+
// Check if this import is from the old module
|
|
507
|
+
const moduleSpecifier = jsImport.moduleSpecifier;
|
|
508
|
+
if (!moduleSpecifier)
|
|
509
|
+
return { found: false };
|
|
510
|
+
const literal = moduleSpecifier.element;
|
|
511
|
+
if (literal.kind !== java_1.J.Kind.Literal)
|
|
512
|
+
return { found: false };
|
|
513
|
+
const value = literal.value;
|
|
514
|
+
if (value !== oldModule)
|
|
515
|
+
return { found: false };
|
|
516
|
+
const importClause = jsImport.importClause;
|
|
517
|
+
if (!importClause) {
|
|
518
|
+
// Side-effect import - not what we're looking for
|
|
519
|
+
return { found: false };
|
|
520
|
+
}
|
|
521
|
+
// Check for default import
|
|
522
|
+
if (oldMember === 'default') {
|
|
523
|
+
if (importClause.name) {
|
|
524
|
+
const nameElem = importClause.name.element;
|
|
525
|
+
if ((0, java_1.isIdentifier)(nameElem)) {
|
|
526
|
+
return { found: true, alias: nameElem.simpleName };
|
|
527
|
+
}
|
|
567
528
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
529
|
+
return { found: false };
|
|
530
|
+
}
|
|
531
|
+
// Check for namespace import
|
|
532
|
+
if (oldMember === '*') {
|
|
533
|
+
const namedBindings = importClause.namedBindings;
|
|
534
|
+
if ((namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === index_1.JS.Kind.Alias) {
|
|
535
|
+
const alias = namedBindings;
|
|
536
|
+
if ((0, java_1.isIdentifier)(alias.alias)) {
|
|
537
|
+
return { found: true, alias: alias.alias.simpleName };
|
|
575
538
|
}
|
|
576
|
-
return { found: false };
|
|
577
539
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
540
|
+
return { found: false };
|
|
541
|
+
}
|
|
542
|
+
// Check for named imports
|
|
543
|
+
const namedBindings = importClause.namedBindings;
|
|
544
|
+
if (!namedBindings)
|
|
545
|
+
return { found: false };
|
|
546
|
+
if (namedBindings.kind !== index_1.JS.Kind.NamedImports)
|
|
547
|
+
return { found: false };
|
|
548
|
+
const namedImports = namedBindings;
|
|
549
|
+
const elements = namedImports.elements.elements;
|
|
550
|
+
for (const elem of elements) {
|
|
551
|
+
const specifier = elem.element;
|
|
552
|
+
const specifierNode = specifier.specifier;
|
|
553
|
+
// Handle direct import: import { act }
|
|
554
|
+
if ((0, java_1.isIdentifier)(specifierNode) && specifierNode.simpleName === oldMember) {
|
|
555
|
+
return { found: true };
|
|
556
|
+
}
|
|
557
|
+
// Handle aliased import: import { act as something }
|
|
558
|
+
if (specifierNode.kind === index_1.JS.Kind.Alias) {
|
|
559
|
+
const alias = specifierNode;
|
|
560
|
+
const propertyName = alias.propertyName.element;
|
|
561
|
+
if ((0, java_1.isIdentifier)(propertyName) && propertyName.simpleName === oldMember) {
|
|
583
562
|
if ((0, java_1.isIdentifier)(alias.alias)) {
|
|
584
563
|
return { found: true, alias: alias.alias.simpleName };
|
|
585
564
|
}
|
|
586
565
|
}
|
|
587
|
-
return { found: false };
|
|
588
566
|
}
|
|
589
|
-
// Check for named imports
|
|
590
|
-
const namedBindings = importClause.namedBindings;
|
|
591
|
-
if (!namedBindings)
|
|
592
|
-
return { found: false };
|
|
593
|
-
if (namedBindings.kind !== index_1.JS.Kind.NamedImports)
|
|
594
|
-
return { found: false };
|
|
595
|
-
const namedImports = namedBindings;
|
|
596
|
-
const elements = namedImports.elements.elements;
|
|
597
|
-
for (const elem of elements) {
|
|
598
|
-
const specifier = elem.element;
|
|
599
|
-
const specifierNode = specifier.specifier;
|
|
600
|
-
// Handle direct import: import { act }
|
|
601
|
-
if ((0, java_1.isIdentifier)(specifierNode) && specifierNode.simpleName === oldMember) {
|
|
602
|
-
return { found: true };
|
|
603
|
-
}
|
|
604
|
-
// Handle aliased import: import { act as something }
|
|
605
|
-
if (specifierNode.kind === index_1.JS.Kind.Alias) {
|
|
606
|
-
const alias = specifierNode;
|
|
607
|
-
const propertyName = alias.propertyName.element;
|
|
608
|
-
if ((0, java_1.isIdentifier)(propertyName) && propertyName.simpleName === oldMember) {
|
|
609
|
-
if ((0, java_1.isIdentifier)(alias.alias)) {
|
|
610
|
-
return { found: true, alias: alias.alias.simpleName };
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return { found: false };
|
|
616
567
|
}
|
|
617
|
-
|
|
618
|
-
|
|
568
|
+
return { found: false };
|
|
569
|
+
}
|
|
570
|
+
}();
|
|
619
571
|
}
|
|
620
572
|
}
|
|
621
573
|
exports.ChangeImport = ChangeImport;
|