@eui/core 22.0.0-alpha.84 → 22.0.0-alpha.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/docs/changelog.html +93 -0
- package/docs/classes/ServiceResolver.html +722 -0
- package/docs/classes/TooltipImportCollector.html +524 -0
- package/docs/interfaces/AstLike.html +477 -0
- package/docs/interfaces/Edit-12.html +15 -15
- package/docs/interfaces/Edit-13.html +1 -1
- package/docs/interfaces/Edit-14.html +59 -8
- package/docs/interfaces/Edit-15.html +15 -15
- package/docs/interfaces/Edit-16.html +15 -15
- package/docs/interfaces/Edit-17.html +395 -0
- package/docs/interfaces/Edit-18.html +395 -0
- package/docs/interfaces/Edit-19.html +395 -0
- package/docs/interfaces/Edit-20.html +395 -0
- package/docs/interfaces/Edit-21.html +395 -0
- package/docs/interfaces/Edit-22.html +446 -0
- package/docs/interfaces/Edit-23.html +395 -0
- package/docs/interfaces/MigrateAllSchema.html +45 -0
- package/docs/interfaces/ProvisionResult.html +407 -0
- package/docs/interfaces/RefInfo.html +323 -0
- package/docs/interfaces/Refs-1.html +443 -0
- package/docs/interfaces/Refs.html +413 -0
- package/docs/interfaces/RewriteResult.html +356 -0
- package/docs/interfaces/Schema-19.html +1 -1
- package/docs/interfaces/Schema-20.html +1 -1
- package/docs/interfaces/Schema-21.html +1 -1
- package/docs/interfaces/Schema-22.html +1 -1
- package/docs/interfaces/Schema-23.html +1 -1
- package/docs/interfaces/Schema-24.html +1 -1
- package/docs/interfaces/Schema-25.html +46 -1
- package/docs/interfaces/Schema-26.html +20 -1
- package/docs/interfaces/Schema-27.html +1 -1
- package/docs/interfaces/Schema-28.html +1 -1
- package/docs/interfaces/Schema-29.html +1 -1
- package/docs/interfaces/Schema-30.html +1 -1
- package/docs/interfaces/Schema-31.html +1 -1
- package/docs/interfaces/Schema-32.html +1 -1
- package/docs/interfaces/Schema-33.html +1 -1
- package/docs/interfaces/Schema-34.html +11 -1
- package/docs/interfaces/Schema-35.html +1 -1
- package/docs/interfaces/Schema-36.html +1 -1
- package/docs/interfaces/Schema-37.html +1 -1
- package/docs/interfaces/Schema-38.html +368 -0
- package/docs/interfaces/Schema-39.html +368 -0
- package/docs/interfaces/Schema-40.html +368 -0
- package/docs/interfaces/Schema-41.html +380 -0
- package/docs/interfaces/Schema-42.html +368 -0
- package/docs/interfaces/Schema-43.html +368 -0
- package/docs/interfaces/TemplateScan.html +373 -0
- package/docs/interfaces/TextChange-1.html +395 -0
- package/docs/interfaces/TextChange.html +1 -1
- package/docs/interfaces/TrackedComponent.html +652 -0
- package/docs/interfaces/TsEnv.html +395 -0
- package/docs/js/menu-wc.js +75 -0
- package/docs/js/search/search_index.js +2 -2
- package/docs/json/documentation.json +30449 -11805
- package/docs/llms.txt +767 -14
- package/docs/miscellaneous/functions.html +17262 -5225
- package/docs/miscellaneous/typealiases.html +182 -0
- package/docs/miscellaneous/variables.html +6059 -2907
- package/docs/overview.html +2 -2
- package/docs/properties.html +1 -1
- package/fesm2022/eui-core.mjs +106 -113
- package/fesm2022/eui-core.mjs.map +1 -1
- package/migrations.json +46 -4
- package/package.json +2 -3
- package/schematics/collection.json +47 -9
- package/schematics/migrate-all/index.d.ts +1 -0
- package/schematics/migrate-all/index.js +7 -1
- package/schematics/migrate-all/index.js.map +1 -1
- package/schematics/migrate-all/schema.json +6 -0
- package/schematics/migrate-eui-autocomplete/index.d.ts +7 -0
- package/schematics/migrate-eui-autocomplete/index.js +552 -0
- package/schematics/migrate-eui-autocomplete/index.js.map +1 -0
- package/schematics/migrate-eui-autocomplete/schema.json +19 -0
- package/schematics/migrate-eui-chip/index.js +15 -1
- package/schematics/migrate-eui-chip/index.js.map +1 -1
- package/schematics/migrate-eui-chip/schema.json +1 -1
- package/schematics/migrate-eui-date-range-selector/index.d.ts +8 -1
- package/schematics/migrate-eui-date-range-selector/index.js +32 -2
- package/schematics/migrate-eui-date-range-selector/index.js.map +1 -1
- package/schematics/migrate-eui-datepicker/adapter-provision.d.ts +16 -0
- package/schematics/migrate-eui-datepicker/adapter-provision.js +278 -0
- package/schematics/migrate-eui-datepicker/adapter-provision.js.map +1 -0
- package/schematics/migrate-eui-datepicker/component-refs.d.ts +51 -0
- package/schematics/migrate-eui-datepicker/component-refs.js +552 -0
- package/schematics/migrate-eui-datepicker/component-refs.js.map +1 -0
- package/schematics/migrate-eui-datepicker/formats.d.ts +8 -0
- package/schematics/migrate-eui-datepicker/formats.js +73 -0
- package/schematics/migrate-eui-datepicker/formats.js.map +1 -0
- package/schematics/migrate-eui-datepicker/index.d.ts +7 -3
- package/schematics/migrate-eui-datepicker/index.js +76 -56
- package/schematics/migrate-eui-datepicker/index.js.map +1 -1
- package/schematics/migrate-eui-datepicker/schema.json +6 -0
- package/schematics/migrate-eui-dialog/index.d.ts +23 -0
- package/schematics/migrate-eui-dialog/index.js +401 -0
- package/schematics/migrate-eui-dialog/index.js.map +1 -0
- package/schematics/migrate-eui-dialog/schema.json +19 -0
- package/schematics/migrate-eui-popover/index.js +44 -8
- package/schematics/migrate-eui-popover/index.js.map +1 -1
- package/schematics/migrate-eui-popover/signals.d.ts +13 -0
- package/schematics/migrate-eui-popover/signals.js +430 -0
- package/schematics/migrate-eui-popover/signals.js.map +1 -0
- package/schematics/migrate-eui-slider/index.d.ts +13 -0
- package/schematics/migrate-eui-slider/index.js +410 -0
- package/schematics/migrate-eui-slider/index.js.map +1 -0
- package/schematics/migrate-eui-slider/schema.json +19 -0
- package/schematics/migrate-eui-tab-signals/index.d.ts +7 -0
- package/schematics/migrate-eui-tab-signals/index.js +382 -0
- package/schematics/migrate-eui-tab-signals/index.js.map +1 -0
- package/schematics/migrate-eui-tab-signals/schema.json +19 -0
- package/schematics/migrate-eui-timepicker/index.d.ts +19 -0
- package/schematics/migrate-eui-timepicker/index.js +38 -0
- package/schematics/migrate-eui-timepicker/index.js.map +1 -0
- package/schematics/migrate-eui-timepicker/schema.json +19 -0
- package/schematics/migrate-eui-tooltip/index.js +270 -8
- package/schematics/migrate-eui-tooltip/index.js.map +1 -1
- package/schematics/migrate-ngx-translate-18/index.d.ts +16 -0
- package/schematics/migrate-ngx-translate-18/index.js +970 -0
- package/schematics/migrate-ngx-translate-18/index.js.map +1 -0
- package/schematics/migrate-ngx-translate-18/schema.json +19 -0
- package/schematics/migrate-to-signals/index.js +402 -59
- package/schematics/migrate-to-signals/index.js.map +1 -1
- package/schematics/migrate-to-signals/signal-map.d.ts +20 -0
- package/schematics/migrate-to-signals/signal-map.js +182 -3
- package/schematics/migrate-to-signals/signal-map.js.map +1 -1
- package/schematics/utils/tooltip-message.d.ts +32 -0
- package/schematics/utils/tooltip-message.js +256 -0
- package/schematics/utils/tooltip-message.js.map +1 -0
- package/types/eui-core.d.ts +7 -0
- package/types/eui-core.d.ts.map +1 -1
|
@@ -47,6 +47,21 @@ const ecl_signal_map_1 = require("./ecl-signal-map");
|
|
|
47
47
|
*/
|
|
48
48
|
const EUI_SIGNAL_MAP = { ...signal_map_1.EUI_SIGNAL_MAP, ...ecl_signal_map_1.ECL_SIGNAL_MAP };
|
|
49
49
|
const EUI_SELECTOR_TO_CLASS = { ...signal_map_1.EUI_SELECTOR_TO_CLASS, ...ecl_signal_map_1.ECL_SELECTOR_TO_CLASS };
|
|
50
|
+
/** Every class the schematic knows about (signals, outputs or removed host bindings). */
|
|
51
|
+
const KNOWN_CLASSES = new Set([
|
|
52
|
+
...Object.keys(EUI_SIGNAL_MAP),
|
|
53
|
+
...Object.keys(signal_map_1.EUI_OUTPUT_MAP),
|
|
54
|
+
...Object.keys(signal_map_1.EUI_HOST_BINDING_REMOVED_MAP),
|
|
55
|
+
]);
|
|
56
|
+
const isKnownClass = (name) => !!name && KNOWN_CLASSES.has(name);
|
|
57
|
+
/** rxjs functions that take Observables as (possibly array-wrapped) arguments. */
|
|
58
|
+
const OBSERVABLE_COMBINATORS = new Set([
|
|
59
|
+
'merge', 'race', 'combineLatest', 'forkJoin', 'concat', 'zip', 'firstValueFrom', 'lastValueFrom', 'raceWith', 'mergeWith', 'concatWith', 'zipWith', 'combineLatestWith',
|
|
60
|
+
]);
|
|
61
|
+
/** Observable methods that need a real Observable instead of an OutputEmitterRef. */
|
|
62
|
+
const OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);
|
|
63
|
+
/** QueryList iteration methods whose callback parameter is an element of the list. */
|
|
64
|
+
const LIST_ITERATION_METHODS = new Set(['forEach', 'map', 'filter', 'some', 'every', 'find', 'findIndex', 'reduce']);
|
|
50
65
|
/**
|
|
51
66
|
* Migrates consumer code that accesses EUI or ECL component instances
|
|
52
67
|
* programmatically.
|
|
@@ -115,7 +130,7 @@ function migrateToSignals(options = {}) {
|
|
|
115
130
|
}
|
|
116
131
|
/** Quick check: does the file reference any EUI class name from the signal map? */
|
|
117
132
|
function hasEuiReference(source) {
|
|
118
|
-
for (const className of
|
|
133
|
+
for (const className of KNOWN_CLASSES) {
|
|
119
134
|
if (source.includes(className))
|
|
120
135
|
return true;
|
|
121
136
|
}
|
|
@@ -133,9 +148,11 @@ function migrateTypeScript(source, filePath, tree, context) {
|
|
|
133
148
|
const templateRefMap = buildTemplateRefMap(sourceFile, source, filePath, tree);
|
|
134
149
|
// Phase 1: Collect all variables/properties typed as EUI classes
|
|
135
150
|
const euiRefs = collectEuiReferences(sourceFile, source, templateRefMap);
|
|
136
|
-
if (euiRefs.size === 0) {
|
|
151
|
+
if (euiRefs.props.size === 0 && euiRefs.propLists.size === 0 && euiRefs.decls.size === 0 && euiRefs.listDecls.size === 0) {
|
|
137
152
|
return { source, editCount: 0, todoCount: 0 };
|
|
138
153
|
}
|
|
154
|
+
const hostTodoEdits = [];
|
|
155
|
+
let needsOutputImport = false;
|
|
139
156
|
// Phase 2: Find property accesses on those references and rewrite signal props
|
|
140
157
|
const visitNode = (node) => {
|
|
141
158
|
// Match: ref.prop (PropertyAccessExpression)
|
|
@@ -144,6 +161,28 @@ function migrateTypeScript(source, filePath, tree, context) {
|
|
|
144
161
|
if (rewrite) {
|
|
145
162
|
edits.push(rewrite);
|
|
146
163
|
}
|
|
164
|
+
// Writable signal (model()): `ref.prop = value` -> `ref.prop.set(value)`
|
|
165
|
+
edits.push(...trySetRewrite(node, euiRefs, sourceFile));
|
|
166
|
+
// Output: `ref.out.subscribe()` -> `outputToObservable(ref.out).subscribe()`
|
|
167
|
+
const wrap = tryWrapOutput(node, euiRefs, sourceFile);
|
|
168
|
+
if (wrap) {
|
|
169
|
+
edits.push(...wrap);
|
|
170
|
+
needsOutputImport = true;
|
|
171
|
+
}
|
|
172
|
+
// Output handed to rxjs combinators / used as a value: wrap or flag
|
|
173
|
+
const outputUse = tryOutputUsage(node, euiRefs, sourceFile, source);
|
|
174
|
+
if (outputUse) {
|
|
175
|
+
edits.push(...outputUse.edits);
|
|
176
|
+
if (outputUse.todo)
|
|
177
|
+
hostTodoEdits.push(outputUse.todo);
|
|
178
|
+
if (outputUse.edits.length > 0)
|
|
179
|
+
needsOutputImport = true;
|
|
180
|
+
}
|
|
181
|
+
// Removed @HostBinding property: flag with a TODO
|
|
182
|
+
const hostTodo = tryHostBindingTodo(node, euiRefs, sourceFile, source);
|
|
183
|
+
if (hostTodo) {
|
|
184
|
+
hostTodoEdits.push(hostTodo);
|
|
185
|
+
}
|
|
147
186
|
// Separately: a programmatic WRITE to a now-signal input cannot be
|
|
148
187
|
// migrated automatically. Flag it with a TODO instead of silently
|
|
149
188
|
// leaving a line that will fail to compile against the signal API.
|
|
@@ -152,22 +191,29 @@ function migrateTypeScript(source, filePath, tree, context) {
|
|
|
152
191
|
todoEdits.push(todo);
|
|
153
192
|
}
|
|
154
193
|
}
|
|
194
|
+
// Destructuring / aliasing of a tracked reference cannot be followed: flag it.
|
|
195
|
+
const alias = tryAliasTodo(node, euiRefs, sourceFile, source);
|
|
196
|
+
if (alias)
|
|
197
|
+
hostTodoEdits.push(alias);
|
|
155
198
|
ts.forEachChild(node, visitNode);
|
|
156
199
|
};
|
|
157
200
|
ts.forEachChild(sourceFile, visitNode);
|
|
158
|
-
if (edits.length === 0 && todoEdits.length === 0) {
|
|
201
|
+
if (edits.length === 0 && todoEdits.length === 0 && hostTodoEdits.length === 0) {
|
|
159
202
|
return { source, editCount: 0, todoCount: 0 };
|
|
160
203
|
}
|
|
161
204
|
const dedupedTodos = deduplicateEdits(todoEdits);
|
|
205
|
+
const dedupedHostTodos = deduplicateEdits(hostTodoEdits);
|
|
162
206
|
// A TODO edit comments out the whole write statement. Any read-rewrite `()`
|
|
163
207
|
// edit whose position falls inside that commented-out range must be dropped,
|
|
164
208
|
// otherwise we'd both edit and comment the same text (and produce overlapping
|
|
165
209
|
// edits that corrupt the output).
|
|
166
210
|
const keptEdits = edits.filter((edit) => !isInsideAnyRange(edit, dedupedTodos));
|
|
211
|
+
const keptHostTodos = dedupedHostTodos.filter((edit) => !isInsideAnyRange(edit, dedupedTodos));
|
|
212
|
+
const importEdit = needsOutputImport ? buildOutputImportEdit(sourceFile) : null;
|
|
167
213
|
return {
|
|
168
|
-
source: applyEdits(source, [...keptEdits, ...dedupedTodos]),
|
|
214
|
+
source: applyEdits(source, [...keptEdits, ...dedupedTodos, ...keptHostTodos, ...(importEdit ? [importEdit] : [])]),
|
|
169
215
|
editCount: keptEdits.length,
|
|
170
|
-
todoCount: dedupedTodos.length,
|
|
216
|
+
todoCount: dedupedTodos.length + keptHostTodos.length,
|
|
171
217
|
};
|
|
172
218
|
}
|
|
173
219
|
/**
|
|
@@ -184,51 +230,151 @@ function migrateTypeScript(source, filePath, tree, context) {
|
|
|
184
230
|
* const alias = this.viewChildRef; (alias tracking)
|
|
185
231
|
*/
|
|
186
232
|
function collectEuiReferences(sourceFile, source, templateRefMap) {
|
|
187
|
-
const
|
|
233
|
+
const tracked = { props: new Map(), propLists: new Map(), decls: new Map(), listDecls: new Map() };
|
|
234
|
+
const { props, propLists, decls, listDecls } = tracked;
|
|
188
235
|
// Pass 1: collect directly-typed references
|
|
189
236
|
const visitDirect = (node) => {
|
|
190
237
|
// Class property declarations
|
|
191
238
|
if (ts.isPropertyDeclaration(node) && node.name && ts.isIdentifier(node.name)) {
|
|
192
239
|
const euiClass = resolveEuiClassName(node, sourceFile, templateRefMap);
|
|
193
|
-
if (euiClass
|
|
194
|
-
|
|
240
|
+
if (isKnownClass(euiClass)) {
|
|
241
|
+
(isListProperty(node) ? propLists : props).set(node.name.text, euiClass);
|
|
195
242
|
}
|
|
196
243
|
}
|
|
197
|
-
// Variable
|
|
198
|
-
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
244
|
+
// Variable (const x: EuiXxxComponent = ...) and parameter (method(ref: EuiXxxComponent)) declarations
|
|
245
|
+
if ((ts.isVariableDeclaration(node) || ts.isParameter(node)) && ts.isIdentifier(node.name)) {
|
|
199
246
|
const typeName = getTypeAnnotationName(node.type);
|
|
200
|
-
if (typeName
|
|
201
|
-
|
|
247
|
+
if (isKnownClass(typeName)) {
|
|
248
|
+
decls.set(node, typeName);
|
|
249
|
+
// constructor parameter property: also reachable as `this.name`
|
|
250
|
+
if (ts.isParameter(node) && (ts.getModifiers?.(node) ?? []).length > 0)
|
|
251
|
+
props.set(node.name.text, typeName);
|
|
202
252
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (typeName && EUI_SIGNAL_MAP[typeName]) {
|
|
208
|
-
refs.set(node.name.text, EUI_SIGNAL_MAP[typeName]);
|
|
253
|
+
else {
|
|
254
|
+
const listClass = listElementClass(node.type);
|
|
255
|
+
if (listClass)
|
|
256
|
+
listDecls.set(node, listClass);
|
|
209
257
|
}
|
|
210
258
|
}
|
|
211
259
|
ts.forEachChild(node, visitDirect);
|
|
212
260
|
};
|
|
213
261
|
ts.forEachChild(sourceFile, visitDirect);
|
|
214
|
-
// Pass 2:
|
|
215
|
-
// e.g. const alias = this.viewChildRef; or const alias = someParam;
|
|
262
|
+
// Pass 2: aliases, QueryList/array iteration (source order)
|
|
216
263
|
const visitAlias = (node) => {
|
|
217
|
-
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
|
|
218
|
-
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
264
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && !decls.has(node)) {
|
|
265
|
+
const aliased = trackedClass(node.initializer, tracked);
|
|
266
|
+
if (aliased)
|
|
267
|
+
decls.set(node, aliased);
|
|
268
|
+
const aliasedList = listClassOf(node.initializer, tracked);
|
|
269
|
+
if (aliasedList)
|
|
270
|
+
listDecls.set(node, aliasedList);
|
|
271
|
+
}
|
|
272
|
+
// list.forEach((el) => ...) / list.map(function (el) {...}) -> `el` is an element of the list
|
|
273
|
+
if (ts.isCallExpression(node) &&
|
|
274
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
275
|
+
LIST_ITERATION_METHODS.has(node.expression.name.text)) {
|
|
276
|
+
const listClass = listClassOf(node.expression.expression, tracked);
|
|
277
|
+
const callback = node.arguments[0];
|
|
278
|
+
if (listClass &&
|
|
279
|
+
callback &&
|
|
280
|
+
(ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) &&
|
|
281
|
+
callback.parameters[0] &&
|
|
282
|
+
ts.isIdentifier(callback.parameters[0].name) &&
|
|
283
|
+
!callback.parameters[0].type) {
|
|
284
|
+
decls.set(callback.parameters[0], listClass);
|
|
226
285
|
}
|
|
227
286
|
}
|
|
287
|
+
// for (const el of list) -> `el` is an element of the list
|
|
288
|
+
if (ts.isForOfStatement(node) && ts.isVariableDeclarationList(node.initializer)) {
|
|
289
|
+
const listClass = listClassOf(node.expression, tracked);
|
|
290
|
+
const decl = node.initializer.declarations[0];
|
|
291
|
+
if (listClass && decl && ts.isIdentifier(decl.name) && !decls.has(decl))
|
|
292
|
+
decls.set(decl, listClass);
|
|
293
|
+
}
|
|
228
294
|
ts.forEachChild(node, visitAlias);
|
|
229
295
|
};
|
|
230
296
|
ts.forEachChild(sourceFile, visitAlias);
|
|
231
|
-
return
|
|
297
|
+
return tracked;
|
|
298
|
+
}
|
|
299
|
+
/** `EuiXxx[]`, `Array<EuiXxx>`, `QueryList<EuiXxx>` -> the known element class. */
|
|
300
|
+
function listElementClass(type) {
|
|
301
|
+
if (!type)
|
|
302
|
+
return null;
|
|
303
|
+
if (ts.isArrayTypeNode(type)) {
|
|
304
|
+
const n = getTypeAnnotationName(type.elementType);
|
|
305
|
+
return isKnownClass(n) ? n : null;
|
|
306
|
+
}
|
|
307
|
+
if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName) && ['Array', 'ReadonlyArray', 'QueryList'].includes(type.typeName.text)) {
|
|
308
|
+
const n = getTypeAnnotationName(type.typeArguments?.[0]);
|
|
309
|
+
return isKnownClass(n) ? n : null;
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
/** Strips parentheses, `!`, `as T`, `<T>x` and `satisfies`. */
|
|
314
|
+
function unwrap(expr) {
|
|
315
|
+
let cur = expr;
|
|
316
|
+
while (ts.isParenthesizedExpression(cur) ||
|
|
317
|
+
ts.isNonNullExpression(cur) ||
|
|
318
|
+
ts.isAsExpression(cur) ||
|
|
319
|
+
ts.isTypeAssertionExpression(cur) ||
|
|
320
|
+
ts.isSatisfiesExpression(cur)) {
|
|
321
|
+
cur = cur.expression;
|
|
322
|
+
}
|
|
323
|
+
return cur;
|
|
324
|
+
}
|
|
325
|
+
/** Nearest declaration (parameter / variable / binding element) of a bare identifier, or null. */
|
|
326
|
+
function findDeclaration(id) {
|
|
327
|
+
const name = id.text;
|
|
328
|
+
const boundIn = (bn) => ts.isIdentifier(bn) ? bn.text === name : bn.elements.some((e) => !ts.isOmittedExpression(e) && boundIn(e.name));
|
|
329
|
+
const matchDecl = (d) => (boundIn(d.name) ? d : null);
|
|
330
|
+
for (let cur = id.parent; cur; cur = cur.parent) {
|
|
331
|
+
if (ts.isFunctionLike(cur)) {
|
|
332
|
+
for (const p of cur.parameters) {
|
|
333
|
+
const m = matchDecl(p);
|
|
334
|
+
if (m)
|
|
335
|
+
return m;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (ts.isBlock(cur) || ts.isSourceFile(cur) || ts.isModuleBlock(cur) || ts.isCaseClause(cur) || ts.isDefaultClause(cur)) {
|
|
339
|
+
const stmts = ts.isCaseClause(cur) || ts.isDefaultClause(cur) ? cur.statements : cur.statements;
|
|
340
|
+
for (const st of stmts) {
|
|
341
|
+
if (ts.isVariableStatement(st)) {
|
|
342
|
+
for (const d of st.declarationList.declarations) {
|
|
343
|
+
const m = matchDecl(d);
|
|
344
|
+
if (m)
|
|
345
|
+
return m;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if ((ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) && cur.initializer && ts.isVariableDeclarationList(cur.initializer)) {
|
|
351
|
+
for (const d of cur.initializer.declarations) {
|
|
352
|
+
const m = matchDecl(d);
|
|
353
|
+
if (m)
|
|
354
|
+
return m;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (ts.isCatchClause(cur) && cur.variableDeclaration) {
|
|
358
|
+
const m = matchDecl(cur.variableDeclaration);
|
|
359
|
+
if (m)
|
|
360
|
+
return m;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
/** `this.name` -> name; anything else null. */
|
|
366
|
+
function thisMemberName(expr) {
|
|
367
|
+
return ts.isPropertyAccessExpression(expr) && expr.expression.kind === ts.SyntaxKind.ThisKeyword ? expr.name.text : null;
|
|
368
|
+
}
|
|
369
|
+
/** Element class of a tracked QueryList / array expression, or null. */
|
|
370
|
+
function listClassOf(expr, tracked) {
|
|
371
|
+
const e = unwrap(expr);
|
|
372
|
+
if (ts.isIdentifier(e)) {
|
|
373
|
+
const d = findDeclaration(e);
|
|
374
|
+
return d ? (tracked.listDecls.get(d) ?? null) : null;
|
|
375
|
+
}
|
|
376
|
+
const member = thisMemberName(e);
|
|
377
|
+
return member ? (tracked.propLists.get(member) ?? null) : null;
|
|
232
378
|
}
|
|
233
379
|
/**
|
|
234
380
|
* Resolves the EUI class name from a property declaration.
|
|
@@ -237,13 +383,16 @@ function collectEuiReferences(sourceFile, source, templateRefMap) {
|
|
|
237
383
|
function resolveEuiClassName(node, sourceFile, templateRefMap) {
|
|
238
384
|
// Check type annotation first
|
|
239
385
|
const typeName = getTypeAnnotationName(node.type);
|
|
240
|
-
if (typeName
|
|
386
|
+
if (isKnownClass(typeName)) {
|
|
241
387
|
return typeName;
|
|
242
388
|
}
|
|
243
|
-
|
|
389
|
+
const arrayClass = listElementClass(node.type);
|
|
390
|
+
if (arrayClass)
|
|
391
|
+
return arrayClass;
|
|
392
|
+
// Check generic type argument: ElementRef<EuiXxxComponent> / QueryList<EuiXxxComponent>
|
|
244
393
|
if (node.type && ts.isTypeReferenceNode(node.type) && node.type.typeArguments?.length) {
|
|
245
394
|
const genericArg = getTypeAnnotationName(node.type.typeArguments[0]);
|
|
246
|
-
if (genericArg
|
|
395
|
+
if (isKnownClass(genericArg)) {
|
|
247
396
|
return genericArg;
|
|
248
397
|
}
|
|
249
398
|
}
|
|
@@ -263,14 +412,14 @@ function resolveEuiClassName(node, sourceFile, templateRefMap) {
|
|
|
263
412
|
if (args.length > 0) {
|
|
264
413
|
const firstArg = args[0];
|
|
265
414
|
// @ViewChild(EuiXxxComponent) — class reference
|
|
266
|
-
if (ts.isIdentifier(firstArg) &&
|
|
415
|
+
if (ts.isIdentifier(firstArg) && isKnownClass(firstArg.text)) {
|
|
267
416
|
return firstArg.text;
|
|
268
417
|
}
|
|
269
418
|
// @ViewChild('refName') — string template ref, resolve via template
|
|
270
419
|
if (ts.isStringLiteralLike(firstArg)) {
|
|
271
420
|
const refName = firstArg.text;
|
|
272
421
|
const euiClass = templateRefMap.get(refName);
|
|
273
|
-
if (euiClass
|
|
422
|
+
if (isKnownClass(euiClass)) {
|
|
274
423
|
return euiClass;
|
|
275
424
|
}
|
|
276
425
|
}
|
|
@@ -279,6 +428,35 @@ function resolveEuiClassName(node, sourceFile, templateRefMap) {
|
|
|
279
428
|
}
|
|
280
429
|
return null;
|
|
281
430
|
}
|
|
431
|
+
/** True for `@ViewChildren/@ContentChildren` fields and `QueryList<...>`-typed fields. */
|
|
432
|
+
function isListProperty(node) {
|
|
433
|
+
if (listElementClass(node.type))
|
|
434
|
+
return true;
|
|
435
|
+
if (node.type && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === 'QueryList') {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return (ts.getDecorators?.(node) ?? []).some((d) => ts.isCallExpression(d.expression) && ['ViewChildren', 'ContentChildren'].includes(getDecoratorName(d.expression) ?? ''));
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Resolves an expression to the tracked EUI class: `ref`, `this.ref`, `this.ref!`, `(this.ref as any)`,
|
|
442
|
+
* the `.first` / `.last` element of a tracked QueryList, or `list[i]` of a tracked list/array.
|
|
443
|
+
*/
|
|
444
|
+
function trackedClass(expr, tracked) {
|
|
445
|
+
const e = unwrap(expr);
|
|
446
|
+
if (ts.isIdentifier(e)) {
|
|
447
|
+
const d = findDeclaration(e);
|
|
448
|
+
return d ? (tracked.decls.get(d) ?? null) : null;
|
|
449
|
+
}
|
|
450
|
+
const member = thisMemberName(e);
|
|
451
|
+
if (member)
|
|
452
|
+
return tracked.props.get(member) ?? null;
|
|
453
|
+
if (ts.isPropertyAccessExpression(e) && (e.name.text === 'first' || e.name.text === 'last')) {
|
|
454
|
+
return listClassOf(e.expression, tracked);
|
|
455
|
+
}
|
|
456
|
+
if (ts.isElementAccessExpression(e))
|
|
457
|
+
return listClassOf(e.expression, tracked);
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
282
460
|
function getDecoratorName(callExpr) {
|
|
283
461
|
if (ts.isIdentifier(callExpr.expression)) {
|
|
284
462
|
return callExpr.expression.text;
|
|
@@ -305,17 +483,27 @@ function getTypeAnnotationName(typeNode) {
|
|
|
305
483
|
*/
|
|
306
484
|
function tryRewritePropertyAccess(node, euiRefs, sourceFile, source) {
|
|
307
485
|
const propName = node.name.text;
|
|
308
|
-
// Resolve the reference
|
|
309
|
-
const
|
|
310
|
-
if (!
|
|
486
|
+
// Resolve the reference class — handle `this.ref.prop`, `ref.prop`, `list.first.prop`
|
|
487
|
+
const cls = trackedClass(node.expression, euiRefs);
|
|
488
|
+
if (!cls)
|
|
311
489
|
return null;
|
|
312
|
-
const signalProps =
|
|
490
|
+
const signalProps = EUI_SIGNAL_MAP[cls];
|
|
313
491
|
if (!signalProps || !signalProps.has(propName))
|
|
314
492
|
return null;
|
|
315
493
|
// Skip if parent is already a call expression on this property: ref.prop(...)
|
|
316
494
|
if (ts.isCallExpression(node.parent) && node.parent.expression === node) {
|
|
317
495
|
return null;
|
|
318
496
|
}
|
|
497
|
+
// Skip a signal handed to toObservable(ref.prop): it needs the signal itself (e.g. written by migrate-eui-tab-signals)
|
|
498
|
+
if (ts.isCallExpression(node.parent) && node.parent.arguments[0] === node &&
|
|
499
|
+
ts.isIdentifier(node.parent.expression) && node.parent.expression.text === 'toObservable') {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
// Skip signal API access already in place: ref.prop.set(..) / .update(..) / .asReadonly()
|
|
503
|
+
if (ts.isPropertyAccessExpression(node.parent) && node.parent.expression === node &&
|
|
504
|
+
['set', 'update', 'asReadonly'].includes(node.parent.name.text)) {
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
319
507
|
// Skip if this is the left side of an assignment: ref.prop = value
|
|
320
508
|
if (ts.isBinaryExpression(node.parent) &&
|
|
321
509
|
node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
@@ -375,10 +563,10 @@ const WRITE_TODO_MARKER = 'TODO(eui-signals):';
|
|
|
375
563
|
*/
|
|
376
564
|
function tryInsertWriteTodo(node, euiRefs, sourceFile, source) {
|
|
377
565
|
const propName = node.name.text;
|
|
378
|
-
const
|
|
379
|
-
if (!
|
|
566
|
+
const cls = trackedClass(node.expression, euiRefs);
|
|
567
|
+
if (!cls)
|
|
380
568
|
return null;
|
|
381
|
-
const signalProps =
|
|
569
|
+
const signalProps = EUI_SIGNAL_MAP[cls];
|
|
382
570
|
if (!signalProps || !signalProps.has(propName))
|
|
383
571
|
return null;
|
|
384
572
|
// Only act on assignment targets: `ref.prop = ...` or `ref.prop <op>= ...`
|
|
@@ -388,6 +576,10 @@ function tryInsertWriteTodo(node, euiRefs, sourceFile, source) {
|
|
|
388
576
|
return null;
|
|
389
577
|
}
|
|
390
578
|
const assignment = node.parent;
|
|
579
|
+
// A plain `=` to a writable signal is migrated to `.set()` by trySetRewrite
|
|
580
|
+
if (assignment.operatorToken.kind === ts.SyntaxKind.EqualsToken && signal_map_1.EUI_WRITABLE_SIGNAL_MAP[cls]?.has(propName)) {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
391
583
|
// Only comment out when the assignment IS the whole statement — otherwise we'd
|
|
392
584
|
// delete unrelated logic from a larger statement.
|
|
393
585
|
const statement = node.parent.parent;
|
|
@@ -406,6 +598,13 @@ function tryInsertWriteTodo(node, euiRefs, sourceFile, source) {
|
|
|
406
598
|
const stmtEnd = statement.getEnd(); // includes the trailing semicolon
|
|
407
599
|
const lineStart = getLineStartPosition(source, stmtStart);
|
|
408
600
|
const indent = source.slice(lineStart, stmtStart);
|
|
601
|
+
// Commenting works per line: the statement must be alone on its lines, otherwise
|
|
602
|
+
// (e.g. `run() { ref.prop = 1; }`) we would comment out surrounding code.
|
|
603
|
+
const eol = source.indexOf('\n', stmtEnd);
|
|
604
|
+
const restOfLine = source.slice(stmtEnd, eol === -1 ? source.length : eol);
|
|
605
|
+
if (indent.trim() !== '' || restOfLine.trim() !== '') {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
409
608
|
// The statement text, as written (may span multiple lines).
|
|
410
609
|
const statementText = source.slice(stmtStart, stmtEnd);
|
|
411
610
|
// Comment out every line of the statement, preserving each line's own
|
|
@@ -432,6 +631,164 @@ function tryInsertWriteTodo(node, euiRefs, sourceFile, source) {
|
|
|
432
631
|
replacement: todo + commentedStatement,
|
|
433
632
|
};
|
|
434
633
|
}
|
|
634
|
+
/** `ref.prop = value;` on a writable signal -> `ref.prop.set(value);` (two zero-width-safe edits). */
|
|
635
|
+
function trySetRewrite(node, euiRefs, sourceFile) {
|
|
636
|
+
const assignment = node.parent;
|
|
637
|
+
if (!ts.isBinaryExpression(assignment) ||
|
|
638
|
+
assignment.left !== node ||
|
|
639
|
+
assignment.operatorToken.kind !== ts.SyntaxKind.EqualsToken ||
|
|
640
|
+
!ts.isExpressionStatement(assignment.parent)) {
|
|
641
|
+
return [];
|
|
642
|
+
}
|
|
643
|
+
const cls = trackedClass(node.expression, euiRefs);
|
|
644
|
+
if (!cls || !signal_map_1.EUI_WRITABLE_SIGNAL_MAP[cls]?.has(node.name.text))
|
|
645
|
+
return [];
|
|
646
|
+
return [
|
|
647
|
+
{ start: node.getEnd(), end: assignment.right.getStart(sourceFile), replacement: '.set(' },
|
|
648
|
+
{ start: assignment.right.getEnd(), end: assignment.right.getEnd(), replacement: ')', after: true },
|
|
649
|
+
];
|
|
650
|
+
}
|
|
651
|
+
/** `ref.out.subscribe(...)` -> `outputToObservable(ref.out).subscribe(...)`. */
|
|
652
|
+
function tryWrapOutput(node, euiRefs, sourceFile) {
|
|
653
|
+
const parent = node.parent;
|
|
654
|
+
if (!ts.isPropertyAccessExpression(parent) || parent.expression !== node || !OBSERVABLE_METHODS.has(parent.name.text)) {
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
const cls = trackedClass(node.expression, euiRefs);
|
|
658
|
+
if (!cls || !signal_map_1.EUI_OUTPUT_MAP[cls]?.has(node.name.text))
|
|
659
|
+
return null;
|
|
660
|
+
const start = node.getStart(sourceFile);
|
|
661
|
+
return [
|
|
662
|
+
{ start, end: start, replacement: 'outputToObservable(' },
|
|
663
|
+
{ start: node.getEnd(), end: node.getEnd(), replacement: ')', after: true },
|
|
664
|
+
];
|
|
665
|
+
}
|
|
666
|
+
/** Marker for a read of a property that was a @HostBinding and no longer exists. */
|
|
667
|
+
const HOST_TODO_MARKER = 'TODO(eui-signals):';
|
|
668
|
+
function tryHostBindingTodo(node, euiRefs, sourceFile, source) {
|
|
669
|
+
const propName = node.name.text;
|
|
670
|
+
const cls = trackedClass(node.expression, euiRefs);
|
|
671
|
+
if (!cls || !signal_map_1.EUI_HOST_BINDING_REMOVED_MAP[cls]?.has(propName) || EUI_SIGNAL_MAP[cls]?.has(propName))
|
|
672
|
+
return null;
|
|
673
|
+
return flagTodo(node, sourceFile, source, `'${propName}' was a @HostBinding`, `'${propName}' was a @HostBinding property of ${cls} and no longer exists on the instance ` +
|
|
674
|
+
'(moved to static host metadata). Remove or replace this access.');
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Inserts a `// TODO(eui-signals): <message>` line above the enclosing statement / class member.
|
|
678
|
+
* `key` identifies the TODO for idempotency (looked for in the comment lines right above).
|
|
679
|
+
*/
|
|
680
|
+
function flagTodo(node, sourceFile, source, key, message) {
|
|
681
|
+
// Anchor on the enclosing statement / class member
|
|
682
|
+
let anchor = node;
|
|
683
|
+
while (anchor.parent &&
|
|
684
|
+
!(ts.isBlock(anchor.parent) ||
|
|
685
|
+
ts.isSourceFile(anchor.parent) ||
|
|
686
|
+
ts.isModuleBlock(anchor.parent) ||
|
|
687
|
+
ts.isCaseClause(anchor.parent) ||
|
|
688
|
+
ts.isDefaultClause(anchor.parent) ||
|
|
689
|
+
ts.isClassLike(anchor.parent))) {
|
|
690
|
+
anchor = anchor.parent;
|
|
691
|
+
}
|
|
692
|
+
const lineStart = getLineStartPosition(source, anchor.getStart(sourceFile));
|
|
693
|
+
const indent = source.slice(lineStart).match(/^[ \t]*/)[0];
|
|
694
|
+
const text = `${indent}// ${HOST_TODO_MARKER} ${message}\n`;
|
|
695
|
+
// Idempotent: look at the contiguous comment lines right above
|
|
696
|
+
const above = source.slice(0, lineStart).split('\n').slice(-8).reverse();
|
|
697
|
+
for (const line of above.slice(1)) {
|
|
698
|
+
if (!line.trim().startsWith('//'))
|
|
699
|
+
break;
|
|
700
|
+
if (line.includes(`${HOST_TODO_MARKER} ${key}`) || line.includes(key))
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
// A single-line anchor like `run() { ... }` shares its line with other code: still fine, the comment goes above the line.
|
|
704
|
+
return { start: lineStart, end: lineStart, replacement: text };
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* An output (OutputEmitterRef) used as a value:
|
|
708
|
+
* - an argument of an rxjs combinator (`merge(ref.out, ...)`, also inside an array) is wrapped in `outputToObservable()`;
|
|
709
|
+
* - any other use that is not `.emit()` / `.subscribe()` & co / already wrapped is flagged with a TODO.
|
|
710
|
+
*/
|
|
711
|
+
function tryOutputUsage(node, euiRefs, sourceFile, source) {
|
|
712
|
+
const cls = trackedClass(node.expression, euiRefs);
|
|
713
|
+
if (!cls || !signal_map_1.EUI_OUTPUT_MAP[cls]?.has(node.name.text))
|
|
714
|
+
return null;
|
|
715
|
+
const parent = node.parent;
|
|
716
|
+
// handled elsewhere (tryWrapOutput) or fine as is
|
|
717
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === node)
|
|
718
|
+
return null;
|
|
719
|
+
if (ts.isNonNullExpression(parent) || ts.isParenthesizedExpression(parent) || ts.isAsExpression(parent))
|
|
720
|
+
return null;
|
|
721
|
+
// declared / written outputs are not reads
|
|
722
|
+
if (ts.isBinaryExpression(parent) && parent.left === node)
|
|
723
|
+
return null;
|
|
724
|
+
// argument of a combinator?
|
|
725
|
+
let arg = node;
|
|
726
|
+
if (ts.isArrayLiteralExpression(arg.parent))
|
|
727
|
+
arg = arg.parent;
|
|
728
|
+
const call = arg.parent;
|
|
729
|
+
if (ts.isCallExpression(call) && call.arguments.includes(arg)) {
|
|
730
|
+
const callee = ts.isIdentifier(call.expression) ? call.expression.text : null;
|
|
731
|
+
if (callee === 'outputToObservable')
|
|
732
|
+
return null; // already migrated
|
|
733
|
+
if (callee && OBSERVABLE_COMBINATORS.has(callee)) {
|
|
734
|
+
const start = node.getStart(sourceFile);
|
|
735
|
+
return {
|
|
736
|
+
edits: [
|
|
737
|
+
{ start, end: start, replacement: 'outputToObservable(' },
|
|
738
|
+
{ start: node.getEnd(), end: node.getEnd(), replacement: ')', after: true },
|
|
739
|
+
],
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return {
|
|
744
|
+
edits: [],
|
|
745
|
+
todo: flagTodo(node, sourceFile, source, `output '${node.name.text}'`, `output '${node.name.text}' of ${cls} is an OutputEmitterRef, not an Observable. Wrap it with outputToObservable() ` +
|
|
746
|
+
'(@angular/core/rxjs-interop) where an Observable is needed.'),
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
/** Destructuring of a tracked reference, or storing it in a field/variable we cannot follow. */
|
|
750
|
+
function tryAliasTodo(node, euiRefs, sourceFile, source) {
|
|
751
|
+
if (ts.isVariableDeclaration(node) && node.initializer && !ts.isIdentifier(node.name)) {
|
|
752
|
+
const cls = trackedClass(node.initializer, euiRefs);
|
|
753
|
+
if (cls) {
|
|
754
|
+
return flagTodo(node, sourceFile, source, `destructuring of ${cls}`, `destructuring of ${cls} cannot be migrated automatically: its signal inputs/outputs must be read as ref.prop() / outputToObservable(ref.out).`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (ts.isBinaryExpression(node) &&
|
|
758
|
+
node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
759
|
+
!ts.isIdentifier(unwrap(node.left)) &&
|
|
760
|
+
ts.isExpressionStatement(node.parent)) {
|
|
761
|
+
const cls = trackedClass(node.right, euiRefs);
|
|
762
|
+
if (cls) {
|
|
763
|
+
return flagTodo(node, sourceFile, source, `aliasing of ${cls}`, `aliasing of ${cls}: this copy is not tracked, so its signal inputs/outputs must be updated manually (ref.prop()).`);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
768
|
+
/** Adds `outputToObservable` to the file's imports (merging into an existing rxjs-interop import). */
|
|
769
|
+
function buildOutputImportEdit(sourceFile) {
|
|
770
|
+
let lastImportEnd = 0;
|
|
771
|
+
for (const stmt of sourceFile.statements) {
|
|
772
|
+
if (!ts.isImportDeclaration(stmt))
|
|
773
|
+
continue;
|
|
774
|
+
lastImportEnd = stmt.getEnd();
|
|
775
|
+
if (!ts.isStringLiteral(stmt.moduleSpecifier) || stmt.moduleSpecifier.text !== '@angular/core/rxjs-interop')
|
|
776
|
+
continue;
|
|
777
|
+
const bindings = stmt.importClause?.namedBindings;
|
|
778
|
+
if (bindings && ts.isNamedImports(bindings)) {
|
|
779
|
+
if (bindings.elements.some((e) => e.name.text === 'outputToObservable'))
|
|
780
|
+
return null;
|
|
781
|
+
const last = bindings.elements[bindings.elements.length - 1];
|
|
782
|
+
if (last) {
|
|
783
|
+
return { start: last.getEnd(), end: last.getEnd(), replacement: ', outputToObservable' };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const line = 'import { outputToObservable } from \'@angular/core/rxjs-interop\';';
|
|
788
|
+
return lastImportEnd === 0
|
|
789
|
+
? { start: 0, end: 0, replacement: `${line}\n` }
|
|
790
|
+
: { start: lastImportEnd, end: lastImportEnd, replacement: `\n${line}` };
|
|
791
|
+
}
|
|
435
792
|
/** True if `edit`'s position falls within any of the given ranges. */
|
|
436
793
|
function isInsideAnyRange(edit, ranges) {
|
|
437
794
|
return ranges.some((range) => edit.start >= range.start && edit.end <= range.end);
|
|
@@ -441,21 +798,6 @@ function getLineStartPosition(source, pos) {
|
|
|
441
798
|
const newlineIndex = source.lastIndexOf('\n', pos - 1);
|
|
442
799
|
return newlineIndex === -1 ? 0 : newlineIndex + 1;
|
|
443
800
|
}
|
|
444
|
-
/**
|
|
445
|
-
* Resolves a reference name from an expression.
|
|
446
|
-
* Handles: `ref`, `this.ref`, `this._ref`
|
|
447
|
-
*/
|
|
448
|
-
function resolveRefName(expr) {
|
|
449
|
-
// Direct identifier: ref.prop
|
|
450
|
-
if (ts.isIdentifier(expr)) {
|
|
451
|
-
return expr.text;
|
|
452
|
-
}
|
|
453
|
-
// this.ref.prop
|
|
454
|
-
if (ts.isPropertyAccessExpression(expr) && expr.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
455
|
-
return expr.name.text;
|
|
456
|
-
}
|
|
457
|
-
return null;
|
|
458
|
-
}
|
|
459
801
|
// ---------------------------------------------------------------------------
|
|
460
802
|
// Template ref resolution
|
|
461
803
|
// ---------------------------------------------------------------------------
|
|
@@ -613,7 +955,8 @@ function resolveElementToEuiClass(element) {
|
|
|
613
955
|
function applyEdits(source, edits) {
|
|
614
956
|
const unique = deduplicateEdits(edits);
|
|
615
957
|
let result = source;
|
|
616
|
-
|
|
958
|
+
// Descending by position; at equal positions `after` edits are applied first so they land last.
|
|
959
|
+
for (const edit of unique.sort((a, b) => b.start - a.start || Number(!!b.after) - Number(!!a.after))) {
|
|
617
960
|
result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);
|
|
618
961
|
}
|
|
619
962
|
return result;
|
|
@@ -621,7 +964,7 @@ function applyEdits(source, edits) {
|
|
|
621
964
|
function deduplicateEdits(edits) {
|
|
622
965
|
const seen = new Map();
|
|
623
966
|
for (const edit of edits) {
|
|
624
|
-
const key = `${edit.start}:${edit.end}`;
|
|
967
|
+
const key = `${edit.start}:${edit.end}:${edit.replacement}`;
|
|
625
968
|
seen.set(key, edit);
|
|
626
969
|
}
|
|
627
970
|
return Array.from(seen.values());
|