@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.
Files changed (197) hide show
  1. package/dist/execution.js +3 -16
  2. package/dist/execution.js.map +1 -1
  3. package/dist/index.js +34 -49
  4. package/dist/index.js.map +1 -1
  5. package/dist/java/markers.js +12 -29
  6. package/dist/java/markers.js.map +1 -1
  7. package/dist/java/print.js +2 -13
  8. package/dist/java/print.js.map +1 -1
  9. package/dist/java/rpc.js +1344 -1725
  10. package/dist/java/rpc.js.map +1 -1
  11. package/dist/java/type-visitor.js +143 -184
  12. package/dist/java/type-visitor.js.map +1 -1
  13. package/dist/java/visitor.js +1072 -1249
  14. package/dist/java/visitor.js.map +1 -1
  15. package/dist/javascript/add-import.js +495 -534
  16. package/dist/javascript/add-import.js.map +1 -1
  17. package/dist/javascript/autodetect.js +116 -159
  18. package/dist/javascript/autodetect.js.map +1 -1
  19. package/dist/javascript/cleanup/add-parse-int-radix.js +41 -57
  20. package/dist/javascript/cleanup/add-parse-int-radix.js.map +1 -1
  21. package/dist/javascript/cleanup/prefer-optional-chain.js +89 -105
  22. package/dist/javascript/cleanup/prefer-optional-chain.js.map +1 -1
  23. package/dist/javascript/cleanup/use-object-property-shorthand.js +74 -95
  24. package/dist/javascript/cleanup/use-object-property-shorthand.js.map +1 -1
  25. package/dist/javascript/comparator.js +815 -1167
  26. package/dist/javascript/comparator.js.map +1 -1
  27. package/dist/javascript/dependency-workspace.js +206 -219
  28. package/dist/javascript/dependency-workspace.js.map +1 -1
  29. package/dist/javascript/format/format.js +682 -908
  30. package/dist/javascript/format/format.js.map +1 -1
  31. package/dist/javascript/format/minimum-viable-spacing-visitor.js +152 -231
  32. package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
  33. package/dist/javascript/format/normalize-whitespace-visitor.js +12 -31
  34. package/dist/javascript/format/normalize-whitespace-visitor.js.map +1 -1
  35. package/dist/javascript/format/prettier-config-loader.js +134 -153
  36. package/dist/javascript/format/prettier-config-loader.js.map +1 -1
  37. package/dist/javascript/format/prettier-format.js +112 -129
  38. package/dist/javascript/format/prettier-format.js.map +1 -1
  39. package/dist/javascript/format/tabs-and-indents-visitor.js +112 -136
  40. package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
  41. package/dist/javascript/markers.js +59 -92
  42. package/dist/javascript/markers.js.map +1 -1
  43. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js +39 -52
  44. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js.map +1 -1
  45. package/dist/javascript/migrate/es6/modernize-octal-literals.js +25 -38
  46. package/dist/javascript/migrate/es6/modernize-octal-literals.js.map +1 -1
  47. package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js +66 -82
  48. package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js.map +1 -1
  49. package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js +10 -23
  50. package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js.map +1 -1
  51. package/dist/javascript/node-resolution-result.js +137 -166
  52. package/dist/javascript/node-resolution-result.js.map +1 -1
  53. package/dist/javascript/package-json-parser.js +312 -343
  54. package/dist/javascript/package-json-parser.js.map +1 -1
  55. package/dist/javascript/package-manager.js +145 -170
  56. package/dist/javascript/package-manager.js.map +1 -1
  57. package/dist/javascript/parser.d.ts.map +1 -1
  58. package/dist/javascript/parser.js +94 -68
  59. package/dist/javascript/parser.js.map +1 -1
  60. package/dist/javascript/print.js +1572 -1835
  61. package/dist/javascript/print.js.map +1 -1
  62. package/dist/javascript/project-parser.js +151 -172
  63. package/dist/javascript/project-parser.js.map +1 -1
  64. package/dist/javascript/recipes/add-dependency.js +140 -175
  65. package/dist/javascript/recipes/add-dependency.js.map +1 -1
  66. package/dist/javascript/recipes/async-callback-in-sync-array-method.js +20 -36
  67. package/dist/javascript/recipes/async-callback-in-sync-array-method.js.map +1 -1
  68. package/dist/javascript/recipes/auto-format.js +3 -14
  69. package/dist/javascript/recipes/auto-format.js.map +1 -1
  70. package/dist/javascript/recipes/change-import.js +447 -495
  71. package/dist/javascript/recipes/change-import.js.map +1 -1
  72. package/dist/javascript/recipes/order-imports.js +162 -175
  73. package/dist/javascript/recipes/order-imports.js.map +1 -1
  74. package/dist/javascript/recipes/upgrade-dependency-version.js +167 -197
  75. package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -1
  76. package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +166 -193
  77. package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +1 -1
  78. package/dist/javascript/remove-import.js +689 -724
  79. package/dist/javascript/remove-import.js.map +1 -1
  80. package/dist/javascript/rpc.js +1007 -1332
  81. package/dist/javascript/rpc.js.map +1 -1
  82. package/dist/javascript/search/find-dependency.js +84 -110
  83. package/dist/javascript/search/find-dependency.js.map +1 -1
  84. package/dist/javascript/search/uses-method.js +5 -19
  85. package/dist/javascript/search/uses-method.js.map +1 -1
  86. package/dist/javascript/search/uses-type.js +9 -20
  87. package/dist/javascript/search/uses-type.js.map +1 -1
  88. package/dist/javascript/templating/comparator.js +737 -822
  89. package/dist/javascript/templating/comparator.js.map +1 -1
  90. package/dist/javascript/templating/engine.js +211 -245
  91. package/dist/javascript/templating/engine.js.map +1 -1
  92. package/dist/javascript/templating/pattern.js +169 -190
  93. package/dist/javascript/templating/pattern.js.map +1 -1
  94. package/dist/javascript/templating/placeholder-replacement.js +172 -210
  95. package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
  96. package/dist/javascript/templating/rewrite.js +75 -97
  97. package/dist/javascript/templating/rewrite.js.map +1 -1
  98. package/dist/javascript/templating/template.js +69 -82
  99. package/dist/javascript/templating/template.js.map +1 -1
  100. package/dist/javascript/tree-debug.js +109 -137
  101. package/dist/javascript/tree-debug.js.map +1 -1
  102. package/dist/javascript/visitor.js +1090 -1254
  103. package/dist/javascript/visitor.js.map +1 -1
  104. package/dist/json/print.js +72 -103
  105. package/dist/json/print.js.map +1 -1
  106. package/dist/json/rpc.js +120 -181
  107. package/dist/json/rpc.js.map +1 -1
  108. package/dist/json/visitor.js +69 -100
  109. package/dist/json/visitor.js.map +1 -1
  110. package/dist/marketplace.js +20 -33
  111. package/dist/marketplace.js.map +1 -1
  112. package/dist/parse-error.js +41 -62
  113. package/dist/parse-error.js.map +1 -1
  114. package/dist/parser.js +7 -18
  115. package/dist/parser.js.map +1 -1
  116. package/dist/path-utils.js +46 -59
  117. package/dist/path-utils.js.map +1 -1
  118. package/dist/preconditions.js +30 -47
  119. package/dist/preconditions.js.map +1 -1
  120. package/dist/print.js +6 -19
  121. package/dist/print.js.map +1 -1
  122. package/dist/recipe.js +42 -73
  123. package/dist/recipe.js.map +1 -1
  124. package/dist/rpc/index.js +74 -115
  125. package/dist/rpc/index.js.map +1 -1
  126. package/dist/rpc/queue.js +71 -90
  127. package/dist/rpc/queue.js.map +1 -1
  128. package/dist/rpc/recipe.js +32 -57
  129. package/dist/rpc/recipe.js.map +1 -1
  130. package/dist/rpc/request/generate.js +4 -13
  131. package/dist/rpc/request/generate.js.map +1 -1
  132. package/dist/rpc/request/get-languages.js +2 -11
  133. package/dist/rpc/request/get-languages.js.map +1 -1
  134. package/dist/rpc/request/get-marketplace.js +9 -20
  135. package/dist/rpc/request/get-marketplace.js.map +1 -1
  136. package/dist/rpc/request/get-object.js +4 -13
  137. package/dist/rpc/request/get-object.js.map +1 -1
  138. package/dist/rpc/request/install-recipes.js +25 -36
  139. package/dist/rpc/request/install-recipes.js.map +1 -1
  140. package/dist/rpc/request/metrics.js +8 -17
  141. package/dist/rpc/request/metrics.js.map +1 -1
  142. package/dist/rpc/request/parse-project.js +36 -45
  143. package/dist/rpc/request/parse-project.js.map +1 -1
  144. package/dist/rpc/request/parse.js +5 -14
  145. package/dist/rpc/request/parse.js.map +1 -1
  146. package/dist/rpc/request/prepare-recipe.js +37 -52
  147. package/dist/rpc/request/prepare-recipe.js.map +1 -1
  148. package/dist/rpc/request/print.js +5 -14
  149. package/dist/rpc/request/print.js.map +1 -1
  150. package/dist/rpc/request/visit.js +56 -71
  151. package/dist/rpc/request/visit.js.map +1 -1
  152. package/dist/rpc/rewrite-rpc.js +70 -97
  153. package/dist/rpc/rewrite-rpc.js.map +1 -1
  154. package/dist/rpc/server.js +76 -89
  155. package/dist/rpc/server.js.map +1 -1
  156. package/dist/run.js +47 -66
  157. package/dist/run.js.map +1 -1
  158. package/dist/search/is-source-file.js +8 -19
  159. package/dist/search/is-source-file.js.map +1 -1
  160. package/dist/test/rewrite-test.js +154 -188
  161. package/dist/test/rewrite-test.js.map +1 -1
  162. package/dist/text/print.js +23 -38
  163. package/dist/text/print.js.map +1 -1
  164. package/dist/text/rpc.js +29 -44
  165. package/dist/text/rpc.js.map +1 -1
  166. package/dist/text/visitor.js +16 -33
  167. package/dist/text/visitor.js.map +1 -1
  168. package/dist/util.js +13 -24
  169. package/dist/util.js.map +1 -1
  170. package/dist/version.txt +1 -1
  171. package/dist/visitor.js +84 -115
  172. package/dist/visitor.js.map +1 -1
  173. package/dist/yaml/index.d.ts +2 -0
  174. package/dist/yaml/index.d.ts.map +1 -1
  175. package/dist/yaml/index.js +2 -0
  176. package/dist/yaml/index.js.map +1 -1
  177. package/dist/yaml/markers.d.ts +21 -0
  178. package/dist/yaml/markers.d.ts.map +1 -0
  179. package/dist/yaml/markers.js +37 -0
  180. package/dist/yaml/markers.js.map +1 -0
  181. package/dist/yaml/parser.d.ts.map +1 -1
  182. package/dist/yaml/parser.js +4 -1
  183. package/dist/yaml/parser.js.map +1 -1
  184. package/dist/yaml/print.d.ts +1 -1
  185. package/dist/yaml/print.d.ts.map +1 -1
  186. package/dist/yaml/print.js +175 -208
  187. package/dist/yaml/print.js.map +1 -1
  188. package/dist/yaml/rpc.js +154 -219
  189. package/dist/yaml/rpc.js.map +1 -1
  190. package/dist/yaml/visitor.js +78 -113
  191. package/dist/yaml/visitor.js.map +1 -1
  192. package/package.json +1 -1
  193. package/src/javascript/parser.ts +56 -14
  194. package/src/yaml/index.ts +2 -0
  195. package/src/yaml/markers.ts +70 -0
  196. package/src/yaml/parser.ts +5 -1
  197. 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
- return __awaiter(this, void 0, void 0, function* () {
77
- var _a;
78
- const oldModule = this.oldModule;
79
- const oldMember = this.oldMember;
80
- const newModule = this.newModule;
81
- const newMember = (_a = this.newMember) !== null && _a !== void 0 ? _a : oldMember;
82
- const newAlias = this.newAlias;
83
- // Build the old and new FQNs for type attribution updates
84
- const oldFqn = oldMember === 'default' || oldMember === '*'
85
- ? oldModule
86
- : `${oldModule}.${oldMember}`;
87
- const newFqn = newMember === 'default' || newMember === '*'
88
- ? newModule
89
- : `${newModule}.${newMember}`;
90
- return new class extends index_1.JavaScriptVisitor {
91
- constructor() {
92
- super(...arguments);
93
- this.hasOldImport = false;
94
- this.transformedImport = false;
95
- }
96
- visitJsCompilationUnit(cu, ctx) {
97
- const _super = Object.create(null, {
98
- visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
99
- });
100
- return __awaiter(this, void 0, void 0, function* () {
101
- var _a;
102
- // Reset tracking for each file
103
- this.hasOldImport = false;
104
- this.oldAlias = undefined;
105
- this.transformedImport = false;
106
- // First pass: check if the old import exists and capture any alias
107
- for (const statement of cu.statements) {
108
- const stmt = (_a = statement.element) !== null && _a !== void 0 ? _a : statement;
109
- if (stmt.kind === index_1.JS.Kind.Import) {
110
- const jsImport = stmt;
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
- return result;
158
- });
103
+ }
159
104
  }
160
- visitImportDeclaration(jsImport, ctx) {
161
- const _super = Object.create(null, {
162
- visitImportDeclaration: { get: () => super.visitImportDeclaration }
163
- });
164
- return __awaiter(this, void 0, void 0, function* () {
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
- let imp = yield _super.visitImportDeclaration.call(this, jsImport, ctx);
167
- if (!this.hasOldImport) {
168
- return imp;
169
- }
170
- const aliasInfo = this.checkForOldImport(imp);
171
- if (!aliasInfo.found) {
172
- return imp;
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
- // Check if this is the only import from the old module
175
- const namedImports = this.getNamedImports(imp);
176
- const isOnlyImport = namedImports.length === 1 ||
177
- (oldMember === 'default' && !((_a = imp.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings)) ||
178
- (oldMember === '*');
179
- if (isOnlyImport) {
180
- // Transform the module specifier in place
181
- this.transformedImport = true;
182
- return (0, mutative_1.create)(imp, draft => {
183
- var _a;
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
- removeNamedImportMember(imp, memberToRemove, _ctx) {
216
- return __awaiter(this, void 0, void 0, function* () {
217
- return (0, mutative_1.create)(imp, draft => {
218
- const importClause = draft.importClause;
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
- getNamedImports(imp) {
245
- const imports = [];
246
- const importClause = imp.importClause;
247
- if (!importClause)
248
- return imports;
249
- const namedBindings = importClause.namedBindings;
250
- if (!namedBindings || namedBindings.kind !== index_1.JS.Kind.NamedImports)
251
- return imports;
252
- const namedImports = namedBindings;
253
- for (const elem of namedImports.elements.elements) {
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 ((0, java_1.isIdentifier)(specifierNode)) {
257
- imports.push(specifierNode.simpleName);
207
+ if (specifierNode.kind === java_1.J.Kind.Identifier) {
208
+ return specifierNode.simpleName !== memberToRemove;
258
209
  }
259
- else if (specifierNode.kind === index_1.JS.Kind.Alias) {
210
+ if (specifierNode.kind === index_1.JS.Kind.Alias) {
260
211
  const alias = specifierNode;
261
212
  const propertyName = alias.propertyName.element;
262
- if ((0, java_1.isIdentifier)(propertyName)) {
263
- imports.push(propertyName.simpleName);
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
- return __awaiter(this, void 0, void 0, function* () {
274
- let ident = yield _super.visitIdentifier.call(this, identifier, ctx);
275
- if (!this.hasOldImport) {
276
- return ident;
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
- // Check and update type attribution
279
- let changed = false;
280
- // Update type if it references the old module
281
- const updatedType = this.updateType(ident.type);
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
- changed = true;
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 (changed) {
296
- return (0, mutative_1.create)(ident, draft => {
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
- visitMethodInvocation(method, ctx) {
309
- const _super = Object.create(null, {
310
- visitMethodInvocation: { get: () => super.visitMethodInvocation }
311
- });
312
- return __awaiter(this, void 0, void 0, function* () {
313
- let m = yield _super.visitMethodInvocation.call(this, method, ctx);
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
- visitFieldAccess(fieldAccess, ctx) {
328
- const _super = Object.create(null, {
329
- visitFieldAccess: { get: () => super.visitFieldAccess }
330
- });
331
- return __awaiter(this, void 0, void 0, function* () {
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
- visitFunctionCall(functionCall, ctx) {
347
- const _super = Object.create(null, {
348
- visitFunctionCall: { get: () => super.visitFunctionCall }
349
- });
350
- return __awaiter(this, void 0, void 0, function* () {
351
- let fc = yield _super.visitFunctionCall.call(this, functionCall, ctx);
352
- if (!this.hasOldImport) {
353
- return fc;
354
- }
355
- // Update methodType if it references the old module
356
- const updatedMethodType = this.updateMethodType(fc.methodType);
357
- if (updatedMethodType !== fc.methodType) {
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
- visitNewClass(newClass, ctx) {
366
- const _super = Object.create(null, {
367
- visitNewClass: { get: () => super.visitNewClass }
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
- return __awaiter(this, void 0, void 0, function* () {
370
- let nc = yield _super.visitNewClass.call(this, newClass, ctx);
371
- if (!this.hasOldImport) {
372
- return nc;
373
- }
374
- let changed = false;
375
- // Update methodType if it references the old module
376
- const updatedMethodType = this.updateMethodType(nc.methodType);
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
- changed = true;
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
- changed = true;
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
- changed = true;
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
- * Update a type if it references the old module
408
- */
409
- updateType(type) {
410
- if (!type)
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
- * Update a Class type if its FQN references the old module
430
- */
431
- updateClassType(classType) {
432
- let changed = false;
433
- let newFullyQualifiedName = classType.fullyQualifiedName;
434
- let newOwningClass = classType.owningClass;
435
- // Check if the FQN matches or starts with the old module
436
- if (classType.fullyQualifiedName === oldFqn) {
437
- newFullyQualifiedName = newFqn;
438
- changed = true;
439
- }
440
- else if (classType.fullyQualifiedName === oldModule) {
441
- newFullyQualifiedName = newModule;
442
- changed = true;
443
- }
444
- else if (classType.fullyQualifiedName.startsWith(oldModule + '.')) {
445
- newFullyQualifiedName = newModule + classType.fullyQualifiedName.substring(oldModule.length);
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
- // Recursively update owningClass
449
- if (classType.owningClass) {
450
- const updatedOwningClass = this.updateClassType(classType.owningClass);
451
- if (updatedOwningClass !== classType.owningClass) {
452
- newOwningClass = updatedOwningClass;
453
- changed = true;
454
- }
455
- }
456
- if (changed) {
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({}, classType), { fullyQualifiedName: newFullyQualifiedName, owningClass: newOwningClass });
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
- * Update a Variable type if its owner references the old module
489
- */
490
- updateVariableType(variableType) {
491
- let changed = false;
492
- let newOwner = variableType.owner;
493
- let newInnerType = variableType.type;
494
- // Update owner if it references the old module
495
- if (variableType.owner) {
496
- const updatedOwner = this.updateType(variableType.owner);
497
- if (updatedOwner !== variableType.owner) {
498
- newOwner = updatedOwner;
499
- changed = true;
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
- if (changed) {
509
- // Type objects are marked as non-draftable, so we manually create new objects
510
- return Object.assign(Object.assign({}, variableType), { owner: newOwner, type: newInnerType });
511
- }
512
- return variableType;
513
- }
514
- /**
515
- * Update a Parameterized type if its base type references the old module
516
- */
517
- updateParameterizedType(paramType) {
518
- let changed = false;
519
- let newBaseType = paramType.type;
520
- let newTypeParams = paramType.typeParameters;
521
- // Update base type
522
- if (java_1.Type.isFullyQualified(paramType.type)) {
523
- const updatedType = this.updateType(paramType.type);
524
- if (updatedType !== paramType.type) {
525
- newBaseType = updatedType;
526
- changed = true;
527
- }
528
- }
529
- // Update type parameters
530
- const updatedParams = paramType.typeParameters.map(tp => this.updateType(tp));
531
- if (updatedParams.some((p, i) => p !== paramType.typeParameters[i])) {
532
- newTypeParams = updatedParams;
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
- if (changed) {
536
- // Type objects are marked as non-draftable, so we manually create new objects
537
- return Object.assign(Object.assign({}, paramType), { type: newBaseType, typeParameters: newTypeParams });
538
- }
539
- return paramType;
540
- }
541
- /**
542
- * Update an Array type if its element type references the old module
543
- */
544
- updateArrayType(arrayType) {
545
- const updatedElemType = this.updateType(arrayType.elemType);
546
- if (updatedElemType !== arrayType.elemType) {
547
- // Type objects are marked as non-draftable, so we manually create new objects
548
- return Object.assign(Object.assign({}, arrayType), { elemType: updatedElemType });
549
- }
550
- return arrayType;
551
- }
552
- checkForOldImport(jsImport) {
553
- // Check if this import is from the old module
554
- const moduleSpecifier = jsImport.moduleSpecifier;
555
- if (!moduleSpecifier)
556
- return { found: false };
557
- const literal = moduleSpecifier.element;
558
- if (literal.kind !== java_1.J.Kind.Literal)
559
- return { found: false };
560
- const value = literal.value;
561
- if (value !== oldModule)
562
- return { found: false };
563
- const importClause = jsImport.importClause;
564
- if (!importClause) {
565
- // Side-effect import - not what we're looking for
566
- return { found: false };
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
- // Check for default import
569
- if (oldMember === 'default') {
570
- if (importClause.name) {
571
- const nameElem = importClause.name.element;
572
- if ((0, java_1.isIdentifier)(nameElem)) {
573
- return { found: true, alias: nameElem.simpleName };
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
- // Check for namespace import
579
- if (oldMember === '*') {
580
- const namedBindings = importClause.namedBindings;
581
- if ((namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === index_1.JS.Kind.Alias) {
582
- const alias = namedBindings;
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;