@arcgis/codemod 6.0.0-next.44 → 6.0.0-next.45

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.
@@ -1,395 +1,407 @@
1
- import { path as x } from "@arcgis/node-toolkit/path";
1
+ import { path as D } from "@arcgis/node-toolkit/path";
2
2
  import { SyntaxKind as I } from "ts-morph";
3
- import { g as D } from "./cli.js";
3
+ import { g as S } from "./cli.js";
4
4
  import { ModuleResolutionKind as K } from "typescript";
5
- import { a as w } from "./log.js";
6
- import { capitalize as A } from "@arcgis/toolkit/string";
7
- import { log as P } from "@arcgis/toolkit/log";
8
- function j(t) {
5
+ import { a as P } from "./log.js";
6
+ import { capitalize as j } from "@arcgis/toolkit/string";
7
+ import { log as q } from "@arcgis/toolkit/log";
8
+ function w(t) {
9
9
  const e = t.typeScriptConfig?.compilerOptions?.moduleResolution ?? K.Bundler;
10
10
  return e >= K.Node16 && e <= K.NodeNext;
11
11
  }
12
- function V(t, e) {
13
- const s = {};
14
- q(t);
15
- const { specifiers: i, names: m, lastImportIndex: r } = b(t), l = [], n = {}, c = [];
16
- let p = j(D.project.projectData);
17
- for (const [o, f] of Object.entries(e)) {
18
- let a = i.get(o) ?? (o.startsWith(".") ? i.get(
19
- x.relative(t.getDirectoryPath(), x.resolve(D.project.projectData.cwd, o))
12
+ function Z(t, e) {
13
+ const o = {};
14
+ b(t);
15
+ const { specifiers: r, names: c, lastImportIndex: s } = R(t), i = [], n = {}, m = [], p = [];
16
+ let f = w(S.project.projectData);
17
+ for (const [a, u] of Object.entries(e)) {
18
+ let l = r.get(a) ?? (a.startsWith(".") ? r.get(
19
+ D.relative(t.getDirectoryPath(), D.resolve(S.project.projectData.cwd, a))
20
20
  ) : void 0);
21
- if (a === void 0) {
22
- const y = i.get(`${o}.js`);
23
- y !== void 0 && (p = !0, a === void 0 ? a = y : a = [...a, ...y]);
21
+ if (l === void 0) {
22
+ const y = r.get(`${a}.js`);
23
+ y !== void 0 && (f = !0, l === void 0 ? l = y : l = [...l, ...y]);
24
24
  }
25
- for (const [y, g] of Object.entries(f)) {
26
- const v = Array.isArray(g) ? g : [g];
27
- for (const N of v)
28
- N.do === "deprecate" ? R(y, o, s, a) : N.do === "add" ? C(o, y, N, a, l, n, m) : N.do === "rename" ? E(o, y, N, a, l, n, m) : N.do === "remove-namespace-import" && W(
29
- o,
25
+ for (const [y, v] of Object.entries(u)) {
26
+ const O = Array.isArray(v) ? v : [v];
27
+ for (const N of O)
28
+ N.do === "deprecate" ? C(y, a, o, l) : N.do === "add" ? E(a, y, N, l, i, n, c) : N.do === "rename" ? W(a, y, N, l, i, n, c) : N.do === "remove" ? p.push(() => $(y, N, l)) : N.do === "remove-namespace-import" && M(
30
29
  a,
31
30
  l,
31
+ i,
32
32
  n,
33
- c,
34
- m
33
+ m,
34
+ c
35
35
  );
36
36
  }
37
37
  }
38
- const d = Object.entries(n);
39
- let u = r;
40
- for (let o = 0; o < d.length; o += 1) {
41
- const [f, a] = d[o], y = f.startsWith(".") ? M(
42
- x.relative(t.getDirectoryPath(), x.resolve(D.project.projectData.cwd, f))
43
- ) : f, g = p && y.startsWith("@arcgis/core") ? `${y}.js` : y, v = a.afterDeclaration === void 0 ? u : a.afterDeclaration.getChildIndex() + 1;
44
- if (a.named.length > 0) {
38
+ const g = Object.entries(n);
39
+ let d = s;
40
+ for (let a = 0; a < g.length; a += 1) {
41
+ const [u, l] = g[a], y = u.startsWith(".") ? F(
42
+ D.relative(t.getDirectoryPath(), D.resolve(S.project.projectData.cwd, u))
43
+ ) : u, v = f && y.startsWith("@arcgis/core") ? `${y}.js` : y, O = l.afterDeclaration === void 0 ? d : l.afterDeclaration.getChildIndex() + 1;
44
+ if (l.named.length > 0) {
45
45
  let N = !0;
46
- for (let h = 0; h < a.named.length; h += 1)
47
- N &&= a.named[h].isTypeOnly;
48
- t.insertImportDeclaration(v, {
46
+ for (let h = 0; h < l.named.length; h += 1)
47
+ N &&= l.named[h].isTypeOnly;
48
+ t.insertImportDeclaration(O, {
49
49
  isTypeOnly: N,
50
- moduleSpecifier: g,
51
- namedImports: a.named.map((h) => ({
50
+ moduleSpecifier: v,
51
+ namedImports: l.named.map((h) => ({
52
52
  name: h.name,
53
53
  alias: h.alias,
54
54
  isTypeOnly: h.isTypeOnly && !N
55
55
  }))
56
- }), u += 1;
56
+ }), d += 1;
57
57
  }
58
- a.default !== void 0 && (t.insertImportDeclaration(v, {
59
- isTypeOnly: a.default.isTypeOnly,
60
- moduleSpecifier: g,
61
- defaultImport: a.default.name
62
- }), u += 1), a["*"] !== void 0 && (t.insertImportDeclaration(v, {
63
- isTypeOnly: a["*"].isTypeOnly,
64
- moduleSpecifier: g,
65
- namespaceImport: a["*"].name
66
- }), u += 1);
58
+ l.default !== void 0 && (t.insertImportDeclaration(O, {
59
+ isTypeOnly: l.default.isTypeOnly,
60
+ moduleSpecifier: v,
61
+ defaultImport: l.default.name
62
+ }), d += 1), l["*"] !== void 0 && (t.insertImportDeclaration(O, {
63
+ isTypeOnly: l["*"].isTypeOnly,
64
+ moduleSpecifier: v,
65
+ namespaceImport: l["*"].name
66
+ }), d += 1);
67
67
  }
68
- if (Object.keys(s).length > 0) {
69
- const o = Object.entries(s).map(([f, a]) => `${a.join(", ")} from ${f}`).join("; ");
70
- P("warn", w(t), `Deprecated API usages found: ${o}`);
68
+ if (Object.keys(o).length > 0) {
69
+ const a = Object.entries(o).map(([u, l]) => `${l.join(", ")} from ${u}`).join("; ");
70
+ q("warn", P(t), `Deprecated API usages found: ${a}`);
71
71
  }
72
- for (const o of c)
73
- o.remove();
74
- return l;
72
+ for (const a of m)
73
+ a.remove();
74
+ for (const a of p)
75
+ a();
76
+ return i;
75
77
  }
76
- function q(t) {
78
+ function b(t) {
77
79
  const e = t.getChildSyntaxList()?.getFirstChild();
78
- if (S === e)
80
+ if (A === e)
79
81
  return;
80
- S = e, O.clear();
81
- const s = /* @__PURE__ */ new Set();
82
- i(t);
83
- function i(m) {
84
- for (const r of m.getStatements())
85
- if (r.isKind(I.ImportDeclaration)) {
86
- const l = r.getDefaultImport(), n = r.getNamespaceImport(), c = r.getNamedImports();
87
- l && s.add(l.getText()), n && s.add(n.getText());
88
- for (const p of c)
89
- s.add(p.getAliasNode()?.getText() ?? p.getName());
90
- } else r.isKind(I.ImportEqualsDeclaration) ? s.add(r.getName()) : r.isKind(I.ModuleDeclaration) ? i(r) : m.forEachDescendant((l) => {
91
- if (!l.isKind(I.Identifier))
82
+ A = e, x.clear();
83
+ const o = /* @__PURE__ */ new Set();
84
+ r(t);
85
+ function r(c) {
86
+ for (const s of c.getStatements())
87
+ if (s.isKind(I.ImportDeclaration)) {
88
+ const i = s.getDefaultImport(), n = s.getNamespaceImport(), m = s.getNamedImports();
89
+ i && o.add(i.getText()), n && o.add(n.getText());
90
+ for (const p of m)
91
+ o.add(p.getAliasNode()?.getText() ?? p.getName());
92
+ } else s.isKind(I.ImportEqualsDeclaration) ? o.add(s.getName()) : s.isKind(I.ModuleDeclaration) ? r(s) : c.forEachDescendant((i) => {
93
+ if (!i.isKind(I.Identifier))
92
94
  return;
93
- const n = l.getParent();
94
- if (n.isKind(I.QualifiedName) && n.getLeft() !== l || n.isKind(I.PropertyAccessExpression) && n.getExpression() !== l || (n.isKind(I.PropertyDeclaration) || n.isKind(I.PropertySignature) || n.isKind(I.PropertyAssignment)) && n.getNameNode() === l)
95
+ const n = i.getParent();
96
+ if (n.isKind(I.QualifiedName) && n.getLeft() !== i || n.isKind(I.PropertyAccessExpression) && n.getExpression() !== i || (n.isKind(I.PropertyDeclaration) || n.isKind(I.PropertySignature) || n.isKind(I.PropertyAssignment)) && n.getNameNode() === i)
95
97
  return;
96
- const c = l.getText();
97
- s.has(c) || O.add(l.getText());
98
+ const m = i.getText();
99
+ o.has(m) || x.add(i.getText());
98
100
  });
99
101
  }
100
102
  }
101
- function b(t) {
102
- const e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), i = t.getStatements();
103
- let m;
104
- for (let l = 0; l < i.length; l += 1) {
105
- const n = i[l];
103
+ function R(t) {
104
+ const e = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), r = t.getStatements();
105
+ let c;
106
+ for (let i = 0; i < r.length; i += 1) {
107
+ const n = r[i];
106
108
  if (!n.isKind(I.ImportDeclaration)) {
107
- const a = n.getName?.();
108
- a !== void 0 && s.add(a);
109
+ const u = n.getName?.();
110
+ u !== void 0 && o.add(u);
109
111
  continue;
110
112
  }
111
- m = n;
112
- const c = n.getModuleSpecifierValue(), p = e.get(c);
113
- p === void 0 ? e.set(c, [n]) : p.push(n);
114
- const d = n.getImportClause();
115
- if (d === void 0)
113
+ c = n;
114
+ const m = n.getModuleSpecifierValue(), p = e.get(m);
115
+ p === void 0 ? e.set(m, [n]) : p.push(n);
116
+ const f = n.getImportClause();
117
+ if (f === void 0)
116
118
  continue;
117
- const u = d.getDefaultImport()?.getText();
118
- u !== void 0 && s.add(u);
119
- const o = d.getNamedBindings();
120
- if (o !== void 0)
121
- if (o.isKind(I.NamedImports))
122
- for (const f of o.getElements()) {
123
- const a = f.getName();
124
- s.add(a);
119
+ const g = f.getDefaultImport()?.getText();
120
+ g !== void 0 && o.add(g);
121
+ const d = f.getNamedBindings();
122
+ if (d !== void 0)
123
+ if (d.isKind(I.NamedImports))
124
+ for (const a of d.getElements()) {
125
+ const u = a.getName();
126
+ o.add(u);
125
127
  }
126
128
  else {
127
- const f = o.getName();
128
- s.add(f);
129
+ const a = d.getName();
130
+ o.add(a);
129
131
  }
130
132
  }
131
- const r = m === void 0 ? 0 : m.getChildIndex() + 1;
132
- return { specifiers: e, names: s, lastImportIndex: r };
133
+ const s = c === void 0 ? 0 : c.getChildIndex() + 1;
134
+ return { specifiers: e, names: o, lastImportIndex: s };
133
135
  }
134
- function R(t, e, s, i) {
135
- if (i !== void 0) {
136
+ function C(t, e, o, r) {
137
+ if (r !== void 0) {
136
138
  if (t === "default")
137
- for (const m of i) {
138
- const r = m.getDefaultImport();
139
- if (r !== void 0) {
140
- s[e] ??= [], s[e].push(r.getText());
139
+ for (const c of r) {
140
+ const s = c.getDefaultImport();
141
+ if (s !== void 0) {
142
+ o[e] ??= [], o[e].push(s.getText());
141
143
  return;
142
144
  }
143
145
  }
144
146
  else if (t === "*")
145
- for (const m of i) {
146
- const r = m.getNamespaceImport();
147
- if (r !== void 0) {
148
- s[e] ??= [], s[e].push(r.getText());
147
+ for (const c of r) {
148
+ const s = c.getNamespaceImport();
149
+ if (s !== void 0) {
150
+ o[e] ??= [], o[e].push(s.getText());
149
151
  return;
150
152
  }
151
153
  }
152
154
  else
153
- for (const m of i)
154
- for (const r of m.getNamedImports())
155
- if (r.getName() === t) {
156
- s[e] ??= [], s[e].push(r.getName());
155
+ for (const c of r)
156
+ for (const s of c.getNamedImports())
157
+ if (s.getName() === t) {
158
+ o[e] ??= [], o[e].push(s.getName());
157
159
  return;
158
160
  }
159
161
  }
160
162
  }
161
- function C(t, e, s, i, m, r, l) {
163
+ function E(t, e, o, r, c, s, i) {
162
164
  const n = e === "default";
163
165
  if (n || e === "*") {
164
- if (i !== void 0)
165
- for (const p of i) {
166
- const d = n ? p.getDefaultImport() : p.getNamespaceImport();
167
- if (d !== void 0) {
168
- s.isTypeOnly !== !0 && p.isTypeOnly() && p.setIsTypeOnly(!1), m.push({
166
+ if (r !== void 0)
167
+ for (const p of r) {
168
+ const f = n ? p.getDefaultImport() : p.getNamespaceImport();
169
+ if (f !== void 0) {
170
+ o.isTypeOnly !== !0 && p.isTypeOnly() && p.setIsTypeOnly(!1), c.push({
169
171
  specifier: t,
170
172
  requestedName: e,
171
- actualName: d.getText()
173
+ actualName: f.getText()
172
174
  });
173
175
  return;
174
176
  }
175
177
  }
176
- const c = T(s.preferredAlias, void 0, t, l);
177
- m.push({ specifier: t, requestedName: e, actualName: c }), r[t] ??= {
178
+ const m = T(o.preferredAlias, void 0, t, i);
179
+ c.push({ specifier: t, requestedName: e, actualName: m }), s[t] ??= {
178
180
  afterDeclaration: void 0,
179
181
  named: [],
180
182
  default: void 0,
181
183
  "*": void 0
182
- }, r[t].afterDeclaration ??= i?.[0], r[t][e] = {
183
- name: c,
184
- isTypeOnly: s.isTypeOnly === !0
184
+ }, s[t].afterDeclaration ??= r?.[0], s[t][e] = {
185
+ name: m,
186
+ isTypeOnly: o.isTypeOnly === !0
185
187
  };
186
188
  } else {
187
- let c, p;
188
- if (i !== void 0) {
189
- let o = !1;
190
- for (const f of i)
191
- if (f.getNamespaceImport() === void 0) {
192
- p ??= f, c ??= f.isTypeOnly() && f.getDefaultImport() === void 0 ? f : void 0;
193
- for (const a of f.getNamedImports())
194
- if (a.getNameNode().getText() === e) {
195
- if (o = !0, s.isTypeOnly !== !0) {
196
- if (a.isTypeOnly())
189
+ let m, p;
190
+ if (r !== void 0) {
191
+ let d = !1;
192
+ for (const a of r)
193
+ if (!(a.getNamespaceImport() !== void 0 || o.isTypeOnly === !0 && a.getImportClause() === void 0)) {
194
+ p ??= a, m ??= a.isTypeOnly() && a.getDefaultImport() === void 0 ? a : void 0;
195
+ for (const u of a.getNamedImports())
196
+ if (u.getNameNode().getText() === e) {
197
+ if (d = !0, o.isTypeOnly !== !0) {
198
+ if (u.isTypeOnly())
199
+ u.setIsTypeOnly(!1);
200
+ else if (a.isTypeOnly()) {
201
+ for (const l of a.getNamedImports())
202
+ l !== u && l.setIsTypeOnly(!0);
197
203
  a.setIsTypeOnly(!1);
198
- else if (f.isTypeOnly()) {
199
- for (const y of f.getNamedImports())
200
- y !== a && y.setIsTypeOnly(!0);
201
- f.setIsTypeOnly(!1);
202
204
  }
203
205
  }
204
- m.push({
206
+ c.push({
205
207
  specifier: t,
206
208
  requestedName: e,
207
- actualName: a.getAliasNode()?.getText() ?? e
209
+ actualName: u.getAliasNode()?.getText() ?? e
208
210
  });
209
211
  break;
210
212
  }
211
213
  }
212
- if (o)
214
+ if (d)
213
215
  return;
214
216
  }
215
- const d = T(
216
- s.preferAlias === !0 ? s.preferredAlias : e,
217
- s.preferAlias === !0 ? e : s.preferredAlias,
217
+ const f = T(
218
+ o.preferAlias === !0 ? o.preferredAlias : e,
219
+ o.preferAlias === !0 ? e : o.preferredAlias,
218
220
  t,
219
- l
220
- ), u = e === d ? void 0 : d;
221
- if (s.isTypeOnly && c !== void 0)
222
- c.addNamedImport({
221
+ i
222
+ ), g = e === f ? void 0 : f;
223
+ if (o.isTypeOnly && m !== void 0)
224
+ m.addNamedImport({
223
225
  name: e,
224
- alias: u
226
+ alias: g
225
227
  });
226
- else if (p !== void 0 && (!s.isTypeOnly || p.getDefaultImport() === void 0)) {
227
- if (p.isTypeOnly() && !s.isTypeOnly) {
228
+ else if (p !== void 0 && (!o.isTypeOnly || p.getDefaultImport() === void 0)) {
229
+ if (p.isTypeOnly() && !o.isTypeOnly) {
228
230
  p.setIsTypeOnly(!1);
229
- for (const o of p.getNamedImports())
230
- o.setIsTypeOnly(!0);
231
+ for (const d of p.getNamedImports())
232
+ d.setIsTypeOnly(!0);
231
233
  }
232
234
  p.addNamedImport({
233
235
  name: e,
234
- alias: u,
235
- isTypeOnly: s.isTypeOnly && !p.isTypeOnly()
236
+ alias: g,
237
+ isTypeOnly: o.isTypeOnly && !p.isTypeOnly()
236
238
  });
237
239
  } else
238
- r[t] ??= {
240
+ s[t] ??= {
239
241
  afterDeclaration: void 0,
240
242
  named: [],
241
243
  default: void 0,
242
244
  "*": void 0
243
- }, r[t].afterDeclaration ??= i?.[0], r[t].named.push({
245
+ }, s[t].afterDeclaration ??= r?.[0], s[t].named.push({
244
246
  name: e,
245
- alias: u,
246
- isTypeOnly: s.isTypeOnly === !0
247
+ alias: g,
248
+ isTypeOnly: o.isTypeOnly === !0
247
249
  });
248
- m.push({ specifier: t, requestedName: e, actualName: d });
250
+ c.push({ specifier: t, requestedName: e, actualName: f });
249
251
  }
250
252
  }
251
- function E(t, e, s, i, m, r, l) {
252
- if (i === void 0)
253
+ function W(t, e, o, r, c, s, i) {
254
+ if (r === void 0)
253
255
  return;
254
- const n = s.name ?? e, c = s.specifier ?? t, p = e === "default";
256
+ const n = o.name ?? e, m = o.specifier ?? t, p = e === "default";
255
257
  if (p || e === "*") {
256
- for (const d of i) {
257
- const u = p ? d.getDefaultImport() : d.getNamespaceImport();
258
- if (u === void 0)
258
+ for (const f of r) {
259
+ const g = p ? f.getDefaultImport() : f.getNamespaceImport();
260
+ if (g === void 0)
259
261
  continue;
260
- if (s.isTypeOnly === !1 && d.isTypeOnly()) {
261
- d.setIsTypeOnly(!1);
262
- for (const f of d.getNamedImports())
263
- f.setIsTypeOnly(!0);
262
+ if (o.isTypeOnly === !1 && f.isTypeOnly()) {
263
+ f.setIsTypeOnly(!1);
264
+ for (const a of f.getNamedImports())
265
+ a.setIsTypeOnly(!0);
264
266
  }
265
- let o = n;
267
+ let d = n;
266
268
  if (n !== e) {
267
- const f = T(n, e, t, l);
268
- n === f ? u.rename(n) : o = u.getText();
269
+ const a = T(n, e, t, i);
270
+ n === a ? g.rename(n) : d = g.getText();
269
271
  } else
270
- o = u.getText();
271
- t !== c && (d.getNamedImports().length === 0 ? d.setModuleSpecifier(c) : (p ? d.removeDefaultImport() : d.removeNamespaceImport(), r[c] ??= {
272
+ d = g.getText();
273
+ t !== m && (f.getNamedImports().length === 0 ? f.setModuleSpecifier(m) : (p ? f.removeDefaultImport() : f.removeNamespaceImport(), s[m] ??= {
272
274
  afterDeclaration: void 0,
273
275
  named: [],
274
276
  default: void 0,
275
277
  "*": void 0
276
- }, r[c].afterDeclaration ??= d, r[c][e] = {
277
- name: o,
278
- isTypeOnly: d.isTypeOnly()
279
- })), m.push({
280
- specifier: c,
278
+ }, s[m].afterDeclaration ??= f, s[m][e] = {
279
+ name: d,
280
+ isTypeOnly: f.isTypeOnly()
281
+ })), c.push({
282
+ specifier: m,
281
283
  requestedName: e,
282
- actualName: o
284
+ actualName: d
283
285
  });
284
286
  break;
285
287
  }
286
288
  return;
287
289
  }
288
- for (const d of i) {
289
- for (const o of d.getNamedImports()) {
290
- if (o.getNameNode().getText() !== e)
290
+ for (const f of r) {
291
+ for (const d of f.getNamedImports()) {
292
+ if (d.getNameNode().getText() !== e)
291
293
  continue;
292
- if (s.isTypeOnly === !1) {
293
- if (o.isTypeOnly())
294
- o.setIsTypeOnly(!1);
295
- else if (d.isTypeOnly()) {
294
+ if (o.isTypeOnly === !1) {
295
+ if (d.isTypeOnly())
296
296
  d.setIsTypeOnly(!1);
297
- for (const y of d.getNamedImports())
298
- y !== o && y.setIsTypeOnly(!0);
297
+ else if (f.isTypeOnly()) {
298
+ f.setIsTypeOnly(!1);
299
+ for (const l of f.getNamedImports())
300
+ l !== d && l.setIsTypeOnly(!0);
299
301
  }
300
302
  }
301
- let f = n;
302
- const a = o.getAliasNode();
303
+ let a = n;
304
+ const u = d.getAliasNode();
303
305
  if (n !== e)
304
- if (a === void 0) {
305
- const y = T(n, e, t, l);
306
- n === y ? o.getNameNode().asKind(I.Identifier)?.rename(n) : (o.setAlias(e), o.getNameNode().replaceWithText(n), f = e);
306
+ if (u === void 0) {
307
+ const l = T(n, e, t, i);
308
+ n === l ? d.getNameNode().asKind(I.Identifier)?.rename(n) : (d.setAlias(e), d.getNameNode().replaceWithText(n), a = e);
307
309
  } else
308
- o.getNameNode().replaceWithText(n), f = a.getText();
309
- if (c !== t) {
310
- const g = (j(D.project.projectData) || d.getModuleSpecifierValue().endsWith(".js")) && c.startsWith("@arcgis/core") ? `${c}.js` : c;
311
- d.getNamedImports().length === 1 && d.getDefaultImport() === void 0 ? d.setModuleSpecifier(g) : (r[g] ??= { named: [] }, r[g].afterDeclaration ??= i?.[0], r[g].named.push({
310
+ d.getNameNode().replaceWithText(n), a = u.getText();
311
+ if (m !== t) {
312
+ const y = (w(S.project.projectData) || f.getModuleSpecifierValue().endsWith(".js")) && m.startsWith("@arcgis/core") ? `${m}.js` : m;
313
+ f.getNamedImports().length === 1 && f.getDefaultImport() === void 0 ? f.setModuleSpecifier(y) : (s[y] ??= { named: [] }, s[y].afterDeclaration ??= r?.[0], s[y].named.push({
312
314
  name: n,
313
- alias: n === f ? void 0 : f,
314
- isTypeOnly: o.isTypeOnly()
315
- }), o.remove());
315
+ alias: n === a ? void 0 : a,
316
+ isTypeOnly: d.isTypeOnly()
317
+ }), d.remove());
316
318
  }
317
- m.push({
318
- specifier: c,
319
+ c.push({
320
+ specifier: m,
319
321
  requestedName: n,
320
- actualName: a?.getText() ?? f
322
+ actualName: u?.getText() ?? a
321
323
  });
322
324
  return;
323
325
  }
324
- const u = d.getNamespaceImport();
325
- if (u)
326
- for (const o of u.findReferencesAsNodes().slice(1)) {
327
- const f = o.getParentIfKind(I.PropertyAccessExpression), a = o.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), y = f ?? a;
328
- if (!y)
326
+ const g = f.getNamespaceImport();
327
+ if (g)
328
+ for (const d of g.findReferencesAsNodes().slice(1)) {
329
+ const a = d.getParentIfKind(I.PropertyAccessExpression), u = d.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), l = a ?? u;
330
+ if (!l)
329
331
  continue;
330
- const g = y.getText();
331
- g.endsWith(e) && y.replaceWithText(g.replaceAll(e, n));
332
+ const y = l.getText();
333
+ y.endsWith(e) && l.replaceWithText(y.replaceAll(e, n));
332
334
  }
333
335
  }
334
336
  }
335
- function W(t, e, s, i, m, r) {
336
- if (e = e?.filter((u) => u.getNamespaceImport() != null), e === void 0 || e.length === 0)
337
+ function $(t, e, o) {
338
+ for (const r of o ?? []) {
339
+ if (r.wasForgotten())
340
+ continue;
341
+ const c = r.getNamedImports().find((i) => i.getName() === t), s = t === "default" ? r.getDefaultImport() : t === "*" ? r.getNamespaceImport() : c?.getAliasNode() ?? c?.getNameNode().asKind(I.Identifier);
342
+ s !== void 0 && (e.unusedOnly && s.findReferencesAsNodes().some(
343
+ (i) => i.getSourceFile() === r.getSourceFile() && i !== s && i.getParent()?.getKind() !== I.ImportSpecifier
344
+ ) || (t === "default" ? r.removeDefaultImport() : t === "*" ? r.removeNamespaceImport() : s.getParentIfKindOrThrow(I.ImportSpecifier).remove(), r.getNamedImports().length === 0 && r.getDefaultImport() === void 0 && r.getNamespaceImport() === void 0 && r.remove()));
345
+ }
346
+ }
347
+ function M(t, e, o, r, c, s) {
348
+ if (e = e?.filter((g) => g.getNamespaceImport() != null), e === void 0 || e.length === 0)
337
349
  return;
338
350
  if (e.length !== 1)
339
351
  throw Error(
340
352
  `Multiple namespace imports of the same specifier (${JSON.stringify(t)}, #${e.length}) are not supported.`
341
353
  );
342
- const [l] = e, n = l.getNamespaceImport(), c = {}, p = /* @__PURE__ */ new Set();
343
- for (const u of n.findReferencesAsNodes()) {
344
- const o = u.getParentIfKind(I.PropertyAccessExpression), f = u.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), a = o ?? f;
345
- if (!a)
354
+ const [i] = e, n = i.getNamespaceImport(), m = {}, p = /* @__PURE__ */ new Set();
355
+ for (const g of n.findReferencesAsNodes()) {
356
+ const d = g.getParentIfKind(I.PropertyAccessExpression), a = g.getParentIfKind(I.QualifiedName)?.getParentIfKind(I.TypeReference), u = d ?? a;
357
+ if (!u)
346
358
  continue;
347
- const y = a.getText().split(".").pop().trim();
348
- c[y] ??= T(y, void 0, t, r);
349
- const g = c[y];
350
- a.replaceWithText(g), f || p.add(g);
359
+ const l = u.getText().split(".").pop().trim();
360
+ m[l] ??= T(l, void 0, t, s);
361
+ const y = m[l];
362
+ u.replaceWithText(y), a || p.add(y);
351
363
  }
352
- i[t] ??= {
353
- afterDeclaration: l,
364
+ r[t] ??= {
365
+ afterDeclaration: i,
354
366
  named: []
355
367
  };
356
- const { named: d } = i[t];
357
- for (const [u, o] of Object.entries(c))
358
- d.push({
359
- name: u,
360
- alias: o === u ? void 0 : o,
361
- isTypeOnly: !p.has(o)
362
- }), s.push({
368
+ const { named: f } = r[t];
369
+ for (const [g, d] of Object.entries(m))
370
+ f.push({
371
+ name: g,
372
+ alias: d === g ? void 0 : d,
373
+ isTypeOnly: !p.has(d)
374
+ }), o.push({
363
375
  specifier: t,
364
- requestedName: u,
365
- actualName: o
376
+ requestedName: g,
377
+ actualName: d
366
378
  });
367
- m.push(l);
379
+ c.push(i);
368
380
  }
369
- function T(t, e, s, i) {
381
+ function T(t, e, o, r) {
370
382
  if (t !== void 0) {
371
- if (!i.has(t) && !O.has(t))
372
- return i.add(t), t;
383
+ if (!r.has(t) && !x.has(t))
384
+ return r.add(t), t;
373
385
  if (e !== void 0)
374
- return T(e, void 0, s, i);
386
+ return T(e, void 0, o, r);
375
387
  }
376
- s.startsWith("@arcgis/core") && (s = `arcgisCore${s.slice(12)}`);
377
- const m = s.split("/");
378
- let r = t ?? "";
379
- for (let l = m.length - 1; l >= 0; l--) {
380
- const n = m[l].replaceAll($, "");
381
- if (n !== r && (r = n + A(r), !i.has(r) && !O.has(r)))
382
- return i.add(r), r;
388
+ o.startsWith("@arcgis/core") && (o = `arcgisCore${o.slice(12)}`);
389
+ const c = o.split("/");
390
+ let s = t ?? "";
391
+ for (let i = c.length - 1; i >= 0; i--) {
392
+ const n = c[i].replaceAll(U, "");
393
+ if (n !== s && (s = n + j(s), !r.has(s) && !x.has(s)))
394
+ return r.add(s), s;
383
395
  }
384
- for (let l = 2; ; l++) {
385
- const n = r + l;
386
- if (!i.has(n) && !O.has(n))
387
- return i.add(n), n;
396
+ for (let i = 2; ; i++) {
397
+ const n = s + i;
398
+ if (!r.has(n) && !x.has(n))
399
+ return r.add(n), n;
388
400
  }
389
401
  }
390
- const $ = /[^a-zA-Z0-9$_]/gu, M = (t) => t.startsWith(".") ? t : `./${t}`, O = /* @__PURE__ */ new Set();
391
- let S;
402
+ const U = /[^a-zA-Z0-9$_]/gu, F = (t) => t.startsWith(".") ? t : `./${t}`, x = /* @__PURE__ */ new Set();
403
+ let A;
392
404
  export {
393
- V as p,
394
- q as u
405
+ Z as p,
406
+ b as u
395
407
  };