@arcgis/codemod 6.0.0-next.43 → 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,72 +1,238 @@
1
- var c = (t, e) => (e = Symbol[t]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + t), d = (t) => {
1
+ var N = (t, e) => (e = Symbol[t]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + t), x = (t) => {
2
2
  throw TypeError(t);
3
3
  };
4
- var g = (t, e, s) => {
4
+ var A = (t, e, n) => {
5
5
  if (e != null) {
6
- typeof e != "object" && typeof e != "function" && d("Object expected");
7
- var i, r;
8
- s && (i = e[c("asyncDispose")]), i === void 0 && (i = e[c("dispose")], s && (r = i)), typeof i != "function" && d("Object not disposable"), r && (i = function() {
6
+ typeof e != "object" && typeof e != "function" && x("Object expected");
7
+ var r, o;
8
+ n && (r = e[N("asyncDispose")]), r === void 0 && (r = e[N("dispose")], n && (o = r)), typeof r != "function" && x("Object not disposable"), o && (r = function() {
9
9
  try {
10
- r.call(this);
11
- } catch (n) {
12
- return Promise.reject(n);
10
+ o.call(this);
11
+ } catch (a) {
12
+ return Promise.reject(a);
13
13
  }
14
- }), t.push([s, i, e]);
15
- } else s && t.push([s]);
14
+ }), t.push([n, r, e]);
15
+ } else n && t.push([n]);
16
16
  return e;
17
- }, f = (t, e, s) => {
18
- var i = typeof SuppressedError == "function" ? SuppressedError : function(o, a, l, m) {
19
- return m = Error(l), m.name = "SuppressedError", m.error = o, m.suppressed = a, m;
20
- }, r = (o) => e = s ? new i(o, e, "An error was suppressed during disposal") : (s = !0, o), n = (o) => {
21
- for (; o = t.pop(); )
17
+ }, y = (t, e, n) => {
18
+ var r = typeof SuppressedError == "function" ? SuppressedError : function(s, c, l, u) {
19
+ return u = Error(l), u.name = "SuppressedError", u.error = s, u.suppressed = c, u;
20
+ }, o = (s) => e = n ? new r(s, e, "An error was suppressed during disposal") : (n = !0, s), a = (s) => {
21
+ for (; s = t.pop(); )
22
22
  try {
23
- var a = o[1] && o[1].call(o[2]);
24
- if (o[0]) return Promise.resolve(a).then(n, (l) => (r(l), n()));
23
+ var c = s[1] && s[1].call(s[2]);
24
+ if (s[0]) return Promise.resolve(c).then(a, (l) => (o(l), a()));
25
25
  } catch (l) {
26
- r(l);
26
+ o(l);
27
27
  }
28
- if (s) throw e;
28
+ if (n) throw e;
29
29
  };
30
- return n();
30
+ return a();
31
31
  };
32
- import { p } from "./actions.js";
33
- import { c as k } from "./useProjectInstance.js";
34
- import { p as C } from "./cli.js";
32
+ import { SyntaxKind as d, Node as i } from "ts-morph";
33
+ import { c as z } from "./useProjectInstance.js";
34
+ const P = /* @__PURE__ */ new Map([
35
+ ["arcgis-survey123", "arcgis-survey-123"],
36
+ ["arrow-double-diagonal1", "arrow-double-diagonal-1"],
37
+ ["arrow-double-diagonal2", "arrow-double-diagonal-2"],
38
+ ["arrow-left10", "arrow-left-10"],
39
+ ["arrow-right10", "arrow-right-10"],
40
+ ["battery1", "battery-1"],
41
+ ["battery2", "battery-2"],
42
+ ["battery3", "battery-3"],
43
+ ["battery4", "battery-4"],
44
+ ["graph-bar100-stacked", "graph-bar-100-stacked"],
45
+ ["hexagon2", "hexagon-2"],
46
+ ["hexagon2-inset-large", "hexagon-2-inset-large"],
47
+ ["hexagon2-inset-medium", "hexagon-2-inset-medium"],
48
+ ["hexagon2-inset-small", "hexagon-2-inset-small"],
49
+ ["i12x", "1-2x"],
50
+ ["i14x", "1-4x"],
51
+ ["i18x", "1-8x"],
52
+ ["i1x", "1x"],
53
+ ["i2d", "2d"],
54
+ ["i2d-explore", "2d-explore"],
55
+ ["i2x", "2-x"],
56
+ ["i360-view", "360-view"],
57
+ ["i3d", "3d"],
58
+ ["i3d-building", "3d-building"],
59
+ ["i3d-building-parameter", "3d-building-parameter"],
60
+ ["i3d-glasses", "3d-glasses"],
61
+ ["i3d-search", "3d-search"],
62
+ ["i4x", "4-x"],
63
+ ["i8x", "8-x"],
64
+ ["language2", "language-2"],
65
+ ["launch2", "launch-2"],
66
+ ["layer3d", "layer-3d"],
67
+ ["merge2", "merge-2"],
68
+ ["number-circle1", "number-circle-1"],
69
+ ["number-circle1f", "number-circle-1-f"],
70
+ ["number-circle2", "number-circle-2"],
71
+ ["number-circle2f", "number-circle-2-f"],
72
+ ["number-circle3", "number-circle-3"],
73
+ ["number-circle3f", "number-circle-3-f"],
74
+ ["number-circle4", "number-circle-4"],
75
+ ["number-circle4f", "number-circle-4-f"],
76
+ ["number-circle5", "number-circle-5"],
77
+ ["number-circle5f", "number-circle-5-f"],
78
+ ["number-circle6", "number-circle-6"],
79
+ ["number-circle6f", "number-circle-6-f"],
80
+ ["number-circle7", "number-circle-7"],
81
+ ["number-circle7f", "number-circle-7-f"],
82
+ ["number-circle8", "number-circle-8"],
83
+ ["number-circle8f", "number-circle-8-f"],
84
+ ["number-circle9", "number-circle-9"],
85
+ ["number-circle9f", "number-circle-9-f"],
86
+ ["person2", "person-2"],
87
+ ["pop-up1", "pop-up-1"],
88
+ ["satellite0", "satellite-0"],
89
+ ["satellite0f", "satellite-0-f"],
90
+ ["satellite1", "satellite-1"],
91
+ ["satellite1f", "satellite-1-f"],
92
+ ["satellite2", "satellite-2"],
93
+ ["satellite2f", "satellite-2-f"],
94
+ ["satellite3", "satellite-3"],
95
+ ["satellite3f", "satellite-3-f"],
96
+ ["shapes2d3d", "shapes-2d-3d"],
97
+ ["subheading1", "subheading-1"],
98
+ ["subheading1-rtl", "subheading-1-rtl"],
99
+ ["subheading2", "subheading-2"],
100
+ ["subheading2-rtl", "subheading-2-rtl"],
101
+ ["subheading3", "subheading-3"],
102
+ ["subheading3-rtl", "subheading-3-rtl"],
103
+ ["subheading4", "subheading-4"],
104
+ ["subheading4-rtl", "subheading-4-rtl"],
105
+ ["subheading5", "subheading-5"],
106
+ ["subheading5-rtl", "subheading-5-rtl"],
107
+ ["summarize-center-and-dispersion1", "summarize-center-and-dispersion-1"],
108
+ ["summarize-center-and-dispersion2", "summarize-center-and-dispersion-2"],
109
+ ["summarize-center-and-dispersion3", "summarize-center-and-dispersion-3"]
110
+ ]), T = /* @__PURE__ */ new Set(["icon", "icon-end", "icon-start", "iconEnd", "iconStart"]), D = /[A-Z]/u, B = /^i\d/u, L = /([A-Z]+)([A-Z][a-z])/gu, I = /([a-z\d])([A-Z])/gu;
111
+ function C(t) {
112
+ let e = t;
113
+ return D.test(e) && (B.test(e) && (e = e.slice(1)), e = e.replace(L, "$1-$2").replace(I, "$1-$2").toLowerCase()), P.get(e) ?? e;
114
+ }
115
+ function w(t) {
116
+ const e = t.getLiteralValue(), n = C(e);
117
+ n !== e && t.setLiteralValue(n);
118
+ }
119
+ function E(t, e) {
120
+ const n = t.getInitializer();
121
+ i.isStringLiteral(n) ? w(n) : i.isJsxExpression(n) && g(n.getExpression(), e);
122
+ }
123
+ function F(t, e) {
124
+ const n = t.getBody();
125
+ i.isExpression(n) ? g(n, e) : n?.getDescendantsOfKind(d.ReturnStatement).forEach((r) => g(r.getExpression(), e));
126
+ }
127
+ function J(t, e) {
128
+ for (const n of t.findReferencesAsNodes()) {
129
+ const r = n.getParent(), o = i.isPropertyAccessExpression(r) ? r : n, a = o.getParent();
130
+ i.isBinaryExpression(a) && a.getLeft() === o && a.getOperatorToken().isKind(d.EqualsToken) ? g(a.getRight(), e) : i.isJsxAttribute(a) && a.getNameNode() === n && E(a, e);
131
+ }
132
+ }
133
+ function h(t, e) {
134
+ if (!(t === void 0 || e.has(t))) {
135
+ e.add(t);
136
+ for (const n of t.getDeclarations())
137
+ if (i.isVariableDeclaration(n) || i.isPropertyDeclaration(n) || i.isParameterDeclaration(n) || i.isBindingElement(n) || i.isPropertyAssignment(n)) {
138
+ g(n.getInitializer(), e);
139
+ const r = n.getNameNode();
140
+ i.isIdentifier(r) && J(r, e);
141
+ } else (i.isFunctionDeclaration(n) || i.isMethodDeclaration(n) || i.isFunctionExpression(n) || i.isArrowFunction(n) || i.isGetAccessorDeclaration(n)) && F(n, e);
142
+ }
143
+ }
144
+ function g(t, e) {
145
+ if (t !== void 0)
146
+ if (i.isStringLiteral(t) || i.isNoSubstitutionTemplateLiteral(t))
147
+ w(t);
148
+ else if (i.isConditionalExpression(t))
149
+ g(t.getWhenTrue(), e), g(t.getWhenFalse(), e);
150
+ else if (i.isBinaryExpression(t)) {
151
+ const n = t.getOperatorToken().getKind();
152
+ (n === d.BarBarToken || n === d.QuestionQuestionToken) && (g(t.getLeft(), e), g(t.getRight(), e));
153
+ } else i.isParenthesizedExpression(t) || i.isAsExpression(t) || i.isSatisfiesExpression(t) || i.isTypeAssertion(t) || i.isNonNullExpression(t) || i.isAwaitExpression(t) ? g(t.getExpression(), e) : i.isArrayLiteralExpression(t) ? t.getElements().forEach((n) => {
154
+ i.isExpression(n) && g(n, e);
155
+ }) : i.isObjectLiteralExpression(t) ? t.getProperties().forEach((n) => {
156
+ i.isPropertyAssignment(n) ? g(n.getInitializer(), e) : i.isShorthandPropertyAssignment(n) ? h(n.getNameNode().getSymbol(), e) : i.isSpreadAssignment(n) && g(n.getExpression(), e);
157
+ }) : i.isCallExpression(t) ? h(t.getExpression().getSymbol(), e) : i.isElementAccessExpression(t) ? g(t.getExpression(), e) : (i.isIdentifier(t) || i.isPropertyAccessExpression(t)) && h(t.getSymbol(), e);
158
+ }
159
+ function K(t) {
160
+ const e = /* @__PURE__ */ new Map();
161
+ for (const n of t)
162
+ for (const r of n.getDescendantsOfKind(d.JsxAttribute)) {
163
+ const o = r.getFirstAncestor(
164
+ (u) => i.isJsxOpeningElement(u) || i.isJsxSelfClosingElement(u)
165
+ );
166
+ if (!i.isJsxOpeningElement(o) && !i.isJsxSelfClosingElement(o))
167
+ continue;
168
+ const a = o.getTagNameNode().getText(), s = r.getNameNode().getText(), c = e.get(a) ?? /* @__PURE__ */ new Map(), l = c.get(s) ?? [];
169
+ l.push(r), c.set(s, l), e.set(a, c);
170
+ }
171
+ return e;
172
+ }
173
+ function O(t) {
174
+ const e = /* @__PURE__ */ new Map();
175
+ for (const n of t)
176
+ for (const r of n.getDescendantsOfKind(d.InterfaceDeclaration))
177
+ if (r.getName() === "DeclareElements")
178
+ for (const o of r.getProperties()) {
179
+ const a = o.getNameNode(), s = o.getTypeNode()?.getText();
180
+ if (!i.isStringLiteral(a) || s === void 0)
181
+ continue;
182
+ const c = a.getLiteralValue(), l = e.get(c) ?? /* @__PURE__ */ new Set();
183
+ l.add(s), e.set(c, l);
184
+ }
185
+ return e;
186
+ }
187
+ function R(t, e, n) {
188
+ const r = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
189
+ for (const a of n)
190
+ for (const s of a.getDeclarations()) {
191
+ if (!i.isPropertyDeclaration(s))
192
+ continue;
193
+ const c = s.getFirstAncestorByKind(d.ClassDeclaration)?.getName();
194
+ if (c === void 0)
195
+ continue;
196
+ const l = s.getName(), u = `${c}.${l}`;
197
+ if (r.has(u))
198
+ continue;
199
+ r.add(u);
200
+ let m = o.get(c);
201
+ if (m === void 0) {
202
+ const b = new RegExp(`\\b${c}\\b`, "u");
203
+ m = [...e].filter(
204
+ ([, f]) => [...f].some((p) => b.test(p))
205
+ ).map(([f]) => f), o.set(c, m);
206
+ }
207
+ for (const b of m)
208
+ for (const f of t.get(b)?.get(l) ?? [])
209
+ E(f, n);
210
+ }
211
+ }
35
212
  const j = {
36
213
  meta: {
37
- needsTypeInformation: !1
214
+ needsTypeInformation: !0
38
215
  },
39
216
  run(t) {
40
- for (const n of t) {
217
+ for (const a of t) {
41
218
  var e = [];
42
219
  try {
43
- const o = g(e, k(n));
44
- for (const a of o.getCodemodFiles())
45
- p(a, {
46
- "@arcgis/toolkit/intl": {
47
- getElementLocale: { do: "rename", specifier: "@arcgis/toolkit/intl/dom" },
48
- startLocaleObserver: { do: "rename", specifier: "@arcgis/toolkit/intl/dom" },
49
- LocaleObserverResult: { do: "rename", specifier: "@arcgis/toolkit/intl/dom" }
50
- },
51
- "@arcgis/toolkit/dom": {
52
- slotChangeHasContent: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
53
- slotChangeGetTextContent: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
54
- slotChangeHasTextContent: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
55
- slotChangeHasAssignedNode: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
56
- slotChangeGetAssignedNodes: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
57
- slotChangeHasAssignedElement: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
58
- slotChangeGetAssignedElements: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
59
- getSlotAssignedElements: { do: "rename", specifier: "@arcgis/toolkit/dom/slots" },
60
- resolveReferenceElement: { do: "rename", specifier: "@arcgis/toolkit/dom/referenceElement" }
61
- }
62
- });
63
- } catch (s) {
64
- var i = s, r = !0;
220
+ const s = A(e, z(a));
221
+ const c = /* @__PURE__ */ new Set();
222
+ const l = s.getCodemodFiles();
223
+ const u = K(l);
224
+ for (const [m, b] of u)
225
+ if (m.startsWith("calcite-"))
226
+ for (const f of T)
227
+ for (const p of b.get(f) ?? [])
228
+ E(p, c);
229
+ R(u, O(l), c);
230
+ } catch (n) {
231
+ var r = n, o = !0;
65
232
  } finally {
66
- f(e, i, r);
233
+ y(e, r, o);
67
234
  }
68
235
  }
69
- C();
70
236
  }
71
237
  };
72
238
  export {
@@ -0,0 +1,260 @@
1
+ var P = (n, t) => (t = Symbol[n]) ? t : /* @__PURE__ */ Symbol.for("Symbol." + n), S = (n) => {
2
+ throw TypeError(n);
3
+ };
4
+ var $ = (n, t, i) => {
5
+ if (t != null) {
6
+ typeof t != "object" && typeof t != "function" && S("Object expected");
7
+ var r, a;
8
+ i && (r = t[P("asyncDispose")]), r === void 0 && (r = t[P("dispose")], i && (a = r)), typeof r != "function" && S("Object not disposable"), a && (r = function() {
9
+ try {
10
+ a.call(this);
11
+ } catch (o) {
12
+ return Promise.reject(o);
13
+ }
14
+ }), n.push([i, r, t]);
15
+ } else i && n.push([i]);
16
+ return t;
17
+ }, I = (n, t, i) => {
18
+ var r = typeof SuppressedError == "function" ? SuppressedError : function(e, s, c, l) {
19
+ return l = Error(c), l.name = "SuppressedError", l.error = e, l.suppressed = s, l;
20
+ }, a = (e) => t = i ? new r(e, t, "An error was suppressed during disposal") : (i = !0, e), o = (e) => {
21
+ for (; e = n.pop(); )
22
+ try {
23
+ var s = e[1] && e[1].call(e[2]);
24
+ if (e[0]) return Promise.resolve(s).then(o, (c) => (a(c), o()));
25
+ } catch (c) {
26
+ a(c);
27
+ }
28
+ if (i) throw t;
29
+ };
30
+ return o();
31
+ };
32
+ import { SyntaxKind as N, Node as m } from "ts-morph";
33
+ import { existsSync as C } from "node:fs";
34
+ import { readFile as F } from "node:fs/promises";
35
+ import { findPath as K } from "@arcgis/node-toolkit/file";
36
+ import { path as x } from "@arcgis/node-toolkit/path";
37
+ import { log as b } from "@arcgis/toolkit/log";
38
+ import { a as V } from "./log.js";
39
+ import { p as M } from "./actions.js";
40
+ import { c as O } from "./useProjectInstance.js";
41
+ import { c as R } from "./componentAudit.js";
42
+ const ie = {
43
+ meta: { needsTypeInformation: !0, needsFooter: !0 },
44
+ async run(n) {
45
+ const t = R();
46
+ for (const e of n) {
47
+ var i = [];
48
+ try {
49
+ const s = $(i, O(e));
50
+ for (const c of s.getCodemodFiles())
51
+ [".ts", ".tsx", ".mts", ".cts"].includes(c.getExtension()) && await s.tsMorph.forgetNodesCreatedInBlock(async () => {
52
+ await k(t, c);
53
+ });
54
+ } catch (r) {
55
+ var a = r, o = !0;
56
+ } finally {
57
+ I(i, a, o);
58
+ }
59
+ }
60
+ }
61
+ };
62
+ async function k(n, t) {
63
+ const i = [], r = /* @__PURE__ */ new Map(), a = [
64
+ ...t.getDescendantsOfKind(N.TypeReference),
65
+ ...t.getDescendantsOfKind(N.ExpressionWithTypeArguments),
66
+ ...t.getDescendantsOfKind(N.ImportType)
67
+ ];
68
+ for (const e of a) {
69
+ const s = w(e);
70
+ if (s === void 0)
71
+ continue;
72
+ const c = j(s.getSymbol());
73
+ if (c === void 0) {
74
+ /^(?:HTML.+Element(?:EventMap)?|(?:React|Preact|Lumina|Stencil).+|.+CustomEvent)$/u.test(s.getText()) && E(t, e, "Unresolved type; install dependencies and load the component declarations before migrating.");
75
+ continue;
76
+ }
77
+ if (!/^(?:HTML.+Element(?:EventMap)?|(?:React|Preact|Lumina|Stencil).+|.+CustomEvent)$/u.test(c.getName()))
78
+ continue;
79
+ let l = r.get(c);
80
+ if (!r.has(c)) {
81
+ const p = c.getDeclarations(), d = (await Promise.all(
82
+ p.map(async (u) => {
83
+ const f = await o(u.getSourceFile().getFilePath());
84
+ return B(c, f, u);
85
+ })
86
+ )).filter((u) => u !== void 0);
87
+ l = d.length === 1 && p.length === 1 ? d[0] : void 0, d.length > 0 && p.length > 1 && E(t, e, "Merged or ambiguous component type; migrate manually."), r.set(c, l);
88
+ }
89
+ if (l !== void 0) {
90
+ if (m.isHeritageClause(e.getParent()) && ["event", "events"].includes(l.family))
91
+ continue;
92
+ const p = { ...l, node: e };
93
+ if (p.family === "event" && (p.eventName = J(e, p.component), p.eventName === void 0)) {
94
+ E(t, e, `Cannot determine the event name. Use the component's ["eventName"] type manually.`);
95
+ continue;
96
+ }
97
+ i.push(p);
98
+ }
99
+ }
100
+ H(t, i);
101
+ async function o(e) {
102
+ const s = K("package.json", x.dirname(e));
103
+ if (s === void 0)
104
+ return [];
105
+ const c = x.join(x.dirname(s), "dist/types/react.d.ts");
106
+ return !C(c) || !(await F(c, "utf8")).includes("ToReactProps") ? [] : (await n(s))?.componentTypes ?? [];
107
+ }
108
+ await W(t, o);
109
+ }
110
+ function w(n) {
111
+ if (m.isTypeReference(n))
112
+ return n.getTypeName();
113
+ if (m.isExpressionWithTypeArguments(n))
114
+ return n.getExpression();
115
+ if (m.isImportTypeNode(n))
116
+ return n.getQualifier();
117
+ }
118
+ function j(n) {
119
+ const t = /* @__PURE__ */ new Set();
120
+ for (; n?.isAlias() && !t.has(n); )
121
+ t.add(n), n = n.getAliasedSymbol();
122
+ return n;
123
+ }
124
+ function B(n, t, i) {
125
+ if (!m.isInterfaceDeclaration(i) && !m.isTypeAliasDeclaration(i))
126
+ return;
127
+ const r = n.getName(), a = t.flatMap((o) => {
128
+ const e = o.pascalCaseName;
129
+ return [
130
+ [`HTML${e}Element`, "element"],
131
+ [`HTML${e}ElementEventMap`, "events"],
132
+ [`${e}CustomEvent`, "event"],
133
+ [`React${e}`, "react"],
134
+ [`Preact${e}`, "preact"],
135
+ [`Lumina${e}`, "lumina"],
136
+ [`Stencil${e}`, "stencil"]
137
+ ].filter(([c]) => c === r).map(([, c]) => ({ symbol: n, component: o, family: c }));
138
+ });
139
+ if (a.length === 1)
140
+ return a[0];
141
+ }
142
+ function J(n, t) {
143
+ const i = new Set(t.events?.map(({ name: p }) => p)), r = (p) => {
144
+ const g = p.getParentIfKind(N.PropertyAccessExpression);
145
+ g?.getNameNode() === p && (p = g);
146
+ for (const d of p.getAncestors()) {
147
+ if (m.isJsxAttribute(d)) {
148
+ const u = d.getInitializer();
149
+ if (!m.isJsxExpression(u) || u.getExpression() !== p)
150
+ continue;
151
+ const f = d.getNameNode().getText();
152
+ return [...i].find(
153
+ (y) => f === `on${y}` || f === `on${y[0].toUpperCase()}${y.slice(1)}`
154
+ );
155
+ }
156
+ if (m.isCallExpression(d)) {
157
+ const u = d.getExpression();
158
+ if (m.isPropertyAccessExpression(u) && ["addEventListener", "removeEventListener", "listen"].includes(u.getName())) {
159
+ const [f, y] = d.getArguments();
160
+ if (m.isStringLiteral(f) && y === p && i.has(f.getLiteralValue()))
161
+ return f.getLiteralValue();
162
+ }
163
+ }
164
+ }
165
+ }, a = n.getParentIfKind(N.CallExpression), o = a?.getExpression();
166
+ if (m.isPropertyAccessExpression(o) && o.getName() === "listen" && a?.getTypeArguments()[0] === n) {
167
+ const p = a.getArguments()[1];
168
+ return p === void 0 ? void 0 : r(p);
169
+ }
170
+ const e = n.getFirstAncestorByKind(N.Parameter), s = e?.getParent();
171
+ if (s === void 0 || !m.isArrowFunction(s) && !m.isFunctionDeclaration(s) && !m.isMethodDeclaration(s) || e?.getTypeNode() !== n || s.getParameters()[0] !== e)
172
+ return;
173
+ const c = r(s);
174
+ if (c !== void 0)
175
+ return c;
176
+ const l = m.isArrowFunction(s) ? (s.getParentIfKind(N.VariableDeclaration) ?? s.getParentIfKind(N.PropertyDeclaration) ?? s.getParentIfKind(N.PropertyAssignment))?.getNameNode() : s.getNameNode();
177
+ if (l !== void 0 && (m.isIdentifier(l) || m.isPrivateIdentifier(l))) {
178
+ const g = l.findReferencesAsNodes().map(r);
179
+ m.isMethodDeclaration(s) && g.push(
180
+ ...s.getDecorators().map((u) => {
181
+ const f = u.getCallExpression(), y = f?.getExpression().getSymbol()?.getDeclarations()[0];
182
+ if (!m.isImportSpecifier(y) || y.getName() !== "Listen" || y.getImportDeclaration().getModuleSpecifierValue() !== "@stencil/core")
183
+ return;
184
+ const h = f?.getArguments()[0];
185
+ return m.isStringLiteral(h) && i.has(h.getLiteralValue()) ? h.getLiteralValue() : void 0;
186
+ })
187
+ );
188
+ const d = new Set(g);
189
+ if (g.length > 0 && !d.has(void 0) && d.size === 1)
190
+ return g[0];
191
+ }
192
+ }
193
+ function H(n, t) {
194
+ const i = /* @__PURE__ */ new Set();
195
+ for (const r of t.toSorted((a, o) => o.node.getStart() - a.node.getStart())) {
196
+ const { node: a, component: o, family: e } = r;
197
+ if (a.wasForgotten())
198
+ continue;
199
+ const s = A(a);
200
+ s !== void 0 && i.add(s);
201
+ const c = a.getFirstAncestorByKind(N.Parameter), l = c?.getParent(), p = l?.getParentIfKind(N.JsxExpression)?.getParent(), g = c?.getTypeNode();
202
+ if (c !== void 0 && g !== void 0 && (a === g || a.getAncestors().includes(g)) && m.isArrowFunction(l) && m.isJsxAttribute(p) && (e === "event" || p.getNameNode().getText() === "ref" || o.events?.some(
203
+ ({ name: v }) => p.getNameNode().getText() === `on${v}` || p.getNameNode().getText() === `on${v[0].toUpperCase()}${v.slice(1)}`
204
+ ))) {
205
+ for (const v of [g, ...g.getDescendantsOfKind(N.TypeReference)]) {
206
+ const T = A(v);
207
+ T !== void 0 && i.add(T);
208
+ }
209
+ c.removeType();
210
+ continue;
211
+ }
212
+ const d = `${o.packageName}/${o.modulePath}`, f = {
213
+ [n.getImportDeclarations().find((v) => {
214
+ const T = v.getModuleSpecifierValue().replace(/\.js$/u, "");
215
+ return (T === d || T === `${d}/customElement`) && v.getNamedImports().some((L) => L.getName() === o.name);
216
+ })?.getModuleSpecifierValue() ?? d]: {
217
+ [o.name]: { do: "add", isTypeOnly: !0 }
218
+ }
219
+ };
220
+ ["react", "preact", "lumina", "stencil"].includes(e) && (f[`${o.packageName}/types/${e}`] = {
221
+ [`To${e[0].toUpperCase()}${e.slice(1)}Props`]: { do: "add", isTypeOnly: !0 }
222
+ });
223
+ const y = M(n, f).map(({ actualName: v }) => v), h = o.typeParameters?.some(({ default: v }) => v === void 0) ? `InstanceType<typeof ${y[0]}>` : y[0], D = e === "element" ? h : e === "events" ? `${h}["@eventTypes"]` : e === "event" ? `${h}[${JSON.stringify(r.eventName)}]` : `${y[1]}<${h}>`;
224
+ a.replaceWithText(D);
225
+ }
226
+ U(n, i);
227
+ }
228
+ function A(n) {
229
+ if (m.isImportTypeNode(n))
230
+ return;
231
+ let t = w(n);
232
+ for (; m.isQualifiedName(t) || m.isPropertyAccessExpression(t); )
233
+ t = m.isQualifiedName(t) ? t.getLeft() : t.getExpression();
234
+ return m.isIdentifier(t) ? t.getText() : void 0;
235
+ }
236
+ function U(n, t) {
237
+ const i = {};
238
+ for (const r of n.getImportDeclarations()) {
239
+ const a = r.getNamedImports().filter((e) => t.has(e.getAliasNode()?.getText() ?? e.getName())).map((e) => e.getName()), o = r.getNamespaceImport();
240
+ o !== void 0 && t.has(o.getText()) && a.push("*");
241
+ for (const e of a)
242
+ (i[r.getModuleSpecifierValue()] ??= {})[e] = { do: "remove", unusedOnly: !0 };
243
+ }
244
+ M(n, i);
245
+ }
246
+ async function W(n, t) {
247
+ for (const i of n.getImportDeclarations()) {
248
+ const r = i.getModuleSpecifierValue();
249
+ if (!r?.endsWith("/types/components"))
250
+ continue;
251
+ const a = r.slice(0, -17), o = i.getModuleSpecifierSourceFile();
252
+ (o === void 0 ? [] : await t(o.getFilePath())).length > 0 && i.setModuleSpecifier(`${a}/types/stencil`);
253
+ }
254
+ }
255
+ function E(n, t, i) {
256
+ b("warn", V(n), `${t.getText()}: ${i}`);
257
+ }
258
+ export {
259
+ ie as codemod
260
+ };