@eui/core 22.0.0-alpha.88 → 22.0.0-alpha.89
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 +9 -0
- package/docs/changelog.html +18 -0
- package/docs/classes/ActivatedRouteAction.html +1 -1
- package/docs/classes/AddApiQueueItemAction.html +1 -1
- package/docs/classes/AddAppLoadedConfigModulesAction.html +1 -1
- package/docs/classes/ApiQueueServiceMock.html +1 -1
- package/docs/classes/EmptyApiQueueAction.html +1 -1
- package/docs/classes/ErrorSubClass.html +1 -1
- package/docs/classes/EuiCoreRootGuardClass.html +1 -1
- package/docs/classes/EuiError.html +1 -1
- package/docs/classes/I18nResourceImpl.html +1 -1
- package/docs/classes/InitStoreAction.html +1 -1
- package/docs/classes/RemoveApiQueueItemAction.html +1 -1
- package/docs/classes/ServiceResolver.html +1 -1
- package/docs/classes/UpdateAppConnectionAction.html +1 -1
- package/docs/classes/UpdateAppStatusAction.html +1 -1
- package/docs/classes/UpdateAppVersionAction.html +1 -1
- package/docs/classes/UpdateCurrentModuleAction.html +1 -1
- package/docs/classes/UpdateI18nStateAction.html +1 -1
- package/docs/classes/UpdateLocaleStateAction.html +1 -1
- package/docs/classes/UpdateNotificationsListAction.html +1 -1
- package/docs/classes/UpdateUserDashboardAction.html +1 -1
- package/docs/classes/UpdateUserDetailsAction.html +1 -1
- package/docs/classes/UpdateUserPreferencesAction.html +1 -1
- package/docs/classes/UpdateUserRightsAction.html +1 -1
- package/docs/classes/UpdateUserStateAction.html +1 -1
- package/docs/injectables/ApiQueueService.html +1 -1
- package/docs/injectables/EuiAppShellService.html +1 -1
- package/docs/injectables/EuiDynamicMenuService.html +1 -1
- package/docs/injectables/EuiPermissionService.html +1 -1
- package/docs/injectables/EuiThemeService.html +1 -1
- package/docs/injectables/I18nLoader.html +1 -1
- package/docs/injectables/I18nService.html +1 -1
- package/docs/injectables/I18nServiceMock.html +1 -1
- package/docs/injectables/LocalForageService.html +1 -1
- package/docs/injectables/LocaleService.html +1 -1
- package/docs/injectables/LocaleServiceMock.html +1 -1
- package/docs/injectables/LogService.html +1 -1
- package/docs/injectables/StoreService.html +1 -1
- package/docs/injectables/StoreServiceMock.html +1 -1
- package/docs/injectables/UserService.html +1 -1
- package/docs/injectables/UserServiceMock.html +1 -1
- package/docs/interfaces/Edit-13.html +8 -59
- package/docs/interfaces/Edit-14.html +52 -1
- package/docs/interfaces/Edit-15.html +15 -15
- package/docs/interfaces/Edit-16.html +1 -1
- package/docs/interfaces/Edit-17.html +1 -1
- package/docs/interfaces/Edit-19.html +1 -1
- package/docs/interfaces/Edit-20.html +1 -1
- package/docs/interfaces/Schema-17.html +1 -1
- package/docs/interfaces/Schema-18.html +1 -1
- package/docs/interfaces/Schema-23.html +1 -1
- package/docs/interfaces/Schema-24.html +1 -46
- package/docs/interfaces/Schema-25.html +46 -20
- package/docs/interfaces/Schema-26.html +20 -1
- package/docs/interfaces/Schema-27.html +1 -1
- package/docs/interfaces/Schema-29.html +1 -1
- package/docs/interfaces/Schema-30.html +1 -1
- package/docs/interfaces/Schema-32.html +1 -1
- package/docs/interfaces/Schema-33.html +1 -11
- package/docs/interfaces/Schema-34.html +11 -1
- package/docs/interfaces/Schema-36.html +1 -1
- package/docs/interfaces/Schema-37.html +1 -1
- package/docs/interfaces/Schema-38.html +1 -1
- package/docs/interfaces/Schema-39.html +1 -1
- package/docs/interfaces/Schema-40.html +1 -1
- package/docs/interfaces/Schema-42.html +1 -1
- package/docs/interfaces/Schema-43.html +1 -1
- package/docs/js/search/search_index.js +2 -2
- package/docs/json/documentation.json +370 -370
- package/docs/llms.txt +127 -127
- package/docs/miscellaneous/functions.html +442 -442
- package/docs/miscellaneous/typealiases.html +6 -6
- package/docs/miscellaneous/variables.html +35 -35
- package/docs/properties.html +1 -1
- package/package.json +2 -2
|
@@ -1481,12 +1481,12 @@
|
|
|
1481
1481
|
},
|
|
1482
1482
|
{
|
|
1483
1483
|
"name": "Edit",
|
|
1484
|
-
"id": "interface-Edit-
|
|
1485
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
1484
|
+
"id": "interface-Edit-05d44cb645a03b21078a2d230ea40452f999bc21ae9f3852a4fe8c62cd94add695db5b7b528cabd6ce04e356ddcf3d1e999b71134cf29bcceb7b057d2b225d5f-10",
|
|
1485
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
1486
1486
|
"deprecated": false,
|
|
1487
1487
|
"deprecationMessage": "",
|
|
1488
1488
|
"type": "interface",
|
|
1489
|
-
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-
|
|
1489
|
+
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-tab` element selector to `div[eclTab]`.\n *\n * In v22 the legacy `ecl-tab` element selector was removed; the component only\n * matches `div[eclTab]`. This schematic rewrites `<ecl-tab>` to `<div eclTab>`\n * (and the closing tag to `</div>`) in external `.html` templates and inline\n * `@Component` templates, preserving existing attributes and content.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst OLD_TAG = 'ecl-tab';\nconst NEW_TAG = 'div';\nconst ATTRIBUTE = 'eclTab';\n\nexport function migrateEclTabs(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(OLD_TAG)) return;\n\n const result = path.endsWith('.html') ? migrateTemplate(original) : migrateTypeScript(original, path);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate ${OLD_TAG} → ${NEW_TAG}[${ATTRIBUTE}] in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated ${OLD_TAG} → ${NEW_TAG}[${ATTRIBUTE}] in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTemplate(source: string): string {\n let parsed;\n try {\n parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return source;\n }\n\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, edits);\n return applyEdits(source, edits);\n}\n\nfunction migrateTypeScript(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (rawTemplate.includes(OLD_TAG)) {\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) {\n edits.push({ start, end, replacement: migrated });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n // Exact tag match only — must not touch e.g. `ecl-tabs` or `ecl-tab-header`.\n if (node.name === OLD_TAG) {\n collectElementRename(node, edits);\n }\n });\n}\n\nfunction collectElementRename(element: TmplAstElement, edits: Edit[]): void {\n const openTagNameStart = element.startSourceSpan.start.offset + 1; // skip '<'\n const openTagNameEnd = openTagNameStart + OLD_TAG.length;\n\n const alreadyHasAttribute =\n element.attributes.some((a) => a.name === ATTRIBUTE) || element.inputs.some((i) => i.name === ATTRIBUTE);\n\n const replacement = alreadyHasAttribute ? NEW_TAG : `${NEW_TAG} ${ATTRIBUTE}`;\n edits.push({ start: openTagNameStart, end: openTagNameEnd, replacement });\n\n if (element.endSourceSpan) {\n const closeTagNameStart = element.endSourceSpan.start.offset + 2; // skip '</'\n edits.push({ start: closeTagNameStart, end: closeTagNameStart + OLD_TAG.length, replacement: NEW_TAG });\n }\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return (\n ts.isDecorator(callExpression.parent) &&\n ts.isIdentifier(callExpression.expression) &&\n callExpression.expression.text === 'Component'\n );\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
1490
1490
|
"displayName": "Edit",
|
|
1491
1491
|
"properties": [
|
|
1492
1492
|
{
|
|
@@ -1498,7 +1498,7 @@
|
|
|
1498
1498
|
"indexKey": "",
|
|
1499
1499
|
"optional": false,
|
|
1500
1500
|
"description": "",
|
|
1501
|
-
"line":
|
|
1501
|
+
"line": 23,
|
|
1502
1502
|
"rawdescription": "\n"
|
|
1503
1503
|
},
|
|
1504
1504
|
{
|
|
@@ -1510,7 +1510,7 @@
|
|
|
1510
1510
|
"indexKey": "",
|
|
1511
1511
|
"optional": false,
|
|
1512
1512
|
"description": "",
|
|
1513
|
-
"line":
|
|
1513
|
+
"line": 24,
|
|
1514
1514
|
"rawdescription": "\n"
|
|
1515
1515
|
},
|
|
1516
1516
|
{
|
|
@@ -1522,7 +1522,7 @@
|
|
|
1522
1522
|
"indexKey": "",
|
|
1523
1523
|
"optional": false,
|
|
1524
1524
|
"description": "",
|
|
1525
|
-
"line":
|
|
1525
|
+
"line": 22,
|
|
1526
1526
|
"rawdescription": "\n"
|
|
1527
1527
|
}
|
|
1528
1528
|
],
|
|
@@ -1540,12 +1540,12 @@
|
|
|
1540
1540
|
},
|
|
1541
1541
|
{
|
|
1542
1542
|
"name": "Edit",
|
|
1543
|
-
"id": "interface-Edit-
|
|
1544
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
1543
|
+
"id": "interface-Edit-589bd8bab1e7a93675c15cfb1fdae37017fefa385aad54880e216cc0206f44c4673fd2840af9433a4c47f9cbf9fd5d471d8fea83e00a17bd47f82ec4961250a5-11",
|
|
1544
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
1545
1545
|
"deprecated": false,
|
|
1546
1546
|
"deprecationMessage": "",
|
|
1547
1547
|
"type": "interface",
|
|
1548
|
-
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-
|
|
1548
|
+
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-timeline` element selectors to their\n * attribute-selector equivalents.\n *\n * In v22 the timeline element selectors were removed in favour of attribute\n * selectors on specific host elements:\n * - `ecl-timeline` → `ol[eclTimeline]`\n * - `ecl-timeline-item` → `li[eclTimelineItem]`\n * - `ecl-timeline-item-toggler` → `li[eclTimelineItemToggler]`\n *\n * This schematic rewrites the element tags and injects the attribute directive\n * (e.g. `<ecl-timeline>` → `<ol eclTimeline>`, `</ecl-timeline>` → `</ol>`) in\n * external `.html` templates and inline `@Component` templates, preserving\n * existing attributes and content.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\ninterface SelectorMapping {\n oldTag: string;\n newTag: string;\n attribute: string;\n}\n\nconst SELECTOR_MAPPINGS: readonly SelectorMapping[] = [\n { oldTag: 'ecl-timeline', newTag: 'ol', attribute: 'eclTimeline' },\n { oldTag: 'ecl-timeline-item', newTag: 'li', attribute: 'eclTimelineItem' },\n { oldTag: 'ecl-timeline-item-toggler', newTag: 'li', attribute: 'eclTimelineItemToggler' },\n];\n\nconst OLD_TAGS = SELECTOR_MAPPINGS.map((m) => m.oldTag);\n\nexport function migrateEclTimeline(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!OLD_TAGS.some((tag) => original.includes(tag))) return;\n\n const result = path.endsWith('.html') ? migrateTemplate(original) : migrateTypeScript(original, path);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate ecl-timeline selector(s) in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated ecl-timeline element selectors in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTemplate(source: string): string {\n let parsed;\n try {\n parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return source;\n }\n\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, edits);\n return applyEdits(source, edits);\n}\n\nfunction migrateTypeScript(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (OLD_TAGS.some((tag) => rawTemplate.includes(tag))) {\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) {\n edits.push({ start, end, replacement: migrated });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n const mapping = SELECTOR_MAPPINGS.find((m) => m.oldTag === node.name);\n if (mapping) {\n collectElementRename(node, mapping, edits);\n }\n });\n}\n\nfunction collectElementRename(element: TmplAstElement, mapping: SelectorMapping, edits: Edit[]): void {\n const { oldTag, newTag, attribute } = mapping;\n\n const openTagNameStart = element.startSourceSpan.start.offset + 1; // skip '<'\n const openTagNameEnd = openTagNameStart + oldTag.length;\n\n const alreadyHasAttribute =\n element.attributes.some((a) => a.name === attribute) || element.inputs.some((i) => i.name === attribute);\n\n const replacement = alreadyHasAttribute ? newTag : `${newTag} ${attribute}`;\n edits.push({ start: openTagNameStart, end: openTagNameEnd, replacement });\n\n if (element.endSourceSpan) {\n const closeTagNameStart = element.endSourceSpan.start.offset + 2; // skip '</'\n edits.push({ start: closeTagNameStart, end: closeTagNameStart + oldTag.length, replacement: newTag });\n }\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return (\n ts.isDecorator(callExpression.parent) &&\n ts.isIdentifier(callExpression.expression) &&\n callExpression.expression.text === 'Component'\n );\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
1549
1549
|
"displayName": "Edit",
|
|
1550
1550
|
"properties": [
|
|
1551
1551
|
{
|
|
@@ -1557,7 +1557,7 @@
|
|
|
1557
1557
|
"indexKey": "",
|
|
1558
1558
|
"optional": false,
|
|
1559
1559
|
"description": "",
|
|
1560
|
-
"line":
|
|
1560
|
+
"line": 30,
|
|
1561
1561
|
"rawdescription": "\n"
|
|
1562
1562
|
},
|
|
1563
1563
|
{
|
|
@@ -1569,7 +1569,7 @@
|
|
|
1569
1569
|
"indexKey": "",
|
|
1570
1570
|
"optional": false,
|
|
1571
1571
|
"description": "",
|
|
1572
|
-
"line":
|
|
1572
|
+
"line": 31,
|
|
1573
1573
|
"rawdescription": "\n"
|
|
1574
1574
|
},
|
|
1575
1575
|
{
|
|
@@ -1581,7 +1581,7 @@
|
|
|
1581
1581
|
"indexKey": "",
|
|
1582
1582
|
"optional": false,
|
|
1583
1583
|
"description": "",
|
|
1584
|
-
"line":
|
|
1584
|
+
"line": 29,
|
|
1585
1585
|
"rawdescription": "\n"
|
|
1586
1586
|
}
|
|
1587
1587
|
],
|
|
@@ -1599,12 +1599,12 @@
|
|
|
1599
1599
|
},
|
|
1600
1600
|
{
|
|
1601
1601
|
"name": "Edit",
|
|
1602
|
-
"id": "interface-Edit-
|
|
1603
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
1602
|
+
"id": "interface-Edit-dc18bc3e10d23f4240b45573a02aa1824883e327513ed13a093bb2c12168dfe15b85fb5496300c5a750b883ec75f43311178c63681955666ee368731cc171fef-12",
|
|
1603
|
+
"file": "packages/core/schematics/migrate-eui-autocomplete/index.ts",
|
|
1604
1604
|
"deprecated": false,
|
|
1605
1605
|
"deprecationMessage": "",
|
|
1606
1606
|
"type": "interface",
|
|
1607
|
-
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement, getTemplateChildren } from '../utils/template-walk';\n\nconst CHIP_LIST_TAG = 'eui-chip-list';\nconst CHIP_LIST_ATTR = 'euiChipList';\nconst CHIP_TAG = 'eui-chip';\nconst CHIP_ATTR = 'euiChip';\n\nconst PROPAGATED_INPUTS = new Set([\n 'euiPrimary', 'euiSecondary', 'euiSuccess', 'euiInfo', 'euiWarning',\n 'euiDanger', 'euiAccent', 'euiVariant', 'euiSizeS', 'euiSizeVariant',\n 'euiOutline', 'euiDisabled',\n]);\n\nconst WARN_PROPERTIES = new Set([...PROPAGATED_INPUTS, 'chipRemove', 'isChipsRemovable', 'chipsLabelTruncateCount',\n 'maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel',\n 'isChipsSorted', 'chipsSortOrder']);\n\nconst REMOVED_INPUTS = new Set(['maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel', 'isChipsSorted', 'chipsSortOrder']);\n\nconst TRUNCATE_PIPE_IMPORT = 'EuiTruncatePipe';\nconst TRUNCATE_PIPE_PATH = '@eui/components/pipes';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nexport function migrateEuiChipList(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n const filesNeedingTruncateImport = new Set<string>();\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(CHIP_LIST_TAG) && !original.includes(CHIP_LIST_ATTR)) return;\n\n let result: string;\n let addedTruncate = false;\n\n if (path.endsWith('.html')) {\n result = migrateTemplate(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n // Find the associated .ts file\n const tsPath = path.replace(/\\.html$/, '.ts');\n if (tree.exists(tsPath)) {\n filesNeedingTruncateImport.add(tsPath);\n } else {\n // Try component naming convention\n const componentTsPath = path.replace(/\\.html$/, '.component.ts');\n if (tree.exists(componentTsPath)) {\n filesNeedingTruncateImport.add(componentTsPath);\n }\n }\n }\n } else {\n result = migrateInlineTemplates(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n addedTruncate = true;\n }\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would move variant/size/outline inputs to child eui-chip in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n if (addedTruncate) {\n filesNeedingTruncateImport.add(path);\n }\n\n // Warn about TS usages of removed properties\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if ([...WARN_PROPERTIES].some((p) => original.includes(p))) {\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && WARN_PROPERTIES.has(node.name.text)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(\n `${path}:${line + 1} - \"${node.name.text}\" has been removed from eui-chip-list. Move it to individual eui-chip elements.`,\n );\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n }\n });\n\n // Add EuiTruncatePipe import to component files that need it\n for (const tsPath of filesNeedingTruncateImport) {\n const buffer = tree.read(tsPath);\n if (!buffer) continue;\n const source = buffer.toString('utf-8');\n if (source.includes(TRUNCATE_PIPE_IMPORT)) continue;\n const result = addTruncatePipeImport(source, tsPath);\n if (result !== source) {\n if (!options.dryRun) {\n tree.overwrite(tsPath, result);\n }\n }\n }\n\n context.logger.info(`Migrated eui-chip-list inputs/outputs to child eui-chip in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction addTruncatePipeImport(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const edits: Edit[] = [];\n\n // 1. Add ES import statement for EuiTruncatePipe\n let hasEsImport = false;\n let lastImportEnd = 0;\n\n for (const stmt of sourceFile.statements) {\n if (ts.isImportDeclaration(stmt)) {\n lastImportEnd = stmt.getEnd();\n const moduleSpec = (stmt.moduleSpecifier as ts.StringLiteral).text;\n if (moduleSpec === TRUNCATE_PIPE_PATH) {\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n if (namedBindings.elements.some((el) => el.name.text === TRUNCATE_PIPE_IMPORT)) {\n hasEsImport = true;\n } else {\n // Add to existing import from same path\n const lastEl = namedBindings.elements[namedBindings.elements.length - 1];\n edits.push({ start: lastEl.getEnd(), end: lastEl.getEnd(), replacement: `, ${TRUNCATE_PIPE_IMPORT}` });\n hasEsImport = true;\n }\n }\n }\n }\n }\n\n if (!hasEsImport) {\n const importStatement = `\\nimport { ${TRUNCATE_PIPE_IMPORT} } from '${TRUNCATE_PIPE_PATH}';`;\n edits.push({ start: lastImportEnd, end: lastImportEnd, replacement: importStatement });\n }\n\n // 2. Add EuiTruncatePipe to @Component imports array\n const visit = (node: ts.Node): void => {\n if (ts.isClassDeclaration(node)) {\n const decs = ts.getDecorators(node);\n if (!decs) return;\n for (const dec of decs) {\n if (!ts.isCallExpression(dec.expression) || !ts.isIdentifier(dec.expression.expression) || dec.expression.expression.text !== 'Component') continue;\n const metadata = dec.expression.arguments[0];\n if (!ts.isObjectLiteralExpression(metadata)) continue;\n for (const prop of metadata.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name) || prop.name.text !== 'imports') continue;\n if (!ts.isArrayLiteralExpression(prop.initializer)) continue;\n const arr = prop.initializer;\n const arrText = source.slice(arr.getStart(sourceFile), arr.getEnd());\n if (arrText.includes(TRUNCATE_PIPE_IMPORT)) continue;\n if (arr.elements.length > 0) {\n const lastElement = arr.elements[arr.elements.length - 1];\n edits.push({ start: lastElement.getEnd(), end: lastElement.getEnd(), replacement: `,\\n ${TRUNCATE_PIPE_IMPORT}` });\n } else {\n edits.push({ start: arr.getStart(sourceFile) + 1, end: arr.getEnd() - 1, replacement: TRUNCATE_PIPE_IMPORT });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: Edit[] = [];\n\n visitNodes(parsed.nodes, source, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(CHIP_LIST_TAG) && !rawTemplate.includes(CHIP_LIST_ATTR)) {\n ts.forEachChild(node, visit);\n return;\n }\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n return applyEdits(source, changes);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n if (isChipListElement(node)) migrateChipListElement(node, source, edits);\n });\n}\n\nfunction isChipListElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_LIST_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_LIST_ATTR);\n}\n\nfunction isChipElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_ATTR);\n}\n\nfunction findChildChips(nodes: TmplAstNode[]): TmplAstElement[] {\n const chips: TmplAstElement[] = [];\n for (const node of nodes) {\n if (node instanceof TmplAstElement && isChipElement(node)) {\n chips.push(node);\n } else {\n chips.push(...findChildChips(getTemplateChildren(node)));\n }\n }\n return chips;\n}\n\nfunction migrateChipListElement(element: TmplAstElement, source: string, edits: Edit[]): void {\n const childChips = findChildChips(element.children);\n const insertions: string[] = [];\n let truncateValue: string | null = null;\n\n // Collect and remove propagated static attributes\n for (const attr of element.attributes) {\n if (PROPAGATED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n insertions.push(attr.value ? `${attr.name}=\"${attr.value}\"` : attr.name);\n }\n if (attr.name === 'isChipsRemovable') {\n edits.push(removalEdit(attr, source));\n insertions.push('isChipRemovable');\n }\n if (attr.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(attr, source));\n truncateValue = attr.value || null;\n }\n if (REMOVED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n }\n }\n\n // Collect and remove propagated bound inputs\n for (const input of element.inputs) {\n if (PROPAGATED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n insertions.push(raw);\n }\n if (input.name === 'isChipsRemovable') {\n edits.push(removalEdit(input, source));\n const valueText = extractBindingValue(input, source);\n insertions.push(`[isChipRemovable]=\"${valueText}\"`);\n }\n if (input.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(input, source));\n truncateValue = extractBindingValue(input, source);\n }\n if (REMOVED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n }\n }\n\n // Collect and remove (chipRemove) output\n let chipRemoveHandler: string | null = null;\n for (const output of element.outputs) {\n if (output.name === 'chipRemove') {\n edits.push(removalEdit(output, source));\n chipRemoveHandler = extractHandlerExpression(output, source);\n }\n }\n\n if (chipRemoveHandler) {\n insertions.push(`(remove)=\"${chipRemoveHandler}\"`);\n }\n\n // Add collected attributes to each child eui-chip\n if (insertions.length > 0) {\n for (const chip of childChips) {\n const existingNames = getExistingAttrNames(chip);\n const toInsert = insertions.filter((ins) => {\n const name = extractAttrName(ins);\n return !existingNames.has(name);\n });\n if (toInsert.length > 0) {\n const insertPos = chip.startSourceSpan.end.offset - 1;\n edits.push({ start: insertPos, end: insertPos, replacement: ' ' + toInsert.join(' ') });\n }\n }\n }\n\n // Add euiTruncate pipe to chip label content\n if (truncateValue) {\n for (const chip of childChips) {\n const labelEdit = buildTruncatePipeEdit(chip, source, truncateValue);\n if (labelEdit) edits.push(labelEdit);\n }\n }\n}\n\nfunction buildTruncatePipeEdit(chip: TmplAstElement, source: string, truncateValue: string): Edit | null {\n // Find <span euiLabel>...</span> inside the chip\n const labelEl = findLabelElement(chip.children);\n if (labelEl !== null && labelEl !== undefined && labelEl.endSourceSpan) {\n const contentStart = labelEl.startSourceSpan.end.offset;\n const contentEnd = labelEl.endSourceSpan.start.offset;\n const content = source.slice(contentStart, contentEnd);\n if (content && !content.includes('euiTruncate')) {\n const trimmed = content.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch) {\n return { start: contentStart, end: contentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n return { start: contentStart, end: contentEnd, replacement: `{{ '${trimmed}' | euiTruncate: ${truncateValue} }}` };\n }\n }\n\n // Check direct text content inside chip (no label element)\n if (chip.endSourceSpan) {\n const chipContentStart = chip.startSourceSpan.end.offset;\n const chipContentEnd = chip.endSourceSpan.start.offset;\n const chipContent = source.slice(chipContentStart, chipContentEnd);\n const trimmed = chipContent.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch && !chipContent.includes('euiTruncate')) {\n return { start: chipContentStart, end: chipContentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n }\n return null;\n}\n\nfunction findLabelElement(nodes: TmplAstNode[]): TmplAstElement | null {\n for (const node of nodes) {\n if (node instanceof TmplAstElement && node.attributes.some((a) => a.name === 'euiLabel')) return node;\n const nested = findLabelElement(getTemplateChildren(node));\n if (nested) return nested;\n }\n return null;\n}\n\nfunction getExistingAttrNames(element: TmplAstElement): Set<string> {\n const names = new Set<string>();\n for (const attr of element.attributes) names.add(attr.name);\n for (const input of element.inputs) names.add(input.name);\n for (const output of element.outputs) names.add(output.name);\n return names;\n}\n\nfunction extractAttrName(insertion: string): string {\n const outputMatch = insertion.match(/^\\(([^)]+)\\)/);\n if (outputMatch) return outputMatch[1];\n const inputMatch = insertion.match(/^\\[([^\\]]+)\\]/);\n if (inputMatch) return inputMatch[1];\n return insertion.split('=')[0];\n}\n\nfunction removalEdit(node: TmplAstTextAttribute | TmplAstBoundAttribute | TmplAstBoundEvent, source: string): Edit {\n let start = node.sourceSpan.start.offset;\n while (start > 0 && (source[start - 1] === ' ' || source[start - 1] === '\\t')) {\n start--;\n }\n return { start, end: node.sourceSpan.end.offset, replacement: '' };\n}\n\nfunction extractBindingValue(input: TmplAstBoundAttribute, source: string): string {\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : 'true';\n}\n\nfunction extractHandlerExpression(output: TmplAstBoundEvent, source: string): string {\n const raw = source.slice(output.sourceSpan.start.offset, output.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : '';\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n seen.set(`${edit.start}:${edit.end}`, edit);\n }\n return Array.from(seen.values());\n}\n",
|
|
1607
|
+
"sourceCode": "import { parseTemplate, TmplAstElement } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ntype Kind = 'ac' | 'panel';\n\nconst AC = 'EuiAutocompleteComponent';\nconst PANEL = 'EuiAutocompletePanelComponent';\nconst KIND_BY_TYPE: Record<string, Kind> = { [AC]: 'ac', [PANEL]: 'panel' };\n\n/** Properties that went from plain value to WritableSignal. */\nconst WRITABLE: Record<Kind, Set<string>> = {\n ac: new Set(['chips', 'selectedOptionIndex', 'isDisabled', 'itemSize']),\n panel: new Set(),\n};\n/** Properties that went from plain value to a read-only signal (viewChild()). */\nconst READONLY: Record<Kind, Set<string>> = { ac: new Set(), panel: new Set(['virtualScrolling']) };\n\nconst ARRAY_MUTATORS = new Set(['splice', 'sort', 'reverse', 'pop', 'shift', 'unshift', 'fill', 'copyWithin']);\nconst SIGNAL_API = new Set(['set', 'update', 'asReadonly']);\nconst COMPOUND_OPS = new Set([\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.AsteriskEqualsToken,\n ts.SyntaxKind.SlashEqualsToken,\n ts.SyntaxKind.PercentEqualsToken,\n ts.SyntaxKind.AsteriskAsteriskEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n]);\n\n/** EuiAutocompleteComponent outputs (EventEmitter -> OutputEmitterRef): no `.pipe`/`.subscribe` anymore. */\nconst AC_OUTPUTS = new Set([\n 'panelClose',\n 'panelOpen',\n 'inputFocus',\n 'inputBlur',\n 'clear',\n 'selectionChange',\n 'itemAdd',\n 'itemRemove',\n 'inputChange',\n 'touch',\n]);\nconst OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);\nconst SIGNAL_INTEROP = '@angular/core/rxjs-interop';\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\nexport function migrateEuiAutocomplete(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n const original = buffer.toString('utf-8');\n if (!/utocomplete|[vV]iewChild/.test(original)) return;\n\n if (path.endsWith('.html')) {\n logFocusEventInfo(original, path, context);\n return;\n }\n\n const { result, warnings, infos } = migrateTs(original, path, tree);\n warnings.forEach((w) => context.logger.warn(w));\n infos.forEach((i) => context.logger.info(i));\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-autocomplete signal members in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n });\n\n context.logger.info(`Migrated eui-autocomplete signal members in ${count} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------\n\nfunction walkTemplate(node: unknown, visit: (el: TmplAstElement) => void, seen = new Set<unknown>()): void {\n if (!node || typeof node !== 'object' || seen.has(node)) return;\n seen.add(node);\n if (Array.isArray(node)) {\n node.forEach((n) => walkTemplate(n, visit, seen));\n return;\n }\n if (!('sourceSpan' in (node as object))) return;\n if (node instanceof TmplAstElement) visit(node);\n for (const [key, value] of Object.entries(node as object)) {\n if (key.endsWith('SourceSpan') || key === 'sourceSpan' || key === 'i18n') continue;\n walkTemplate(value, visit, seen);\n }\n}\n\nfunction parseSafe(source: string): ReturnType<typeof parseTemplate> | null {\n try {\n return parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return null;\n }\n}\n\n/** Template reference names (#ref) declared on <eui-autocomplete>. */\nfunction autocompleteRefs(templates: string[]): Set<string> {\n const refs = new Set<string>();\n for (const t of templates) {\n const parsed = parseSafe(t);\n if (!parsed) continue;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name === 'eui-autocomplete') el.references.forEach((r) => refs.add(r.name));\n });\n }\n return refs;\n}\n\nfunction logFocusEventInfo(template: string, path: string, context: SchematicContext): void {\n if (!template.includes('eui-autocomplete')) return;\n const parsed = parseSafe(template);\n if (!parsed) return;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name !== 'eui-autocomplete') return;\n for (const out of el.outputs) {\n if (out.name !== 'inputFocus' && out.name !== 'inputBlur') continue;\n const handler = (out.handler as unknown as { source?: string }).source ?? '';\n if (handler.includes('$event')) {\n context.logger.info(\n `${path} - eui-autocomplete (${out.name}) now emits a FocusEvent instead of void; check that the handler accepts a FocusEvent.`,\n );\n }\n }\n });\n}\n\n// ---------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------\n\nfunction typeKind(type: ts.TypeNode | undefined): Kind | undefined {\n if (!type) return undefined;\n if (ts.isParenthesizedTypeNode(type)) return typeKind(type.type);\n if (ts.isUnionTypeNode(type)) {\n for (const t of type.types) {\n const k = typeKind(t);\n if (k) return k;\n }\n return undefined;\n }\n if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName)) return KIND_BY_TYPE[type.typeName.text];\n return undefined;\n}\n\nfunction callKind(expr: ts.Expression | undefined): Kind | undefined {\n if (!expr || !ts.isCallExpression(expr)) return undefined;\n const callee = expr.expression;\n const isFactory =\n (ts.isIdentifier(callee) && (callee.text === 'inject' || callee.text === 'viewChild')) ||\n (ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text === 'viewChild' &&\n callee.name.text === 'required');\n const arg = expr.arguments[0];\n if (isFactory && arg && ts.isIdentifier(arg)) return KIND_BY_TYPE[arg.text];\n return undefined;\n}\n\nfunction isSignalQuery(expr: ts.Expression | undefined): boolean {\n if (!expr || !ts.isCallExpression(expr)) return false;\n const c = expr.expression;\n return (\n (ts.isIdentifier(c) && c.text === 'viewChild') ||\n (ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === 'viewChild')\n );\n}\n\nfunction decoratorsOf(node: ts.Node): readonly ts.Decorator[] {\n return ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? []) : [];\n}\n\nfunction extractInlineAndLinkedTemplates(sf: ts.SourceFile, path: string, tree: Tree): string[] {\n const templates: string[] = [];\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {\n const init = node.initializer;\n if (node.name.text === 'template' && (ts.isStringLiteralLike(init) || ts.isNoSubstitutionTemplateLiteral(init))) {\n templates.push(init.text);\n } else if (node.name.text === 'templateUrl' && ts.isStringLiteralLike(init)) {\n const dir = path.slice(0, path.lastIndexOf('/'));\n const segments = `${dir}/${init.text}`.split('/');\n const resolved: string[] = [];\n for (const s of segments) {\n if (s === '..') resolved.pop();\n else if (s !== '.' && s !== '') resolved.push(s);\n }\n const buf = tree.read('/' + resolved.join('/'));\n if (buf) templates.push(buf.toString('utf-8'));\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n return templates;\n}\n\nfunction migrateTs(source: string, path: string, tree: Tree): { result: string; warnings: string[]; infos: string[] } {\n const warnings: string[] = [];\n const infos: string[] = [];\n const sf = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);\n const templates = extractInlineAndLinkedTemplates(sf, path, tree);\n const refs = autocompleteRefs(templates);\n templates.forEach((t) => logFocusEventInfo(t, path, { logger: { info: (m: string) => infos.push(m) } } as unknown as SchematicContext));\n\n // name -> kind, for `this.name`, bare `name` and `this.name()` (signal queries)\n const thisNames = new Map<string, Kind>();\n const bareNames = new Map<string, Kind>();\n const callNames = new Map<string, Kind>();\n\n const collect = (node: ts.Node): void => {\n if (ts.isPropertyDeclaration(node) && ts.isIdentifier(node.name)) {\n const name = node.name.text;\n let kind = typeKind(node.type) ?? callKind(node.initializer);\n for (const d of decoratorsOf(node)) {\n if (!ts.isCallExpression(d.expression) || !ts.isIdentifier(d.expression.expression)) continue;\n if (d.expression.expression.text !== 'ViewChild') continue;\n const arg = d.expression.arguments[0];\n if (arg && ts.isIdentifier(arg) && KIND_BY_TYPE[arg.text]) kind ??= KIND_BY_TYPE[arg.text];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) kind ??= 'ac';\n }\n const init = node.initializer;\n if (!kind && init && isSignalQuery(init) && ts.isCallExpression(init)) {\n const arg = init.arguments[0];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) {\n callNames.set(name, 'ac');\n return;\n }\n }\n if (kind) {\n if (init && isSignalQuery(init)) callNames.set(name, kind);\n else thisNames.set(name, kind);\n }\n } else if (ts.isParameter(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type);\n if (kind) {\n bareNames.set(node.name.text, kind);\n if (ts.isConstructorDeclaration(node.parent) && ts.getModifiers(node)?.length) thisNames.set(node.name.text, kind);\n }\n } else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type) ?? callKind(node.initializer);\n if (kind) bareNames.set(node.name.text, kind);\n }\n ts.forEachChild(node, collect);\n };\n collect(sf);\n\n if (!thisNames.size && !bareNames.size && !callNames.size) return { result: source, warnings, infos };\n\n /** Nearest enclosing parameter/variable declaration decides the kind, so a shadowing param of another type is ignored. */\n const resolveBare = (id: ts.Identifier): Kind | undefined => {\n for (let n: ts.Node | undefined = id.parent; n; n = n.parent) {\n const decls: (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(n)) decls.push(...n.parameters);\n if (ts.isBlock(n) || ts.isSourceFile(n)) {\n n.statements.forEach((st) => ts.isVariableStatement(st) && decls.push(...st.declarationList.declarations));\n }\n for (const d of decls) {\n if (ts.isIdentifier(d.name) && d.name.text === id.text) return typeKind(d.type) ?? callKind(d.initializer);\n }\n }\n return bareNames.get(id.text);\n };\n\n const kindOf = (expr: ts.Expression): Kind | undefined => {\n let e = expr;\n while (ts.isNonNullExpression(e) || ts.isParenthesizedExpression(e)) e = e.expression;\n if (ts.isIdentifier(e)) return resolveBare(e);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) return thisNames.get(e.name.text);\n if (\n ts.isCallExpression(e) &&\n e.arguments.length === 0 &&\n ts.isPropertyAccessExpression(e.expression) &&\n e.expression.expression.kind === ts.SyntaxKind.ThisKeyword\n ) {\n return callNames.get(e.expression.name.text);\n }\n return undefined;\n };\n\n const edits: Edit[] = [];\n const where = (n: ts.Node): string => `${path}:${sf.getLineAndCharacterOfPosition(n.getStart()).line + 1}`;\n const warn = (n: ts.Node, msg: string): void => {\n warnings.push(`${where(n)} - Manual action needed: ${msg}`);\n };\n const isStatementLike = (n: ts.Node): boolean =>\n ts.isExpressionStatement(n.parent) || (ts.isArrowFunction(n.parent) && n.parent.body === n);\n const fresh = (name: string, text: string): string => (new RegExp(`\\\\b${name}\\\\b`).test(text) ? `${name}x` : name);\n const simple = (e: ts.Expression): boolean =>\n ts.isNumericLiteral(e) || ts.isIdentifier(e) || ts.isPropertyAccessExpression(e) || ts.isStringLiteral(e) || ts.isParenthesizedExpression(e);\n\n let needsOutputImport = false;\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const kind = kindOf(node.expression);\n if (kind) {\n if (kind === 'ac' && AC_OUTPUTS.has(node.name.text) && isObservableUse(node)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'outputToObservable(' });\n edits.push({ start: node.end, end: node.end, text: ')' });\n needsOutputImport = true;\n noteFocusEvent(node);\n } else {\n handle(node, node.name.text, kind);\n }\n }\n } else if (ts.isVariableDeclaration(node) && node.initializer && kindOf(node.initializer)) {\n const kind = kindOf(node.initializer)!;\n if (ts.isIdentifier(node.name)) {\n warn(node, `\"${node.name.text}\" is an alias of an eUI autocomplete reference; member usages through the alias are not migrated. Check \"${node.name.text}\" manually (chips, selectedOptionIndex, isDisabled, itemSize, autocompleteDataSelected are signals now).`);\n } else if (ts.isObjectBindingPattern(node.name)) {\n const migrated = node.name.elements\n .map((el) => (el.propertyName ?? el.name).getText())\n .filter((m) => WRITABLE[kind].has(m) || READONLY[kind].has(m) || (kind === 'ac' && m === 'autocompleteDataSelected'));\n if (migrated.length) {\n warn(node, `destructuring of ${migrated.join(', ')} from an eUI autocomplete reference now yields a signal, not a value; read it with \"()\" (or use the property access).`);\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n const noteFocusEvent = (pa: ts.PropertyAccessExpression): void => {\n const member = pa.name.text;\n if (member !== 'inputFocus' && member !== 'inputBlur') return;\n const sub = pa.parent;\n const call = ts.isPropertyAccessExpression(sub) && sub.name.text === 'subscribe' ? sub.parent : undefined;\n const handler = call && ts.isCallExpression(call) ? call.arguments[0] : undefined;\n if (handler && (ts.isArrowFunction(handler) || ts.isFunctionExpression(handler)) && handler.parameters.length === 0) {\n infos.push(`${where(pa)} - eui-autocomplete (${member}) now emits a FocusEvent instead of void; check that this subscribe handler accepts a FocusEvent.`);\n }\n };\n\n const handle = (pa: ts.PropertyAccessExpression, member: string, kind: Kind): void => {\n const parent = pa.parent;\n const isWritable = WRITABLE[kind].has(member);\n const isReadonly = READONLY[kind].has(member);\n const isDataSelected = kind === 'ac' && member === 'autocompleteDataSelected';\n if (!isWritable && !isReadonly && !isDataSelected) return;\n\n // already migrated: `x.member()` or `x.member.set/update/asReadonly`\n if (ts.isCallExpression(parent) && parent.expression === pa) return;\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && SIGNAL_API.has(parent.name.text)) return;\n\n const isAssignTarget =\n ts.isBinaryExpression(parent) &&\n parent.left === pa &&\n parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n\n if (isDataSelected) {\n const mutating =\n ts.isPropertyAccessExpression(parent) &&\n parent.expression === pa &&\n ts.isCallExpression(parent.parent) &&\n parent.parent.expression === parent &&\n (parent.name.text === 'push' || ARRAY_MUTATORS.has(parent.name.text));\n const written = (n: ts.Node): boolean =>\n ts.isBinaryExpression(n.parent) &&\n n.parent.left === n &&\n n.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n n.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n const memberWritten =\n (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === pa && written(parent);\n if (isAssignTarget || mutating || memberWritten) {\n warn(pa, '\"autocompleteDataSelected\" is now a read-only signal input and cannot be assigned or mutated programmatically. Bind [autocompleteDataSelected] in the template instead.');\n return;\n }\n // plain read: falls through to the `()` rewrite below\n }\n\n if (isAssignTarget && !isDataSelected) {\n const bin = parent as ts.BinaryExpression;\n const op = bin.operatorToken.kind;\n if (!isStatementLike(bin)) {\n warn(pa, `\"${member}\" is now a signal; assignment is used as a value and could not be rewritten automatically.`);\n return;\n }\n if (isReadonly) {\n warn(pa, `\"${member}\" is now a read-only signal and cannot be assigned.`);\n return;\n }\n if (op === ts.SyntaxKind.EqualsToken) {\n edits.push({ start: pa.end, end: bin.right.getStart(), text: '.set(' });\n edits.push({ start: bin.right.end, end: bin.right.end, text: ')' });\n } else if (COMPOUND_OPS.has(op)) {\n const sym = ts.tokenToString(op)!.slice(0, -1);\n const rightText = bin.right.getText();\n const v = fresh('v', rightText);\n const wrapRight = !simple(bin.right);\n edits.push({ start: pa.end, end: bin.right.getStart(), text: `.update(${v} => ${v} ${sym} ${wrapRight ? '(' : ''}` });\n edits.push({ start: bin.right.end, end: bin.right.end, text: `${wrapRight ? ')' : ''})` });\n } else {\n warn(pa, `\"${member}\" is now a signal; unsupported assignment operator.`);\n }\n return;\n }\n\n if ((ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {\n if (!isStatementLike(parent) || isReadonly) {\n warn(pa, `\"${member}\" is now a signal; ++/-- cannot be rewritten automatically here. Use ${member}.update(...).`);\n return;\n }\n const sym = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';\n if (ts.isPrefixUnaryExpression(parent)) edits.push({ start: parent.getStart(), end: pa.getStart(), text: '' });\n edits.push({ start: pa.end, end: parent.end, text: `.update(v => v ${sym} 1)` });\n return;\n }\n\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && member === 'chips') {\n const call = parent.parent;\n const method = parent.name.text;\n if (ts.isCallExpression(call) && call.expression === parent) {\n if (method === 'push') {\n if (!call.arguments.length) return;\n if (!isStatementLike(call)) {\n warn(pa, '\"chips\" is now a signal; the return value of push() is used, rewrite with chips.update(...) manually.');\n return;\n }\n const argsText = call.arguments.map((a) => a.getText()).join(',');\n const c = fresh('c', argsText);\n const first = call.arguments[0];\n const last = call.arguments[call.arguments.length - 1];\n edits.push({ start: pa.end, end: first.getStart(), text: `.update(${c} => [...${c}, ` });\n edits.push({ start: last.end, end: call.end, text: '])' });\n return;\n }\n if (ARRAY_MUTATORS.has(method)) {\n warn(pa, `\"chips\" is now a WritableSignal; \"${method}()\" mutates the array in place. Rewrite with chips.update(...) / chips.set(...).`);\n return;\n }\n }\n }\n\n // plain read\n edits.push({ start: pa.end, end: pa.end, text: '()' });\n };\n\n visit(sf);\n\n if (needsOutputImport) {\n const imp = outputImportEdit(sf, source);\n if (imp) edits.push(imp);\n }\n\n const result = [...edits]\n .sort((a, b) => b.start - a.start || b.end - a.end)\n .reduce((acc, e) => acc.slice(0, e.start) + e.text + acc.slice(e.end), source);\n return { result, warnings, infos };\n}\n\n/**\n * True when `node` (an output reference) is used as an Observable: receiver of subscribe/pipe/...,\n * or an argument (directly or inside an array literal) of another call such as merge(...).\n * Already wrapped (`outputToObservable(x.out)`) is not matched.\n */\nfunction isObservableUse(node: ts.PropertyAccessExpression): boolean {\n const p = node.parent;\n if (ts.isPropertyAccessExpression(p) && p.expression === node) {\n return OBSERVABLE_METHODS.has(p.name.text) && ts.isCallExpression(p.parent) && p.parent.expression === p;\n }\n const arg: ts.Node = ts.isArrayLiteralExpression(p) ? p : node;\n const call = arg.parent;\n if (ts.isCallExpression(call) && (call.arguments as readonly ts.Node[]).includes(arg)) {\n const callee = call.expression;\n return !(ts.isIdentifier(callee) && callee.text === 'outputToObservable');\n }\n return false;\n}\n\n/** Adds `outputToObservable` to the rxjs-interop import, or creates the import after the last one. */\nfunction outputImportEdit(sf: ts.SourceFile, source: string): Edit | null {\n const imports = sf.statements.filter(ts.isImportDeclaration);\n const existing = imports.find((i) => (i.moduleSpecifier as ts.StringLiteral).text === SIGNAL_INTEROP);\n const bindings = existing?.importClause?.namedBindings;\n if (existing && bindings && ts.isNamedImports(bindings)) {\n if (bindings.elements.some((e) => e.name.text === 'outputToObservable')) return null;\n const last = bindings.elements[bindings.elements.length - 1];\n if (!last) return { start: bindings.getStart(), end: bindings.getEnd(), text: '{ outputToObservable }' };\n return { start: last.getEnd(), end: last.getEnd(), text: ', outputToObservable' };\n }\n const line = `import { outputToObservable } from '${SIGNAL_INTEROP}';`;\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lastImport = imports[imports.length - 1];\n if (lastImport) return { start: lastImport.getEnd(), end: lastImport.getEnd(), text: `${eol}${line}` };\n return { start: 0, end: 0, text: `${line}${eol}` };\n}\n",
|
|
1608
1608
|
"displayName": "Edit",
|
|
1609
1609
|
"properties": [
|
|
1610
1610
|
{
|
|
@@ -1616,31 +1616,31 @@
|
|
|
1616
1616
|
"indexKey": "",
|
|
1617
1617
|
"optional": false,
|
|
1618
1618
|
"description": "",
|
|
1619
|
-
"line":
|
|
1619
|
+
"line": 57,
|
|
1620
1620
|
"rawdescription": "\n"
|
|
1621
1621
|
},
|
|
1622
1622
|
{
|
|
1623
|
-
"name": "
|
|
1623
|
+
"name": "start",
|
|
1624
1624
|
"coverageIgnore": false,
|
|
1625
1625
|
"deprecated": false,
|
|
1626
1626
|
"deprecationMessage": "",
|
|
1627
|
-
"type": "
|
|
1627
|
+
"type": "number",
|
|
1628
1628
|
"indexKey": "",
|
|
1629
1629
|
"optional": false,
|
|
1630
1630
|
"description": "",
|
|
1631
|
-
"line":
|
|
1631
|
+
"line": 56,
|
|
1632
1632
|
"rawdescription": "\n"
|
|
1633
1633
|
},
|
|
1634
1634
|
{
|
|
1635
|
-
"name": "
|
|
1635
|
+
"name": "text",
|
|
1636
1636
|
"coverageIgnore": false,
|
|
1637
1637
|
"deprecated": false,
|
|
1638
1638
|
"deprecationMessage": "",
|
|
1639
|
-
"type": "
|
|
1639
|
+
"type": "string",
|
|
1640
1640
|
"indexKey": "",
|
|
1641
1641
|
"optional": false,
|
|
1642
1642
|
"description": "",
|
|
1643
|
-
"line":
|
|
1643
|
+
"line": 58,
|
|
1644
1644
|
"rawdescription": "\n"
|
|
1645
1645
|
}
|
|
1646
1646
|
],
|
|
@@ -1658,12 +1658,12 @@
|
|
|
1658
1658
|
},
|
|
1659
1659
|
{
|
|
1660
1660
|
"name": "Edit",
|
|
1661
|
-
"id": "interface-Edit-
|
|
1662
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
1661
|
+
"id": "interface-Edit-ec63cf1ec803c75d650624c294e956ecef8c4347eb9f1f3d67164ae66222f0c4148af1789dd40b60686696b75c4d8eb3671f97f6b62044a25468f8b18624b514-13",
|
|
1662
|
+
"file": "packages/core/schematics/migrate-eui-chip-list/index.ts",
|
|
1663
1663
|
"deprecated": false,
|
|
1664
1664
|
"deprecationMessage": "",
|
|
1665
1665
|
"type": "interface",
|
|
1666
|
-
"sourceCode": "import { parseTemplate, TmplAstElement } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ntype Kind = 'ac' | 'panel';\n\nconst AC = 'EuiAutocompleteComponent';\nconst PANEL = 'EuiAutocompletePanelComponent';\nconst KIND_BY_TYPE: Record<string, Kind> = { [AC]: 'ac', [PANEL]: 'panel' };\n\n/** Properties that went from plain value to WritableSignal. */\nconst WRITABLE: Record<Kind, Set<string>> = {\n ac: new Set(['chips', 'selectedOptionIndex', 'isDisabled', 'itemSize']),\n panel: new Set(),\n};\n/** Properties that went from plain value to a read-only signal (viewChild()). */\nconst READONLY: Record<Kind, Set<string>> = { ac: new Set(), panel: new Set(['virtualScrolling']) };\n\nconst ARRAY_MUTATORS = new Set(['splice', 'sort', 'reverse', 'pop', 'shift', 'unshift', 'fill', 'copyWithin']);\nconst SIGNAL_API = new Set(['set', 'update', 'asReadonly']);\nconst COMPOUND_OPS = new Set([\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.AsteriskEqualsToken,\n ts.SyntaxKind.SlashEqualsToken,\n ts.SyntaxKind.PercentEqualsToken,\n ts.SyntaxKind.AsteriskAsteriskEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n]);\n\n/** EuiAutocompleteComponent outputs (EventEmitter -> OutputEmitterRef): no `.pipe`/`.subscribe` anymore. */\nconst AC_OUTPUTS = new Set([\n 'panelClose',\n 'panelOpen',\n 'inputFocus',\n 'inputBlur',\n 'clear',\n 'selectionChange',\n 'itemAdd',\n 'itemRemove',\n 'inputChange',\n 'touch',\n]);\nconst OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);\nconst SIGNAL_INTEROP = '@angular/core/rxjs-interop';\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\nexport function migrateEuiAutocomplete(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n const original = buffer.toString('utf-8');\n if (!/utocomplete|[vV]iewChild/.test(original)) return;\n\n if (path.endsWith('.html')) {\n logFocusEventInfo(original, path, context);\n return;\n }\n\n const { result, warnings, infos } = migrateTs(original, path, tree);\n warnings.forEach((w) => context.logger.warn(w));\n infos.forEach((i) => context.logger.info(i));\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-autocomplete signal members in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n });\n\n context.logger.info(`Migrated eui-autocomplete signal members in ${count} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------\n\nfunction walkTemplate(node: unknown, visit: (el: TmplAstElement) => void, seen = new Set<unknown>()): void {\n if (!node || typeof node !== 'object' || seen.has(node)) return;\n seen.add(node);\n if (Array.isArray(node)) {\n node.forEach((n) => walkTemplate(n, visit, seen));\n return;\n }\n if (!('sourceSpan' in (node as object))) return;\n if (node instanceof TmplAstElement) visit(node);\n for (const [key, value] of Object.entries(node as object)) {\n if (key.endsWith('SourceSpan') || key === 'sourceSpan' || key === 'i18n') continue;\n walkTemplate(value, visit, seen);\n }\n}\n\nfunction parseSafe(source: string): ReturnType<typeof parseTemplate> | null {\n try {\n return parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return null;\n }\n}\n\n/** Template reference names (#ref) declared on <eui-autocomplete>. */\nfunction autocompleteRefs(templates: string[]): Set<string> {\n const refs = new Set<string>();\n for (const t of templates) {\n const parsed = parseSafe(t);\n if (!parsed) continue;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name === 'eui-autocomplete') el.references.forEach((r) => refs.add(r.name));\n });\n }\n return refs;\n}\n\nfunction logFocusEventInfo(template: string, path: string, context: SchematicContext): void {\n if (!template.includes('eui-autocomplete')) return;\n const parsed = parseSafe(template);\n if (!parsed) return;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name !== 'eui-autocomplete') return;\n for (const out of el.outputs) {\n if (out.name !== 'inputFocus' && out.name !== 'inputBlur') continue;\n const handler = (out.handler as unknown as { source?: string }).source ?? '';\n if (handler.includes('$event')) {\n context.logger.info(\n `${path} - eui-autocomplete (${out.name}) now emits a FocusEvent instead of void; check that the handler accepts a FocusEvent.`,\n );\n }\n }\n });\n}\n\n// ---------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------\n\nfunction typeKind(type: ts.TypeNode | undefined): Kind | undefined {\n if (!type) return undefined;\n if (ts.isParenthesizedTypeNode(type)) return typeKind(type.type);\n if (ts.isUnionTypeNode(type)) {\n for (const t of type.types) {\n const k = typeKind(t);\n if (k) return k;\n }\n return undefined;\n }\n if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName)) return KIND_BY_TYPE[type.typeName.text];\n return undefined;\n}\n\nfunction callKind(expr: ts.Expression | undefined): Kind | undefined {\n if (!expr || !ts.isCallExpression(expr)) return undefined;\n const callee = expr.expression;\n const isFactory =\n (ts.isIdentifier(callee) && (callee.text === 'inject' || callee.text === 'viewChild')) ||\n (ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text === 'viewChild' &&\n callee.name.text === 'required');\n const arg = expr.arguments[0];\n if (isFactory && arg && ts.isIdentifier(arg)) return KIND_BY_TYPE[arg.text];\n return undefined;\n}\n\nfunction isSignalQuery(expr: ts.Expression | undefined): boolean {\n if (!expr || !ts.isCallExpression(expr)) return false;\n const c = expr.expression;\n return (\n (ts.isIdentifier(c) && c.text === 'viewChild') ||\n (ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === 'viewChild')\n );\n}\n\nfunction decoratorsOf(node: ts.Node): readonly ts.Decorator[] {\n return ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? []) : [];\n}\n\nfunction extractInlineAndLinkedTemplates(sf: ts.SourceFile, path: string, tree: Tree): string[] {\n const templates: string[] = [];\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {\n const init = node.initializer;\n if (node.name.text === 'template' && (ts.isStringLiteralLike(init) || ts.isNoSubstitutionTemplateLiteral(init))) {\n templates.push(init.text);\n } else if (node.name.text === 'templateUrl' && ts.isStringLiteralLike(init)) {\n const dir = path.slice(0, path.lastIndexOf('/'));\n const segments = `${dir}/${init.text}`.split('/');\n const resolved: string[] = [];\n for (const s of segments) {\n if (s === '..') resolved.pop();\n else if (s !== '.' && s !== '') resolved.push(s);\n }\n const buf = tree.read('/' + resolved.join('/'));\n if (buf) templates.push(buf.toString('utf-8'));\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n return templates;\n}\n\nfunction migrateTs(source: string, path: string, tree: Tree): { result: string; warnings: string[]; infos: string[] } {\n const warnings: string[] = [];\n const infos: string[] = [];\n const sf = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);\n const templates = extractInlineAndLinkedTemplates(sf, path, tree);\n const refs = autocompleteRefs(templates);\n templates.forEach((t) => logFocusEventInfo(t, path, { logger: { info: (m: string) => infos.push(m) } } as unknown as SchematicContext));\n\n // name -> kind, for `this.name`, bare `name` and `this.name()` (signal queries)\n const thisNames = new Map<string, Kind>();\n const bareNames = new Map<string, Kind>();\n const callNames = new Map<string, Kind>();\n\n const collect = (node: ts.Node): void => {\n if (ts.isPropertyDeclaration(node) && ts.isIdentifier(node.name)) {\n const name = node.name.text;\n let kind = typeKind(node.type) ?? callKind(node.initializer);\n for (const d of decoratorsOf(node)) {\n if (!ts.isCallExpression(d.expression) || !ts.isIdentifier(d.expression.expression)) continue;\n if (d.expression.expression.text !== 'ViewChild') continue;\n const arg = d.expression.arguments[0];\n if (arg && ts.isIdentifier(arg) && KIND_BY_TYPE[arg.text]) kind ??= KIND_BY_TYPE[arg.text];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) kind ??= 'ac';\n }\n const init = node.initializer;\n if (!kind && init && isSignalQuery(init) && ts.isCallExpression(init)) {\n const arg = init.arguments[0];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) {\n callNames.set(name, 'ac');\n return;\n }\n }\n if (kind) {\n if (init && isSignalQuery(init)) callNames.set(name, kind);\n else thisNames.set(name, kind);\n }\n } else if (ts.isParameter(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type);\n if (kind) {\n bareNames.set(node.name.text, kind);\n if (ts.isConstructorDeclaration(node.parent) && ts.getModifiers(node)?.length) thisNames.set(node.name.text, kind);\n }\n } else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type) ?? callKind(node.initializer);\n if (kind) bareNames.set(node.name.text, kind);\n }\n ts.forEachChild(node, collect);\n };\n collect(sf);\n\n if (!thisNames.size && !bareNames.size && !callNames.size) return { result: source, warnings, infos };\n\n /** Nearest enclosing parameter/variable declaration decides the kind, so a shadowing param of another type is ignored. */\n const resolveBare = (id: ts.Identifier): Kind | undefined => {\n for (let n: ts.Node | undefined = id.parent; n; n = n.parent) {\n const decls: (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(n)) decls.push(...n.parameters);\n if (ts.isBlock(n) || ts.isSourceFile(n)) {\n n.statements.forEach((st) => ts.isVariableStatement(st) && decls.push(...st.declarationList.declarations));\n }\n for (const d of decls) {\n if (ts.isIdentifier(d.name) && d.name.text === id.text) return typeKind(d.type) ?? callKind(d.initializer);\n }\n }\n return bareNames.get(id.text);\n };\n\n const kindOf = (expr: ts.Expression): Kind | undefined => {\n let e = expr;\n while (ts.isNonNullExpression(e) || ts.isParenthesizedExpression(e)) e = e.expression;\n if (ts.isIdentifier(e)) return resolveBare(e);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) return thisNames.get(e.name.text);\n if (\n ts.isCallExpression(e) &&\n e.arguments.length === 0 &&\n ts.isPropertyAccessExpression(e.expression) &&\n e.expression.expression.kind === ts.SyntaxKind.ThisKeyword\n ) {\n return callNames.get(e.expression.name.text);\n }\n return undefined;\n };\n\n const edits: Edit[] = [];\n const where = (n: ts.Node): string => `${path}:${sf.getLineAndCharacterOfPosition(n.getStart()).line + 1}`;\n const warn = (n: ts.Node, msg: string): void => {\n warnings.push(`${where(n)} - Manual action needed: ${msg}`);\n };\n const isStatementLike = (n: ts.Node): boolean =>\n ts.isExpressionStatement(n.parent) || (ts.isArrowFunction(n.parent) && n.parent.body === n);\n const fresh = (name: string, text: string): string => (new RegExp(`\\\\b${name}\\\\b`).test(text) ? `${name}x` : name);\n const simple = (e: ts.Expression): boolean =>\n ts.isNumericLiteral(e) || ts.isIdentifier(e) || ts.isPropertyAccessExpression(e) || ts.isStringLiteral(e) || ts.isParenthesizedExpression(e);\n\n let needsOutputImport = false;\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const kind = kindOf(node.expression);\n if (kind) {\n if (kind === 'ac' && AC_OUTPUTS.has(node.name.text) && isObservableUse(node)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'outputToObservable(' });\n edits.push({ start: node.end, end: node.end, text: ')' });\n needsOutputImport = true;\n noteFocusEvent(node);\n } else {\n handle(node, node.name.text, kind);\n }\n }\n } else if (ts.isVariableDeclaration(node) && node.initializer && kindOf(node.initializer)) {\n const kind = kindOf(node.initializer)!;\n if (ts.isIdentifier(node.name)) {\n warn(node, `\"${node.name.text}\" is an alias of an eUI autocomplete reference; member usages through the alias are not migrated. Check \"${node.name.text}\" manually (chips, selectedOptionIndex, isDisabled, itemSize, autocompleteDataSelected are signals now).`);\n } else if (ts.isObjectBindingPattern(node.name)) {\n const migrated = node.name.elements\n .map((el) => (el.propertyName ?? el.name).getText())\n .filter((m) => WRITABLE[kind].has(m) || READONLY[kind].has(m) || (kind === 'ac' && m === 'autocompleteDataSelected'));\n if (migrated.length) {\n warn(node, `destructuring of ${migrated.join(', ')} from an eUI autocomplete reference now yields a signal, not a value; read it with \"()\" (or use the property access).`);\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n const noteFocusEvent = (pa: ts.PropertyAccessExpression): void => {\n const member = pa.name.text;\n if (member !== 'inputFocus' && member !== 'inputBlur') return;\n const sub = pa.parent;\n const call = ts.isPropertyAccessExpression(sub) && sub.name.text === 'subscribe' ? sub.parent : undefined;\n const handler = call && ts.isCallExpression(call) ? call.arguments[0] : undefined;\n if (handler && (ts.isArrowFunction(handler) || ts.isFunctionExpression(handler)) && handler.parameters.length === 0) {\n infos.push(`${where(pa)} - eui-autocomplete (${member}) now emits a FocusEvent instead of void; check that this subscribe handler accepts a FocusEvent.`);\n }\n };\n\n const handle = (pa: ts.PropertyAccessExpression, member: string, kind: Kind): void => {\n const parent = pa.parent;\n const isWritable = WRITABLE[kind].has(member);\n const isReadonly = READONLY[kind].has(member);\n const isDataSelected = kind === 'ac' && member === 'autocompleteDataSelected';\n if (!isWritable && !isReadonly && !isDataSelected) return;\n\n // already migrated: `x.member()` or `x.member.set/update/asReadonly`\n if (ts.isCallExpression(parent) && parent.expression === pa) return;\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && SIGNAL_API.has(parent.name.text)) return;\n\n const isAssignTarget =\n ts.isBinaryExpression(parent) &&\n parent.left === pa &&\n parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n\n if (isDataSelected) {\n const mutating =\n ts.isPropertyAccessExpression(parent) &&\n parent.expression === pa &&\n ts.isCallExpression(parent.parent) &&\n parent.parent.expression === parent &&\n (parent.name.text === 'push' || ARRAY_MUTATORS.has(parent.name.text));\n const written = (n: ts.Node): boolean =>\n ts.isBinaryExpression(n.parent) &&\n n.parent.left === n &&\n n.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n n.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n const memberWritten =\n (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === pa && written(parent);\n if (isAssignTarget || mutating || memberWritten) {\n warn(pa, '\"autocompleteDataSelected\" is now a read-only signal input and cannot be assigned or mutated programmatically. Bind [autocompleteDataSelected] in the template instead.');\n return;\n }\n // plain read: falls through to the `()` rewrite below\n }\n\n if (isAssignTarget && !isDataSelected) {\n const bin = parent as ts.BinaryExpression;\n const op = bin.operatorToken.kind;\n if (!isStatementLike(bin)) {\n warn(pa, `\"${member}\" is now a signal; assignment is used as a value and could not be rewritten automatically.`);\n return;\n }\n if (isReadonly) {\n warn(pa, `\"${member}\" is now a read-only signal and cannot be assigned.`);\n return;\n }\n if (op === ts.SyntaxKind.EqualsToken) {\n edits.push({ start: pa.end, end: bin.right.getStart(), text: '.set(' });\n edits.push({ start: bin.right.end, end: bin.right.end, text: ')' });\n } else if (COMPOUND_OPS.has(op)) {\n const sym = ts.tokenToString(op)!.slice(0, -1);\n const rightText = bin.right.getText();\n const v = fresh('v', rightText);\n const wrapRight = !simple(bin.right);\n edits.push({ start: pa.end, end: bin.right.getStart(), text: `.update(${v} => ${v} ${sym} ${wrapRight ? '(' : ''}` });\n edits.push({ start: bin.right.end, end: bin.right.end, text: `${wrapRight ? ')' : ''})` });\n } else {\n warn(pa, `\"${member}\" is now a signal; unsupported assignment operator.`);\n }\n return;\n }\n\n if ((ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {\n if (!isStatementLike(parent) || isReadonly) {\n warn(pa, `\"${member}\" is now a signal; ++/-- cannot be rewritten automatically here. Use ${member}.update(...).`);\n return;\n }\n const sym = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';\n if (ts.isPrefixUnaryExpression(parent)) edits.push({ start: parent.getStart(), end: pa.getStart(), text: '' });\n edits.push({ start: pa.end, end: parent.end, text: `.update(v => v ${sym} 1)` });\n return;\n }\n\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && member === 'chips') {\n const call = parent.parent;\n const method = parent.name.text;\n if (ts.isCallExpression(call) && call.expression === parent) {\n if (method === 'push') {\n if (!call.arguments.length) return;\n if (!isStatementLike(call)) {\n warn(pa, '\"chips\" is now a signal; the return value of push() is used, rewrite with chips.update(...) manually.');\n return;\n }\n const argsText = call.arguments.map((a) => a.getText()).join(',');\n const c = fresh('c', argsText);\n const first = call.arguments[0];\n const last = call.arguments[call.arguments.length - 1];\n edits.push({ start: pa.end, end: first.getStart(), text: `.update(${c} => [...${c}, ` });\n edits.push({ start: last.end, end: call.end, text: '])' });\n return;\n }\n if (ARRAY_MUTATORS.has(method)) {\n warn(pa, `\"chips\" is now a WritableSignal; \"${method}()\" mutates the array in place. Rewrite with chips.update(...) / chips.set(...).`);\n return;\n }\n }\n }\n\n // plain read\n edits.push({ start: pa.end, end: pa.end, text: '()' });\n };\n\n visit(sf);\n\n if (needsOutputImport) {\n const imp = outputImportEdit(sf, source);\n if (imp) edits.push(imp);\n }\n\n const result = [...edits]\n .sort((a, b) => b.start - a.start || b.end - a.end)\n .reduce((acc, e) => acc.slice(0, e.start) + e.text + acc.slice(e.end), source);\n return { result, warnings, infos };\n}\n\n/**\n * True when `node` (an output reference) is used as an Observable: receiver of subscribe/pipe/...,\n * or an argument (directly or inside an array literal) of another call such as merge(...).\n * Already wrapped (`outputToObservable(x.out)`) is not matched.\n */\nfunction isObservableUse(node: ts.PropertyAccessExpression): boolean {\n const p = node.parent;\n if (ts.isPropertyAccessExpression(p) && p.expression === node) {\n return OBSERVABLE_METHODS.has(p.name.text) && ts.isCallExpression(p.parent) && p.parent.expression === p;\n }\n const arg: ts.Node = ts.isArrayLiteralExpression(p) ? p : node;\n const call = arg.parent;\n if (ts.isCallExpression(call) && (call.arguments as readonly ts.Node[]).includes(arg)) {\n const callee = call.expression;\n return !(ts.isIdentifier(callee) && callee.text === 'outputToObservable');\n }\n return false;\n}\n\n/** Adds `outputToObservable` to the rxjs-interop import, or creates the import after the last one. */\nfunction outputImportEdit(sf: ts.SourceFile, source: string): Edit | null {\n const imports = sf.statements.filter(ts.isImportDeclaration);\n const existing = imports.find((i) => (i.moduleSpecifier as ts.StringLiteral).text === SIGNAL_INTEROP);\n const bindings = existing?.importClause?.namedBindings;\n if (existing && bindings && ts.isNamedImports(bindings)) {\n if (bindings.elements.some((e) => e.name.text === 'outputToObservable')) return null;\n const last = bindings.elements[bindings.elements.length - 1];\n if (!last) return { start: bindings.getStart(), end: bindings.getEnd(), text: '{ outputToObservable }' };\n return { start: last.getEnd(), end: last.getEnd(), text: ', outputToObservable' };\n }\n const line = `import { outputToObservable } from '${SIGNAL_INTEROP}';`;\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lastImport = imports[imports.length - 1];\n if (lastImport) return { start: lastImport.getEnd(), end: lastImport.getEnd(), text: `${eol}${line}` };\n return { start: 0, end: 0, text: `${line}${eol}` };\n}\n",
|
|
1666
|
+
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement, getTemplateChildren } from '../utils/template-walk';\n\nconst CHIP_LIST_TAG = 'eui-chip-list';\nconst CHIP_LIST_ATTR = 'euiChipList';\nconst CHIP_TAG = 'eui-chip';\nconst CHIP_ATTR = 'euiChip';\n\nconst PROPAGATED_INPUTS = new Set([\n 'euiPrimary', 'euiSecondary', 'euiSuccess', 'euiInfo', 'euiWarning',\n 'euiDanger', 'euiAccent', 'euiVariant', 'euiSizeS', 'euiSizeVariant',\n 'euiOutline', 'euiDisabled',\n]);\n\nconst WARN_PROPERTIES = new Set([...PROPAGATED_INPUTS, 'chipRemove', 'isChipsRemovable', 'chipsLabelTruncateCount',\n 'maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel',\n 'isChipsSorted', 'chipsSortOrder']);\n\nconst REMOVED_INPUTS = new Set(['maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel', 'isChipsSorted', 'chipsSortOrder']);\n\nconst TRUNCATE_PIPE_IMPORT = 'EuiTruncatePipe';\nconst TRUNCATE_PIPE_PATH = '@eui/components/pipes';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nexport function migrateEuiChipList(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n const filesNeedingTruncateImport = new Set<string>();\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(CHIP_LIST_TAG) && !original.includes(CHIP_LIST_ATTR)) return;\n\n let result: string;\n let addedTruncate = false;\n\n if (path.endsWith('.html')) {\n result = migrateTemplate(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n // Find the associated .ts file\n const tsPath = path.replace(/\\.html$/, '.ts');\n if (tree.exists(tsPath)) {\n filesNeedingTruncateImport.add(tsPath);\n } else {\n // Try component naming convention\n const componentTsPath = path.replace(/\\.html$/, '.component.ts');\n if (tree.exists(componentTsPath)) {\n filesNeedingTruncateImport.add(componentTsPath);\n }\n }\n }\n } else {\n result = migrateInlineTemplates(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n addedTruncate = true;\n }\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would move variant/size/outline inputs to child eui-chip in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n if (addedTruncate) {\n filesNeedingTruncateImport.add(path);\n }\n\n // Warn about TS usages of removed properties\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if ([...WARN_PROPERTIES].some((p) => original.includes(p))) {\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && WARN_PROPERTIES.has(node.name.text)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(\n `${path}:${line + 1} - \"${node.name.text}\" has been removed from eui-chip-list. Move it to individual eui-chip elements.`,\n );\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n }\n });\n\n // Add EuiTruncatePipe import to component files that need it\n for (const tsPath of filesNeedingTruncateImport) {\n const buffer = tree.read(tsPath);\n if (!buffer) continue;\n const source = buffer.toString('utf-8');\n if (source.includes(TRUNCATE_PIPE_IMPORT)) continue;\n const result = addTruncatePipeImport(source, tsPath);\n if (result !== source) {\n if (!options.dryRun) {\n tree.overwrite(tsPath, result);\n }\n }\n }\n\n context.logger.info(`Migrated eui-chip-list inputs/outputs to child eui-chip in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction addTruncatePipeImport(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const edits: Edit[] = [];\n\n // 1. Add ES import statement for EuiTruncatePipe\n let hasEsImport = false;\n let lastImportEnd = 0;\n\n for (const stmt of sourceFile.statements) {\n if (ts.isImportDeclaration(stmt)) {\n lastImportEnd = stmt.getEnd();\n const moduleSpec = (stmt.moduleSpecifier as ts.StringLiteral).text;\n if (moduleSpec === TRUNCATE_PIPE_PATH) {\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n if (namedBindings.elements.some((el) => el.name.text === TRUNCATE_PIPE_IMPORT)) {\n hasEsImport = true;\n } else {\n // Add to existing import from same path\n const lastEl = namedBindings.elements[namedBindings.elements.length - 1];\n edits.push({ start: lastEl.getEnd(), end: lastEl.getEnd(), replacement: `, ${TRUNCATE_PIPE_IMPORT}` });\n hasEsImport = true;\n }\n }\n }\n }\n }\n\n if (!hasEsImport) {\n const importStatement = `\\nimport { ${TRUNCATE_PIPE_IMPORT} } from '${TRUNCATE_PIPE_PATH}';`;\n edits.push({ start: lastImportEnd, end: lastImportEnd, replacement: importStatement });\n }\n\n // 2. Add EuiTruncatePipe to @Component imports array\n const visit = (node: ts.Node): void => {\n if (ts.isClassDeclaration(node)) {\n const decs = ts.getDecorators(node);\n if (!decs) return;\n for (const dec of decs) {\n if (!ts.isCallExpression(dec.expression) || !ts.isIdentifier(dec.expression.expression) || dec.expression.expression.text !== 'Component') continue;\n const metadata = dec.expression.arguments[0];\n if (!ts.isObjectLiteralExpression(metadata)) continue;\n for (const prop of metadata.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name) || prop.name.text !== 'imports') continue;\n if (!ts.isArrayLiteralExpression(prop.initializer)) continue;\n const arr = prop.initializer;\n const arrText = source.slice(arr.getStart(sourceFile), arr.getEnd());\n if (arrText.includes(TRUNCATE_PIPE_IMPORT)) continue;\n if (arr.elements.length > 0) {\n const lastElement = arr.elements[arr.elements.length - 1];\n edits.push({ start: lastElement.getEnd(), end: lastElement.getEnd(), replacement: `,\\n ${TRUNCATE_PIPE_IMPORT}` });\n } else {\n edits.push({ start: arr.getStart(sourceFile) + 1, end: arr.getEnd() - 1, replacement: TRUNCATE_PIPE_IMPORT });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: Edit[] = [];\n\n visitNodes(parsed.nodes, source, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(CHIP_LIST_TAG) && !rawTemplate.includes(CHIP_LIST_ATTR)) {\n ts.forEachChild(node, visit);\n return;\n }\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n return applyEdits(source, changes);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n if (isChipListElement(node)) migrateChipListElement(node, source, edits);\n });\n}\n\nfunction isChipListElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_LIST_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_LIST_ATTR);\n}\n\nfunction isChipElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_ATTR);\n}\n\nfunction findChildChips(nodes: TmplAstNode[]): TmplAstElement[] {\n const chips: TmplAstElement[] = [];\n for (const node of nodes) {\n if (node instanceof TmplAstElement && isChipElement(node)) {\n chips.push(node);\n } else {\n chips.push(...findChildChips(getTemplateChildren(node)));\n }\n }\n return chips;\n}\n\nfunction migrateChipListElement(element: TmplAstElement, source: string, edits: Edit[]): void {\n const childChips = findChildChips(element.children);\n const insertions: string[] = [];\n let truncateValue: string | null = null;\n\n // Collect and remove propagated static attributes\n for (const attr of element.attributes) {\n if (PROPAGATED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n insertions.push(attr.value ? `${attr.name}=\"${attr.value}\"` : attr.name);\n }\n if (attr.name === 'isChipsRemovable') {\n edits.push(removalEdit(attr, source));\n insertions.push('isChipRemovable');\n }\n if (attr.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(attr, source));\n truncateValue = attr.value || null;\n }\n if (REMOVED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n }\n }\n\n // Collect and remove propagated bound inputs\n for (const input of element.inputs) {\n if (PROPAGATED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n insertions.push(raw);\n }\n if (input.name === 'isChipsRemovable') {\n edits.push(removalEdit(input, source));\n const valueText = extractBindingValue(input, source);\n insertions.push(`[isChipRemovable]=\"${valueText}\"`);\n }\n if (input.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(input, source));\n truncateValue = extractBindingValue(input, source);\n }\n if (REMOVED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n }\n }\n\n // Collect and remove (chipRemove) output\n let chipRemoveHandler: string | null = null;\n for (const output of element.outputs) {\n if (output.name === 'chipRemove') {\n edits.push(removalEdit(output, source));\n chipRemoveHandler = extractHandlerExpression(output, source);\n }\n }\n\n if (chipRemoveHandler) {\n insertions.push(`(remove)=\"${chipRemoveHandler}\"`);\n }\n\n // Add collected attributes to each child eui-chip\n if (insertions.length > 0) {\n for (const chip of childChips) {\n const existingNames = getExistingAttrNames(chip);\n const toInsert = insertions.filter((ins) => {\n const name = extractAttrName(ins);\n return !existingNames.has(name);\n });\n if (toInsert.length > 0) {\n const insertPos = chip.startSourceSpan.end.offset - 1;\n edits.push({ start: insertPos, end: insertPos, replacement: ' ' + toInsert.join(' ') });\n }\n }\n }\n\n // Add euiTruncate pipe to chip label content\n if (truncateValue) {\n for (const chip of childChips) {\n const labelEdit = buildTruncatePipeEdit(chip, source, truncateValue);\n if (labelEdit) edits.push(labelEdit);\n }\n }\n}\n\nfunction buildTruncatePipeEdit(chip: TmplAstElement, source: string, truncateValue: string): Edit | null {\n // Find <span euiLabel>...</span> inside the chip\n const labelEl = findLabelElement(chip.children);\n if (labelEl !== null && labelEl !== undefined && labelEl.endSourceSpan) {\n const contentStart = labelEl.startSourceSpan.end.offset;\n const contentEnd = labelEl.endSourceSpan.start.offset;\n const content = source.slice(contentStart, contentEnd);\n if (content && !content.includes('euiTruncate')) {\n const trimmed = content.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch) {\n return { start: contentStart, end: contentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n return { start: contentStart, end: contentEnd, replacement: `{{ '${trimmed}' | euiTruncate: ${truncateValue} }}` };\n }\n }\n\n // Check direct text content inside chip (no label element)\n if (chip.endSourceSpan) {\n const chipContentStart = chip.startSourceSpan.end.offset;\n const chipContentEnd = chip.endSourceSpan.start.offset;\n const chipContent = source.slice(chipContentStart, chipContentEnd);\n const trimmed = chipContent.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch && !chipContent.includes('euiTruncate')) {\n return { start: chipContentStart, end: chipContentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n }\n return null;\n}\n\nfunction findLabelElement(nodes: TmplAstNode[]): TmplAstElement | null {\n for (const node of nodes) {\n if (node instanceof TmplAstElement && node.attributes.some((a) => a.name === 'euiLabel')) return node;\n const nested = findLabelElement(getTemplateChildren(node));\n if (nested) return nested;\n }\n return null;\n}\n\nfunction getExistingAttrNames(element: TmplAstElement): Set<string> {\n const names = new Set<string>();\n for (const attr of element.attributes) names.add(attr.name);\n for (const input of element.inputs) names.add(input.name);\n for (const output of element.outputs) names.add(output.name);\n return names;\n}\n\nfunction extractAttrName(insertion: string): string {\n const outputMatch = insertion.match(/^\\(([^)]+)\\)/);\n if (outputMatch) return outputMatch[1];\n const inputMatch = insertion.match(/^\\[([^\\]]+)\\]/);\n if (inputMatch) return inputMatch[1];\n return insertion.split('=')[0];\n}\n\nfunction removalEdit(node: TmplAstTextAttribute | TmplAstBoundAttribute | TmplAstBoundEvent, source: string): Edit {\n let start = node.sourceSpan.start.offset;\n while (start > 0 && (source[start - 1] === ' ' || source[start - 1] === '\\t')) {\n start--;\n }\n return { start, end: node.sourceSpan.end.offset, replacement: '' };\n}\n\nfunction extractBindingValue(input: TmplAstBoundAttribute, source: string): string {\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : 'true';\n}\n\nfunction extractHandlerExpression(output: TmplAstBoundEvent, source: string): string {\n const raw = source.slice(output.sourceSpan.start.offset, output.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : '';\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n seen.set(`${edit.start}:${edit.end}`, edit);\n }\n return Array.from(seen.values());\n}\n",
|
|
1667
1667
|
"displayName": "Edit",
|
|
1668
1668
|
"properties": [
|
|
1669
1669
|
{
|
|
@@ -1675,31 +1675,31 @@
|
|
|
1675
1675
|
"indexKey": "",
|
|
1676
1676
|
"optional": false,
|
|
1677
1677
|
"description": "",
|
|
1678
|
-
"line":
|
|
1678
|
+
"line": 34,
|
|
1679
1679
|
"rawdescription": "\n"
|
|
1680
1680
|
},
|
|
1681
1681
|
{
|
|
1682
|
-
"name": "
|
|
1682
|
+
"name": "replacement",
|
|
1683
1683
|
"coverageIgnore": false,
|
|
1684
1684
|
"deprecated": false,
|
|
1685
1685
|
"deprecationMessage": "",
|
|
1686
|
-
"type": "
|
|
1686
|
+
"type": "string",
|
|
1687
1687
|
"indexKey": "",
|
|
1688
1688
|
"optional": false,
|
|
1689
1689
|
"description": "",
|
|
1690
|
-
"line":
|
|
1690
|
+
"line": 35,
|
|
1691
1691
|
"rawdescription": "\n"
|
|
1692
1692
|
},
|
|
1693
1693
|
{
|
|
1694
|
-
"name": "
|
|
1694
|
+
"name": "start",
|
|
1695
1695
|
"coverageIgnore": false,
|
|
1696
1696
|
"deprecated": false,
|
|
1697
1697
|
"deprecationMessage": "",
|
|
1698
|
-
"type": "
|
|
1698
|
+
"type": "number",
|
|
1699
1699
|
"indexKey": "",
|
|
1700
1700
|
"optional": false,
|
|
1701
1701
|
"description": "",
|
|
1702
|
-
"line":
|
|
1702
|
+
"line": 33,
|
|
1703
1703
|
"rawdescription": "\n"
|
|
1704
1704
|
}
|
|
1705
1705
|
],
|
|
@@ -2083,12 +2083,12 @@
|
|
|
2083
2083
|
},
|
|
2084
2084
|
{
|
|
2085
2085
|
"name": "Edit",
|
|
2086
|
-
"id": "interface-Edit-
|
|
2087
|
-
"file": "packages/core/schematics/migrate-
|
|
2086
|
+
"id": "interface-Edit-85d506677a88d24ac5314a45baa87ebcf9819f4d8375ebff75fd7dd3eb56602606744787c8eaa07b0049a17bfeb30b2ad99fb4b760709d0c66b30365ae949899-20",
|
|
2087
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
2088
2088
|
"deprecated": false,
|
|
2089
2089
|
"deprecationMessage": "",
|
|
2090
2090
|
"type": "interface",
|
|
2091
|
-
"sourceCode": "import { BindingType, parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit } from '../utils/todo-comment';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst OLD_CLASS = 'EuiTooltipConfig';\nconst NEW_INTERFACE = 'EuiTooltipInterface';\nconst REMOVED_ANIMATION = 'showHide';\nconst DIRECTIVE_CLASS = 'EuiTooltipDirective';\n\nconst RENAMED_INPUTS: Record<string, string> = {\n isPrimary: 'euiTooltipPrimary',\n isSecondary: 'euiTooltipSecondary',\n isInfo: 'euiTooltipInfo',\n isSuccess: 'euiTooltipSuccess',\n isWarning: 'euiTooltipWarning',\n isDanger: 'euiTooltipDanger',\n isAccent: 'euiTooltipAccent',\n};\n\nexport function migrateEuiTooltip(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n let result = original;\n if (path.endsWith('.html')) {\n if (!original.includes('euiTooltip')) return;\n result = migrateTemplate(original, path, context);\n } else {\n if (\n !original.includes(OLD_CLASS) &&\n !original.includes(REMOVED_ANIMATION) &&\n !original.includes('euiTooltip') &&\n !original.includes(DIRECTIVE_CLASS)\n ) {\n return;\n }\n if (original.includes(OLD_CLASS)) result = migrateTypeScript(result, path, context);\n if (result.includes(DIRECTIVE_CLASS)) result = migrateProgrammaticUsage(result, path, context);\n if (result.includes(REMOVED_ANIMATION)) result = removeShowHideAnimation(result, path, context);\n if (result.includes('euiTooltip')) result = migrateInlineTemplates(result, path, context);\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-tooltip usages in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated eui-tooltip usages in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n // Track if EuiTooltipInterface is already imported\n let hasInterfaceImport = false;\n let classImportDecl: ts.ImportDeclaration | null = null;\n let classImportModuleSpecifier: string | null = null;\n\n // First pass: analyze imports\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n for (const specifier of namedBindings.elements) {\n if (specifier.name.text === NEW_INTERFACE) {\n hasInterfaceImport = true;\n }\n if (specifier.name.text === OLD_CLASS) {\n classImportDecl = stmt;\n classImportModuleSpecifier = (stmt.moduleSpecifier as ts.StringLiteral).text;\n }\n }\n }\n\n // Second pass: handle import declarations\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n const specifiers = namedBindings.elements;\n const classSpecifier = specifiers.find((s) => s.name.text === OLD_CLASS);\n if (!classSpecifier) continue;\n\n if (hasInterfaceImport) {\n // EuiTooltipInterface is already imported elsewhere → remove EuiTooltipConfig from this import\n removeImportSpecifier(namedBindings, classSpecifier, sourceFile, edits);\n } else {\n // Rename EuiTooltipConfig → EuiTooltipInterface in the import\n edits.push({\n start: classSpecifier.name.getStart(sourceFile),\n end: classSpecifier.name.getEnd(),\n replacement: NEW_INTERFACE,\n });\n hasInterfaceImport = true;\n }\n }\n\n // Third pass: replace `new EuiTooltipConfig(...)` → spread/cast to interface\n const visitNewExpressions = (node: ts.Node): void => {\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) {\n const args = node.arguments;\n if (args !== undefined && args.length === 1) {\n const arg = args[0];\n // `new EuiTooltipConfig({ ... })` → `{ ... } as EuiTooltipInterface`\n // But if the argument is just a variable, we keep it: `varName as EuiTooltipInterface`\n const argText = source.slice(arg.getStart(sourceFile), arg.getEnd());\n\n if (ts.isObjectLiteralExpression(arg)) {\n // Inline object: `new EuiTooltipConfig({ x: 1 })` → `{ x: 1 }`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n } else {\n // Variable or expression: `new EuiTooltipConfig(opts)` → `opts`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n }\n } else if (args === undefined || args.length === 0) {\n // `new EuiTooltipConfig()` → `{} as EuiTooltipInterface`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: `{} as ${NEW_INTERFACE}`,\n });\n }\n return; // don't recurse into children we've already replaced\n }\n ts.forEachChild(node, visitNewExpressions);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitNewExpressions(stmt);\n }\n }\n\n // Fourth pass: rename all remaining identifier references (type annotations, etc.)\n const visitRefs = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n // Skip nodes we already covered in new expressions\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) return;\n\n if (ts.isIdentifier(node) && node.text === OLD_CLASS) {\n // Ensure this is not part of an import declaration\n if (!isPartOfImport(node)) {\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: NEW_INTERFACE,\n });\n }\n }\n ts.forEachChild(node, visitRefs);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitRefs(stmt);\n }\n }\n\n return applyEdits(source, edits);\n}\n\n/** Removes the `showHide` animation (import + `animations: [...]` entries) imported from an @eui package. */\nfunction removeShowHideAnimation(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n let found = false;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;\n if (!stmt.moduleSpecifier.text.startsWith('@eui/')) continue;\n const named = stmt.importClause?.namedBindings;\n if (!named || !ts.isNamedImports(named)) continue;\n const spec = named.elements.find((e) => e.name.text === REMOVED_ANIMATION && !e.propertyName);\n if (!spec) continue;\n found = true;\n removeImportSpecifier(named, spec, sourceFile, edits);\n }\n if (!found) return source;\n\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'animations' &&\n ts.isArrayLiteralExpression(node.initializer)\n ) {\n const arr = node.initializer;\n const kept = arr.elements.filter((e) => !(ts.isIdentifier(e) && e.text === REMOVED_ANIMATION));\n if (kept.length !== arr.elements.length) {\n if (kept.length === 0) {\n removeObjectProperty(node, sourceFile, edits);\n } else {\n edits.push({\n start: arr.getStart(sourceFile) + 1,\n end: arr.getEnd() - 1,\n replacement: kept.map((e) => e.getText(sourceFile)).join(', '),\n });\n }\n }\n } else if (ts.isIdentifier(node) && node.text === REMOVED_ANIMATION && !isPartOfImport(node) && !isInRemovedArray(node)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));\n context.logger.warn(`${filePath}:${line + 1} - Manual action needed: the \"showHide\" animation has been removed from @eui/components.`);\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction isInRemovedArray(node: ts.Node): boolean {\n const parent = node.parent;\n return (\n !!parent &&\n ts.isArrayLiteralExpression(parent) &&\n ts.isPropertyAssignment(parent.parent) &&\n ts.isIdentifier(parent.parent.name) &&\n parent.parent.name.text === 'animations'\n );\n}\n\nfunction removeObjectProperty(prop: ts.PropertyAssignment, sourceFile: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sourceFile.getFullText();\n let start = prop.getFullStart();\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getFullStart();\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\nfunction migrateInlineTemplates(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'template' &&\n (ts.isNoSubstitutionTemplateLiteral(node.initializer) || ts.isStringLiteral(node.initializer))\n ) {\n const lit = node.initializer;\n const start = lit.getStart(sourceFile) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (raw.includes('euiTooltip')) {\n const migrated = migrateTemplate(raw, filePath, context);\n if (migrated !== raw) edits.push({ start, end: lit.getEnd() - 1, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string, filePath: string, context: SchematicContext): string {\n const parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, source, filePath, context, edits);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n forEachElement(nodes, (node) => collectElementEdits(node, source, filePath, context, edits));\n}\n\nfunction collectElementEdits(el: TmplAstElement, source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n const tooltipAttr = el.attributes.find((a) => a.name === 'euiTooltip');\n const tooltipInput = el.inputs.find((i) => i.name === 'euiTooltip' && i.type === BindingType.Property);\n if (!tooltipAttr && !tooltipInput) return;\n\n // All messages of one element are merged into ONE comment: several TODOs would be inserted at the\n // same offset and overwrite each other.\n const messages: string[] = [];\n const warn = (offset: number, message: string): void => {\n messages.push(message);\n const { line } = lineOf(source, offset);\n context.logger.warn(`${filePath}:${line} - Manual action needed on <${el.name}>: ${message}`);\n };\n\n for (const attr of el.attributes) {\n if (RENAMED_INPUTS[attr.name]) {\n edits.push({ start: attr.keySpan!.start.offset, end: attr.keySpan!.end.offset, replacement: RENAMED_INPUTS[attr.name] });\n }\n }\n for (const input of el.inputs) {\n if (input.type === BindingType.Property && RENAMED_INPUTS[input.name]) {\n edits.push({ start: input.keySpan!.start.offset, end: input.keySpan!.end.offset, replacement: RENAMED_INPUTS[input.name] });\n }\n }\n\n // `position`: the migration guide lists it as removed, but EuiTooltipDirective still declares it\n // (model()). Deleting it would silently change behavior, so it is kept and flagged.\n const position = [\n ...el.attributes.filter((a) => a.name === 'position'),\n ...el.inputs.filter((i) => i.type === BindingType.Property && i.name === 'position'),\n ][0];\n if (position) {\n warn(\n position.sourceSpan.start.offset,\n 'input position of euiTooltip is documented as removed in eUI v22 but is still declared by EuiTooltipDirective. It was kept unchanged; verify it against the version you upgrade to.',\n );\n }\n\n const config = el.inputs.find((i) => i.type === BindingType.Property && i.name === 'config');\n if (config) {\n warn(\n config.sourceSpan.start.offset,\n 'input config of euiTooltip has been removed. Use the individual inputs (euiTooltip, euiTooltipPrimary, showDelay, hideDelay, contentAlignment, isDisabled) instead.',\n );\n }\n\n if (tooltipAttr && !tooltipAttr.value && !tooltipInput) {\n warn(tooltipAttr.sourceSpan.start.offset, 'input euiTooltip is now required and needs a value, e.g. euiTooltip=\"My tooltip\".');\n }\n\n if (messages.length > 0) {\n const todo = createTodoEdit(source, el.startSourceSpan.start.offset, messages.join(' '));\n if (todo) edits.push(todo);\n }\n}\n\n/**\n * Programmatic usage of a `EuiTooltipDirective` reference (`tt.isPrimary = true`, `tt.config`).\n * Renamed flags are renamed; `config` cannot be migrated and is flagged. Name based, scope aware for\n * parameters/variables (a differently typed parameter with the same name is left alone).\n * shortcut: only `this.x` and locals/params typed `EuiTooltipDirective` are followed; aliases are not.\n */\nfunction migrateProgrammaticUsage(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const isTyped = (t: ts.TypeNode | undefined): boolean =>\n !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === DIRECTIVE_CLASS;\n const isViewChildOf = (n: ts.PropertyDeclaration): boolean =>\n (ts.getDecorators?.(n) ?? []).some(\n (d) =>\n ts.isCallExpression(d.expression) &&\n ['ViewChild', 'ContentChild'].includes(d.expression.expression.getText(sourceFile)) &&\n d.expression.arguments[0]?.getText(sourceFile) === DIRECTIVE_CLASS,\n );\n\n const props = new Set<string>();\n const collect = (n: ts.Node): void => {\n if (ts.isPropertyDeclaration(n) && ts.isIdentifier(n.name) && (isTyped(n.type) || isViewChildOf(n))) props.add(n.name.text);\n ts.forEachChild(n, collect);\n };\n collect(sourceFile);\n\n /** Nearest declaration of a bare identifier: true = typed directive, false = something else, undefined = none found. */\n const bareIsDirective = (id: ts.Identifier): boolean | undefined => {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if ((ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) && cur.initializer && ts.isVariableDeclarationList(cur.initializer)) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return isTyped(d.type);\n }\n return undefined;\n };\n\n const visit = (n: ts.Node): void => {\n if (ts.isPropertyAccessExpression(n) && (RENAMED_INPUTS[n.name.text] || n.name.text === 'config')) {\n const target = n.expression;\n const tracked =\n (ts.isPropertyAccessExpression(target) && target.expression.kind === ts.SyntaxKind.ThisKeyword && props.has(target.name.text)) ||\n (ts.isIdentifier(target) && bareIsDirective(target) === true);\n if (tracked) {\n if (RENAMED_INPUTS[n.name.text]) {\n edits.push({ start: n.name.getStart(sourceFile), end: n.name.getEnd(), replacement: RENAMED_INPUTS[n.name.text] });\n } else {\n const { line } = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));\n context.logger.warn(\n `${filePath}:${line + 1} - Manual action needed: the \"config\" input of EuiTooltipDirective has been removed. Use the individual inputs instead.`,\n );\n }\n }\n }\n ts.forEachChild(n, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction lineOf(source: string, offset: number): { line: number } {\n return { line: source.slice(0, offset).split('\\n').length };\n}\n\nfunction isPartOfImport(node: ts.Node): boolean {\n let current: ts.Node | undefined = node.parent;\n while (current) {\n if (ts.isImportDeclaration(current)) return true;\n current = current.parent;\n }\n return false;\n}\n\nfunction removeImportSpecifier(\n namedImports: ts.NamedImports,\n specifier: ts.ImportSpecifier,\n sourceFile: ts.SourceFile,\n edits: Edit[],\n): void {\n const elements = namedImports.elements;\n if (elements.length === 1) {\n // Remove the entire import declaration\n const importDecl = namedImports.parent.parent;\n let end = importDecl.getEnd();\n // Also remove trailing newline if present\n const fullText = sourceFile.getFullText();\n if (fullText[end] === '\\n') end++;\n edits.push({\n start: importDecl.getStart(sourceFile),\n end,\n replacement: '',\n });\n } else {\n // Remove just this specifier with surrounding comma/whitespace\n const idx = elements.indexOf(specifier);\n let start: number;\n let end: number;\n if (idx < elements.length - 1) {\n // Not the last → remove from this specifier start to next specifier start\n start = specifier.getStart(sourceFile);\n end = elements[idx + 1].getStart(sourceFile);\n } else {\n // Last element → remove from previous element end to this end\n start = elements[idx - 1].getEnd();\n end = specifier.getEnd();\n }\n edits.push({ start, end, replacement: '' });\n }\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
2091
|
+
"sourceCode": "import {\n Binary,\n BindingPipe,\n BindingType,\n CombinedRecursiveAstVisitor,\n ImplicitReceiver,\n parseTemplate,\n PropertyRead,\n SafePropertyRead,\n TmplAstElement,\n TmplAstText,\n} from '@angular/compiler';\nimport { dirname, join, normalize } from '@angular-devkit/core';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit, TODO_PREFIX } from '../utils/todo-comment';\n\n/**\n * Migrates @ngx-translate/core v17 -> v18 breaking changes.\n *\n * No type checker is used: a `TranslateService` receiver is resolved from its declaration in the same\n * file (`: TranslateService`, `inject(TranslateService)`, constructor parameter properties) and, for\n * templates, from the component class that owns the template.\n * shortcut: receivers that are aliased, destructured, passed through other types or declared in another\n * file are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst CORE = '@ngx-translate/core';\nconst HTTP_LOADER = '@ngx-translate/http-loader';\n\nconst TOKEN_PROVIDERS: Record<string, string> = {\n TranslateLoader: 'provideTranslateLoader',\n TranslateCompiler: 'provideTranslateCompiler',\n TranslateParser: 'provideTranslateParser',\n MissingTranslationHandler: 'provideMissingTranslationHandler',\n};\nconst PLUGIN_KEYS = ['loader', 'compiler', 'parser', 'missingTranslationHandler'];\nconst MEMBER_RENAMES: Record<string, string> = {\n setDefaultLang: 'setFallbackLang',\n getDefaultLang: 'getFallbackLang',\n onDefaultLangChange: 'onFallbackLangChange',\n};\nconst ASSIGN_OPS = new Set<ts.SyntaxKind>([\n ts.SyntaxKind.EqualsToken,\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n]);\n\nexport function migrateNgxTranslate18(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n const tsFiles: string[] = [];\n const htmlFiles: string[] = [];\n visitDir(tree.getDir(scanPath || '/'), (path) => (path.endsWith('.html') ? htmlFiles : tsFiles).push(path));\n\n const projectUsesNgx = tsFiles.some((f) => tree.read(f)?.toString('utf-8').includes(CORE));\n const read = (p: string): string | undefined => tree.read(p)?.toString('utf-8');\n // forChild({ extend: true }) services merge translations; setTranslation(lang, t) callers need a review then.\n const projectHasExtend = tsFiles.some((f) => {\n const s = read(f);\n return !!s && s.includes('forChild') && /extend\\s*:\\s*true/.test(s);\n });\n\n let fileCount = 0;\n const write = (path: string, original: string, result: string): void => {\n if (result === original) return;\n if (options.dryRun) logDryRun(context, `Would migrate @ngx-translate/core usages in ${path}`);\n else tree.overwrite(path, result);\n fileCount++;\n };\n\n for (const path of tsFiles) {\n const original = read(path);\n if (!original) continue;\n const hasCore = original.includes(CORE) || original.includes(HTTP_LOADER);\n if (!hasCore && !(original.includes('template') && original.includes('translate'))) continue;\n write(path, original, migrateTypeScript(original, path, context, { projectHasExtend, projectUsesNgx, read }));\n }\n\n for (const path of htmlFiles) {\n const original = read(path);\n if (!original || !/translate|currentLang/.test(original)) continue;\n const members = membersForExternalTemplate(path, tsFiles, read);\n const scan = scanTemplate(original, path, context, {\n members,\n allowKeyRewrite: true,\n checkAttributes: projectUsesNgx,\n where: (o) => `${path}:${lineOf(original, o)}`,\n });\n write(path, original, applyEdits(original, scan.edits));\n }\n\n context.logger.info(`Migrated @ngx-translate/core usages in ${fileCount} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TemplateScan {\n edits: Edit[];\n usage: { pipe: boolean; directive: boolean };\n}\n\nfunction scanTemplate(\n source: string,\n filePath: string,\n context: SchematicContext,\n opts: {\n members: Set<string>;\n allowKeyRewrite: boolean;\n checkAttributes?: boolean;\n where: (offset: number) => string;\n quiet?: boolean\n }\n): TemplateScan {\n const result: TemplateScan = { edits: [], usage: { pipe: false, directive: false } };\n let parsed;\n try {\n parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n } catch {\n return result;\n }\n if (parsed.errors && parsed.errors.length > 0) return result;\n\n const seenWarnings = new Set<string>();\n const warn = (offset: number, message: string): void => {\n const text = `${opts.where(offset)} - Manual action needed: ${message}`;\n if (opts.quiet || seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const writes = new Set<unknown>();\n const isSvc = (r: unknown): boolean =>\n r instanceof PropertyRead && r.receiver instanceof ImplicitReceiver && opts.members.has(r.name);\n\n const visitor = new (class extends CombinedRecursiveAstVisitor {\n override visitBinary(ast: Binary, context: unknown): void {\n if (ast.operation.endsWith('=') && !['==', '===', '!=', '!==', '<=', '>='].includes(ast.operation)) {\n const left = ast.left;\n if ((left instanceof PropertyRead || left instanceof SafePropertyRead) && left.name === 'currentLang' && isSvc(left.receiver)) {\n writes.add(left);\n warn(left.sourceSpan.start, 'TranslateService.currentLang is a read-only Signal in @ngx-translate/core v18; use translate.use(lang) instead of assigning it.');\n }\n }\n super.visitBinary(ast, context);\n }\n\n override visitPropertyRead(ast: PropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitPropertyRead(ast, context);\n }\n\n override visitSafePropertyRead(ast: SafePropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitSafePropertyRead(ast, context);\n }\n\n override visitPipe(ast: BindingPipe, context: unknown): void {\n if (ast.name === 'translate') result.usage.pipe = true;\n super.visitPipe(ast, context);\n }\n\n override visitElement(el: TmplAstElement): void {\n this.checkTranslateAttribute(el);\n super.visitElement(el);\n }\n\n override visitTemplate(t: Parameters<CombinedRecursiveAstVisitor['visitTemplate']>[0]): void {\n if (\n [...t.attributes, ...t.inputs, ...t.templateAttrs].some((a) => a.name === 'translate' || a.name === 'ngx-translate')\n ) {\n result.usage.directive = true;\n }\n super.visitTemplate(t);\n }\n\n private rewriteCurrentLang(ast: PropertyRead | SafePropertyRead): void {\n if (ast.name !== 'currentLang' || writes.has(ast) || !isSvc(ast.receiver)) return;\n const end = ast.nameSpan.end;\n if (/^\\s*\\(/.test(source.slice(end))) return; // already a call\n result.edits.push({ start: end, end, replacement: '()' });\n }\n\n private checkTranslateAttribute(el: TmplAstElement): void {\n if (opts.checkAttributes === false) return;\n const textAttr = el.attributes.find((a) => a.name === 'translate' || a.name === 'ngx-translate');\n const bound = el.inputs.find((i) => i.name === 'translate' && i.type === BindingType.Property);\n if (textAttr || bound) result.usage.directive = true;\n const at = el.startSourceSpan.start.offset;\n const todo = (message: string): void => {\n warn(at, `<${el.name}> ${message}`);\n const edit = createTodoEdit(source, at, message);\n if (edit) result.edits.push(edit);\n };\n\n // 7: [translate]=\"'KEY'\" now sets textContent: element children are overwritten.\n if (bound && el.children.some((c) => !(c instanceof TmplAstText))) {\n todo(\n 'with [translate] the element content is replaced by the translation (textContent) in @ngx-translate/core v18, child elements are lost. Restructure the markup.'\n );\n return;\n }\n\n // 8: <el translate>KEY</el> (text as key) is deprecated.\n if (!textAttr || textAttr.name !== 'translate' || textAttr.value !== '' || bound) return;\n const meaningful = el.children.filter((c) => !(c instanceof TmplAstText && c.value.trim() === ''));\n if (meaningful.length === 0) return;\n const only = meaningful[0];\n const isPlain =\n meaningful.length === 1 &&\n el.children.length === 1 &&\n only instanceof TmplAstText &&\n !!el.endSourceSpan &&\n source.slice(el.startSourceSpan.end.offset, el.endSourceSpan.start.offset) === only.value &&\n !/[\"'`&<>{}\\\\]/.test(only.value);\n if (!isPlain) {\n todo(\n 'uses its text content as translation key, which is deprecated and not safely convertible here (interpolation or nested elements). Use [translate]=\"\\'KEY\\'\", the translate pipe or *translateBlock.'\n );\n return;\n }\n if (!opts.allowKeyRewrite) {\n warn(at, `<${el.name}> text as translation key is deprecated; replace with [translate]=\"'KEY'\" (not rewritten inside a quoted inline template).`);\n return;\n }\n const key = (only as TmplAstText).value.trim();\n result.edits.push({\n start: textAttr.sourceSpan.start.offset,\n end: textAttr.sourceSpan.end.offset,\n replacement: `[translate]=\"'${key}'\"`,\n });\n result.edits.push({ start: el.startSourceSpan.end.offset, end: el.endSourceSpan!.start.offset, replacement: '' });\n }\n })();\n\n for (const node of parsed.nodes) visitor.visit(node);\n return result;\n}\n\n/** Members typed/injected as TranslateService of the component whose templateUrl points at `htmlPath`. */\nfunction membersForExternalTemplate(htmlPath: string, tsFiles: string[], read: (p: string) => string | undefined): Set<string> {\n const dir = dirOf(htmlPath);\n for (const f of tsFiles) {\n if (dirOf(f) !== dir || f.endsWith('.spec.ts')) continue;\n const src = read(f);\n if (!src || !src.includes('templateUrl') || !src.includes(CORE)) continue;\n const sf = ts.createSourceFile(f, src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const helper = new ServiceResolver(sf);\n for (const stmt of sf.statements) {\n if (!ts.isClassDeclaration(stmt)) continue;\n const url = componentProp(stmt, 'templateUrl');\n if (url && ts.isStringLiteralLike(url.initializer) && resolveUrl(dir, url.initializer.text) === normalize(htmlPath)) {\n return helper.members(stmt);\n }\n }\n }\n return new Set();\n}\n\nfunction componentObject(cls: ts.ClassDeclaration): ts.ObjectLiteralExpression | undefined {\n for (const d of ts.getDecorators(cls) ?? []) {\n if (ts.isCallExpression(d.expression) && ts.isIdentifier(d.expression.expression) && d.expression.expression.text === 'Component') {\n const arg = d.expression.arguments[0];\n if (arg && ts.isObjectLiteralExpression(arg)) return arg;\n }\n }\n return undefined;\n}\n\nfunction componentProp(cls: ts.ClassDeclaration, name: string): ts.PropertyAssignment | undefined {\n return componentObject(cls)?.properties.find(\n (p): p is ts.PropertyAssignment => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === name\n );\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TranslateService receiver resolution\n// ---------------------------------------------------------------------------------------------------------------------\n\nclass ServiceResolver {\n readonly svcName: string | undefined;\n private cache = new Map<ts.Node, Set<string>>();\n\n constructor(private readonly sf: ts.SourceFile, typeName = 'TranslateService') {\n this.svcName = importedLocalName(sf, typeName);\n }\n\n isType(t: ts.TypeNode | undefined): boolean {\n return !!this.svcName && !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === this.svcName;\n }\n\n isInject(e: ts.Expression | undefined): boolean {\n if (!this.svcName || !e) return false;\n const x = unwrap(e);\n if (!ts.isCallExpression(x)) return false;\n const c = x.expression;\n const named = (ts.isIdentifier(c) && c.text === 'inject') || (ts.isPropertyAccessExpression(c) && c.name.text === 'inject');\n const a = x.arguments[0];\n return named && !!a && ts.isIdentifier(a) && a.text === this.svcName;\n }\n\n members(cls: ts.ClassLikeDeclaration): Set<string> {\n const cached = this.cache.get(cls);\n if (cached) return cached;\n const set = new Set<string>();\n for (const m of cls.members) {\n if (ts.isPropertyDeclaration(m) && ts.isIdentifier(m.name) && (this.isType(m.type) || this.isInject(m.initializer))) set.add(m.name.text);\n if (ts.isConstructorDeclaration(m)) {\n for (const p of m.parameters) {\n const isProp = ts.getModifiers(p)?.some((x) =>\n [ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(x.kind)\n );\n if (isProp && ts.isIdentifier(p.name) && this.isType(p.type)) set.add(p.name.text);\n }\n }\n }\n this.cache.set(cls, set);\n return set;\n }\n\n /** true: declared as TranslateService, false: declared as something else, undefined: not found. */\n bare(id: ts.Identifier): boolean | undefined {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur) || ts.isModuleBlock(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if (\n (ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) &&\n cur.initializer &&\n ts.isVariableDeclarationList(cur.initializer)\n ) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return this.isType(d.type) || (ts.isVariableDeclaration(d) && this.isInject(d.initializer));\n }\n return undefined;\n }\n\n isService(expr: ts.Expression): boolean {\n const e = unwrap(expr);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) {\n for (let cur: ts.Node | undefined = e.parent; cur; cur = cur.parent) {\n if (ts.isClassLike(cur)) return this.members(cur).has(e.name.text);\n }\n return false;\n }\n return ts.isIdentifier(e) && this.bare(e) === true;\n }\n}\n\nfunction unwrap(e: ts.Expression): ts.Expression {\n while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n return e;\n}\n\n/** Local name of a non-type-only named import of `imported` from @ngx-translate/core. */\nfunction importedLocalName(sf: ts.SourceFile, imported: string, module = CORE): string | undefined {\n for (const stmt of sf.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier) || stmt.moduleSpecifier.text !== module) continue;\n const nb = stmt.importClause?.namedBindings;\n if (!nb || !ts.isNamedImports(nb)) continue;\n for (const el of nb.elements) if ((el.propertyName ?? el.name).text === imported) return el.name.text;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TsEnv {\n projectHasExtend: boolean;\n projectUsesNgx: boolean;\n read: (p: string) => string | undefined;\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext, env: TsEnv): string {\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const resolver = new ServiceResolver(sf);\n const edits: Edit[] = [];\n const todos = new Map<number, { anchor: ts.Node; messages: string[] }>();\n const needed = new Set<string>();\n const touched = new Set<string>();\n const handled = new Set<ts.Node>();\n const moves = new Map<ts.ObjectLiteralExpression, { calls: ts.CallExpression[]; texts: string[] }>();\n const moduleName = importedLocalName(sf, 'TranslateModule') === 'TranslateModule' ? 'TranslateModule' : undefined;\n const setValueName = importedLocalName(sf, 'setValue') === 'setValue' ? 'setValue' : undefined;\n const defaultEvent = importedLocalName(sf, 'DefaultLangChangeEvent') === 'DefaultLangChangeEvent';\n const tokenImported = (t: string): boolean => importedLocalName(sf, t) === t;\n const providerNames = new Set(['provideTranslateService'].filter((n) => importedLocalName(sf, n) === n));\n let importProvidersTouched = false;\n\n const seenWarnings = new Set<string>();\n const warnOnce = (text: string): void => {\n if (seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const storeResolver = new ServiceResolver(sf, 'TranslateStore');\n const httpNames = new Set(\n ['provideTranslateHttpLoader', 'TranslateHttpLoader'].map((n) => importedLocalName(sf, n, HTTP_LOADER)).filter((n): n is string => !!n)\n );\n const iServiceName = importedLocalName(sf, 'ITranslateService');\n const lineNo = (node: ts.Node): number => sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;\n const flag = (node: ts.Node, message: string, comment = true): void => {\n warnOnce(`${filePath}:${lineNo(node)} - Manual action needed: ${message}`);\n if (!comment) return;\n const anchor = anchorOf(node);\n const key = anchor.getStart(sf);\n const entry = todos.get(key) ?? { anchor, messages: [] };\n const clean = sanitize(message);\n if (!entry.messages.includes(clean)) entry.messages.push(clean);\n todos.set(key, entry);\n };\n\n const nameOf = (n: ts.PropertyName | undefined): string | undefined =>\n n && (ts.isIdentifier(n) || ts.isStringLiteral(n)) ? n.text : undefined;\n const propOf = (obj: ts.ObjectLiteralExpression, name: string): ts.ObjectLiteralElementLike | undefined =>\n obj.properties.find((p) => !!p.name && nameOf(p.name) === name);\n\n // ----- config object transforms (defaultLanguage, useDefaultLang, plugin providers, extend/isolate) -----\n const CHILD_UNSUPPORTED = ['defaultLanguage', 'fallbackLang', 'lang', 'langs', 'useDefaultLang'];\n const transformConfig = (obj: ts.ObjectLiteralExpression, dropChildProps: boolean, out: Edit[], childTarget = false): number => {\n const drop = new Set<ts.ObjectLiteralElementLike>();\n for (const p of obj.properties) {\n const name = nameOf(p.name);\n if (!name) continue;\n if (childTarget && CHILD_UNSUPPORTED.includes(name) && ts.isPropertyAssignment(p)) {\n drop.add(p);\n flag(p, `${name} was removed: ChildTranslateServiceConfig has no such option, child services inherit the parent's fallbackLang and language. Set it on the root provideTranslateService() if needed.`);\n continue;\n }\n if (name === 'defaultLanguage') {\n if (ts.isPropertyAssignment(p)) out.push({\n start: p.name.getStart(sf),\n end: p.name.getEnd(),\n replacement: 'fallbackLang',\n });\n else if (ts.isShorthandPropertyAssignment(p)) out.push({\n start: p.getStart(sf),\n end: p.getEnd(),\n replacement: 'fallbackLang: defaultLanguage',\n });\n } else if (name === 'useDefaultLang' && ts.isPropertyAssignment(p)) {\n if (p.initializer.kind === ts.SyntaxKind.TrueKeyword) {\n drop.add(p);\n } else {\n flag(\n p,\n 'useDefaultLang was removed in @ngx-translate/core v18 and is kept only because its value is false: v18 always falls back to fallbackLang when it is set. Remove the leftover property manually (it does not compile as is); drop fallbackLang too if you relied on useDefaultLang: false.'\n );\n }\n } else if (dropChildProps && (name === 'extend' || name === 'isolate') && ts.isPropertyAssignment(p)) {\n drop.add(p);\n } else if (PLUGIN_KEYS.includes(name) && ts.isPropertyAssignment(p) && ts.isObjectLiteralExpression(p.initializer)) {\n const init = p.initializer;\n const provide = propOf(init, 'provide');\n const token = provide && ts.isPropertyAssignment(provide) && ts.isIdentifier(provide.initializer) ? provide.initializer.text : undefined;\n if (!token || !TOKEN_PROVIDERS[token]) continue;\n const useClass = propOf(init, 'useClass');\n if (init.properties.length === 2 && useClass && ts.isPropertyAssignment(useClass) && tokenImported(token)) {\n const fn = TOKEN_PROVIDERS[token];\n out.push({\n start: init.getStart(sf),\n end: init.getEnd(),\n replacement: `${fn}(${useClass.initializer.getText(sf)})`,\n });\n needed.add(fn);\n touched.add(token);\n } else {\n flag(\n p,\n `the ${token} provider uses a form other than { provide, useClass } (useFactory/useValue/deps). Convert it manually to ${TOKEN_PROVIDERS[token]}(...).`\n );\n }\n }\n }\n if (drop.size > 0) out.push(...removeArrayElements(obj, new Set([...drop].map((d) => obj.properties.indexOf(d))), sf));\n return drop.size;\n };\n\n // ----- TranslateModule.forRoot / forChild -----\n const convertModuleCall = (call: ts.CallExpression): void => {\n const callee = call.expression as ts.PropertyAccessExpression;\n handled.add(callee.expression);\n const method = callee.name.text;\n const args = call.arguments;\n const undecidable = (why: string): void =>\n flag(call, `TranslateModule.${method}() was left unchanged: ${why}. Use provideTranslateService() / provideChildTranslateService() manually.`);\n\n if (args.length > 1 || (args.length === 1 && !ts.isObjectLiteralExpression(args[0]))) return undecidable('its config is not an object literal');\n const obj = args[0] as ts.ObjectLiteralExpression | undefined;\n let fn = method === 'forRoot' ? 'provideTranslateService' : 'provideChildTranslateService';\n let hadExtendTrue = false;\n if (method === 'forChild' && obj) {\n for (const p of obj.properties) {\n const name = p.name ? nameOf(p.name) : undefined;\n if (ts.isSpreadAssignment(p)) return undecidable('its config contains a spread');\n if (name !== 'isolate' && name !== 'extend') continue;\n const init = ts.isPropertyAssignment(p) ? p.initializer.kind : undefined;\n if (init !== ts.SyntaxKind.TrueKeyword && init !== ts.SyntaxKind.FalseKeyword) return undecidable(`${name} is not a boolean literal`);\n if (name === 'isolate' && init === ts.SyntaxKind.TrueKeyword) fn = 'provideTranslateService';\n if (name === 'extend' && init === ts.SyntaxKind.TrueKeyword) hadExtendTrue = true;\n }\n }\n\n // the placement is decided first, so nothing is emitted for an unmovable call\n const parent = call.parent;\n let move: ts.ObjectLiteralExpression | undefined;\n let unwrapImportProviders: ts.CallExpression | undefined;\n if (ts.isArrayLiteralExpression(parent) && ts.isPropertyAssignment(parent.parent) && nameOf(parent.parent.name) === 'imports' && ts.isObjectLiteralExpression(parent.parent.parent)) {\n const owner = parent.parent.parent;\n const decorator = owner.parent;\n if (ts.isCallExpression(decorator) && ts.isIdentifier(decorator.expression) && decorator.expression.text === 'Component') {\n return undecidable('a standalone @Component cannot take environment providers; provide it in the application/route providers instead');\n }\n move = owner;\n } else if (ts.isCallExpression(parent) && ts.isIdentifier(parent.expression) && parent.expression.text === 'importProvidersFrom') {\n if (parent.arguments.length !== 1) return undecidable('it is combined with other sources in importProvidersFrom()');\n unwrapImportProviders = parent;\n }\n\n const local: Edit[] = [];\n const removed = obj ? transformConfig(obj, method === 'forChild', local, fn === 'provideChildTranslateService') : 0;\n const keepConfig = !!obj && obj.properties.length - removed > 0;\n const cfgText = keepConfig ? applyEdits(source.slice(obj!.getStart(sf), obj!.getEnd()), shift(local, -obj!.getStart(sf))) : '';\n const text = `${fn}(${cfgText})`;\n needed.add(fn);\n touched.add('TranslateModule');\n if (method === 'forChild') {\n warnOnce(\n `${filePath}:${lineNo(call)} - forChild() was converted to ${fn}(): v18 child services use their own store with parent fallback, review isolation semantics.${hadExtendTrue ? ' extend: true was removed: setTranslation(lang, t) no longer merges, pass true as third argument where needed.' : ''}`\n );\n }\n\n if (move) {\n const g = moves.get(move) ?? { calls: [], texts: [] };\n g.calls.push(call);\n g.texts.push(text);\n moves.set(move, g);\n } else if (unwrapImportProviders) {\n edits.push({ start: unwrapImportProviders.getStart(sf), end: unwrapImportProviders.getEnd(), replacement: text });\n importProvidersTouched = true;\n } else {\n edits.push({ start: call.getStart(sf), end: call.getEnd(), replacement: text });\n }\n };\n\n // ----- bare TranslateModule in imports/exports -----\n const convertBareModule = (id: ts.Identifier, arr: ts.ArrayLiteralExpression, owner: ts.ObjectLiteralExpression): void => {\n handled.add(id);\n const callNode = owner.parent;\n const kind = ts.isCallExpression(callNode) && ts.isIdentifier(callNode.expression) ? callNode.expression.text : '';\n let names = ['TranslatePipe', 'TranslateDirective'];\n if (kind === 'Component') {\n const u = componentUsage(owner);\n if (u) names = [u.pipe ? 'TranslatePipe' : '', u.directive ? 'TranslateDirective' : ''].filter(Boolean);\n }\n const present = new Set(arr.elements.filter(ts.isIdentifier).map((e) => e.text));\n const add = names.filter((n) => !present.has(n));\n touched.add('TranslateModule');\n for (const n of names) needed.add(n);\n if (add.length > 0) {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: add.join(', ') });\n } else {\n edits.push(...removeArrayElements(arr, new Set([arr.elements.indexOf(id)]), sf));\n }\n };\n\n const componentUsage = (owner: ts.ObjectLiteralExpression): { pipe: boolean; directive: boolean } | null => {\n const tpl = propOf(owner, 'template');\n const url = propOf(owner, 'templateUrl');\n const quiet = { members: new Set<string>(), allowKeyRewrite: false, where: (): string => '', quiet: true };\n if (tpl && ts.isPropertyAssignment(tpl) && (ts.isNoSubstitutionTemplateLiteral(tpl.initializer) || ts.isStringLiteral(tpl.initializer))) {\n const lit = tpl.initializer;\n return scanTemplate(source.slice(lit.getStart(sf) + 1, lit.getEnd() - 1), filePath, context, quiet).usage;\n }\n if (url && ts.isPropertyAssignment(url) && ts.isStringLiteralLike(url.initializer)) {\n const target = resolveUrl(dirOf(filePath), url.initializer.text);\n const html = env.read(target);\n if (html !== undefined) return scanTemplate(html, target, context, quiet).usage;\n }\n return null;\n };\n\n // ----- visitor -----\n const visit = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n\n if (ts.isCallExpression(node)) visitCall(node);\n else if (ts.isPropertyAccessExpression(node)) visitMember(node);\n else if (ts.isVariableDeclaration(node)) visitAlias(node.name, node.initializer, node);\n else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) visitAlias(undefined, node.right, node);\n else if (ts.isIdentifier(node)) visitIdentifier(node);\n else if (ts.isClassDeclaration(node)) visitInlineTemplate(node);\n\n ts.forEachChild(node, visit);\n };\n\n const visitCall = (call: ts.CallExpression): void => {\n const c = call.expression;\n if (moduleName && ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === moduleName && (c.name.text === 'forRoot' || c.name.text === 'forChild')) {\n convertModuleCall(call);\n return;\n }\n if (ts.isIdentifier(c) && providerNames.has(c.text) && call.arguments[0] && ts.isObjectLiteralExpression(call.arguments[0])) {\n transformConfig(call.arguments[0], false, edits);\n }\n if (setValueName && ts.isIdentifier(c) && c.text === setValueName) {\n const a0 = call.arguments[0];\n const assignable = !!a0 && (ts.isIdentifier(a0) || ts.isPropertyAccessExpression(a0) || ts.isElementAccessExpression(a0));\n if (ts.isExpressionStatement(call.parent) && call.arguments.length === 3 && assignable) {\n edits.push({ start: c.getStart(sf), end: c.getEnd(), replacement: `${a0.getText(sf)} = insertValue` });\n needed.add('insertValue');\n touched.add('setValue');\n } else {\n flag(call, 'setValue() was replaced by insertValue(), which returns a new object instead of mutating its argument. Use `target = insertValue(target, key, value)` manually.');\n }\n }\n if (ts.isPropertyAccessExpression(c) && resolver.isService(c.expression)) {\n if (c.name.text === 'getCurrentLang') {\n flag(call, 'getCurrentLang() returns Language | null in @ngx-translate/core v18 (null before a language is set). Handle the null case, e.g. `?? fallback`.');\n } else if (c.name.text === 'setTranslation' && call.arguments.length === 2 && env.projectHasExtend) {\n flag(call, 'setTranslation(lang, translations) no longer merges for services that used forChild({ extend: true }); pass `true` as third argument if you relied on merging.');\n }\n }\n };\n\n const visitMember = (n: ts.PropertyAccessExpression): void => {\n const member = n.name.text;\n if ((member === 'onTranslationChange' || member === 'getValue') && storeResolver.isService(n.expression)) {\n edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: member === 'getValue' ? 'getTranslationValue' : 'translationChange$',\n });\n return;\n }\n const isTracked = ['currentLang', 'langs', 'defaultLang', ...Object.keys(MEMBER_RENAMES)].includes(member);\n if (!isTracked || !resolver.isService(n.expression)) return;\n const parent = n.parent;\n if (MEMBER_RENAMES[member]) {\n edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: MEMBER_RENAMES[member] });\n return;\n }\n if (ts.isCallExpression(parent) && parent.expression === n) return; // already `currentLang()` etc.\n const isWrite =\n (ts.isBinaryExpression(parent) && parent.left === n && ASSIGN_OPS.has(parent.operatorToken.kind)) ||\n ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) ||\n ts.isDeleteExpression(parent);\n if (isWrite) {\n flag(n, `${member} cannot be assigned in @ngx-translate/core v18 (read-only Signal / removed). Use use(), setFallbackLang() or setTranslation() instead.`);\n return;\n }\n if (member === 'currentLang') edits.push({ start: n.getEnd(), end: n.getEnd(), replacement: '()' });\n else if (member === 'langs') edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: 'getLangs()',\n });\n else edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: 'fallbackLang()' });\n };\n\n const visitAlias = (name: ts.BindingName | undefined, init: ts.Expression | undefined, at: ts.Node): void => {\n if (!init) return;\n if (!resolver.isService(init) && !(name && ts.isObjectBindingPattern(name) && resolver.isInject(init))) return;\n if (name && ts.isIdentifier(name) && ts.isVariableDeclaration(at) && resolver.isType(at.type)) return; // typed alias is tracked\n flag(\n at,\n 'TranslateService is aliased or destructured here, so currentLang/default*/langs usages through it are not migrated automatically. Review them against the v18 API (currentLang() signal, fallbackLang, getLangs()).'\n );\n };\n\n const visitIdentifier = (id: ts.Identifier): void => {\n const p = id.parent;\n if ((ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id)) return;\n if (httpNames.has(id.text)) {\n const call = ts.isCallExpression(p) && p.expression === id ? p : undefined;\n const cfg = call?.arguments[0];\n const hasFlag = !!cfg && ts.isObjectLiteralExpression(cfg) && !!propOf(cfg, 'failOnError');\n if (!hasFlag) {\n flag(id, 'the v18 http-loader no longer fails the whole language load when a translation file request fails (it logs a warning and uses {}). Pass failOnError: true to provideTranslateHttpLoader() if you rely on the v17 behaviour.');\n }\n }\n if (iServiceName && id.text === iServiceName && ts.isExpressionWithTypeArguments(p) && ts.isHeritageClause(p.parent) && p.parent.token === ts.SyntaxKind.ImplementsKeyword) {\n flag(id, 'ITranslateService gained isLoading: Signal<boolean> in @ngx-translate/core v18. Add isLoading = signal(false).asReadonly() to this class.');\n }\n if (defaultEvent && id.text === 'DefaultLangChangeEvent') {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: 'FallbackLangChangeEvent' });\n needed.add('FallbackLangChangeEvent');\n touched.add('DefaultLangChangeEvent');\n }\n if (moduleName && id.text === moduleName && !handled.has(id)) {\n // `TranslateModule` as an element of imports / exports\n if (ts.isArrayLiteralExpression(p) && ts.isPropertyAssignment(p.parent) && ['imports', 'exports'].includes(nameOf(p.parent.name) ?? '') && ts.isObjectLiteralExpression(p.parent.parent)) {\n convertBareModule(id, p, p.parent.parent);\n }\n }\n };\n\n const visitInlineTemplate = (cls: ts.ClassDeclaration): void => {\n const tpl = componentProp(cls, 'template');\n if (!tpl) return;\n const lit = tpl.initializer;\n if (!ts.isNoSubstitutionTemplateLiteral(lit) && !ts.isStringLiteral(lit)) return;\n const start = lit.getStart(sf) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (!/translate|currentLang/.test(raw)) return;\n const baseLine = sf.getLineAndCharacterOfPosition(start).line;\n const scan = scanTemplate(raw, filePath, context, {\n members: resolver.members(cls),\n allowKeyRewrite: ts.isNoSubstitutionTemplateLiteral(lit),\n checkAttributes: env.projectUsesNgx,\n where: (o) => `${filePath}:${baseLine + lineOf(raw, o)}`,\n });\n edits.push(...shift(scan.edits, start));\n };\n\n visit(sf);\n\n // moved forRoot/forChild calls: imports -> providers\n for (const [obj, g] of moves) {\n const importsProp = propOf(obj, 'imports') as ts.PropertyAssignment;\n const arr = importsProp.initializer as ts.ArrayLiteralExpression;\n const providersProp = propOf(obj, 'providers');\n if (providersProp && !(ts.isPropertyAssignment(providersProp) && ts.isArrayLiteralExpression(providersProp.initializer))) {\n for (const call of g.calls) flag(call, 'the providers property is not an array literal, so the converted provider could not be moved there. Move it manually.');\n continue;\n }\n const texts = g.texts.join(', ');\n const movedIdx = new Set(g.calls.map((c) => arr.elements.indexOf(c)));\n const keepsOthers = arr.elements.length > movedIdx.size;\n if (providersProp) {\n const parr = (providersProp as ts.PropertyAssignment).initializer as ts.ArrayLiteralExpression;\n if (parr.elements.length > 0) {\n edits.push({\n start: parr.elements[parr.elements.length - 1].getEnd(),\n end: parr.elements[parr.elements.length - 1].getEnd(),\n replacement: `, ${texts}`,\n });\n } else {\n edits.push({ start: parr.getStart(sf) + 1, end: parr.getEnd() - 1, replacement: texts });\n }\n if (keepsOthers) edits.push(...removeArrayElements(arr, movedIdx, sf));\n else removeObjectProperty(importsProp, sf, edits);\n } else if (!keepsOthers) {\n edits.push({ start: importsProp.getStart(sf), end: importsProp.getEnd(), replacement: `providers: [${texts}]` });\n } else {\n edits.push(...removeArrayElements(arr, movedIdx, sf));\n const multiline = source.slice(obj.getStart(sf), importsProp.getEnd()).includes('\\n');\n const indent = multiline ? /[ \\t]*$/.exec(source.slice(0, importsProp.getStart(sf)))![0] : '';\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n edits.push({\n start: importsProp.getEnd(),\n end: importsProp.getEnd(),\n replacement: multiline ? `,${eol}${indent}providers: [${texts}]` : `, providers: [${texts}]`,\n });\n }\n }\n\n // remaining references to the removed module\n if (moduleName) {\n const mark = (n: ts.Node): void => {\n if (ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === moduleName && !handled.has(n) && !isPropertyName(n)) {\n flag(n, 'TranslateModule was removed in @ngx-translate/core v18. Use provideTranslateService() / provideChildTranslateService() and import TranslatePipe / TranslateDirective directly.');\n }\n ts.forEachChild(n, mark);\n };\n mark(sf);\n }\n\n // TODO comments, one line above the anchor, never duplicated\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n for (const { anchor, messages } of todos.values()) {\n const start = anchor.getStart(sf);\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))![0];\n const above = new Set<string>();\n const lines = source.slice(0, lineStart).split(/\\r?\\n/);\n for (let i = lines.length - 2; i >= 0 && lines[i].trim().startsWith('// ' + TODO_PREFIX); i--) above.add(lines[i].trim());\n const fresh = messages.map((m) => `// ${TODO_PREFIX} ${m}`).filter((l) => !above.has(l));\n if (fresh.length > 0) edits.push({\n start: lineStart,\n end: lineStart,\n replacement: fresh.map((l) => `${indent}${l}${eol}`).join(''),\n });\n }\n\n let result = applyEdits(source, edits);\n if (result === source) return source;\n result = fixImports(result, filePath, CORE, needed, touched);\n if (importProvidersTouched) result = fixImports(result, filePath, '@angular/core', new Set(), new Set(['importProvidersFrom']));\n return result;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Imports\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst RENAME_IN_PLACE: Record<string, string> = {\n DefaultLangChangeEvent: 'FallbackLangChangeEvent',\n setValue: 'insertValue',\n};\n\n/**\n * Drops `touched` specifiers that are no longer referenced (renaming in place when a rename is known) and\n * appends the `needed` names to the first named import of `moduleName`.\n */\nfunction fixImports(text: string, filePath: string, moduleName: string, needed: Set<string>, touched: Set<string>): string {\n const sf = ts.createSourceFile(filePath, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const referenced = (name: string): boolean => {\n let found = false;\n const walk = (n: ts.Node): void => {\n if (found || ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === name && !isPropertyName(n)) found = true;\n ts.forEachChild(n, walk);\n };\n walk(sf);\n return found;\n };\n\n const decls = sf.statements.filter(\n (s): s is ts.ImportDeclaration =>\n ts.isImportDeclaration(s) &&\n ts.isStringLiteral(s.moduleSpecifier) &&\n s.moduleSpecifier.text === moduleName &&\n !!s.importClause?.namedBindings &&\n ts.isNamedImports(s.importClause.namedBindings) &&\n !s.importClause.isTypeOnly\n );\n if (decls.length === 0) return text;\n\n const all = new Set<string>();\n for (const d of decls) for (const e of (d.importClause!.namedBindings as ts.NamedImports).elements) all.add(e.name.text);\n const placed = new Set<string>();\n const edits: Edit[] = [];\n const pendingNeeded = [...needed];\n\n decls.forEach((d, di) => {\n const named = d.importClause!.namedBindings as ts.NamedImports;\n const items: string[] = [];\n for (const e of named.elements) {\n const name = e.name.text;\n if (touched.has(name) && !e.propertyName && !referenced(name)) {\n const to = RENAME_IN_PLACE[name];\n if (to && needed.has(to) && !all.has(to) && !placed.has(to)) {\n items.push(to);\n placed.add(to);\n }\n continue;\n }\n items.push(e.getText(sf));\n }\n if (di === 0) {\n for (const n of pendingNeeded) if (!all.has(n) && !placed.has(n) && !items.includes(n)) items.push(n);\n }\n const before = named.elements.map((e) => e.getText(sf));\n if (items.length === before.length && items.every((v, i) => v === before[i])) return;\n if (items.length === 0 && !d.importClause!.name) {\n let end = d.getEnd();\n if (text[end] === '\\r') end++;\n if (text[end] === '\\n') end++;\n edits.push({ start: d.getStart(sf), end, replacement: '' });\n } else {\n const multiline = named.getText(sf).includes('\\n');\n const body = multiline ? `{\\n ${items.join(',\\n ')},\\n}` : `{ ${items.join(', ')} }`;\n edits.push({ start: named.getStart(sf), end: named.getEnd(), replacement: body });\n }\n });\n return applyEdits(text, edits);\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------------------------------------------------\n\nfunction isPropertyName(id: ts.Identifier): boolean {\n const p = id.parent;\n return (ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id);\n}\n\nfunction sanitize(message: string): string {\n return message.replace(/\\s+/g, ' ').trim();\n}\n\n/** Nearest ancestor that is a statement, class member or object property: the TODO goes on the line above it. */\nfunction anchorOf(node: ts.Node): ts.Node {\n let cur = node;\n while (cur.parent) {\n const p = cur.parent;\n if (ts.isSourceFile(p) || ts.isBlock(p) || ts.isModuleBlock(p) || ts.isClassLike(p) || ts.isObjectLiteralExpression(p) || ts.isCaseClause(p) || ts.isDefaultClause(p)) {\n return cur;\n }\n cur = p;\n }\n return cur;\n}\n\nconst dirOf = (p: string): string => dirname(normalize(p));\nconst resolveUrl = (dir: string, url: string): string => normalize(join(normalize(dir), url));\n\nfunction lineOf(source: string, offset: number): number {\n return source.slice(0, offset).split('\\n').length;\n}\n\nfunction shift(edits: Edit[], by: number): Edit[] {\n return edits.map((e) => ({ ...e, start: e.start + by, end: e.end + by }));\n}\n\n/** Removes one object property together with its separating comma. */\nfunction removeObjectProperty(prop: ts.ObjectLiteralElementLike, sf: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sf.getFullText();\n let start = prop.getStart(sf);\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getStart(sf);\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\n/** Removes the array elements at `indices`; non-overlapping ranges even for neighbouring elements. */\nfunction removeArrayElements(arr: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression, indices: Set<number>, sf: ts.SourceFile): Edit[] {\n const els: readonly ts.Node[] = ts.isArrayLiteralExpression(arr) ? arr.elements : arr.properties;\n const keptIdx = els.findIndex((_, i) => !indices.has(i));\n if (keptIdx === -1) return [{ start: arr.getStart(sf) + 1, end: arr.getEnd() - 1, replacement: '' }];\n const out: Edit[] = [];\n if (keptIdx > 0) out.push({ start: els[0].getStart(sf), end: els[keptIdx].getStart(sf), replacement: '' });\n for (let i = keptIdx + 1; i < els.length; i++) {\n if (indices.has(i)) out.push({ start: els[i - 1].getEnd(), end: els[i].getEnd(), replacement: '' });\n }\n return out;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const seen = new Map<string, Edit>();\n for (const e of edits) seen.set(`${e.start}:${e.end}:${e.replacement}`, e);\n let result = source;\n for (const e of [...seen.values()].sort((a, b) => b.start - a.start || b.end - a.end)) {\n result = result.slice(0, e.start) + e.replacement + result.slice(e.end);\n }\n return result;\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
2092
2092
|
"displayName": "Edit",
|
|
2093
2093
|
"properties": [
|
|
2094
2094
|
{
|
|
@@ -2100,7 +2100,7 @@
|
|
|
2100
2100
|
"indexKey": "",
|
|
2101
2101
|
"optional": false,
|
|
2102
2102
|
"description": "",
|
|
2103
|
-
"line":
|
|
2103
|
+
"line": 37,
|
|
2104
2104
|
"rawdescription": "\n"
|
|
2105
2105
|
},
|
|
2106
2106
|
{
|
|
@@ -2112,7 +2112,7 @@
|
|
|
2112
2112
|
"indexKey": "",
|
|
2113
2113
|
"optional": false,
|
|
2114
2114
|
"description": "",
|
|
2115
|
-
"line":
|
|
2115
|
+
"line": 38,
|
|
2116
2116
|
"rawdescription": "\n"
|
|
2117
2117
|
},
|
|
2118
2118
|
{
|
|
@@ -2124,7 +2124,7 @@
|
|
|
2124
2124
|
"indexKey": "",
|
|
2125
2125
|
"optional": false,
|
|
2126
2126
|
"description": "",
|
|
2127
|
-
"line":
|
|
2127
|
+
"line": 36,
|
|
2128
2128
|
"rawdescription": "\n"
|
|
2129
2129
|
}
|
|
2130
2130
|
],
|
|
@@ -2142,12 +2142,12 @@
|
|
|
2142
2142
|
},
|
|
2143
2143
|
{
|
|
2144
2144
|
"name": "Edit",
|
|
2145
|
-
"id": "interface-Edit-
|
|
2146
|
-
"file": "packages/core/schematics/migrate-
|
|
2145
|
+
"id": "interface-Edit-e82ad5d05a8363ecab95140e3f129427949eb3d53d4272814efdb8f6458ebc01b92b07c76d5e15e5491679d59f5b9b723c3f191c3c12257261a751583757f3fe-21",
|
|
2146
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
2147
2147
|
"deprecated": false,
|
|
2148
2148
|
"deprecationMessage": "",
|
|
2149
2149
|
"type": "interface",
|
|
2150
|
-
"sourceCode": "import {\n Binary,\n BindingPipe,\n BindingType,\n CombinedRecursiveAstVisitor,\n ImplicitReceiver,\n parseTemplate,\n PropertyRead,\n SafePropertyRead,\n TmplAstElement,\n TmplAstText,\n} from '@angular/compiler';\nimport { dirname, join, normalize } from '@angular-devkit/core';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit, TODO_PREFIX } from '../utils/todo-comment';\n\n/**\n * Migrates @ngx-translate/core v17 -> v18 breaking changes.\n *\n * No type checker is used: a `TranslateService` receiver is resolved from its declaration in the same\n * file (`: TranslateService`, `inject(TranslateService)`, constructor parameter properties) and, for\n * templates, from the component class that owns the template.\n * shortcut: receivers that are aliased, destructured, passed through other types or declared in another\n * file are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst CORE = '@ngx-translate/core';\nconst HTTP_LOADER = '@ngx-translate/http-loader';\n\nconst TOKEN_PROVIDERS: Record<string, string> = {\n TranslateLoader: 'provideTranslateLoader',\n TranslateCompiler: 'provideTranslateCompiler',\n TranslateParser: 'provideTranslateParser',\n MissingTranslationHandler: 'provideMissingTranslationHandler',\n};\nconst PLUGIN_KEYS = ['loader', 'compiler', 'parser', 'missingTranslationHandler'];\nconst MEMBER_RENAMES: Record<string, string> = {\n setDefaultLang: 'setFallbackLang',\n getDefaultLang: 'getFallbackLang',\n onDefaultLangChange: 'onFallbackLangChange',\n};\nconst ASSIGN_OPS = new Set<ts.SyntaxKind>([\n ts.SyntaxKind.EqualsToken,\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n]);\n\nexport function migrateNgxTranslate18(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n const tsFiles: string[] = [];\n const htmlFiles: string[] = [];\n visitDir(tree.getDir(scanPath || '/'), (path) => (path.endsWith('.html') ? htmlFiles : tsFiles).push(path));\n\n const projectUsesNgx = tsFiles.some((f) => tree.read(f)?.toString('utf-8').includes(CORE));\n const read = (p: string): string | undefined => tree.read(p)?.toString('utf-8');\n // forChild({ extend: true }) services merge translations; setTranslation(lang, t) callers need a review then.\n const projectHasExtend = tsFiles.some((f) => {\n const s = read(f);\n return !!s && s.includes('forChild') && /extend\\s*:\\s*true/.test(s);\n });\n\n let fileCount = 0;\n const write = (path: string, original: string, result: string): void => {\n if (result === original) return;\n if (options.dryRun) logDryRun(context, `Would migrate @ngx-translate/core usages in ${path}`);\n else tree.overwrite(path, result);\n fileCount++;\n };\n\n for (const path of tsFiles) {\n const original = read(path);\n if (!original) continue;\n const hasCore = original.includes(CORE) || original.includes(HTTP_LOADER);\n if (!hasCore && !(original.includes('template') && original.includes('translate'))) continue;\n write(path, original, migrateTypeScript(original, path, context, { projectHasExtend, projectUsesNgx, read }));\n }\n\n for (const path of htmlFiles) {\n const original = read(path);\n if (!original || !/translate|currentLang/.test(original)) continue;\n const members = membersForExternalTemplate(path, tsFiles, read);\n const scan = scanTemplate(original, path, context, {\n members,\n allowKeyRewrite: true,\n checkAttributes: projectUsesNgx,\n where: (o) => `${path}:${lineOf(original, o)}`,\n });\n write(path, original, applyEdits(original, scan.edits));\n }\n\n context.logger.info(`Migrated @ngx-translate/core usages in ${fileCount} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TemplateScan {\n edits: Edit[];\n usage: { pipe: boolean; directive: boolean };\n}\n\nfunction scanTemplate(\n source: string,\n filePath: string,\n context: SchematicContext,\n opts: {\n members: Set<string>;\n allowKeyRewrite: boolean;\n checkAttributes?: boolean;\n where: (offset: number) => string;\n quiet?: boolean\n }\n): TemplateScan {\n const result: TemplateScan = { edits: [], usage: { pipe: false, directive: false } };\n let parsed;\n try {\n parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n } catch {\n return result;\n }\n if (parsed.errors && parsed.errors.length > 0) return result;\n\n const seenWarnings = new Set<string>();\n const warn = (offset: number, message: string): void => {\n const text = `${opts.where(offset)} - Manual action needed: ${message}`;\n if (opts.quiet || seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const writes = new Set<unknown>();\n const isSvc = (r: unknown): boolean =>\n r instanceof PropertyRead && r.receiver instanceof ImplicitReceiver && opts.members.has(r.name);\n\n const visitor = new (class extends CombinedRecursiveAstVisitor {\n override visitBinary(ast: Binary, context: unknown): void {\n if (ast.operation.endsWith('=') && !['==', '===', '!=', '!==', '<=', '>='].includes(ast.operation)) {\n const left = ast.left;\n if ((left instanceof PropertyRead || left instanceof SafePropertyRead) && left.name === 'currentLang' && isSvc(left.receiver)) {\n writes.add(left);\n warn(left.sourceSpan.start, 'TranslateService.currentLang is a read-only Signal in @ngx-translate/core v18; use translate.use(lang) instead of assigning it.');\n }\n }\n super.visitBinary(ast, context);\n }\n\n override visitPropertyRead(ast: PropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitPropertyRead(ast, context);\n }\n\n override visitSafePropertyRead(ast: SafePropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitSafePropertyRead(ast, context);\n }\n\n override visitPipe(ast: BindingPipe, context: unknown): void {\n if (ast.name === 'translate') result.usage.pipe = true;\n super.visitPipe(ast, context);\n }\n\n override visitElement(el: TmplAstElement): void {\n this.checkTranslateAttribute(el);\n super.visitElement(el);\n }\n\n override visitTemplate(t: Parameters<CombinedRecursiveAstVisitor['visitTemplate']>[0]): void {\n if (\n [...t.attributes, ...t.inputs, ...t.templateAttrs].some((a) => a.name === 'translate' || a.name === 'ngx-translate')\n ) {\n result.usage.directive = true;\n }\n super.visitTemplate(t);\n }\n\n private rewriteCurrentLang(ast: PropertyRead | SafePropertyRead): void {\n if (ast.name !== 'currentLang' || writes.has(ast) || !isSvc(ast.receiver)) return;\n const end = ast.nameSpan.end;\n if (/^\\s*\\(/.test(source.slice(end))) return; // already a call\n result.edits.push({ start: end, end, replacement: '()' });\n }\n\n private checkTranslateAttribute(el: TmplAstElement): void {\n if (opts.checkAttributes === false) return;\n const textAttr = el.attributes.find((a) => a.name === 'translate' || a.name === 'ngx-translate');\n const bound = el.inputs.find((i) => i.name === 'translate' && i.type === BindingType.Property);\n if (textAttr || bound) result.usage.directive = true;\n const at = el.startSourceSpan.start.offset;\n const todo = (message: string): void => {\n warn(at, `<${el.name}> ${message}`);\n const edit = createTodoEdit(source, at, message);\n if (edit) result.edits.push(edit);\n };\n\n // 7: [translate]=\"'KEY'\" now sets textContent: element children are overwritten.\n if (bound && el.children.some((c) => !(c instanceof TmplAstText))) {\n todo(\n 'with [translate] the element content is replaced by the translation (textContent) in @ngx-translate/core v18, child elements are lost. Restructure the markup.'\n );\n return;\n }\n\n // 8: <el translate>KEY</el> (text as key) is deprecated.\n if (!textAttr || textAttr.name !== 'translate' || textAttr.value !== '' || bound) return;\n const meaningful = el.children.filter((c) => !(c instanceof TmplAstText && c.value.trim() === ''));\n if (meaningful.length === 0) return;\n const only = meaningful[0];\n const isPlain =\n meaningful.length === 1 &&\n el.children.length === 1 &&\n only instanceof TmplAstText &&\n !!el.endSourceSpan &&\n source.slice(el.startSourceSpan.end.offset, el.endSourceSpan.start.offset) === only.value &&\n !/[\"'`&<>{}\\\\]/.test(only.value);\n if (!isPlain) {\n todo(\n 'uses its text content as translation key, which is deprecated and not safely convertible here (interpolation or nested elements). Use [translate]=\"\\'KEY\\'\", the translate pipe or *translateBlock.'\n );\n return;\n }\n if (!opts.allowKeyRewrite) {\n warn(at, `<${el.name}> text as translation key is deprecated; replace with [translate]=\"'KEY'\" (not rewritten inside a quoted inline template).`);\n return;\n }\n const key = (only as TmplAstText).value.trim();\n result.edits.push({\n start: textAttr.sourceSpan.start.offset,\n end: textAttr.sourceSpan.end.offset,\n replacement: `[translate]=\"'${key}'\"`,\n });\n result.edits.push({ start: el.startSourceSpan.end.offset, end: el.endSourceSpan!.start.offset, replacement: '' });\n }\n })();\n\n for (const node of parsed.nodes) visitor.visit(node);\n return result;\n}\n\n/** Members typed/injected as TranslateService of the component whose templateUrl points at `htmlPath`. */\nfunction membersForExternalTemplate(htmlPath: string, tsFiles: string[], read: (p: string) => string | undefined): Set<string> {\n const dir = dirOf(htmlPath);\n for (const f of tsFiles) {\n if (dirOf(f) !== dir || f.endsWith('.spec.ts')) continue;\n const src = read(f);\n if (!src || !src.includes('templateUrl') || !src.includes(CORE)) continue;\n const sf = ts.createSourceFile(f, src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const helper = new ServiceResolver(sf);\n for (const stmt of sf.statements) {\n if (!ts.isClassDeclaration(stmt)) continue;\n const url = componentProp(stmt, 'templateUrl');\n if (url && ts.isStringLiteralLike(url.initializer) && resolveUrl(dir, url.initializer.text) === normalize(htmlPath)) {\n return helper.members(stmt);\n }\n }\n }\n return new Set();\n}\n\nfunction componentObject(cls: ts.ClassDeclaration): ts.ObjectLiteralExpression | undefined {\n for (const d of ts.getDecorators(cls) ?? []) {\n if (ts.isCallExpression(d.expression) && ts.isIdentifier(d.expression.expression) && d.expression.expression.text === 'Component') {\n const arg = d.expression.arguments[0];\n if (arg && ts.isObjectLiteralExpression(arg)) return arg;\n }\n }\n return undefined;\n}\n\nfunction componentProp(cls: ts.ClassDeclaration, name: string): ts.PropertyAssignment | undefined {\n return componentObject(cls)?.properties.find(\n (p): p is ts.PropertyAssignment => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === name\n );\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TranslateService receiver resolution\n// ---------------------------------------------------------------------------------------------------------------------\n\nclass ServiceResolver {\n readonly svcName: string | undefined;\n private cache = new Map<ts.Node, Set<string>>();\n\n constructor(private readonly sf: ts.SourceFile, typeName = 'TranslateService') {\n this.svcName = importedLocalName(sf, typeName);\n }\n\n isType(t: ts.TypeNode | undefined): boolean {\n return !!this.svcName && !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === this.svcName;\n }\n\n isInject(e: ts.Expression | undefined): boolean {\n if (!this.svcName || !e) return false;\n const x = unwrap(e);\n if (!ts.isCallExpression(x)) return false;\n const c = x.expression;\n const named = (ts.isIdentifier(c) && c.text === 'inject') || (ts.isPropertyAccessExpression(c) && c.name.text === 'inject');\n const a = x.arguments[0];\n return named && !!a && ts.isIdentifier(a) && a.text === this.svcName;\n }\n\n members(cls: ts.ClassLikeDeclaration): Set<string> {\n const cached = this.cache.get(cls);\n if (cached) return cached;\n const set = new Set<string>();\n for (const m of cls.members) {\n if (ts.isPropertyDeclaration(m) && ts.isIdentifier(m.name) && (this.isType(m.type) || this.isInject(m.initializer))) set.add(m.name.text);\n if (ts.isConstructorDeclaration(m)) {\n for (const p of m.parameters) {\n const isProp = ts.getModifiers(p)?.some((x) =>\n [ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(x.kind)\n );\n if (isProp && ts.isIdentifier(p.name) && this.isType(p.type)) set.add(p.name.text);\n }\n }\n }\n this.cache.set(cls, set);\n return set;\n }\n\n /** true: declared as TranslateService, false: declared as something else, undefined: not found. */\n bare(id: ts.Identifier): boolean | undefined {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur) || ts.isModuleBlock(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if (\n (ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) &&\n cur.initializer &&\n ts.isVariableDeclarationList(cur.initializer)\n ) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return this.isType(d.type) || (ts.isVariableDeclaration(d) && this.isInject(d.initializer));\n }\n return undefined;\n }\n\n isService(expr: ts.Expression): boolean {\n const e = unwrap(expr);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) {\n for (let cur: ts.Node | undefined = e.parent; cur; cur = cur.parent) {\n if (ts.isClassLike(cur)) return this.members(cur).has(e.name.text);\n }\n return false;\n }\n return ts.isIdentifier(e) && this.bare(e) === true;\n }\n}\n\nfunction unwrap(e: ts.Expression): ts.Expression {\n while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n return e;\n}\n\n/** Local name of a non-type-only named import of `imported` from @ngx-translate/core. */\nfunction importedLocalName(sf: ts.SourceFile, imported: string, module = CORE): string | undefined {\n for (const stmt of sf.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier) || stmt.moduleSpecifier.text !== module) continue;\n const nb = stmt.importClause?.namedBindings;\n if (!nb || !ts.isNamedImports(nb)) continue;\n for (const el of nb.elements) if ((el.propertyName ?? el.name).text === imported) return el.name.text;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TsEnv {\n projectHasExtend: boolean;\n projectUsesNgx: boolean;\n read: (p: string) => string | undefined;\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext, env: TsEnv): string {\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const resolver = new ServiceResolver(sf);\n const edits: Edit[] = [];\n const todos = new Map<number, { anchor: ts.Node; messages: string[] }>();\n const needed = new Set<string>();\n const touched = new Set<string>();\n const handled = new Set<ts.Node>();\n const moves = new Map<ts.ObjectLiteralExpression, { calls: ts.CallExpression[]; texts: string[] }>();\n const moduleName = importedLocalName(sf, 'TranslateModule') === 'TranslateModule' ? 'TranslateModule' : undefined;\n const setValueName = importedLocalName(sf, 'setValue') === 'setValue' ? 'setValue' : undefined;\n const defaultEvent = importedLocalName(sf, 'DefaultLangChangeEvent') === 'DefaultLangChangeEvent';\n const tokenImported = (t: string): boolean => importedLocalName(sf, t) === t;\n const providerNames = new Set(['provideTranslateService'].filter((n) => importedLocalName(sf, n) === n));\n let importProvidersTouched = false;\n\n const seenWarnings = new Set<string>();\n const warnOnce = (text: string): void => {\n if (seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const storeResolver = new ServiceResolver(sf, 'TranslateStore');\n const httpNames = new Set(\n ['provideTranslateHttpLoader', 'TranslateHttpLoader'].map((n) => importedLocalName(sf, n, HTTP_LOADER)).filter((n): n is string => !!n)\n );\n const iServiceName = importedLocalName(sf, 'ITranslateService');\n const lineNo = (node: ts.Node): number => sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;\n const flag = (node: ts.Node, message: string, comment = true): void => {\n warnOnce(`${filePath}:${lineNo(node)} - Manual action needed: ${message}`);\n if (!comment) return;\n const anchor = anchorOf(node);\n const key = anchor.getStart(sf);\n const entry = todos.get(key) ?? { anchor, messages: [] };\n const clean = sanitize(message);\n if (!entry.messages.includes(clean)) entry.messages.push(clean);\n todos.set(key, entry);\n };\n\n const nameOf = (n: ts.PropertyName | undefined): string | undefined =>\n n && (ts.isIdentifier(n) || ts.isStringLiteral(n)) ? n.text : undefined;\n const propOf = (obj: ts.ObjectLiteralExpression, name: string): ts.ObjectLiteralElementLike | undefined =>\n obj.properties.find((p) => !!p.name && nameOf(p.name) === name);\n\n // ----- config object transforms (defaultLanguage, useDefaultLang, plugin providers, extend/isolate) -----\n const CHILD_UNSUPPORTED = ['defaultLanguage', 'fallbackLang', 'lang', 'langs', 'useDefaultLang'];\n const transformConfig = (obj: ts.ObjectLiteralExpression, dropChildProps: boolean, out: Edit[], childTarget = false): number => {\n const drop = new Set<ts.ObjectLiteralElementLike>();\n for (const p of obj.properties) {\n const name = nameOf(p.name);\n if (!name) continue;\n if (childTarget && CHILD_UNSUPPORTED.includes(name) && ts.isPropertyAssignment(p)) {\n drop.add(p);\n flag(p, `${name} was removed: ChildTranslateServiceConfig has no such option, child services inherit the parent's fallbackLang and language. Set it on the root provideTranslateService() if needed.`);\n continue;\n }\n if (name === 'defaultLanguage') {\n if (ts.isPropertyAssignment(p)) out.push({\n start: p.name.getStart(sf),\n end: p.name.getEnd(),\n replacement: 'fallbackLang',\n });\n else if (ts.isShorthandPropertyAssignment(p)) out.push({\n start: p.getStart(sf),\n end: p.getEnd(),\n replacement: 'fallbackLang: defaultLanguage',\n });\n } else if (name === 'useDefaultLang' && ts.isPropertyAssignment(p)) {\n if (p.initializer.kind === ts.SyntaxKind.TrueKeyword) {\n drop.add(p);\n } else {\n flag(\n p,\n 'useDefaultLang was removed in @ngx-translate/core v18 and is kept only because its value is false: v18 always falls back to fallbackLang when it is set. Remove the leftover property manually (it does not compile as is); drop fallbackLang too if you relied on useDefaultLang: false.'\n );\n }\n } else if (dropChildProps && (name === 'extend' || name === 'isolate') && ts.isPropertyAssignment(p)) {\n drop.add(p);\n } else if (PLUGIN_KEYS.includes(name) && ts.isPropertyAssignment(p) && ts.isObjectLiteralExpression(p.initializer)) {\n const init = p.initializer;\n const provide = propOf(init, 'provide');\n const token = provide && ts.isPropertyAssignment(provide) && ts.isIdentifier(provide.initializer) ? provide.initializer.text : undefined;\n if (!token || !TOKEN_PROVIDERS[token]) continue;\n const useClass = propOf(init, 'useClass');\n if (init.properties.length === 2 && useClass && ts.isPropertyAssignment(useClass) && tokenImported(token)) {\n const fn = TOKEN_PROVIDERS[token];\n out.push({\n start: init.getStart(sf),\n end: init.getEnd(),\n replacement: `${fn}(${useClass.initializer.getText(sf)})`,\n });\n needed.add(fn);\n touched.add(token);\n } else {\n flag(\n p,\n `the ${token} provider uses a form other than { provide, useClass } (useFactory/useValue/deps). Convert it manually to ${TOKEN_PROVIDERS[token]}(...).`\n );\n }\n }\n }\n if (drop.size > 0) out.push(...removeArrayElements(obj, new Set([...drop].map((d) => obj.properties.indexOf(d))), sf));\n return drop.size;\n };\n\n // ----- TranslateModule.forRoot / forChild -----\n const convertModuleCall = (call: ts.CallExpression): void => {\n const callee = call.expression as ts.PropertyAccessExpression;\n handled.add(callee.expression);\n const method = callee.name.text;\n const args = call.arguments;\n const undecidable = (why: string): void =>\n flag(call, `TranslateModule.${method}() was left unchanged: ${why}. Use provideTranslateService() / provideChildTranslateService() manually.`);\n\n if (args.length > 1 || (args.length === 1 && !ts.isObjectLiteralExpression(args[0]))) return undecidable('its config is not an object literal');\n const obj = args[0] as ts.ObjectLiteralExpression | undefined;\n let fn = method === 'forRoot' ? 'provideTranslateService' : 'provideChildTranslateService';\n let hadExtendTrue = false;\n if (method === 'forChild' && obj) {\n for (const p of obj.properties) {\n const name = p.name ? nameOf(p.name) : undefined;\n if (ts.isSpreadAssignment(p)) return undecidable('its config contains a spread');\n if (name !== 'isolate' && name !== 'extend') continue;\n const init = ts.isPropertyAssignment(p) ? p.initializer.kind : undefined;\n if (init !== ts.SyntaxKind.TrueKeyword && init !== ts.SyntaxKind.FalseKeyword) return undecidable(`${name} is not a boolean literal`);\n if (name === 'isolate' && init === ts.SyntaxKind.TrueKeyword) fn = 'provideTranslateService';\n if (name === 'extend' && init === ts.SyntaxKind.TrueKeyword) hadExtendTrue = true;\n }\n }\n\n // the placement is decided first, so nothing is emitted for an unmovable call\n const parent = call.parent;\n let move: ts.ObjectLiteralExpression | undefined;\n let unwrapImportProviders: ts.CallExpression | undefined;\n if (ts.isArrayLiteralExpression(parent) && ts.isPropertyAssignment(parent.parent) && nameOf(parent.parent.name) === 'imports' && ts.isObjectLiteralExpression(parent.parent.parent)) {\n const owner = parent.parent.parent;\n const decorator = owner.parent;\n if (ts.isCallExpression(decorator) && ts.isIdentifier(decorator.expression) && decorator.expression.text === 'Component') {\n return undecidable('a standalone @Component cannot take environment providers; provide it in the application/route providers instead');\n }\n move = owner;\n } else if (ts.isCallExpression(parent) && ts.isIdentifier(parent.expression) && parent.expression.text === 'importProvidersFrom') {\n if (parent.arguments.length !== 1) return undecidable('it is combined with other sources in importProvidersFrom()');\n unwrapImportProviders = parent;\n }\n\n const local: Edit[] = [];\n const removed = obj ? transformConfig(obj, method === 'forChild', local, fn === 'provideChildTranslateService') : 0;\n const keepConfig = !!obj && obj.properties.length - removed > 0;\n const cfgText = keepConfig ? applyEdits(source.slice(obj!.getStart(sf), obj!.getEnd()), shift(local, -obj!.getStart(sf))) : '';\n const text = `${fn}(${cfgText})`;\n needed.add(fn);\n touched.add('TranslateModule');\n if (method === 'forChild') {\n warnOnce(\n `${filePath}:${lineNo(call)} - forChild() was converted to ${fn}(): v18 child services use their own store with parent fallback, review isolation semantics.${hadExtendTrue ? ' extend: true was removed: setTranslation(lang, t) no longer merges, pass true as third argument where needed.' : ''}`\n );\n }\n\n if (move) {\n const g = moves.get(move) ?? { calls: [], texts: [] };\n g.calls.push(call);\n g.texts.push(text);\n moves.set(move, g);\n } else if (unwrapImportProviders) {\n edits.push({ start: unwrapImportProviders.getStart(sf), end: unwrapImportProviders.getEnd(), replacement: text });\n importProvidersTouched = true;\n } else {\n edits.push({ start: call.getStart(sf), end: call.getEnd(), replacement: text });\n }\n };\n\n // ----- bare TranslateModule in imports/exports -----\n const convertBareModule = (id: ts.Identifier, arr: ts.ArrayLiteralExpression, owner: ts.ObjectLiteralExpression): void => {\n handled.add(id);\n const callNode = owner.parent;\n const kind = ts.isCallExpression(callNode) && ts.isIdentifier(callNode.expression) ? callNode.expression.text : '';\n let names = ['TranslatePipe', 'TranslateDirective'];\n if (kind === 'Component') {\n const u = componentUsage(owner);\n if (u) names = [u.pipe ? 'TranslatePipe' : '', u.directive ? 'TranslateDirective' : ''].filter(Boolean);\n }\n const present = new Set(arr.elements.filter(ts.isIdentifier).map((e) => e.text));\n const add = names.filter((n) => !present.has(n));\n touched.add('TranslateModule');\n for (const n of names) needed.add(n);\n if (add.length > 0) {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: add.join(', ') });\n } else {\n edits.push(...removeArrayElements(arr, new Set([arr.elements.indexOf(id)]), sf));\n }\n };\n\n const componentUsage = (owner: ts.ObjectLiteralExpression): { pipe: boolean; directive: boolean } | null => {\n const tpl = propOf(owner, 'template');\n const url = propOf(owner, 'templateUrl');\n const quiet = { members: new Set<string>(), allowKeyRewrite: false, where: (): string => '', quiet: true };\n if (tpl && ts.isPropertyAssignment(tpl) && (ts.isNoSubstitutionTemplateLiteral(tpl.initializer) || ts.isStringLiteral(tpl.initializer))) {\n const lit = tpl.initializer;\n return scanTemplate(source.slice(lit.getStart(sf) + 1, lit.getEnd() - 1), filePath, context, quiet).usage;\n }\n if (url && ts.isPropertyAssignment(url) && ts.isStringLiteralLike(url.initializer)) {\n const target = resolveUrl(dirOf(filePath), url.initializer.text);\n const html = env.read(target);\n if (html !== undefined) return scanTemplate(html, target, context, quiet).usage;\n }\n return null;\n };\n\n // ----- visitor -----\n const visit = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n\n if (ts.isCallExpression(node)) visitCall(node);\n else if (ts.isPropertyAccessExpression(node)) visitMember(node);\n else if (ts.isVariableDeclaration(node)) visitAlias(node.name, node.initializer, node);\n else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) visitAlias(undefined, node.right, node);\n else if (ts.isIdentifier(node)) visitIdentifier(node);\n else if (ts.isClassDeclaration(node)) visitInlineTemplate(node);\n\n ts.forEachChild(node, visit);\n };\n\n const visitCall = (call: ts.CallExpression): void => {\n const c = call.expression;\n if (moduleName && ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === moduleName && (c.name.text === 'forRoot' || c.name.text === 'forChild')) {\n convertModuleCall(call);\n return;\n }\n if (ts.isIdentifier(c) && providerNames.has(c.text) && call.arguments[0] && ts.isObjectLiteralExpression(call.arguments[0])) {\n transformConfig(call.arguments[0], false, edits);\n }\n if (setValueName && ts.isIdentifier(c) && c.text === setValueName) {\n const a0 = call.arguments[0];\n const assignable = !!a0 && (ts.isIdentifier(a0) || ts.isPropertyAccessExpression(a0) || ts.isElementAccessExpression(a0));\n if (ts.isExpressionStatement(call.parent) && call.arguments.length === 3 && assignable) {\n edits.push({ start: c.getStart(sf), end: c.getEnd(), replacement: `${a0.getText(sf)} = insertValue` });\n needed.add('insertValue');\n touched.add('setValue');\n } else {\n flag(call, 'setValue() was replaced by insertValue(), which returns a new object instead of mutating its argument. Use `target = insertValue(target, key, value)` manually.');\n }\n }\n if (ts.isPropertyAccessExpression(c) && resolver.isService(c.expression)) {\n if (c.name.text === 'getCurrentLang') {\n flag(call, 'getCurrentLang() returns Language | null in @ngx-translate/core v18 (null before a language is set). Handle the null case, e.g. `?? fallback`.');\n } else if (c.name.text === 'setTranslation' && call.arguments.length === 2 && env.projectHasExtend) {\n flag(call, 'setTranslation(lang, translations) no longer merges for services that used forChild({ extend: true }); pass `true` as third argument if you relied on merging.');\n }\n }\n };\n\n const visitMember = (n: ts.PropertyAccessExpression): void => {\n const member = n.name.text;\n if ((member === 'onTranslationChange' || member === 'getValue') && storeResolver.isService(n.expression)) {\n edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: member === 'getValue' ? 'getTranslationValue' : 'translationChange$',\n });\n return;\n }\n const isTracked = ['currentLang', 'langs', 'defaultLang', ...Object.keys(MEMBER_RENAMES)].includes(member);\n if (!isTracked || !resolver.isService(n.expression)) return;\n const parent = n.parent;\n if (MEMBER_RENAMES[member]) {\n edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: MEMBER_RENAMES[member] });\n return;\n }\n if (ts.isCallExpression(parent) && parent.expression === n) return; // already `currentLang()` etc.\n const isWrite =\n (ts.isBinaryExpression(parent) && parent.left === n && ASSIGN_OPS.has(parent.operatorToken.kind)) ||\n ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) ||\n ts.isDeleteExpression(parent);\n if (isWrite) {\n flag(n, `${member} cannot be assigned in @ngx-translate/core v18 (read-only Signal / removed). Use use(), setFallbackLang() or setTranslation() instead.`);\n return;\n }\n if (member === 'currentLang') edits.push({ start: n.getEnd(), end: n.getEnd(), replacement: '()' });\n else if (member === 'langs') edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: 'getLangs()',\n });\n else edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: 'fallbackLang()' });\n };\n\n const visitAlias = (name: ts.BindingName | undefined, init: ts.Expression | undefined, at: ts.Node): void => {\n if (!init) return;\n if (!resolver.isService(init) && !(name && ts.isObjectBindingPattern(name) && resolver.isInject(init))) return;\n if (name && ts.isIdentifier(name) && ts.isVariableDeclaration(at) && resolver.isType(at.type)) return; // typed alias is tracked\n flag(\n at,\n 'TranslateService is aliased or destructured here, so currentLang/default*/langs usages through it are not migrated automatically. Review them against the v18 API (currentLang() signal, fallbackLang, getLangs()).'\n );\n };\n\n const visitIdentifier = (id: ts.Identifier): void => {\n const p = id.parent;\n if ((ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id)) return;\n if (httpNames.has(id.text)) {\n const call = ts.isCallExpression(p) && p.expression === id ? p : undefined;\n const cfg = call?.arguments[0];\n const hasFlag = !!cfg && ts.isObjectLiteralExpression(cfg) && !!propOf(cfg, 'failOnError');\n if (!hasFlag) {\n flag(id, 'the v18 http-loader no longer fails the whole language load when a translation file request fails (it logs a warning and uses {}). Pass failOnError: true to provideTranslateHttpLoader() if you rely on the v17 behaviour.');\n }\n }\n if (iServiceName && id.text === iServiceName && ts.isExpressionWithTypeArguments(p) && ts.isHeritageClause(p.parent) && p.parent.token === ts.SyntaxKind.ImplementsKeyword) {\n flag(id, 'ITranslateService gained isLoading: Signal<boolean> in @ngx-translate/core v18. Add isLoading = signal(false).asReadonly() to this class.');\n }\n if (defaultEvent && id.text === 'DefaultLangChangeEvent') {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: 'FallbackLangChangeEvent' });\n needed.add('FallbackLangChangeEvent');\n touched.add('DefaultLangChangeEvent');\n }\n if (moduleName && id.text === moduleName && !handled.has(id)) {\n // `TranslateModule` as an element of imports / exports\n if (ts.isArrayLiteralExpression(p) && ts.isPropertyAssignment(p.parent) && ['imports', 'exports'].includes(nameOf(p.parent.name) ?? '') && ts.isObjectLiteralExpression(p.parent.parent)) {\n convertBareModule(id, p, p.parent.parent);\n }\n }\n };\n\n const visitInlineTemplate = (cls: ts.ClassDeclaration): void => {\n const tpl = componentProp(cls, 'template');\n if (!tpl) return;\n const lit = tpl.initializer;\n if (!ts.isNoSubstitutionTemplateLiteral(lit) && !ts.isStringLiteral(lit)) return;\n const start = lit.getStart(sf) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (!/translate|currentLang/.test(raw)) return;\n const baseLine = sf.getLineAndCharacterOfPosition(start).line;\n const scan = scanTemplate(raw, filePath, context, {\n members: resolver.members(cls),\n allowKeyRewrite: ts.isNoSubstitutionTemplateLiteral(lit),\n checkAttributes: env.projectUsesNgx,\n where: (o) => `${filePath}:${baseLine + lineOf(raw, o)}`,\n });\n edits.push(...shift(scan.edits, start));\n };\n\n visit(sf);\n\n // moved forRoot/forChild calls: imports -> providers\n for (const [obj, g] of moves) {\n const importsProp = propOf(obj, 'imports') as ts.PropertyAssignment;\n const arr = importsProp.initializer as ts.ArrayLiteralExpression;\n const providersProp = propOf(obj, 'providers');\n if (providersProp && !(ts.isPropertyAssignment(providersProp) && ts.isArrayLiteralExpression(providersProp.initializer))) {\n for (const call of g.calls) flag(call, 'the providers property is not an array literal, so the converted provider could not be moved there. Move it manually.');\n continue;\n }\n const texts = g.texts.join(', ');\n const movedIdx = new Set(g.calls.map((c) => arr.elements.indexOf(c)));\n const keepsOthers = arr.elements.length > movedIdx.size;\n if (providersProp) {\n const parr = (providersProp as ts.PropertyAssignment).initializer as ts.ArrayLiteralExpression;\n if (parr.elements.length > 0) {\n edits.push({\n start: parr.elements[parr.elements.length - 1].getEnd(),\n end: parr.elements[parr.elements.length - 1].getEnd(),\n replacement: `, ${texts}`,\n });\n } else {\n edits.push({ start: parr.getStart(sf) + 1, end: parr.getEnd() - 1, replacement: texts });\n }\n if (keepsOthers) edits.push(...removeArrayElements(arr, movedIdx, sf));\n else removeObjectProperty(importsProp, sf, edits);\n } else if (!keepsOthers) {\n edits.push({ start: importsProp.getStart(sf), end: importsProp.getEnd(), replacement: `providers: [${texts}]` });\n } else {\n edits.push(...removeArrayElements(arr, movedIdx, sf));\n const multiline = source.slice(obj.getStart(sf), importsProp.getEnd()).includes('\\n');\n const indent = multiline ? /[ \\t]*$/.exec(source.slice(0, importsProp.getStart(sf)))![0] : '';\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n edits.push({\n start: importsProp.getEnd(),\n end: importsProp.getEnd(),\n replacement: multiline ? `,${eol}${indent}providers: [${texts}]` : `, providers: [${texts}]`,\n });\n }\n }\n\n // remaining references to the removed module\n if (moduleName) {\n const mark = (n: ts.Node): void => {\n if (ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === moduleName && !handled.has(n) && !isPropertyName(n)) {\n flag(n, 'TranslateModule was removed in @ngx-translate/core v18. Use provideTranslateService() / provideChildTranslateService() and import TranslatePipe / TranslateDirective directly.');\n }\n ts.forEachChild(n, mark);\n };\n mark(sf);\n }\n\n // TODO comments, one line above the anchor, never duplicated\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n for (const { anchor, messages } of todos.values()) {\n const start = anchor.getStart(sf);\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))![0];\n const above = new Set<string>();\n const lines = source.slice(0, lineStart).split(/\\r?\\n/);\n for (let i = lines.length - 2; i >= 0 && lines[i].trim().startsWith('// ' + TODO_PREFIX); i--) above.add(lines[i].trim());\n const fresh = messages.map((m) => `// ${TODO_PREFIX} ${m}`).filter((l) => !above.has(l));\n if (fresh.length > 0) edits.push({\n start: lineStart,\n end: lineStart,\n replacement: fresh.map((l) => `${indent}${l}${eol}`).join(''),\n });\n }\n\n let result = applyEdits(source, edits);\n if (result === source) return source;\n result = fixImports(result, filePath, CORE, needed, touched);\n if (importProvidersTouched) result = fixImports(result, filePath, '@angular/core', new Set(), new Set(['importProvidersFrom']));\n return result;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Imports\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst RENAME_IN_PLACE: Record<string, string> = {\n DefaultLangChangeEvent: 'FallbackLangChangeEvent',\n setValue: 'insertValue',\n};\n\n/**\n * Drops `touched` specifiers that are no longer referenced (renaming in place when a rename is known) and\n * appends the `needed` names to the first named import of `moduleName`.\n */\nfunction fixImports(text: string, filePath: string, moduleName: string, needed: Set<string>, touched: Set<string>): string {\n const sf = ts.createSourceFile(filePath, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const referenced = (name: string): boolean => {\n let found = false;\n const walk = (n: ts.Node): void => {\n if (found || ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === name && !isPropertyName(n)) found = true;\n ts.forEachChild(n, walk);\n };\n walk(sf);\n return found;\n };\n\n const decls = sf.statements.filter(\n (s): s is ts.ImportDeclaration =>\n ts.isImportDeclaration(s) &&\n ts.isStringLiteral(s.moduleSpecifier) &&\n s.moduleSpecifier.text === moduleName &&\n !!s.importClause?.namedBindings &&\n ts.isNamedImports(s.importClause.namedBindings) &&\n !s.importClause.isTypeOnly\n );\n if (decls.length === 0) return text;\n\n const all = new Set<string>();\n for (const d of decls) for (const e of (d.importClause!.namedBindings as ts.NamedImports).elements) all.add(e.name.text);\n const placed = new Set<string>();\n const edits: Edit[] = [];\n const pendingNeeded = [...needed];\n\n decls.forEach((d, di) => {\n const named = d.importClause!.namedBindings as ts.NamedImports;\n const items: string[] = [];\n for (const e of named.elements) {\n const name = e.name.text;\n if (touched.has(name) && !e.propertyName && !referenced(name)) {\n const to = RENAME_IN_PLACE[name];\n if (to && needed.has(to) && !all.has(to) && !placed.has(to)) {\n items.push(to);\n placed.add(to);\n }\n continue;\n }\n items.push(e.getText(sf));\n }\n if (di === 0) {\n for (const n of pendingNeeded) if (!all.has(n) && !placed.has(n) && !items.includes(n)) items.push(n);\n }\n const before = named.elements.map((e) => e.getText(sf));\n if (items.length === before.length && items.every((v, i) => v === before[i])) return;\n if (items.length === 0 && !d.importClause!.name) {\n let end = d.getEnd();\n if (text[end] === '\\r') end++;\n if (text[end] === '\\n') end++;\n edits.push({ start: d.getStart(sf), end, replacement: '' });\n } else {\n const multiline = named.getText(sf).includes('\\n');\n const body = multiline ? `{\\n ${items.join(',\\n ')},\\n}` : `{ ${items.join(', ')} }`;\n edits.push({ start: named.getStart(sf), end: named.getEnd(), replacement: body });\n }\n });\n return applyEdits(text, edits);\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------------------------------------------------\n\nfunction isPropertyName(id: ts.Identifier): boolean {\n const p = id.parent;\n return (ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id);\n}\n\nfunction sanitize(message: string): string {\n return message.replace(/\\s+/g, ' ').trim();\n}\n\n/** Nearest ancestor that is a statement, class member or object property: the TODO goes on the line above it. */\nfunction anchorOf(node: ts.Node): ts.Node {\n let cur = node;\n while (cur.parent) {\n const p = cur.parent;\n if (ts.isSourceFile(p) || ts.isBlock(p) || ts.isModuleBlock(p) || ts.isClassLike(p) || ts.isObjectLiteralExpression(p) || ts.isCaseClause(p) || ts.isDefaultClause(p)) {\n return cur;\n }\n cur = p;\n }\n return cur;\n}\n\nconst dirOf = (p: string): string => dirname(normalize(p));\nconst resolveUrl = (dir: string, url: string): string => normalize(join(normalize(dir), url));\n\nfunction lineOf(source: string, offset: number): number {\n return source.slice(0, offset).split('\\n').length;\n}\n\nfunction shift(edits: Edit[], by: number): Edit[] {\n return edits.map((e) => ({ ...e, start: e.start + by, end: e.end + by }));\n}\n\n/** Removes one object property together with its separating comma. */\nfunction removeObjectProperty(prop: ts.ObjectLiteralElementLike, sf: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sf.getFullText();\n let start = prop.getStart(sf);\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getStart(sf);\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\n/** Removes the array elements at `indices`; non-overlapping ranges even for neighbouring elements. */\nfunction removeArrayElements(arr: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression, indices: Set<number>, sf: ts.SourceFile): Edit[] {\n const els: readonly ts.Node[] = ts.isArrayLiteralExpression(arr) ? arr.elements : arr.properties;\n const keptIdx = els.findIndex((_, i) => !indices.has(i));\n if (keptIdx === -1) return [{ start: arr.getStart(sf) + 1, end: arr.getEnd() - 1, replacement: '' }];\n const out: Edit[] = [];\n if (keptIdx > 0) out.push({ start: els[0].getStart(sf), end: els[keptIdx].getStart(sf), replacement: '' });\n for (let i = keptIdx + 1; i < els.length; i++) {\n if (indices.has(i)) out.push({ start: els[i - 1].getEnd(), end: els[i].getEnd(), replacement: '' });\n }\n return out;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const seen = new Map<string, Edit>();\n for (const e of edits) seen.set(`${e.start}:${e.end}:${e.replacement}`, e);\n let result = source;\n for (const e of [...seen.values()].sort((a, b) => b.start - a.start || b.end - a.end)) {\n result = result.slice(0, e.start) + e.replacement + result.slice(e.end);\n }\n return result;\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
2150
|
+
"sourceCode": "import { BindingType, parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit } from '../utils/todo-comment';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst OLD_CLASS = 'EuiTooltipConfig';\nconst NEW_INTERFACE = 'EuiTooltipInterface';\nconst REMOVED_ANIMATION = 'showHide';\nconst DIRECTIVE_CLASS = 'EuiTooltipDirective';\n\nconst RENAMED_INPUTS: Record<string, string> = {\n isPrimary: 'euiTooltipPrimary',\n isSecondary: 'euiTooltipSecondary',\n isInfo: 'euiTooltipInfo',\n isSuccess: 'euiTooltipSuccess',\n isWarning: 'euiTooltipWarning',\n isDanger: 'euiTooltipDanger',\n isAccent: 'euiTooltipAccent',\n};\n\nexport function migrateEuiTooltip(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n let result = original;\n if (path.endsWith('.html')) {\n if (!original.includes('euiTooltip')) return;\n result = migrateTemplate(original, path, context);\n } else {\n if (\n !original.includes(OLD_CLASS) &&\n !original.includes(REMOVED_ANIMATION) &&\n !original.includes('euiTooltip') &&\n !original.includes(DIRECTIVE_CLASS)\n ) {\n return;\n }\n if (original.includes(OLD_CLASS)) result = migrateTypeScript(result, path, context);\n if (result.includes(DIRECTIVE_CLASS)) result = migrateProgrammaticUsage(result, path, context);\n if (result.includes(REMOVED_ANIMATION)) result = removeShowHideAnimation(result, path, context);\n if (result.includes('euiTooltip')) result = migrateInlineTemplates(result, path, context);\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-tooltip usages in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated eui-tooltip usages in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n // Track if EuiTooltipInterface is already imported\n let hasInterfaceImport = false;\n let classImportDecl: ts.ImportDeclaration | null = null;\n let classImportModuleSpecifier: string | null = null;\n\n // First pass: analyze imports\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n for (const specifier of namedBindings.elements) {\n if (specifier.name.text === NEW_INTERFACE) {\n hasInterfaceImport = true;\n }\n if (specifier.name.text === OLD_CLASS) {\n classImportDecl = stmt;\n classImportModuleSpecifier = (stmt.moduleSpecifier as ts.StringLiteral).text;\n }\n }\n }\n\n // Second pass: handle import declarations\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n const specifiers = namedBindings.elements;\n const classSpecifier = specifiers.find((s) => s.name.text === OLD_CLASS);\n if (!classSpecifier) continue;\n\n if (hasInterfaceImport) {\n // EuiTooltipInterface is already imported elsewhere → remove EuiTooltipConfig from this import\n removeImportSpecifier(namedBindings, classSpecifier, sourceFile, edits);\n } else {\n // Rename EuiTooltipConfig → EuiTooltipInterface in the import\n edits.push({\n start: classSpecifier.name.getStart(sourceFile),\n end: classSpecifier.name.getEnd(),\n replacement: NEW_INTERFACE,\n });\n hasInterfaceImport = true;\n }\n }\n\n // Third pass: replace `new EuiTooltipConfig(...)` → spread/cast to interface\n const visitNewExpressions = (node: ts.Node): void => {\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) {\n const args = node.arguments;\n if (args !== undefined && args.length === 1) {\n const arg = args[0];\n // `new EuiTooltipConfig({ ... })` → `{ ... } as EuiTooltipInterface`\n // But if the argument is just a variable, we keep it: `varName as EuiTooltipInterface`\n const argText = source.slice(arg.getStart(sourceFile), arg.getEnd());\n\n if (ts.isObjectLiteralExpression(arg)) {\n // Inline object: `new EuiTooltipConfig({ x: 1 })` → `{ x: 1 }`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n } else {\n // Variable or expression: `new EuiTooltipConfig(opts)` → `opts`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n }\n } else if (args === undefined || args.length === 0) {\n // `new EuiTooltipConfig()` → `{} as EuiTooltipInterface`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: `{} as ${NEW_INTERFACE}`,\n });\n }\n return; // don't recurse into children we've already replaced\n }\n ts.forEachChild(node, visitNewExpressions);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitNewExpressions(stmt);\n }\n }\n\n // Fourth pass: rename all remaining identifier references (type annotations, etc.)\n const visitRefs = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n // Skip nodes we already covered in new expressions\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) return;\n\n if (ts.isIdentifier(node) && node.text === OLD_CLASS) {\n // Ensure this is not part of an import declaration\n if (!isPartOfImport(node)) {\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: NEW_INTERFACE,\n });\n }\n }\n ts.forEachChild(node, visitRefs);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitRefs(stmt);\n }\n }\n\n return applyEdits(source, edits);\n}\n\n/** Removes the `showHide` animation (import + `animations: [...]` entries) imported from an @eui package. */\nfunction removeShowHideAnimation(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n let found = false;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;\n if (!stmt.moduleSpecifier.text.startsWith('@eui/')) continue;\n const named = stmt.importClause?.namedBindings;\n if (!named || !ts.isNamedImports(named)) continue;\n const spec = named.elements.find((e) => e.name.text === REMOVED_ANIMATION && !e.propertyName);\n if (!spec) continue;\n found = true;\n removeImportSpecifier(named, spec, sourceFile, edits);\n }\n if (!found) return source;\n\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'animations' &&\n ts.isArrayLiteralExpression(node.initializer)\n ) {\n const arr = node.initializer;\n const kept = arr.elements.filter((e) => !(ts.isIdentifier(e) && e.text === REMOVED_ANIMATION));\n if (kept.length !== arr.elements.length) {\n if (kept.length === 0) {\n removeObjectProperty(node, sourceFile, edits);\n } else {\n edits.push({\n start: arr.getStart(sourceFile) + 1,\n end: arr.getEnd() - 1,\n replacement: kept.map((e) => e.getText(sourceFile)).join(', '),\n });\n }\n }\n } else if (ts.isIdentifier(node) && node.text === REMOVED_ANIMATION && !isPartOfImport(node) && !isInRemovedArray(node)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));\n context.logger.warn(`${filePath}:${line + 1} - Manual action needed: the \"showHide\" animation has been removed from @eui/components.`);\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction isInRemovedArray(node: ts.Node): boolean {\n const parent = node.parent;\n return (\n !!parent &&\n ts.isArrayLiteralExpression(parent) &&\n ts.isPropertyAssignment(parent.parent) &&\n ts.isIdentifier(parent.parent.name) &&\n parent.parent.name.text === 'animations'\n );\n}\n\nfunction removeObjectProperty(prop: ts.PropertyAssignment, sourceFile: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sourceFile.getFullText();\n let start = prop.getFullStart();\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getFullStart();\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\nfunction migrateInlineTemplates(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'template' &&\n (ts.isNoSubstitutionTemplateLiteral(node.initializer) || ts.isStringLiteral(node.initializer))\n ) {\n const lit = node.initializer;\n const start = lit.getStart(sourceFile) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (raw.includes('euiTooltip')) {\n const migrated = migrateTemplate(raw, filePath, context);\n if (migrated !== raw) edits.push({ start, end: lit.getEnd() - 1, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string, filePath: string, context: SchematicContext): string {\n const parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, source, filePath, context, edits);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n forEachElement(nodes, (node) => collectElementEdits(node, source, filePath, context, edits));\n}\n\nfunction collectElementEdits(el: TmplAstElement, source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n const tooltipAttr = el.attributes.find((a) => a.name === 'euiTooltip');\n const tooltipInput = el.inputs.find((i) => i.name === 'euiTooltip' && i.type === BindingType.Property);\n if (!tooltipAttr && !tooltipInput) return;\n\n // All messages of one element are merged into ONE comment: several TODOs would be inserted at the\n // same offset and overwrite each other.\n const messages: string[] = [];\n const warn = (offset: number, message: string): void => {\n messages.push(message);\n const { line } = lineOf(source, offset);\n context.logger.warn(`${filePath}:${line} - Manual action needed on <${el.name}>: ${message}`);\n };\n\n for (const attr of el.attributes) {\n if (RENAMED_INPUTS[attr.name]) {\n edits.push({ start: attr.keySpan!.start.offset, end: attr.keySpan!.end.offset, replacement: RENAMED_INPUTS[attr.name] });\n }\n }\n for (const input of el.inputs) {\n if (input.type === BindingType.Property && RENAMED_INPUTS[input.name]) {\n edits.push({ start: input.keySpan!.start.offset, end: input.keySpan!.end.offset, replacement: RENAMED_INPUTS[input.name] });\n }\n }\n\n // `position`: the migration guide lists it as removed, but EuiTooltipDirective still declares it\n // (model()). Deleting it would silently change behavior, so it is kept and flagged.\n const position = [\n ...el.attributes.filter((a) => a.name === 'position'),\n ...el.inputs.filter((i) => i.type === BindingType.Property && i.name === 'position'),\n ][0];\n if (position) {\n warn(\n position.sourceSpan.start.offset,\n 'input position of euiTooltip is documented as removed in eUI v22 but is still declared by EuiTooltipDirective. It was kept unchanged; verify it against the version you upgrade to.',\n );\n }\n\n const config = el.inputs.find((i) => i.type === BindingType.Property && i.name === 'config');\n if (config) {\n warn(\n config.sourceSpan.start.offset,\n 'input config of euiTooltip has been removed. Use the individual inputs (euiTooltip, euiTooltipPrimary, showDelay, hideDelay, contentAlignment, isDisabled) instead.',\n );\n }\n\n if (tooltipAttr && !tooltipAttr.value && !tooltipInput) {\n warn(tooltipAttr.sourceSpan.start.offset, 'input euiTooltip is now required and needs a value, e.g. euiTooltip=\"My tooltip\".');\n }\n\n if (messages.length > 0) {\n const todo = createTodoEdit(source, el.startSourceSpan.start.offset, messages.join(' '));\n if (todo) edits.push(todo);\n }\n}\n\n/**\n * Programmatic usage of a `EuiTooltipDirective` reference (`tt.isPrimary = true`, `tt.config`).\n * Renamed flags are renamed; `config` cannot be migrated and is flagged. Name based, scope aware for\n * parameters/variables (a differently typed parameter with the same name is left alone).\n * shortcut: only `this.x` and locals/params typed `EuiTooltipDirective` are followed; aliases are not.\n */\nfunction migrateProgrammaticUsage(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const isTyped = (t: ts.TypeNode | undefined): boolean =>\n !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === DIRECTIVE_CLASS;\n const isViewChildOf = (n: ts.PropertyDeclaration): boolean =>\n (ts.getDecorators?.(n) ?? []).some(\n (d) =>\n ts.isCallExpression(d.expression) &&\n ['ViewChild', 'ContentChild'].includes(d.expression.expression.getText(sourceFile)) &&\n d.expression.arguments[0]?.getText(sourceFile) === DIRECTIVE_CLASS,\n );\n\n const props = new Set<string>();\n const collect = (n: ts.Node): void => {\n if (ts.isPropertyDeclaration(n) && ts.isIdentifier(n.name) && (isTyped(n.type) || isViewChildOf(n))) props.add(n.name.text);\n ts.forEachChild(n, collect);\n };\n collect(sourceFile);\n\n /** Nearest declaration of a bare identifier: true = typed directive, false = something else, undefined = none found. */\n const bareIsDirective = (id: ts.Identifier): boolean | undefined => {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if ((ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) && cur.initializer && ts.isVariableDeclarationList(cur.initializer)) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return isTyped(d.type);\n }\n return undefined;\n };\n\n const visit = (n: ts.Node): void => {\n if (ts.isPropertyAccessExpression(n) && (RENAMED_INPUTS[n.name.text] || n.name.text === 'config')) {\n const target = n.expression;\n const tracked =\n (ts.isPropertyAccessExpression(target) && target.expression.kind === ts.SyntaxKind.ThisKeyword && props.has(target.name.text)) ||\n (ts.isIdentifier(target) && bareIsDirective(target) === true);\n if (tracked) {\n if (RENAMED_INPUTS[n.name.text]) {\n edits.push({ start: n.name.getStart(sourceFile), end: n.name.getEnd(), replacement: RENAMED_INPUTS[n.name.text] });\n } else {\n const { line } = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));\n context.logger.warn(\n `${filePath}:${line + 1} - Manual action needed: the \"config\" input of EuiTooltipDirective has been removed. Use the individual inputs instead.`,\n );\n }\n }\n }\n ts.forEachChild(n, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction lineOf(source: string, offset: number): { line: number } {\n return { line: source.slice(0, offset).split('\\n').length };\n}\n\nfunction isPartOfImport(node: ts.Node): boolean {\n let current: ts.Node | undefined = node.parent;\n while (current) {\n if (ts.isImportDeclaration(current)) return true;\n current = current.parent;\n }\n return false;\n}\n\nfunction removeImportSpecifier(\n namedImports: ts.NamedImports,\n specifier: ts.ImportSpecifier,\n sourceFile: ts.SourceFile,\n edits: Edit[],\n): void {\n const elements = namedImports.elements;\n if (elements.length === 1) {\n // Remove the entire import declaration\n const importDecl = namedImports.parent.parent;\n let end = importDecl.getEnd();\n // Also remove trailing newline if present\n const fullText = sourceFile.getFullText();\n if (fullText[end] === '\\n') end++;\n edits.push({\n start: importDecl.getStart(sourceFile),\n end,\n replacement: '',\n });\n } else {\n // Remove just this specifier with surrounding comma/whitespace\n const idx = elements.indexOf(specifier);\n let start: number;\n let end: number;\n if (idx < elements.length - 1) {\n // Not the last → remove from this specifier start to next specifier start\n start = specifier.getStart(sourceFile);\n end = elements[idx + 1].getStart(sourceFile);\n } else {\n // Last element → remove from previous element end to this end\n start = elements[idx - 1].getEnd();\n end = specifier.getEnd();\n }\n edits.push({ start, end, replacement: '' });\n }\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
2151
2151
|
"displayName": "Edit",
|
|
2152
2152
|
"properties": [
|
|
2153
2153
|
{
|
|
@@ -2159,7 +2159,7 @@
|
|
|
2159
2159
|
"indexKey": "",
|
|
2160
2160
|
"optional": false,
|
|
2161
2161
|
"description": "",
|
|
2162
|
-
"line":
|
|
2162
|
+
"line": 15,
|
|
2163
2163
|
"rawdescription": "\n"
|
|
2164
2164
|
},
|
|
2165
2165
|
{
|
|
@@ -2171,7 +2171,7 @@
|
|
|
2171
2171
|
"indexKey": "",
|
|
2172
2172
|
"optional": false,
|
|
2173
2173
|
"description": "",
|
|
2174
|
-
"line":
|
|
2174
|
+
"line": 16,
|
|
2175
2175
|
"rawdescription": "\n"
|
|
2176
2176
|
},
|
|
2177
2177
|
{
|
|
@@ -2183,7 +2183,7 @@
|
|
|
2183
2183
|
"indexKey": "",
|
|
2184
2184
|
"optional": false,
|
|
2185
2185
|
"description": "",
|
|
2186
|
-
"line":
|
|
2186
|
+
"line": 14,
|
|
2187
2187
|
"rawdescription": "\n"
|
|
2188
2188
|
}
|
|
2189
2189
|
],
|
|
@@ -4673,12 +4673,12 @@
|
|
|
4673
4673
|
},
|
|
4674
4674
|
{
|
|
4675
4675
|
"name": "Schema",
|
|
4676
|
-
"id": "interface-Schema-
|
|
4677
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
4676
|
+
"id": "interface-Schema-05d44cb645a03b21078a2d230ea40452f999bc21ae9f3852a4fe8c62cd94add695db5b7b528cabd6ce04e356ddcf3d1e999b71134cf29bcceb7b057d2b225d5f-15",
|
|
4677
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
4678
4678
|
"deprecated": false,
|
|
4679
4679
|
"deprecationMessage": "",
|
|
4680
4680
|
"type": "interface",
|
|
4681
|
-
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-
|
|
4681
|
+
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-tab` element selector to `div[eclTab]`.\n *\n * In v22 the legacy `ecl-tab` element selector was removed; the component only\n * matches `div[eclTab]`. This schematic rewrites `<ecl-tab>` to `<div eclTab>`\n * (and the closing tag to `</div>`) in external `.html` templates and inline\n * `@Component` templates, preserving existing attributes and content.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst OLD_TAG = 'ecl-tab';\nconst NEW_TAG = 'div';\nconst ATTRIBUTE = 'eclTab';\n\nexport function migrateEclTabs(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(OLD_TAG)) return;\n\n const result = path.endsWith('.html') ? migrateTemplate(original) : migrateTypeScript(original, path);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate ${OLD_TAG} → ${NEW_TAG}[${ATTRIBUTE}] in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated ${OLD_TAG} → ${NEW_TAG}[${ATTRIBUTE}] in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTemplate(source: string): string {\n let parsed;\n try {\n parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return source;\n }\n\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, edits);\n return applyEdits(source, edits);\n}\n\nfunction migrateTypeScript(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (rawTemplate.includes(OLD_TAG)) {\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) {\n edits.push({ start, end, replacement: migrated });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n // Exact tag match only — must not touch e.g. `ecl-tabs` or `ecl-tab-header`.\n if (node.name === OLD_TAG) {\n collectElementRename(node, edits);\n }\n });\n}\n\nfunction collectElementRename(element: TmplAstElement, edits: Edit[]): void {\n const openTagNameStart = element.startSourceSpan.start.offset + 1; // skip '<'\n const openTagNameEnd = openTagNameStart + OLD_TAG.length;\n\n const alreadyHasAttribute =\n element.attributes.some((a) => a.name === ATTRIBUTE) || element.inputs.some((i) => i.name === ATTRIBUTE);\n\n const replacement = alreadyHasAttribute ? NEW_TAG : `${NEW_TAG} ${ATTRIBUTE}`;\n edits.push({ start: openTagNameStart, end: openTagNameEnd, replacement });\n\n if (element.endSourceSpan) {\n const closeTagNameStart = element.endSourceSpan.start.offset + 2; // skip '</'\n edits.push({ start: closeTagNameStart, end: closeTagNameStart + OLD_TAG.length, replacement: NEW_TAG });\n }\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return (\n ts.isDecorator(callExpression.parent) &&\n ts.isIdentifier(callExpression.expression) &&\n callExpression.expression.text === 'Component'\n );\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
4682
4682
|
"displayName": "Schema",
|
|
4683
4683
|
"properties": [
|
|
4684
4684
|
{
|
|
@@ -4690,7 +4690,7 @@
|
|
|
4690
4690
|
"indexKey": "",
|
|
4691
4691
|
"optional": true,
|
|
4692
4692
|
"description": "",
|
|
4693
|
-
"line":
|
|
4693
|
+
"line": 18,
|
|
4694
4694
|
"rawdescription": "\n"
|
|
4695
4695
|
},
|
|
4696
4696
|
{
|
|
@@ -4702,14 +4702,14 @@
|
|
|
4702
4702
|
"indexKey": "",
|
|
4703
4703
|
"optional": true,
|
|
4704
4704
|
"description": "",
|
|
4705
|
-
"line":
|
|
4705
|
+
"line": 17,
|
|
4706
4706
|
"rawdescription": "\n"
|
|
4707
4707
|
}
|
|
4708
4708
|
],
|
|
4709
4709
|
"indexSignatures": [],
|
|
4710
4710
|
"kind": 172,
|
|
4711
|
-
"description": "<p>Migrates the removed <code>ecl-
|
|
4712
|
-
"rawdescription": "\n\nMigrates the removed `ecl-
|
|
4711
|
+
"description": "<p>Migrates the removed <code>ecl-tab</code> element selector to <code>div[eclTab]</code>.</p>\n<p>In v22 the legacy <code>ecl-tab</code> element selector was removed; the component only\nmatches <code>div[eclTab]</code>. This schematic rewrites <code><ecl-tab></code> to <code><div eclTab></code>\n(and the closing tag to <code></div></code>) in external <code>.html</code> templates and inline\n<code>@Component</code> templates, preserving existing attributes and content.</p>\n",
|
|
4712
|
+
"rawdescription": "\n\nMigrates the removed `ecl-tab` element selector to `div[eclTab]`.\n\nIn v22 the legacy `ecl-tab` element selector was removed; the component only\nmatches `div[eclTab]`. This schematic rewrites `<ecl-tab>` to `<div eclTab>`\n(and the closing tag to `</div>`) in external `.html` templates and inline\n`@Component` templates, preserving existing attributes and content.\n",
|
|
4713
4713
|
"methods": [],
|
|
4714
4714
|
"extends": [],
|
|
4715
4715
|
"isDuplicate": true,
|
|
@@ -4722,12 +4722,12 @@
|
|
|
4722
4722
|
},
|
|
4723
4723
|
{
|
|
4724
4724
|
"name": "Schema",
|
|
4725
|
-
"id": "interface-Schema-
|
|
4726
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
4725
|
+
"id": "interface-Schema-589bd8bab1e7a93675c15cfb1fdae37017fefa385aad54880e216cc0206f44c4673fd2840af9433a4c47f9cbf9fd5d471d8fea83e00a17bd47f82ec4961250a5-16",
|
|
4726
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
4727
4727
|
"deprecated": false,
|
|
4728
4728
|
"deprecationMessage": "",
|
|
4729
4729
|
"type": "interface",
|
|
4730
|
-
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-
|
|
4730
|
+
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\n/**\n * Migrates the removed `ecl-timeline` element selectors to their\n * attribute-selector equivalents.\n *\n * In v22 the timeline element selectors were removed in favour of attribute\n * selectors on specific host elements:\n * - `ecl-timeline` → `ol[eclTimeline]`\n * - `ecl-timeline-item` → `li[eclTimelineItem]`\n * - `ecl-timeline-item-toggler` → `li[eclTimelineItemToggler]`\n *\n * This schematic rewrites the element tags and injects the attribute directive\n * (e.g. `<ecl-timeline>` → `<ol eclTimeline>`, `</ecl-timeline>` → `</ol>`) in\n * external `.html` templates and inline `@Component` templates, preserving\n * existing attributes and content.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\ninterface SelectorMapping {\n oldTag: string;\n newTag: string;\n attribute: string;\n}\n\nconst SELECTOR_MAPPINGS: readonly SelectorMapping[] = [\n { oldTag: 'ecl-timeline', newTag: 'ol', attribute: 'eclTimeline' },\n { oldTag: 'ecl-timeline-item', newTag: 'li', attribute: 'eclTimelineItem' },\n { oldTag: 'ecl-timeline-item-toggler', newTag: 'li', attribute: 'eclTimelineItemToggler' },\n];\n\nconst OLD_TAGS = SELECTOR_MAPPINGS.map((m) => m.oldTag);\n\nexport function migrateEclTimeline(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!OLD_TAGS.some((tag) => original.includes(tag))) return;\n\n const result = path.endsWith('.html') ? migrateTemplate(original) : migrateTypeScript(original, path);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate ecl-timeline selector(s) in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated ecl-timeline element selectors in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTemplate(source: string): string {\n let parsed;\n try {\n parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return source;\n }\n\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, edits);\n return applyEdits(source, edits);\n}\n\nfunction migrateTypeScript(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (OLD_TAGS.some((tag) => rawTemplate.includes(tag))) {\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) {\n edits.push({ start, end, replacement: migrated });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n const mapping = SELECTOR_MAPPINGS.find((m) => m.oldTag === node.name);\n if (mapping) {\n collectElementRename(node, mapping, edits);\n }\n });\n}\n\nfunction collectElementRename(element: TmplAstElement, mapping: SelectorMapping, edits: Edit[]): void {\n const { oldTag, newTag, attribute } = mapping;\n\n const openTagNameStart = element.startSourceSpan.start.offset + 1; // skip '<'\n const openTagNameEnd = openTagNameStart + oldTag.length;\n\n const alreadyHasAttribute =\n element.attributes.some((a) => a.name === attribute) || element.inputs.some((i) => i.name === attribute);\n\n const replacement = alreadyHasAttribute ? newTag : `${newTag} ${attribute}`;\n edits.push({ start: openTagNameStart, end: openTagNameEnd, replacement });\n\n if (element.endSourceSpan) {\n const closeTagNameStart = element.endSourceSpan.start.offset + 2; // skip '</'\n edits.push({ start: closeTagNameStart, end: closeTagNameStart + oldTag.length, replacement: newTag });\n }\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return (\n ts.isDecorator(callExpression.parent) &&\n ts.isIdentifier(callExpression.expression) &&\n callExpression.expression.text === 'Component'\n );\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
4731
4731
|
"displayName": "Schema",
|
|
4732
4732
|
"properties": [
|
|
4733
4733
|
{
|
|
@@ -4739,7 +4739,7 @@
|
|
|
4739
4739
|
"indexKey": "",
|
|
4740
4740
|
"optional": true,
|
|
4741
4741
|
"description": "",
|
|
4742
|
-
"line":
|
|
4742
|
+
"line": 25,
|
|
4743
4743
|
"rawdescription": "\n"
|
|
4744
4744
|
},
|
|
4745
4745
|
{
|
|
@@ -4751,14 +4751,14 @@
|
|
|
4751
4751
|
"indexKey": "",
|
|
4752
4752
|
"optional": true,
|
|
4753
4753
|
"description": "",
|
|
4754
|
-
"line":
|
|
4754
|
+
"line": 24,
|
|
4755
4755
|
"rawdescription": "\n"
|
|
4756
4756
|
}
|
|
4757
4757
|
],
|
|
4758
4758
|
"indexSignatures": [],
|
|
4759
4759
|
"kind": 172,
|
|
4760
|
-
"description": "<p>Migrates the removed <code>ecl-
|
|
4761
|
-
"rawdescription": "\n\nMigrates the removed `ecl-
|
|
4760
|
+
"description": "<p>Migrates the removed <code>ecl-timeline</code> element selectors to their\nattribute-selector equivalents.</p>\n<p>In v22 the timeline element selectors were removed in favour of attribute\nselectors on specific host elements:</p>\n<ul>\n<li><code>ecl-timeline</code> → <code>ol[eclTimeline]</code></li>\n<li><code>ecl-timeline-item</code> → <code>li[eclTimelineItem]</code></li>\n<li><code>ecl-timeline-item-toggler</code> → <code>li[eclTimelineItemToggler]</code></li>\n</ul>\n<p>This schematic rewrites the element tags and injects the attribute directive\n(e.g. <code><ecl-timeline></code> → <code><ol eclTimeline></code>, <code></ecl-timeline></code> → <code></ol></code>) in\nexternal <code>.html</code> templates and inline <code>@Component</code> templates, preserving\nexisting attributes and content.</p>\n",
|
|
4761
|
+
"rawdescription": "\n\nMigrates the removed `ecl-timeline` element selectors to their\nattribute-selector equivalents.\n\nIn v22 the timeline element selectors were removed in favour of attribute\nselectors on specific host elements:\n - `ecl-timeline` → `ol[eclTimeline]`\n - `ecl-timeline-item` → `li[eclTimelineItem]`\n - `ecl-timeline-item-toggler` → `li[eclTimelineItemToggler]`\n\nThis schematic rewrites the element tags and injects the attribute directive\n(e.g. `<ecl-timeline>` → `<ol eclTimeline>`, `</ecl-timeline>` → `</ol>`) in\nexternal `.html` templates and inline `@Component` templates, preserving\nexisting attributes and content.\n",
|
|
4762
4762
|
"methods": [],
|
|
4763
4763
|
"extends": [],
|
|
4764
4764
|
"isDuplicate": true,
|
|
@@ -4865,12 +4865,12 @@
|
|
|
4865
4865
|
},
|
|
4866
4866
|
{
|
|
4867
4867
|
"name": "Schema",
|
|
4868
|
-
"id": "interface-Schema-
|
|
4869
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
4868
|
+
"id": "interface-Schema-dc18bc3e10d23f4240b45573a02aa1824883e327513ed13a093bb2c12168dfe15b85fb5496300c5a750b883ec75f43311178c63681955666ee368731cc171fef-19",
|
|
4869
|
+
"file": "packages/core/schematics/migrate-eui-autocomplete/index.ts",
|
|
4870
4870
|
"deprecated": false,
|
|
4871
4871
|
"deprecationMessage": "",
|
|
4872
4872
|
"type": "interface",
|
|
4873
|
-
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstElement, TmplAstNode, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nconst REMOVED_INPUTS = new Set(['isFlat']);\n\nexport function migrateEuiAvatar(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes('eui-avatar') && !original.includes('euiAvatar')) return;\n\n const result = path.endsWith('.html')\n ? migrateTemplate(original)\n : migrateInlineTemplates(original);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would remove 'isFlat' input in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n // Warn about TS property access usages\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if (!original.includes('isFlat')) return;\n\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === 'isFlat') {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"isFlat\" is no longer a valid input on eui-avatar. Remove this assignment.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n });\n\n context.logger.info(`Removed deprecated eui-avatar 'isFlat' input from ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const removals: { start: number; end: number }[] = [];\n\n visitNodes(parsed.nodes, removals);\n\n let result = source;\n for (const { start, end } of removals.sort((a, b) => b.start - a.start)) {\n let adjustedStart = start;\n while (adjustedStart > 0 && (result[adjustedStart - 1] === ' ' || result[adjustedStart - 1] === '\\t')) {\n adjustedStart--;\n }\n result = result.slice(0, adjustedStart) + result.slice(end);\n }\n\n return result;\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const templateRegex = /template\\s*:\\s*`([^`]*)`/gs;\n return source.replace(templateRegex, (match, templateContent: string) => {\n if (!templateContent.includes('eui-avatar') && !templateContent.includes('euiAvatar')) return match;\n const migrated = migrateTemplate(templateContent);\n if (migrated === templateContent) return match;\n return match.replace(templateContent, migrated);\n });\n}\n\nfunction isAvatarElement(element: TmplAstElement): boolean {\n if (element.name === 'eui-avatar') return true;\n return element.attributes.some((a) => a.name === 'euiAvatar');\n}\n\nfunction visitNodes(nodes: TmplAstNode[], removals: { start: number; end: number }[]): void {\n forEachElement(nodes, (node) => {\n if (isAvatarElement(node)) collectRemovals(node, removals);\n });\n}\n\nfunction collectRemovals(element: TmplAstElement, removals: { start: number; end: number }[]): void {\n for (const attr of element.attributes) {\n if (REMOVED_INPUTS.has(attr.name)) {\n removals.push(getAttributeSpan(attr));\n }\n }\n for (const input of element.inputs) {\n if (REMOVED_INPUTS.has(input.name)) {\n removals.push(getAttributeSpan(input));\n }\n }\n}\n\nfunction getAttributeSpan(attr: TmplAstTextAttribute | TmplAstBoundAttribute): { start: number; end: number } {\n return { start: attr.sourceSpan.start.offset, end: attr.sourceSpan.end.offset };\n}\n",
|
|
4873
|
+
"sourceCode": "import { parseTemplate, TmplAstElement } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ntype Kind = 'ac' | 'panel';\n\nconst AC = 'EuiAutocompleteComponent';\nconst PANEL = 'EuiAutocompletePanelComponent';\nconst KIND_BY_TYPE: Record<string, Kind> = { [AC]: 'ac', [PANEL]: 'panel' };\n\n/** Properties that went from plain value to WritableSignal. */\nconst WRITABLE: Record<Kind, Set<string>> = {\n ac: new Set(['chips', 'selectedOptionIndex', 'isDisabled', 'itemSize']),\n panel: new Set(),\n};\n/** Properties that went from plain value to a read-only signal (viewChild()). */\nconst READONLY: Record<Kind, Set<string>> = { ac: new Set(), panel: new Set(['virtualScrolling']) };\n\nconst ARRAY_MUTATORS = new Set(['splice', 'sort', 'reverse', 'pop', 'shift', 'unshift', 'fill', 'copyWithin']);\nconst SIGNAL_API = new Set(['set', 'update', 'asReadonly']);\nconst COMPOUND_OPS = new Set([\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.AsteriskEqualsToken,\n ts.SyntaxKind.SlashEqualsToken,\n ts.SyntaxKind.PercentEqualsToken,\n ts.SyntaxKind.AsteriskAsteriskEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n]);\n\n/** EuiAutocompleteComponent outputs (EventEmitter -> OutputEmitterRef): no `.pipe`/`.subscribe` anymore. */\nconst AC_OUTPUTS = new Set([\n 'panelClose',\n 'panelOpen',\n 'inputFocus',\n 'inputBlur',\n 'clear',\n 'selectionChange',\n 'itemAdd',\n 'itemRemove',\n 'inputChange',\n 'touch',\n]);\nconst OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);\nconst SIGNAL_INTEROP = '@angular/core/rxjs-interop';\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\nexport function migrateEuiAutocomplete(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n const original = buffer.toString('utf-8');\n if (!/utocomplete|[vV]iewChild/.test(original)) return;\n\n if (path.endsWith('.html')) {\n logFocusEventInfo(original, path, context);\n return;\n }\n\n const { result, warnings, infos } = migrateTs(original, path, tree);\n warnings.forEach((w) => context.logger.warn(w));\n infos.forEach((i) => context.logger.info(i));\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-autocomplete signal members in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n });\n\n context.logger.info(`Migrated eui-autocomplete signal members in ${count} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------\n\nfunction walkTemplate(node: unknown, visit: (el: TmplAstElement) => void, seen = new Set<unknown>()): void {\n if (!node || typeof node !== 'object' || seen.has(node)) return;\n seen.add(node);\n if (Array.isArray(node)) {\n node.forEach((n) => walkTemplate(n, visit, seen));\n return;\n }\n if (!('sourceSpan' in (node as object))) return;\n if (node instanceof TmplAstElement) visit(node);\n for (const [key, value] of Object.entries(node as object)) {\n if (key.endsWith('SourceSpan') || key === 'sourceSpan' || key === 'i18n') continue;\n walkTemplate(value, visit, seen);\n }\n}\n\nfunction parseSafe(source: string): ReturnType<typeof parseTemplate> | null {\n try {\n return parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return null;\n }\n}\n\n/** Template reference names (#ref) declared on <eui-autocomplete>. */\nfunction autocompleteRefs(templates: string[]): Set<string> {\n const refs = new Set<string>();\n for (const t of templates) {\n const parsed = parseSafe(t);\n if (!parsed) continue;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name === 'eui-autocomplete') el.references.forEach((r) => refs.add(r.name));\n });\n }\n return refs;\n}\n\nfunction logFocusEventInfo(template: string, path: string, context: SchematicContext): void {\n if (!template.includes('eui-autocomplete')) return;\n const parsed = parseSafe(template);\n if (!parsed) return;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name !== 'eui-autocomplete') return;\n for (const out of el.outputs) {\n if (out.name !== 'inputFocus' && out.name !== 'inputBlur') continue;\n const handler = (out.handler as unknown as { source?: string }).source ?? '';\n if (handler.includes('$event')) {\n context.logger.info(\n `${path} - eui-autocomplete (${out.name}) now emits a FocusEvent instead of void; check that the handler accepts a FocusEvent.`,\n );\n }\n }\n });\n}\n\n// ---------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------\n\nfunction typeKind(type: ts.TypeNode | undefined): Kind | undefined {\n if (!type) return undefined;\n if (ts.isParenthesizedTypeNode(type)) return typeKind(type.type);\n if (ts.isUnionTypeNode(type)) {\n for (const t of type.types) {\n const k = typeKind(t);\n if (k) return k;\n }\n return undefined;\n }\n if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName)) return KIND_BY_TYPE[type.typeName.text];\n return undefined;\n}\n\nfunction callKind(expr: ts.Expression | undefined): Kind | undefined {\n if (!expr || !ts.isCallExpression(expr)) return undefined;\n const callee = expr.expression;\n const isFactory =\n (ts.isIdentifier(callee) && (callee.text === 'inject' || callee.text === 'viewChild')) ||\n (ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text === 'viewChild' &&\n callee.name.text === 'required');\n const arg = expr.arguments[0];\n if (isFactory && arg && ts.isIdentifier(arg)) return KIND_BY_TYPE[arg.text];\n return undefined;\n}\n\nfunction isSignalQuery(expr: ts.Expression | undefined): boolean {\n if (!expr || !ts.isCallExpression(expr)) return false;\n const c = expr.expression;\n return (\n (ts.isIdentifier(c) && c.text === 'viewChild') ||\n (ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === 'viewChild')\n );\n}\n\nfunction decoratorsOf(node: ts.Node): readonly ts.Decorator[] {\n return ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? []) : [];\n}\n\nfunction extractInlineAndLinkedTemplates(sf: ts.SourceFile, path: string, tree: Tree): string[] {\n const templates: string[] = [];\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {\n const init = node.initializer;\n if (node.name.text === 'template' && (ts.isStringLiteralLike(init) || ts.isNoSubstitutionTemplateLiteral(init))) {\n templates.push(init.text);\n } else if (node.name.text === 'templateUrl' && ts.isStringLiteralLike(init)) {\n const dir = path.slice(0, path.lastIndexOf('/'));\n const segments = `${dir}/${init.text}`.split('/');\n const resolved: string[] = [];\n for (const s of segments) {\n if (s === '..') resolved.pop();\n else if (s !== '.' && s !== '') resolved.push(s);\n }\n const buf = tree.read('/' + resolved.join('/'));\n if (buf) templates.push(buf.toString('utf-8'));\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n return templates;\n}\n\nfunction migrateTs(source: string, path: string, tree: Tree): { result: string; warnings: string[]; infos: string[] } {\n const warnings: string[] = [];\n const infos: string[] = [];\n const sf = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);\n const templates = extractInlineAndLinkedTemplates(sf, path, tree);\n const refs = autocompleteRefs(templates);\n templates.forEach((t) => logFocusEventInfo(t, path, { logger: { info: (m: string) => infos.push(m) } } as unknown as SchematicContext));\n\n // name -> kind, for `this.name`, bare `name` and `this.name()` (signal queries)\n const thisNames = new Map<string, Kind>();\n const bareNames = new Map<string, Kind>();\n const callNames = new Map<string, Kind>();\n\n const collect = (node: ts.Node): void => {\n if (ts.isPropertyDeclaration(node) && ts.isIdentifier(node.name)) {\n const name = node.name.text;\n let kind = typeKind(node.type) ?? callKind(node.initializer);\n for (const d of decoratorsOf(node)) {\n if (!ts.isCallExpression(d.expression) || !ts.isIdentifier(d.expression.expression)) continue;\n if (d.expression.expression.text !== 'ViewChild') continue;\n const arg = d.expression.arguments[0];\n if (arg && ts.isIdentifier(arg) && KIND_BY_TYPE[arg.text]) kind ??= KIND_BY_TYPE[arg.text];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) kind ??= 'ac';\n }\n const init = node.initializer;\n if (!kind && init && isSignalQuery(init) && ts.isCallExpression(init)) {\n const arg = init.arguments[0];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) {\n callNames.set(name, 'ac');\n return;\n }\n }\n if (kind) {\n if (init && isSignalQuery(init)) callNames.set(name, kind);\n else thisNames.set(name, kind);\n }\n } else if (ts.isParameter(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type);\n if (kind) {\n bareNames.set(node.name.text, kind);\n if (ts.isConstructorDeclaration(node.parent) && ts.getModifiers(node)?.length) thisNames.set(node.name.text, kind);\n }\n } else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type) ?? callKind(node.initializer);\n if (kind) bareNames.set(node.name.text, kind);\n }\n ts.forEachChild(node, collect);\n };\n collect(sf);\n\n if (!thisNames.size && !bareNames.size && !callNames.size) return { result: source, warnings, infos };\n\n /** Nearest enclosing parameter/variable declaration decides the kind, so a shadowing param of another type is ignored. */\n const resolveBare = (id: ts.Identifier): Kind | undefined => {\n for (let n: ts.Node | undefined = id.parent; n; n = n.parent) {\n const decls: (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(n)) decls.push(...n.parameters);\n if (ts.isBlock(n) || ts.isSourceFile(n)) {\n n.statements.forEach((st) => ts.isVariableStatement(st) && decls.push(...st.declarationList.declarations));\n }\n for (const d of decls) {\n if (ts.isIdentifier(d.name) && d.name.text === id.text) return typeKind(d.type) ?? callKind(d.initializer);\n }\n }\n return bareNames.get(id.text);\n };\n\n const kindOf = (expr: ts.Expression): Kind | undefined => {\n let e = expr;\n while (ts.isNonNullExpression(e) || ts.isParenthesizedExpression(e)) e = e.expression;\n if (ts.isIdentifier(e)) return resolveBare(e);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) return thisNames.get(e.name.text);\n if (\n ts.isCallExpression(e) &&\n e.arguments.length === 0 &&\n ts.isPropertyAccessExpression(e.expression) &&\n e.expression.expression.kind === ts.SyntaxKind.ThisKeyword\n ) {\n return callNames.get(e.expression.name.text);\n }\n return undefined;\n };\n\n const edits: Edit[] = [];\n const where = (n: ts.Node): string => `${path}:${sf.getLineAndCharacterOfPosition(n.getStart()).line + 1}`;\n const warn = (n: ts.Node, msg: string): void => {\n warnings.push(`${where(n)} - Manual action needed: ${msg}`);\n };\n const isStatementLike = (n: ts.Node): boolean =>\n ts.isExpressionStatement(n.parent) || (ts.isArrowFunction(n.parent) && n.parent.body === n);\n const fresh = (name: string, text: string): string => (new RegExp(`\\\\b${name}\\\\b`).test(text) ? `${name}x` : name);\n const simple = (e: ts.Expression): boolean =>\n ts.isNumericLiteral(e) || ts.isIdentifier(e) || ts.isPropertyAccessExpression(e) || ts.isStringLiteral(e) || ts.isParenthesizedExpression(e);\n\n let needsOutputImport = false;\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const kind = kindOf(node.expression);\n if (kind) {\n if (kind === 'ac' && AC_OUTPUTS.has(node.name.text) && isObservableUse(node)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'outputToObservable(' });\n edits.push({ start: node.end, end: node.end, text: ')' });\n needsOutputImport = true;\n noteFocusEvent(node);\n } else {\n handle(node, node.name.text, kind);\n }\n }\n } else if (ts.isVariableDeclaration(node) && node.initializer && kindOf(node.initializer)) {\n const kind = kindOf(node.initializer)!;\n if (ts.isIdentifier(node.name)) {\n warn(node, `\"${node.name.text}\" is an alias of an eUI autocomplete reference; member usages through the alias are not migrated. Check \"${node.name.text}\" manually (chips, selectedOptionIndex, isDisabled, itemSize, autocompleteDataSelected are signals now).`);\n } else if (ts.isObjectBindingPattern(node.name)) {\n const migrated = node.name.elements\n .map((el) => (el.propertyName ?? el.name).getText())\n .filter((m) => WRITABLE[kind].has(m) || READONLY[kind].has(m) || (kind === 'ac' && m === 'autocompleteDataSelected'));\n if (migrated.length) {\n warn(node, `destructuring of ${migrated.join(', ')} from an eUI autocomplete reference now yields a signal, not a value; read it with \"()\" (or use the property access).`);\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n const noteFocusEvent = (pa: ts.PropertyAccessExpression): void => {\n const member = pa.name.text;\n if (member !== 'inputFocus' && member !== 'inputBlur') return;\n const sub = pa.parent;\n const call = ts.isPropertyAccessExpression(sub) && sub.name.text === 'subscribe' ? sub.parent : undefined;\n const handler = call && ts.isCallExpression(call) ? call.arguments[0] : undefined;\n if (handler && (ts.isArrowFunction(handler) || ts.isFunctionExpression(handler)) && handler.parameters.length === 0) {\n infos.push(`${where(pa)} - eui-autocomplete (${member}) now emits a FocusEvent instead of void; check that this subscribe handler accepts a FocusEvent.`);\n }\n };\n\n const handle = (pa: ts.PropertyAccessExpression, member: string, kind: Kind): void => {\n const parent = pa.parent;\n const isWritable = WRITABLE[kind].has(member);\n const isReadonly = READONLY[kind].has(member);\n const isDataSelected = kind === 'ac' && member === 'autocompleteDataSelected';\n if (!isWritable && !isReadonly && !isDataSelected) return;\n\n // already migrated: `x.member()` or `x.member.set/update/asReadonly`\n if (ts.isCallExpression(parent) && parent.expression === pa) return;\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && SIGNAL_API.has(parent.name.text)) return;\n\n const isAssignTarget =\n ts.isBinaryExpression(parent) &&\n parent.left === pa &&\n parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n\n if (isDataSelected) {\n const mutating =\n ts.isPropertyAccessExpression(parent) &&\n parent.expression === pa &&\n ts.isCallExpression(parent.parent) &&\n parent.parent.expression === parent &&\n (parent.name.text === 'push' || ARRAY_MUTATORS.has(parent.name.text));\n const written = (n: ts.Node): boolean =>\n ts.isBinaryExpression(n.parent) &&\n n.parent.left === n &&\n n.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n n.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n const memberWritten =\n (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === pa && written(parent);\n if (isAssignTarget || mutating || memberWritten) {\n warn(pa, '\"autocompleteDataSelected\" is now a read-only signal input and cannot be assigned or mutated programmatically. Bind [autocompleteDataSelected] in the template instead.');\n return;\n }\n // plain read: falls through to the `()` rewrite below\n }\n\n if (isAssignTarget && !isDataSelected) {\n const bin = parent as ts.BinaryExpression;\n const op = bin.operatorToken.kind;\n if (!isStatementLike(bin)) {\n warn(pa, `\"${member}\" is now a signal; assignment is used as a value and could not be rewritten automatically.`);\n return;\n }\n if (isReadonly) {\n warn(pa, `\"${member}\" is now a read-only signal and cannot be assigned.`);\n return;\n }\n if (op === ts.SyntaxKind.EqualsToken) {\n edits.push({ start: pa.end, end: bin.right.getStart(), text: '.set(' });\n edits.push({ start: bin.right.end, end: bin.right.end, text: ')' });\n } else if (COMPOUND_OPS.has(op)) {\n const sym = ts.tokenToString(op)!.slice(0, -1);\n const rightText = bin.right.getText();\n const v = fresh('v', rightText);\n const wrapRight = !simple(bin.right);\n edits.push({ start: pa.end, end: bin.right.getStart(), text: `.update(${v} => ${v} ${sym} ${wrapRight ? '(' : ''}` });\n edits.push({ start: bin.right.end, end: bin.right.end, text: `${wrapRight ? ')' : ''})` });\n } else {\n warn(pa, `\"${member}\" is now a signal; unsupported assignment operator.`);\n }\n return;\n }\n\n if ((ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {\n if (!isStatementLike(parent) || isReadonly) {\n warn(pa, `\"${member}\" is now a signal; ++/-- cannot be rewritten automatically here. Use ${member}.update(...).`);\n return;\n }\n const sym = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';\n if (ts.isPrefixUnaryExpression(parent)) edits.push({ start: parent.getStart(), end: pa.getStart(), text: '' });\n edits.push({ start: pa.end, end: parent.end, text: `.update(v => v ${sym} 1)` });\n return;\n }\n\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && member === 'chips') {\n const call = parent.parent;\n const method = parent.name.text;\n if (ts.isCallExpression(call) && call.expression === parent) {\n if (method === 'push') {\n if (!call.arguments.length) return;\n if (!isStatementLike(call)) {\n warn(pa, '\"chips\" is now a signal; the return value of push() is used, rewrite with chips.update(...) manually.');\n return;\n }\n const argsText = call.arguments.map((a) => a.getText()).join(',');\n const c = fresh('c', argsText);\n const first = call.arguments[0];\n const last = call.arguments[call.arguments.length - 1];\n edits.push({ start: pa.end, end: first.getStart(), text: `.update(${c} => [...${c}, ` });\n edits.push({ start: last.end, end: call.end, text: '])' });\n return;\n }\n if (ARRAY_MUTATORS.has(method)) {\n warn(pa, `\"chips\" is now a WritableSignal; \"${method}()\" mutates the array in place. Rewrite with chips.update(...) / chips.set(...).`);\n return;\n }\n }\n }\n\n // plain read\n edits.push({ start: pa.end, end: pa.end, text: '()' });\n };\n\n visit(sf);\n\n if (needsOutputImport) {\n const imp = outputImportEdit(sf, source);\n if (imp) edits.push(imp);\n }\n\n const result = [...edits]\n .sort((a, b) => b.start - a.start || b.end - a.end)\n .reduce((acc, e) => acc.slice(0, e.start) + e.text + acc.slice(e.end), source);\n return { result, warnings, infos };\n}\n\n/**\n * True when `node` (an output reference) is used as an Observable: receiver of subscribe/pipe/...,\n * or an argument (directly or inside an array literal) of another call such as merge(...).\n * Already wrapped (`outputToObservable(x.out)`) is not matched.\n */\nfunction isObservableUse(node: ts.PropertyAccessExpression): boolean {\n const p = node.parent;\n if (ts.isPropertyAccessExpression(p) && p.expression === node) {\n return OBSERVABLE_METHODS.has(p.name.text) && ts.isCallExpression(p.parent) && p.parent.expression === p;\n }\n const arg: ts.Node = ts.isArrayLiteralExpression(p) ? p : node;\n const call = arg.parent;\n if (ts.isCallExpression(call) && (call.arguments as readonly ts.Node[]).includes(arg)) {\n const callee = call.expression;\n return !(ts.isIdentifier(callee) && callee.text === 'outputToObservable');\n }\n return false;\n}\n\n/** Adds `outputToObservable` to the rxjs-interop import, or creates the import after the last one. */\nfunction outputImportEdit(sf: ts.SourceFile, source: string): Edit | null {\n const imports = sf.statements.filter(ts.isImportDeclaration);\n const existing = imports.find((i) => (i.moduleSpecifier as ts.StringLiteral).text === SIGNAL_INTEROP);\n const bindings = existing?.importClause?.namedBindings;\n if (existing && bindings && ts.isNamedImports(bindings)) {\n if (bindings.elements.some((e) => e.name.text === 'outputToObservable')) return null;\n const last = bindings.elements[bindings.elements.length - 1];\n if (!last) return { start: bindings.getStart(), end: bindings.getEnd(), text: '{ outputToObservable }' };\n return { start: last.getEnd(), end: last.getEnd(), text: ', outputToObservable' };\n }\n const line = `import { outputToObservable } from '${SIGNAL_INTEROP}';`;\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lastImport = imports[imports.length - 1];\n if (lastImport) return { start: lastImport.getEnd(), end: lastImport.getEnd(), text: `${eol}${line}` };\n return { start: 0, end: 0, text: `${line}${eol}` };\n}\n",
|
|
4874
4874
|
"displayName": "Schema",
|
|
4875
4875
|
"properties": [
|
|
4876
4876
|
{
|
|
@@ -4882,7 +4882,7 @@
|
|
|
4882
4882
|
"indexKey": "",
|
|
4883
4883
|
"optional": true,
|
|
4884
4884
|
"description": "",
|
|
4885
|
-
"line":
|
|
4885
|
+
"line": 8,
|
|
4886
4886
|
"rawdescription": "\n"
|
|
4887
4887
|
},
|
|
4888
4888
|
{
|
|
@@ -4894,7 +4894,7 @@
|
|
|
4894
4894
|
"indexKey": "",
|
|
4895
4895
|
"optional": true,
|
|
4896
4896
|
"description": "",
|
|
4897
|
-
"line":
|
|
4897
|
+
"line": 7,
|
|
4898
4898
|
"rawdescription": "\n"
|
|
4899
4899
|
}
|
|
4900
4900
|
],
|
|
@@ -4912,12 +4912,12 @@
|
|
|
4912
4912
|
},
|
|
4913
4913
|
{
|
|
4914
4914
|
"name": "Schema",
|
|
4915
|
-
"id": "interface-Schema-
|
|
4916
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
4915
|
+
"id": "interface-Schema-74d524a3dc4b33caacc5422e3ba0d4112abcfd8004b99d2a96f94486770a91b450f8eb566af3438119a016966930c3bfac18e5f004252554b603c4413525bc94-20",
|
|
4916
|
+
"file": "packages/core/schematics/migrate-eui-avatar/index.ts",
|
|
4917
4917
|
"deprecated": false,
|
|
4918
4918
|
"deprecationMessage": "",
|
|
4919
4919
|
"type": "interface",
|
|
4920
|
-
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nconst
|
|
4920
|
+
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstElement, TmplAstNode, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nconst REMOVED_INPUTS = new Set(['isFlat']);\n\nexport function migrateEuiAvatar(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes('eui-avatar') && !original.includes('euiAvatar')) return;\n\n const result = path.endsWith('.html')\n ? migrateTemplate(original)\n : migrateInlineTemplates(original);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would remove 'isFlat' input in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n // Warn about TS property access usages\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if (!original.includes('isFlat')) return;\n\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === 'isFlat') {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"isFlat\" is no longer a valid input on eui-avatar. Remove this assignment.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n });\n\n context.logger.info(`Removed deprecated eui-avatar 'isFlat' input from ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const removals: { start: number; end: number }[] = [];\n\n visitNodes(parsed.nodes, removals);\n\n let result = source;\n for (const { start, end } of removals.sort((a, b) => b.start - a.start)) {\n let adjustedStart = start;\n while (adjustedStart > 0 && (result[adjustedStart - 1] === ' ' || result[adjustedStart - 1] === '\\t')) {\n adjustedStart--;\n }\n result = result.slice(0, adjustedStart) + result.slice(end);\n }\n\n return result;\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const templateRegex = /template\\s*:\\s*`([^`]*)`/gs;\n return source.replace(templateRegex, (match, templateContent: string) => {\n if (!templateContent.includes('eui-avatar') && !templateContent.includes('euiAvatar')) return match;\n const migrated = migrateTemplate(templateContent);\n if (migrated === templateContent) return match;\n return match.replace(templateContent, migrated);\n });\n}\n\nfunction isAvatarElement(element: TmplAstElement): boolean {\n if (element.name === 'eui-avatar') return true;\n return element.attributes.some((a) => a.name === 'euiAvatar');\n}\n\nfunction visitNodes(nodes: TmplAstNode[], removals: { start: number; end: number }[]): void {\n forEachElement(nodes, (node) => {\n if (isAvatarElement(node)) collectRemovals(node, removals);\n });\n}\n\nfunction collectRemovals(element: TmplAstElement, removals: { start: number; end: number }[]): void {\n for (const attr of element.attributes) {\n if (REMOVED_INPUTS.has(attr.name)) {\n removals.push(getAttributeSpan(attr));\n }\n }\n for (const input of element.inputs) {\n if (REMOVED_INPUTS.has(input.name)) {\n removals.push(getAttributeSpan(input));\n }\n }\n}\n\nfunction getAttributeSpan(attr: TmplAstTextAttribute | TmplAstBoundAttribute): { start: number; end: number } {\n return { start: attr.sourceSpan.start.offset, end: attr.sourceSpan.end.offset };\n}\n",
|
|
4921
4921
|
"displayName": "Schema",
|
|
4922
4922
|
"properties": [
|
|
4923
4923
|
{
|
|
@@ -4959,12 +4959,12 @@
|
|
|
4959
4959
|
},
|
|
4960
4960
|
{
|
|
4961
4961
|
"name": "Schema",
|
|
4962
|
-
"id": "interface-Schema-
|
|
4963
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
4962
|
+
"id": "interface-Schema-7b319020159256ba85f5fbbcc6000b16ef0ff853182bf943060694f4e8632cd2e93f2da34c16b2cd0862cf5d8bc540cba335cf0df6dd20ae08231ecc44e462b6-21",
|
|
4963
|
+
"file": "packages/core/schematics/migrate-eui-button/index.ts",
|
|
4964
4964
|
"deprecated": false,
|
|
4965
4965
|
"deprecationMessage": "",
|
|
4966
4966
|
"type": "interface",
|
|
4967
|
-
"sourceCode": "import { parseTemplate,
|
|
4967
|
+
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nconst OLD_NAME = 'euiButtonCall';\nconst NEW_NAME = 'euiCTAButton';\n\nexport function migrateEuiButton(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(OLD_NAME)) return;\n\n let result: string;\n\n if (path.endsWith('.html')) {\n result = migrateTemplate(original);\n } else {\n result = migrateInlineTemplates(original);\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would rename '${OLD_NAME}' → '${NEW_NAME}' in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n // Warn about TS property access usages\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if (!original.includes(OLD_NAME)) return;\n\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === OLD_NAME) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"${OLD_NAME}\" has been renamed to \"${NEW_NAME}\". Update this reference manually.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n });\n\n context.logger.info(`Renamed '${OLD_NAME}' → '${NEW_NAME}' on elements with euiButton in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: { start: number; end: number; replacement: string }[] = [];\n\n visitNodes(parsed.nodes, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: { start: number; end: number; text: string }[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(OLD_NAME)) {\n ts.forEachChild(node, visit); return; \n}\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, text: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n let result = source;\n for (const change of changes.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, change.start) + change.text + result.slice(change.end);\n }\n return result;\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction hasEuiButtonAttribute(element: TmplAstElement): boolean {\n return element.attributes.some((a) => a.name === 'euiButton') ||\n element.inputs.some((i) => i.name === 'euiButton');\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: { start: number; end: number; replacement: string }[]): void {\n forEachElement(nodes, (node) => {\n if (hasEuiButtonAttribute(node)) collectRenames(node, edits);\n });\n}\n\nfunction collectRenames(element: TmplAstElement, edits: { start: number; end: number; replacement: string }[]): void {\n for (const attr of element.attributes) {\n if (attr.name === OLD_NAME) {\n edits.push({ start: attr.keySpan!.start.offset, end: attr.keySpan!.end.offset, replacement: NEW_NAME });\n }\n }\n for (const input of element.inputs) {\n if (input.name === OLD_NAME) {\n edits.push({ start: input.keySpan!.start.offset, end: input.keySpan!.end.offset, replacement: NEW_NAME });\n }\n }\n}\n\nfunction applyEdits(source: string, edits: { start: number; end: number; replacement: string }[]): string {\n let result = source;\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n",
|
|
4968
4968
|
"displayName": "Schema",
|
|
4969
4969
|
"properties": [
|
|
4970
4970
|
{
|
|
@@ -4976,7 +4976,7 @@
|
|
|
4976
4976
|
"indexKey": "",
|
|
4977
4977
|
"optional": true,
|
|
4978
4978
|
"description": "",
|
|
4979
|
-
"line":
|
|
4979
|
+
"line": 9,
|
|
4980
4980
|
"rawdescription": "\n"
|
|
4981
4981
|
},
|
|
4982
4982
|
{
|
|
@@ -4988,7 +4988,7 @@
|
|
|
4988
4988
|
"indexKey": "",
|
|
4989
4989
|
"optional": true,
|
|
4990
4990
|
"description": "",
|
|
4991
|
-
"line":
|
|
4991
|
+
"line": 8,
|
|
4992
4992
|
"rawdescription": "\n"
|
|
4993
4993
|
}
|
|
4994
4994
|
],
|
|
@@ -5006,12 +5006,12 @@
|
|
|
5006
5006
|
},
|
|
5007
5007
|
{
|
|
5008
5008
|
"name": "Schema",
|
|
5009
|
-
"id": "interface-Schema-
|
|
5010
|
-
"file": "packages/core/schematics/migrate-eui-chip
|
|
5009
|
+
"id": "interface-Schema-2d1c8a4a3675f5af29b762135efb0111d9573366f5595f85a6b4ac4ef2679068cf4d7209d85c38969ef1107107e7cb064939a28ae54b1fb7f76c171f40d7ec2c-22",
|
|
5010
|
+
"file": "packages/core/schematics/migrate-eui-chip/index.ts",
|
|
5011
5011
|
"deprecated": false,
|
|
5012
5012
|
"deprecationMessage": "",
|
|
5013
5013
|
"type": "interface",
|
|
5014
|
-
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement, getTemplateChildren } from '../utils/template-walk';\n\nconst CHIP_LIST_TAG = 'eui-chip-list';\nconst CHIP_LIST_ATTR = 'euiChipList';\nconst CHIP_TAG = 'eui-chip';\nconst CHIP_ATTR = 'euiChip';\n\nconst PROPAGATED_INPUTS = new Set([\n 'euiPrimary', 'euiSecondary', 'euiSuccess', 'euiInfo', 'euiWarning',\n 'euiDanger', 'euiAccent', 'euiVariant', 'euiSizeS', 'euiSizeVariant',\n 'euiOutline', 'euiDisabled',\n]);\n\nconst WARN_PROPERTIES = new Set([...PROPAGATED_INPUTS, 'chipRemove', 'isChipsRemovable', 'chipsLabelTruncateCount',\n 'maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel',\n 'isChipsSorted', 'chipsSortOrder']);\n\nconst REMOVED_INPUTS = new Set(['maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel', 'isChipsSorted', 'chipsSortOrder']);\n\nconst TRUNCATE_PIPE_IMPORT = 'EuiTruncatePipe';\nconst TRUNCATE_PIPE_PATH = '@eui/components/pipes';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nexport function migrateEuiChipList(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n const filesNeedingTruncateImport = new Set<string>();\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(CHIP_LIST_TAG) && !original.includes(CHIP_LIST_ATTR)) return;\n\n let result: string;\n let addedTruncate = false;\n\n if (path.endsWith('.html')) {\n result = migrateTemplate(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n // Find the associated .ts file\n const tsPath = path.replace(/\\.html$/, '.ts');\n if (tree.exists(tsPath)) {\n filesNeedingTruncateImport.add(tsPath);\n } else {\n // Try component naming convention\n const componentTsPath = path.replace(/\\.html$/, '.component.ts');\n if (tree.exists(componentTsPath)) {\n filesNeedingTruncateImport.add(componentTsPath);\n }\n }\n }\n } else {\n result = migrateInlineTemplates(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n addedTruncate = true;\n }\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would move variant/size/outline inputs to child eui-chip in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n if (addedTruncate) {\n filesNeedingTruncateImport.add(path);\n }\n\n // Warn about TS usages of removed properties\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if ([...WARN_PROPERTIES].some((p) => original.includes(p))) {\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && WARN_PROPERTIES.has(node.name.text)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(\n `${path}:${line + 1} - \"${node.name.text}\" has been removed from eui-chip-list. Move it to individual eui-chip elements.`,\n );\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n }\n });\n\n // Add EuiTruncatePipe import to component files that need it\n for (const tsPath of filesNeedingTruncateImport) {\n const buffer = tree.read(tsPath);\n if (!buffer) continue;\n const source = buffer.toString('utf-8');\n if (source.includes(TRUNCATE_PIPE_IMPORT)) continue;\n const result = addTruncatePipeImport(source, tsPath);\n if (result !== source) {\n if (!options.dryRun) {\n tree.overwrite(tsPath, result);\n }\n }\n }\n\n context.logger.info(`Migrated eui-chip-list inputs/outputs to child eui-chip in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction addTruncatePipeImport(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const edits: Edit[] = [];\n\n // 1. Add ES import statement for EuiTruncatePipe\n let hasEsImport = false;\n let lastImportEnd = 0;\n\n for (const stmt of sourceFile.statements) {\n if (ts.isImportDeclaration(stmt)) {\n lastImportEnd = stmt.getEnd();\n const moduleSpec = (stmt.moduleSpecifier as ts.StringLiteral).text;\n if (moduleSpec === TRUNCATE_PIPE_PATH) {\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n if (namedBindings.elements.some((el) => el.name.text === TRUNCATE_PIPE_IMPORT)) {\n hasEsImport = true;\n } else {\n // Add to existing import from same path\n const lastEl = namedBindings.elements[namedBindings.elements.length - 1];\n edits.push({ start: lastEl.getEnd(), end: lastEl.getEnd(), replacement: `, ${TRUNCATE_PIPE_IMPORT}` });\n hasEsImport = true;\n }\n }\n }\n }\n }\n\n if (!hasEsImport) {\n const importStatement = `\\nimport { ${TRUNCATE_PIPE_IMPORT} } from '${TRUNCATE_PIPE_PATH}';`;\n edits.push({ start: lastImportEnd, end: lastImportEnd, replacement: importStatement });\n }\n\n // 2. Add EuiTruncatePipe to @Component imports array\n const visit = (node: ts.Node): void => {\n if (ts.isClassDeclaration(node)) {\n const decs = ts.getDecorators(node);\n if (!decs) return;\n for (const dec of decs) {\n if (!ts.isCallExpression(dec.expression) || !ts.isIdentifier(dec.expression.expression) || dec.expression.expression.text !== 'Component') continue;\n const metadata = dec.expression.arguments[0];\n if (!ts.isObjectLiteralExpression(metadata)) continue;\n for (const prop of metadata.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name) || prop.name.text !== 'imports') continue;\n if (!ts.isArrayLiteralExpression(prop.initializer)) continue;\n const arr = prop.initializer;\n const arrText = source.slice(arr.getStart(sourceFile), arr.getEnd());\n if (arrText.includes(TRUNCATE_PIPE_IMPORT)) continue;\n if (arr.elements.length > 0) {\n const lastElement = arr.elements[arr.elements.length - 1];\n edits.push({ start: lastElement.getEnd(), end: lastElement.getEnd(), replacement: `,\\n ${TRUNCATE_PIPE_IMPORT}` });\n } else {\n edits.push({ start: arr.getStart(sourceFile) + 1, end: arr.getEnd() - 1, replacement: TRUNCATE_PIPE_IMPORT });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: Edit[] = [];\n\n visitNodes(parsed.nodes, source, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(CHIP_LIST_TAG) && !rawTemplate.includes(CHIP_LIST_ATTR)) {\n ts.forEachChild(node, visit);\n return;\n }\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n return applyEdits(source, changes);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n if (isChipListElement(node)) migrateChipListElement(node, source, edits);\n });\n}\n\nfunction isChipListElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_LIST_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_LIST_ATTR);\n}\n\nfunction isChipElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_ATTR);\n}\n\nfunction findChildChips(nodes: TmplAstNode[]): TmplAstElement[] {\n const chips: TmplAstElement[] = [];\n for (const node of nodes) {\n if (node instanceof TmplAstElement && isChipElement(node)) {\n chips.push(node);\n } else {\n chips.push(...findChildChips(getTemplateChildren(node)));\n }\n }\n return chips;\n}\n\nfunction migrateChipListElement(element: TmplAstElement, source: string, edits: Edit[]): void {\n const childChips = findChildChips(element.children);\n const insertions: string[] = [];\n let truncateValue: string | null = null;\n\n // Collect and remove propagated static attributes\n for (const attr of element.attributes) {\n if (PROPAGATED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n insertions.push(attr.value ? `${attr.name}=\"${attr.value}\"` : attr.name);\n }\n if (attr.name === 'isChipsRemovable') {\n edits.push(removalEdit(attr, source));\n insertions.push('isChipRemovable');\n }\n if (attr.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(attr, source));\n truncateValue = attr.value || null;\n }\n if (REMOVED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n }\n }\n\n // Collect and remove propagated bound inputs\n for (const input of element.inputs) {\n if (PROPAGATED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n insertions.push(raw);\n }\n if (input.name === 'isChipsRemovable') {\n edits.push(removalEdit(input, source));\n const valueText = extractBindingValue(input, source);\n insertions.push(`[isChipRemovable]=\"${valueText}\"`);\n }\n if (input.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(input, source));\n truncateValue = extractBindingValue(input, source);\n }\n if (REMOVED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n }\n }\n\n // Collect and remove (chipRemove) output\n let chipRemoveHandler: string | null = null;\n for (const output of element.outputs) {\n if (output.name === 'chipRemove') {\n edits.push(removalEdit(output, source));\n chipRemoveHandler = extractHandlerExpression(output, source);\n }\n }\n\n if (chipRemoveHandler) {\n insertions.push(`(remove)=\"${chipRemoveHandler}\"`);\n }\n\n // Add collected attributes to each child eui-chip\n if (insertions.length > 0) {\n for (const chip of childChips) {\n const existingNames = getExistingAttrNames(chip);\n const toInsert = insertions.filter((ins) => {\n const name = extractAttrName(ins);\n return !existingNames.has(name);\n });\n if (toInsert.length > 0) {\n const insertPos = chip.startSourceSpan.end.offset - 1;\n edits.push({ start: insertPos, end: insertPos, replacement: ' ' + toInsert.join(' ') });\n }\n }\n }\n\n // Add euiTruncate pipe to chip label content\n if (truncateValue) {\n for (const chip of childChips) {\n const labelEdit = buildTruncatePipeEdit(chip, source, truncateValue);\n if (labelEdit) edits.push(labelEdit);\n }\n }\n}\n\nfunction buildTruncatePipeEdit(chip: TmplAstElement, source: string, truncateValue: string): Edit | null {\n // Find <span euiLabel>...</span> inside the chip\n const labelEl = findLabelElement(chip.children);\n if (labelEl !== null && labelEl !== undefined && labelEl.endSourceSpan) {\n const contentStart = labelEl.startSourceSpan.end.offset;\n const contentEnd = labelEl.endSourceSpan.start.offset;\n const content = source.slice(contentStart, contentEnd);\n if (content && !content.includes('euiTruncate')) {\n const trimmed = content.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch) {\n return { start: contentStart, end: contentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n return { start: contentStart, end: contentEnd, replacement: `{{ '${trimmed}' | euiTruncate: ${truncateValue} }}` };\n }\n }\n\n // Check direct text content inside chip (no label element)\n if (chip.endSourceSpan) {\n const chipContentStart = chip.startSourceSpan.end.offset;\n const chipContentEnd = chip.endSourceSpan.start.offset;\n const chipContent = source.slice(chipContentStart, chipContentEnd);\n const trimmed = chipContent.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch && !chipContent.includes('euiTruncate')) {\n return { start: chipContentStart, end: chipContentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n }\n return null;\n}\n\nfunction findLabelElement(nodes: TmplAstNode[]): TmplAstElement | null {\n for (const node of nodes) {\n if (node instanceof TmplAstElement && node.attributes.some((a) => a.name === 'euiLabel')) return node;\n const nested = findLabelElement(getTemplateChildren(node));\n if (nested) return nested;\n }\n return null;\n}\n\nfunction getExistingAttrNames(element: TmplAstElement): Set<string> {\n const names = new Set<string>();\n for (const attr of element.attributes) names.add(attr.name);\n for (const input of element.inputs) names.add(input.name);\n for (const output of element.outputs) names.add(output.name);\n return names;\n}\n\nfunction extractAttrName(insertion: string): string {\n const outputMatch = insertion.match(/^\\(([^)]+)\\)/);\n if (outputMatch) return outputMatch[1];\n const inputMatch = insertion.match(/^\\[([^\\]]+)\\]/);\n if (inputMatch) return inputMatch[1];\n return insertion.split('=')[0];\n}\n\nfunction removalEdit(node: TmplAstTextAttribute | TmplAstBoundAttribute | TmplAstBoundEvent, source: string): Edit {\n let start = node.sourceSpan.start.offset;\n while (start > 0 && (source[start - 1] === ' ' || source[start - 1] === '\\t')) {\n start--;\n }\n return { start, end: node.sourceSpan.end.offset, replacement: '' };\n}\n\nfunction extractBindingValue(input: TmplAstBoundAttribute, source: string): string {\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : 'true';\n}\n\nfunction extractHandlerExpression(output: TmplAstBoundEvent, source: string): string {\n const raw = source.slice(output.sourceSpan.start.offset, output.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : '';\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n seen.set(`${edit.start}:${edit.end}`, edit);\n }\n return Array.from(seen.values());\n}\n",
|
|
5014
|
+
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstElement, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\nimport { renameTooltipMessageInFile, TooltipImportCollector, warnTooltipMessageUsages } from '../utils/tooltip-message';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nconst REMOVED_INPUTS = new Set(['isSquared']);\n\nexport function migrateEuiChip(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n const tooltipImports = new TooltipImportCollector();\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes('eui-chip') && !original.includes('euiChip')) return;\n\n let result = path.endsWith('.html')\n ? migrateTemplate(original)\n : migrateInlineTemplates(original);\n\n // tooltipMessage input removed: replaced by the euiTooltip directive\n const tooltip = renameTooltipMessageInFile(result, path, isChipElement, (message) => context.logger.warn(`${path} - ${message}`));\n result = tooltip.result;\n if (tooltip.renamed > 0 && !options.dryRun) {\n if (path.endsWith('.html')) tooltipImports.addExternal(tree, path);\n else tooltipImports.addInline(path);\n }\n warnTooltipMessageUsages(original, path, context);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would remove 'isSquared' input in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n // Warn about TS usages inline\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts') && original.includes('isSquared')) {\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === 'isSquared') {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"isSquared\" is no longer a valid input on eui-chip. Remove this assignment.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n });\n\n if (!options.dryRun) tooltipImports.apply(tree, context);\n\n context.logger.info(`Removed deprecated eui-chip 'isSquared' input from ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const removals: { start: number; end: number }[] = [];\n\n forEachElement(parsed.nodes, (element) => {\n if (isChipElement(element)) collectRemovals(element, removals);\n });\n\n let result = source;\n for (const { start, end } of removals.sort((a, b) => b.start - a.start)) {\n let adjustedStart = start;\n while (adjustedStart > 0 && (result[adjustedStart - 1] === ' ' || result[adjustedStart - 1] === '\\t')) {\n adjustedStart--;\n }\n result = result.slice(0, adjustedStart) + result.slice(end);\n }\n\n return result;\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const templateRegex = /template\\s*:\\s*`([^`]*)`/gs;\n return source.replace(templateRegex, (match, templateContent: string) => {\n if (!templateContent.includes('eui-chip') && !templateContent.includes('euiChip')) return match;\n const migrated = migrateTemplate(templateContent);\n if (migrated === templateContent) return match;\n return match.replace(templateContent, migrated);\n });\n}\n\nfunction isChipElement(element: TmplAstElement): boolean {\n if (element.name === 'eui-chip') return true;\n return element.attributes.some((a) => a.name === 'euiChip');\n}\n\nfunction collectRemovals(element: TmplAstElement, removals: { start: number; end: number }[]): void {\n for (const attr of element.attributes) {\n if (REMOVED_INPUTS.has(attr.name)) {\n removals.push(getAttributeSpan(attr));\n }\n }\n for (const input of element.inputs) {\n if (REMOVED_INPUTS.has(input.name)) {\n removals.push(getAttributeSpan(input));\n }\n }\n}\n\nfunction getAttributeSpan(attr: TmplAstTextAttribute | TmplAstBoundAttribute): { start: number; end: number } {\n return { start: attr.sourceSpan.start.offset, end: attr.sourceSpan.end.offset };\n}\n",
|
|
5015
5015
|
"displayName": "Schema",
|
|
5016
5016
|
"properties": [
|
|
5017
5017
|
{
|
|
@@ -5023,7 +5023,7 @@
|
|
|
5023
5023
|
"indexKey": "",
|
|
5024
5024
|
"optional": true,
|
|
5025
5025
|
"description": "",
|
|
5026
|
-
"line":
|
|
5026
|
+
"line": 10,
|
|
5027
5027
|
"rawdescription": "\n"
|
|
5028
5028
|
},
|
|
5029
5029
|
{
|
|
@@ -5035,7 +5035,7 @@
|
|
|
5035
5035
|
"indexKey": "",
|
|
5036
5036
|
"optional": true,
|
|
5037
5037
|
"description": "",
|
|
5038
|
-
"line":
|
|
5038
|
+
"line": 9,
|
|
5039
5039
|
"rawdescription": "\n"
|
|
5040
5040
|
}
|
|
5041
5041
|
],
|
|
@@ -5053,12 +5053,12 @@
|
|
|
5053
5053
|
},
|
|
5054
5054
|
{
|
|
5055
5055
|
"name": "Schema",
|
|
5056
|
-
"id": "interface-Schema-
|
|
5057
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
5056
|
+
"id": "interface-Schema-ec63cf1ec803c75d650624c294e956ecef8c4347eb9f1f3d67164ae66222f0c4148af1789dd40b60686696b75c4d8eb3671f97f6b62044a25468f8b18624b514-23",
|
|
5057
|
+
"file": "packages/core/schematics/migrate-eui-chip-list/index.ts",
|
|
5058
5058
|
"deprecated": false,
|
|
5059
5059
|
"deprecationMessage": "",
|
|
5060
5060
|
"type": "interface",
|
|
5061
|
-
"sourceCode": "import { parseTemplate, TmplAstElement } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ntype Kind = 'ac' | 'panel';\n\nconst AC = 'EuiAutocompleteComponent';\nconst PANEL = 'EuiAutocompletePanelComponent';\nconst KIND_BY_TYPE: Record<string, Kind> = { [AC]: 'ac', [PANEL]: 'panel' };\n\n/** Properties that went from plain value to WritableSignal. */\nconst WRITABLE: Record<Kind, Set<string>> = {\n ac: new Set(['chips', 'selectedOptionIndex', 'isDisabled', 'itemSize']),\n panel: new Set(),\n};\n/** Properties that went from plain value to a read-only signal (viewChild()). */\nconst READONLY: Record<Kind, Set<string>> = { ac: new Set(), panel: new Set(['virtualScrolling']) };\n\nconst ARRAY_MUTATORS = new Set(['splice', 'sort', 'reverse', 'pop', 'shift', 'unshift', 'fill', 'copyWithin']);\nconst SIGNAL_API = new Set(['set', 'update', 'asReadonly']);\nconst COMPOUND_OPS = new Set([\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.AsteriskEqualsToken,\n ts.SyntaxKind.SlashEqualsToken,\n ts.SyntaxKind.PercentEqualsToken,\n ts.SyntaxKind.AsteriskAsteriskEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n]);\n\n/** EuiAutocompleteComponent outputs (EventEmitter -> OutputEmitterRef): no `.pipe`/`.subscribe` anymore. */\nconst AC_OUTPUTS = new Set([\n 'panelClose',\n 'panelOpen',\n 'inputFocus',\n 'inputBlur',\n 'clear',\n 'selectionChange',\n 'itemAdd',\n 'itemRemove',\n 'inputChange',\n 'touch',\n]);\nconst OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);\nconst SIGNAL_INTEROP = '@angular/core/rxjs-interop';\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\nexport function migrateEuiAutocomplete(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n const original = buffer.toString('utf-8');\n if (!/utocomplete|[vV]iewChild/.test(original)) return;\n\n if (path.endsWith('.html')) {\n logFocusEventInfo(original, path, context);\n return;\n }\n\n const { result, warnings, infos } = migrateTs(original, path, tree);\n warnings.forEach((w) => context.logger.warn(w));\n infos.forEach((i) => context.logger.info(i));\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-autocomplete signal members in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n });\n\n context.logger.info(`Migrated eui-autocomplete signal members in ${count} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------\n\nfunction walkTemplate(node: unknown, visit: (el: TmplAstElement) => void, seen = new Set<unknown>()): void {\n if (!node || typeof node !== 'object' || seen.has(node)) return;\n seen.add(node);\n if (Array.isArray(node)) {\n node.forEach((n) => walkTemplate(n, visit, seen));\n return;\n }\n if (!('sourceSpan' in (node as object))) return;\n if (node instanceof TmplAstElement) visit(node);\n for (const [key, value] of Object.entries(node as object)) {\n if (key.endsWith('SourceSpan') || key === 'sourceSpan' || key === 'i18n') continue;\n walkTemplate(value, visit, seen);\n }\n}\n\nfunction parseSafe(source: string): ReturnType<typeof parseTemplate> | null {\n try {\n return parseTemplate(source, '', { preserveWhitespaces: true });\n } catch {\n return null;\n }\n}\n\n/** Template reference names (#ref) declared on <eui-autocomplete>. */\nfunction autocompleteRefs(templates: string[]): Set<string> {\n const refs = new Set<string>();\n for (const t of templates) {\n const parsed = parseSafe(t);\n if (!parsed) continue;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name === 'eui-autocomplete') el.references.forEach((r) => refs.add(r.name));\n });\n }\n return refs;\n}\n\nfunction logFocusEventInfo(template: string, path: string, context: SchematicContext): void {\n if (!template.includes('eui-autocomplete')) return;\n const parsed = parseSafe(template);\n if (!parsed) return;\n walkTemplate(parsed.nodes, (el) => {\n if (el.name !== 'eui-autocomplete') return;\n for (const out of el.outputs) {\n if (out.name !== 'inputFocus' && out.name !== 'inputBlur') continue;\n const handler = (out.handler as unknown as { source?: string }).source ?? '';\n if (handler.includes('$event')) {\n context.logger.info(\n `${path} - eui-autocomplete (${out.name}) now emits a FocusEvent instead of void; check that the handler accepts a FocusEvent.`,\n );\n }\n }\n });\n}\n\n// ---------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------\n\nfunction typeKind(type: ts.TypeNode | undefined): Kind | undefined {\n if (!type) return undefined;\n if (ts.isParenthesizedTypeNode(type)) return typeKind(type.type);\n if (ts.isUnionTypeNode(type)) {\n for (const t of type.types) {\n const k = typeKind(t);\n if (k) return k;\n }\n return undefined;\n }\n if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName)) return KIND_BY_TYPE[type.typeName.text];\n return undefined;\n}\n\nfunction callKind(expr: ts.Expression | undefined): Kind | undefined {\n if (!expr || !ts.isCallExpression(expr)) return undefined;\n const callee = expr.expression;\n const isFactory =\n (ts.isIdentifier(callee) && (callee.text === 'inject' || callee.text === 'viewChild')) ||\n (ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text === 'viewChild' &&\n callee.name.text === 'required');\n const arg = expr.arguments[0];\n if (isFactory && arg && ts.isIdentifier(arg)) return KIND_BY_TYPE[arg.text];\n return undefined;\n}\n\nfunction isSignalQuery(expr: ts.Expression | undefined): boolean {\n if (!expr || !ts.isCallExpression(expr)) return false;\n const c = expr.expression;\n return (\n (ts.isIdentifier(c) && c.text === 'viewChild') ||\n (ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === 'viewChild')\n );\n}\n\nfunction decoratorsOf(node: ts.Node): readonly ts.Decorator[] {\n return ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? []) : [];\n}\n\nfunction extractInlineAndLinkedTemplates(sf: ts.SourceFile, path: string, tree: Tree): string[] {\n const templates: string[] = [];\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {\n const init = node.initializer;\n if (node.name.text === 'template' && (ts.isStringLiteralLike(init) || ts.isNoSubstitutionTemplateLiteral(init))) {\n templates.push(init.text);\n } else if (node.name.text === 'templateUrl' && ts.isStringLiteralLike(init)) {\n const dir = path.slice(0, path.lastIndexOf('/'));\n const segments = `${dir}/${init.text}`.split('/');\n const resolved: string[] = [];\n for (const s of segments) {\n if (s === '..') resolved.pop();\n else if (s !== '.' && s !== '') resolved.push(s);\n }\n const buf = tree.read('/' + resolved.join('/'));\n if (buf) templates.push(buf.toString('utf-8'));\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n return templates;\n}\n\nfunction migrateTs(source: string, path: string, tree: Tree): { result: string; warnings: string[]; infos: string[] } {\n const warnings: string[] = [];\n const infos: string[] = [];\n const sf = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);\n const templates = extractInlineAndLinkedTemplates(sf, path, tree);\n const refs = autocompleteRefs(templates);\n templates.forEach((t) => logFocusEventInfo(t, path, { logger: { info: (m: string) => infos.push(m) } } as unknown as SchematicContext));\n\n // name -> kind, for `this.name`, bare `name` and `this.name()` (signal queries)\n const thisNames = new Map<string, Kind>();\n const bareNames = new Map<string, Kind>();\n const callNames = new Map<string, Kind>();\n\n const collect = (node: ts.Node): void => {\n if (ts.isPropertyDeclaration(node) && ts.isIdentifier(node.name)) {\n const name = node.name.text;\n let kind = typeKind(node.type) ?? callKind(node.initializer);\n for (const d of decoratorsOf(node)) {\n if (!ts.isCallExpression(d.expression) || !ts.isIdentifier(d.expression.expression)) continue;\n if (d.expression.expression.text !== 'ViewChild') continue;\n const arg = d.expression.arguments[0];\n if (arg && ts.isIdentifier(arg) && KIND_BY_TYPE[arg.text]) kind ??= KIND_BY_TYPE[arg.text];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) kind ??= 'ac';\n }\n const init = node.initializer;\n if (!kind && init && isSignalQuery(init) && ts.isCallExpression(init)) {\n const arg = init.arguments[0];\n if (arg && ts.isStringLiteralLike(arg) && refs.has(arg.text)) {\n callNames.set(name, 'ac');\n return;\n }\n }\n if (kind) {\n if (init && isSignalQuery(init)) callNames.set(name, kind);\n else thisNames.set(name, kind);\n }\n } else if (ts.isParameter(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type);\n if (kind) {\n bareNames.set(node.name.text, kind);\n if (ts.isConstructorDeclaration(node.parent) && ts.getModifiers(node)?.length) thisNames.set(node.name.text, kind);\n }\n } else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {\n const kind = typeKind(node.type) ?? callKind(node.initializer);\n if (kind) bareNames.set(node.name.text, kind);\n }\n ts.forEachChild(node, collect);\n };\n collect(sf);\n\n if (!thisNames.size && !bareNames.size && !callNames.size) return { result: source, warnings, infos };\n\n /** Nearest enclosing parameter/variable declaration decides the kind, so a shadowing param of another type is ignored. */\n const resolveBare = (id: ts.Identifier): Kind | undefined => {\n for (let n: ts.Node | undefined = id.parent; n; n = n.parent) {\n const decls: (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(n)) decls.push(...n.parameters);\n if (ts.isBlock(n) || ts.isSourceFile(n)) {\n n.statements.forEach((st) => ts.isVariableStatement(st) && decls.push(...st.declarationList.declarations));\n }\n for (const d of decls) {\n if (ts.isIdentifier(d.name) && d.name.text === id.text) return typeKind(d.type) ?? callKind(d.initializer);\n }\n }\n return bareNames.get(id.text);\n };\n\n const kindOf = (expr: ts.Expression): Kind | undefined => {\n let e = expr;\n while (ts.isNonNullExpression(e) || ts.isParenthesizedExpression(e)) e = e.expression;\n if (ts.isIdentifier(e)) return resolveBare(e);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) return thisNames.get(e.name.text);\n if (\n ts.isCallExpression(e) &&\n e.arguments.length === 0 &&\n ts.isPropertyAccessExpression(e.expression) &&\n e.expression.expression.kind === ts.SyntaxKind.ThisKeyword\n ) {\n return callNames.get(e.expression.name.text);\n }\n return undefined;\n };\n\n const edits: Edit[] = [];\n const where = (n: ts.Node): string => `${path}:${sf.getLineAndCharacterOfPosition(n.getStart()).line + 1}`;\n const warn = (n: ts.Node, msg: string): void => {\n warnings.push(`${where(n)} - Manual action needed: ${msg}`);\n };\n const isStatementLike = (n: ts.Node): boolean =>\n ts.isExpressionStatement(n.parent) || (ts.isArrowFunction(n.parent) && n.parent.body === n);\n const fresh = (name: string, text: string): string => (new RegExp(`\\\\b${name}\\\\b`).test(text) ? `${name}x` : name);\n const simple = (e: ts.Expression): boolean =>\n ts.isNumericLiteral(e) || ts.isIdentifier(e) || ts.isPropertyAccessExpression(e) || ts.isStringLiteral(e) || ts.isParenthesizedExpression(e);\n\n let needsOutputImport = false;\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const kind = kindOf(node.expression);\n if (kind) {\n if (kind === 'ac' && AC_OUTPUTS.has(node.name.text) && isObservableUse(node)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'outputToObservable(' });\n edits.push({ start: node.end, end: node.end, text: ')' });\n needsOutputImport = true;\n noteFocusEvent(node);\n } else {\n handle(node, node.name.text, kind);\n }\n }\n } else if (ts.isVariableDeclaration(node) && node.initializer && kindOf(node.initializer)) {\n const kind = kindOf(node.initializer)!;\n if (ts.isIdentifier(node.name)) {\n warn(node, `\"${node.name.text}\" is an alias of an eUI autocomplete reference; member usages through the alias are not migrated. Check \"${node.name.text}\" manually (chips, selectedOptionIndex, isDisabled, itemSize, autocompleteDataSelected are signals now).`);\n } else if (ts.isObjectBindingPattern(node.name)) {\n const migrated = node.name.elements\n .map((el) => (el.propertyName ?? el.name).getText())\n .filter((m) => WRITABLE[kind].has(m) || READONLY[kind].has(m) || (kind === 'ac' && m === 'autocompleteDataSelected'));\n if (migrated.length) {\n warn(node, `destructuring of ${migrated.join(', ')} from an eUI autocomplete reference now yields a signal, not a value; read it with \"()\" (or use the property access).`);\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n const noteFocusEvent = (pa: ts.PropertyAccessExpression): void => {\n const member = pa.name.text;\n if (member !== 'inputFocus' && member !== 'inputBlur') return;\n const sub = pa.parent;\n const call = ts.isPropertyAccessExpression(sub) && sub.name.text === 'subscribe' ? sub.parent : undefined;\n const handler = call && ts.isCallExpression(call) ? call.arguments[0] : undefined;\n if (handler && (ts.isArrowFunction(handler) || ts.isFunctionExpression(handler)) && handler.parameters.length === 0) {\n infos.push(`${where(pa)} - eui-autocomplete (${member}) now emits a FocusEvent instead of void; check that this subscribe handler accepts a FocusEvent.`);\n }\n };\n\n const handle = (pa: ts.PropertyAccessExpression, member: string, kind: Kind): void => {\n const parent = pa.parent;\n const isWritable = WRITABLE[kind].has(member);\n const isReadonly = READONLY[kind].has(member);\n const isDataSelected = kind === 'ac' && member === 'autocompleteDataSelected';\n if (!isWritable && !isReadonly && !isDataSelected) return;\n\n // already migrated: `x.member()` or `x.member.set/update/asReadonly`\n if (ts.isCallExpression(parent) && parent.expression === pa) return;\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && SIGNAL_API.has(parent.name.text)) return;\n\n const isAssignTarget =\n ts.isBinaryExpression(parent) &&\n parent.left === pa &&\n parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n\n if (isDataSelected) {\n const mutating =\n ts.isPropertyAccessExpression(parent) &&\n parent.expression === pa &&\n ts.isCallExpression(parent.parent) &&\n parent.parent.expression === parent &&\n (parent.name.text === 'push' || ARRAY_MUTATORS.has(parent.name.text));\n const written = (n: ts.Node): boolean =>\n ts.isBinaryExpression(n.parent) &&\n n.parent.left === n &&\n n.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n n.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n const memberWritten =\n (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === pa && written(parent);\n if (isAssignTarget || mutating || memberWritten) {\n warn(pa, '\"autocompleteDataSelected\" is now a read-only signal input and cannot be assigned or mutated programmatically. Bind [autocompleteDataSelected] in the template instead.');\n return;\n }\n // plain read: falls through to the `()` rewrite below\n }\n\n if (isAssignTarget && !isDataSelected) {\n const bin = parent as ts.BinaryExpression;\n const op = bin.operatorToken.kind;\n if (!isStatementLike(bin)) {\n warn(pa, `\"${member}\" is now a signal; assignment is used as a value and could not be rewritten automatically.`);\n return;\n }\n if (isReadonly) {\n warn(pa, `\"${member}\" is now a read-only signal and cannot be assigned.`);\n return;\n }\n if (op === ts.SyntaxKind.EqualsToken) {\n edits.push({ start: pa.end, end: bin.right.getStart(), text: '.set(' });\n edits.push({ start: bin.right.end, end: bin.right.end, text: ')' });\n } else if (COMPOUND_OPS.has(op)) {\n const sym = ts.tokenToString(op)!.slice(0, -1);\n const rightText = bin.right.getText();\n const v = fresh('v', rightText);\n const wrapRight = !simple(bin.right);\n edits.push({ start: pa.end, end: bin.right.getStart(), text: `.update(${v} => ${v} ${sym} ${wrapRight ? '(' : ''}` });\n edits.push({ start: bin.right.end, end: bin.right.end, text: `${wrapRight ? ')' : ''})` });\n } else {\n warn(pa, `\"${member}\" is now a signal; unsupported assignment operator.`);\n }\n return;\n }\n\n if ((ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {\n if (!isStatementLike(parent) || isReadonly) {\n warn(pa, `\"${member}\" is now a signal; ++/-- cannot be rewritten automatically here. Use ${member}.update(...).`);\n return;\n }\n const sym = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';\n if (ts.isPrefixUnaryExpression(parent)) edits.push({ start: parent.getStart(), end: pa.getStart(), text: '' });\n edits.push({ start: pa.end, end: parent.end, text: `.update(v => v ${sym} 1)` });\n return;\n }\n\n if (ts.isPropertyAccessExpression(parent) && parent.expression === pa && member === 'chips') {\n const call = parent.parent;\n const method = parent.name.text;\n if (ts.isCallExpression(call) && call.expression === parent) {\n if (method === 'push') {\n if (!call.arguments.length) return;\n if (!isStatementLike(call)) {\n warn(pa, '\"chips\" is now a signal; the return value of push() is used, rewrite with chips.update(...) manually.');\n return;\n }\n const argsText = call.arguments.map((a) => a.getText()).join(',');\n const c = fresh('c', argsText);\n const first = call.arguments[0];\n const last = call.arguments[call.arguments.length - 1];\n edits.push({ start: pa.end, end: first.getStart(), text: `.update(${c} => [...${c}, ` });\n edits.push({ start: last.end, end: call.end, text: '])' });\n return;\n }\n if (ARRAY_MUTATORS.has(method)) {\n warn(pa, `\"chips\" is now a WritableSignal; \"${method}()\" mutates the array in place. Rewrite with chips.update(...) / chips.set(...).`);\n return;\n }\n }\n }\n\n // plain read\n edits.push({ start: pa.end, end: pa.end, text: '()' });\n };\n\n visit(sf);\n\n if (needsOutputImport) {\n const imp = outputImportEdit(sf, source);\n if (imp) edits.push(imp);\n }\n\n const result = [...edits]\n .sort((a, b) => b.start - a.start || b.end - a.end)\n .reduce((acc, e) => acc.slice(0, e.start) + e.text + acc.slice(e.end), source);\n return { result, warnings, infos };\n}\n\n/**\n * True when `node` (an output reference) is used as an Observable: receiver of subscribe/pipe/...,\n * or an argument (directly or inside an array literal) of another call such as merge(...).\n * Already wrapped (`outputToObservable(x.out)`) is not matched.\n */\nfunction isObservableUse(node: ts.PropertyAccessExpression): boolean {\n const p = node.parent;\n if (ts.isPropertyAccessExpression(p) && p.expression === node) {\n return OBSERVABLE_METHODS.has(p.name.text) && ts.isCallExpression(p.parent) && p.parent.expression === p;\n }\n const arg: ts.Node = ts.isArrayLiteralExpression(p) ? p : node;\n const call = arg.parent;\n if (ts.isCallExpression(call) && (call.arguments as readonly ts.Node[]).includes(arg)) {\n const callee = call.expression;\n return !(ts.isIdentifier(callee) && callee.text === 'outputToObservable');\n }\n return false;\n}\n\n/** Adds `outputToObservable` to the rxjs-interop import, or creates the import after the last one. */\nfunction outputImportEdit(sf: ts.SourceFile, source: string): Edit | null {\n const imports = sf.statements.filter(ts.isImportDeclaration);\n const existing = imports.find((i) => (i.moduleSpecifier as ts.StringLiteral).text === SIGNAL_INTEROP);\n const bindings = existing?.importClause?.namedBindings;\n if (existing && bindings && ts.isNamedImports(bindings)) {\n if (bindings.elements.some((e) => e.name.text === 'outputToObservable')) return null;\n const last = bindings.elements[bindings.elements.length - 1];\n if (!last) return { start: bindings.getStart(), end: bindings.getEnd(), text: '{ outputToObservable }' };\n return { start: last.getEnd(), end: last.getEnd(), text: ', outputToObservable' };\n }\n const line = `import { outputToObservable } from '${SIGNAL_INTEROP}';`;\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lastImport = imports[imports.length - 1];\n if (lastImport) return { start: lastImport.getEnd(), end: lastImport.getEnd(), text: `${eol}${line}` };\n return { start: 0, end: 0, text: `${line}${eol}` };\n}\n",
|
|
5061
|
+
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstTextAttribute } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement, getTemplateChildren } from '../utils/template-walk';\n\nconst CHIP_LIST_TAG = 'eui-chip-list';\nconst CHIP_LIST_ATTR = 'euiChipList';\nconst CHIP_TAG = 'eui-chip';\nconst CHIP_ATTR = 'euiChip';\n\nconst PROPAGATED_INPUTS = new Set([\n 'euiPrimary', 'euiSecondary', 'euiSuccess', 'euiInfo', 'euiWarning',\n 'euiDanger', 'euiAccent', 'euiVariant', 'euiSizeS', 'euiSizeVariant',\n 'euiOutline', 'euiDisabled',\n]);\n\nconst WARN_PROPERTIES = new Set([...PROPAGATED_INPUTS, 'chipRemove', 'isChipsRemovable', 'chipsLabelTruncateCount',\n 'maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel',\n 'isChipsSorted', 'chipsSortOrder']);\n\nconst REMOVED_INPUTS = new Set(['maxVisibleChipsCount', 'isMaxVisibleChipsOpened', 'toggleLinkMoreLabel', 'toggleLinkLessLabel', 'isChipsSorted', 'chipsSortOrder']);\n\nconst TRUNCATE_PIPE_IMPORT = 'EuiTruncatePipe';\nconst TRUNCATE_PIPE_PATH = '@eui/components/pipes';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nexport function migrateEuiChipList(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n const filesNeedingTruncateImport = new Set<string>();\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(CHIP_LIST_TAG) && !original.includes(CHIP_LIST_ATTR)) return;\n\n let result: string;\n let addedTruncate = false;\n\n if (path.endsWith('.html')) {\n result = migrateTemplate(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n // Find the associated .ts file\n const tsPath = path.replace(/\\.html$/, '.ts');\n if (tree.exists(tsPath)) {\n filesNeedingTruncateImport.add(tsPath);\n } else {\n // Try component naming convention\n const componentTsPath = path.replace(/\\.html$/, '.component.ts');\n if (tree.exists(componentTsPath)) {\n filesNeedingTruncateImport.add(componentTsPath);\n }\n }\n }\n } else {\n result = migrateInlineTemplates(original);\n if (result !== original && result.includes('euiTruncate') && !original.includes('euiTruncate')) {\n addedTruncate = true;\n }\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would move variant/size/outline inputs to child eui-chip in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n if (addedTruncate) {\n filesNeedingTruncateImport.add(path);\n }\n\n // Warn about TS usages of removed properties\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {\n if ([...WARN_PROPERTIES].some((p) => original.includes(p))) {\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && WARN_PROPERTIES.has(node.name.text)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(\n `${path}:${line + 1} - \"${node.name.text}\" has been removed from eui-chip-list. Move it to individual eui-chip elements.`,\n );\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n }\n });\n\n // Add EuiTruncatePipe import to component files that need it\n for (const tsPath of filesNeedingTruncateImport) {\n const buffer = tree.read(tsPath);\n if (!buffer) continue;\n const source = buffer.toString('utf-8');\n if (source.includes(TRUNCATE_PIPE_IMPORT)) continue;\n const result = addTruncatePipeImport(source, tsPath);\n if (result !== source) {\n if (!options.dryRun) {\n tree.overwrite(tsPath, result);\n }\n }\n }\n\n context.logger.info(`Migrated eui-chip-list inputs/outputs to child eui-chip in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction addTruncatePipeImport(source: string, filePath: string): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const edits: Edit[] = [];\n\n // 1. Add ES import statement for EuiTruncatePipe\n let hasEsImport = false;\n let lastImportEnd = 0;\n\n for (const stmt of sourceFile.statements) {\n if (ts.isImportDeclaration(stmt)) {\n lastImportEnd = stmt.getEnd();\n const moduleSpec = (stmt.moduleSpecifier as ts.StringLiteral).text;\n if (moduleSpec === TRUNCATE_PIPE_PATH) {\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n if (namedBindings.elements.some((el) => el.name.text === TRUNCATE_PIPE_IMPORT)) {\n hasEsImport = true;\n } else {\n // Add to existing import from same path\n const lastEl = namedBindings.elements[namedBindings.elements.length - 1];\n edits.push({ start: lastEl.getEnd(), end: lastEl.getEnd(), replacement: `, ${TRUNCATE_PIPE_IMPORT}` });\n hasEsImport = true;\n }\n }\n }\n }\n }\n\n if (!hasEsImport) {\n const importStatement = `\\nimport { ${TRUNCATE_PIPE_IMPORT} } from '${TRUNCATE_PIPE_PATH}';`;\n edits.push({ start: lastImportEnd, end: lastImportEnd, replacement: importStatement });\n }\n\n // 2. Add EuiTruncatePipe to @Component imports array\n const visit = (node: ts.Node): void => {\n if (ts.isClassDeclaration(node)) {\n const decs = ts.getDecorators(node);\n if (!decs) return;\n for (const dec of decs) {\n if (!ts.isCallExpression(dec.expression) || !ts.isIdentifier(dec.expression.expression) || dec.expression.expression.text !== 'Component') continue;\n const metadata = dec.expression.arguments[0];\n if (!ts.isObjectLiteralExpression(metadata)) continue;\n for (const prop of metadata.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name) || prop.name.text !== 'imports') continue;\n if (!ts.isArrayLiteralExpression(prop.initializer)) continue;\n const arr = prop.initializer;\n const arrText = source.slice(arr.getStart(sourceFile), arr.getEnd());\n if (arrText.includes(TRUNCATE_PIPE_IMPORT)) continue;\n if (arr.elements.length > 0) {\n const lastElement = arr.elements[arr.elements.length - 1];\n edits.push({ start: lastElement.getEnd(), end: lastElement.getEnd(), replacement: `,\\n ${TRUNCATE_PIPE_IMPORT}` });\n } else {\n edits.push({ start: arr.getStart(sourceFile) + 1, end: arr.getEnd() - 1, replacement: TRUNCATE_PIPE_IMPORT });\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: Edit[] = [];\n\n visitNodes(parsed.nodes, source, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: Edit[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(CHIP_LIST_TAG) && !rawTemplate.includes(CHIP_LIST_ATTR)) {\n ts.forEachChild(node, visit);\n return;\n }\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n return applyEdits(source, changes);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, edits: Edit[]): void {\n forEachElement(nodes, (node) => {\n if (isChipListElement(node)) migrateChipListElement(node, source, edits);\n });\n}\n\nfunction isChipListElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_LIST_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_LIST_ATTR);\n}\n\nfunction isChipElement(element: TmplAstElement): boolean {\n if (element.name === CHIP_TAG) return true;\n return element.attributes.some((a) => a.name === CHIP_ATTR);\n}\n\nfunction findChildChips(nodes: TmplAstNode[]): TmplAstElement[] {\n const chips: TmplAstElement[] = [];\n for (const node of nodes) {\n if (node instanceof TmplAstElement && isChipElement(node)) {\n chips.push(node);\n } else {\n chips.push(...findChildChips(getTemplateChildren(node)));\n }\n }\n return chips;\n}\n\nfunction migrateChipListElement(element: TmplAstElement, source: string, edits: Edit[]): void {\n const childChips = findChildChips(element.children);\n const insertions: string[] = [];\n let truncateValue: string | null = null;\n\n // Collect and remove propagated static attributes\n for (const attr of element.attributes) {\n if (PROPAGATED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n insertions.push(attr.value ? `${attr.name}=\"${attr.value}\"` : attr.name);\n }\n if (attr.name === 'isChipsRemovable') {\n edits.push(removalEdit(attr, source));\n insertions.push('isChipRemovable');\n }\n if (attr.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(attr, source));\n truncateValue = attr.value || null;\n }\n if (REMOVED_INPUTS.has(attr.name)) {\n edits.push(removalEdit(attr, source));\n }\n }\n\n // Collect and remove propagated bound inputs\n for (const input of element.inputs) {\n if (PROPAGATED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n insertions.push(raw);\n }\n if (input.name === 'isChipsRemovable') {\n edits.push(removalEdit(input, source));\n const valueText = extractBindingValue(input, source);\n insertions.push(`[isChipRemovable]=\"${valueText}\"`);\n }\n if (input.name === 'chipsLabelTruncateCount') {\n edits.push(removalEdit(input, source));\n truncateValue = extractBindingValue(input, source);\n }\n if (REMOVED_INPUTS.has(input.name)) {\n edits.push(removalEdit(input, source));\n }\n }\n\n // Collect and remove (chipRemove) output\n let chipRemoveHandler: string | null = null;\n for (const output of element.outputs) {\n if (output.name === 'chipRemove') {\n edits.push(removalEdit(output, source));\n chipRemoveHandler = extractHandlerExpression(output, source);\n }\n }\n\n if (chipRemoveHandler) {\n insertions.push(`(remove)=\"${chipRemoveHandler}\"`);\n }\n\n // Add collected attributes to each child eui-chip\n if (insertions.length > 0) {\n for (const chip of childChips) {\n const existingNames = getExistingAttrNames(chip);\n const toInsert = insertions.filter((ins) => {\n const name = extractAttrName(ins);\n return !existingNames.has(name);\n });\n if (toInsert.length > 0) {\n const insertPos = chip.startSourceSpan.end.offset - 1;\n edits.push({ start: insertPos, end: insertPos, replacement: ' ' + toInsert.join(' ') });\n }\n }\n }\n\n // Add euiTruncate pipe to chip label content\n if (truncateValue) {\n for (const chip of childChips) {\n const labelEdit = buildTruncatePipeEdit(chip, source, truncateValue);\n if (labelEdit) edits.push(labelEdit);\n }\n }\n}\n\nfunction buildTruncatePipeEdit(chip: TmplAstElement, source: string, truncateValue: string): Edit | null {\n // Find <span euiLabel>...</span> inside the chip\n const labelEl = findLabelElement(chip.children);\n if (labelEl !== null && labelEl !== undefined && labelEl.endSourceSpan) {\n const contentStart = labelEl.startSourceSpan.end.offset;\n const contentEnd = labelEl.endSourceSpan.start.offset;\n const content = source.slice(contentStart, contentEnd);\n if (content && !content.includes('euiTruncate')) {\n const trimmed = content.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch) {\n return { start: contentStart, end: contentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n return { start: contentStart, end: contentEnd, replacement: `{{ '${trimmed}' | euiTruncate: ${truncateValue} }}` };\n }\n }\n\n // Check direct text content inside chip (no label element)\n if (chip.endSourceSpan) {\n const chipContentStart = chip.startSourceSpan.end.offset;\n const chipContentEnd = chip.endSourceSpan.start.offset;\n const chipContent = source.slice(chipContentStart, chipContentEnd);\n const trimmed = chipContent.trim();\n const interpMatch = trimmed.match(/^\\{\\{\\s*(.+?)\\s*\\}\\}$/);\n if (interpMatch && !chipContent.includes('euiTruncate')) {\n return { start: chipContentStart, end: chipContentEnd, replacement: `{{ ${interpMatch[1]} | euiTruncate: ${truncateValue} }}` };\n }\n }\n return null;\n}\n\nfunction findLabelElement(nodes: TmplAstNode[]): TmplAstElement | null {\n for (const node of nodes) {\n if (node instanceof TmplAstElement && node.attributes.some((a) => a.name === 'euiLabel')) return node;\n const nested = findLabelElement(getTemplateChildren(node));\n if (nested) return nested;\n }\n return null;\n}\n\nfunction getExistingAttrNames(element: TmplAstElement): Set<string> {\n const names = new Set<string>();\n for (const attr of element.attributes) names.add(attr.name);\n for (const input of element.inputs) names.add(input.name);\n for (const output of element.outputs) names.add(output.name);\n return names;\n}\n\nfunction extractAttrName(insertion: string): string {\n const outputMatch = insertion.match(/^\\(([^)]+)\\)/);\n if (outputMatch) return outputMatch[1];\n const inputMatch = insertion.match(/^\\[([^\\]]+)\\]/);\n if (inputMatch) return inputMatch[1];\n return insertion.split('=')[0];\n}\n\nfunction removalEdit(node: TmplAstTextAttribute | TmplAstBoundAttribute | TmplAstBoundEvent, source: string): Edit {\n let start = node.sourceSpan.start.offset;\n while (start > 0 && (source[start - 1] === ' ' || source[start - 1] === '\\t')) {\n start--;\n }\n return { start, end: node.sourceSpan.end.offset, replacement: '' };\n}\n\nfunction extractBindingValue(input: TmplAstBoundAttribute, source: string): string {\n const raw = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : 'true';\n}\n\nfunction extractHandlerExpression(output: TmplAstBoundEvent, source: string): string {\n const raw = source.slice(output.sourceSpan.start.offset, output.sourceSpan.end.offset);\n const match = raw.match(/=[\"']([^\"']*)[\"']/);\n return match ? match[1] : '';\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n seen.set(`${edit.start}:${edit.end}`, edit);\n }\n return Array.from(seen.values());\n}\n",
|
|
5062
5062
|
"displayName": "Schema",
|
|
5063
5063
|
"properties": [
|
|
5064
5064
|
{
|
|
@@ -5070,7 +5070,7 @@
|
|
|
5070
5070
|
"indexKey": "",
|
|
5071
5071
|
"optional": true,
|
|
5072
5072
|
"description": "",
|
|
5073
|
-
"line":
|
|
5073
|
+
"line": 29,
|
|
5074
5074
|
"rawdescription": "\n"
|
|
5075
5075
|
},
|
|
5076
5076
|
{
|
|
@@ -5082,7 +5082,7 @@
|
|
|
5082
5082
|
"indexKey": "",
|
|
5083
5083
|
"optional": true,
|
|
5084
5084
|
"description": "",
|
|
5085
|
-
"line":
|
|
5085
|
+
"line": 28,
|
|
5086
5086
|
"rawdescription": "\n"
|
|
5087
5087
|
}
|
|
5088
5088
|
],
|
|
@@ -5206,12 +5206,12 @@
|
|
|
5206
5206
|
},
|
|
5207
5207
|
{
|
|
5208
5208
|
"name": "Schema",
|
|
5209
|
-
"id": "interface-Schema-
|
|
5210
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
5209
|
+
"id": "interface-Schema-4486b2ff645679826ae9eb409e089e7ca0390f03b2f6a831ab9cf027339caa7615e2946de8d5f61764ad21209c46bf3be643b9006715ab37995097b47e45f29d-26",
|
|
5210
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
5211
5211
|
"deprecated": false,
|
|
5212
5212
|
"deprecationMessage": "",
|
|
5213
5213
|
"type": "interface",
|
|
5214
|
-
"sourceCode": "import { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { TODO_PREFIX } from '../utils/todo-comment';\n\n/**\n * eUI v21 -> v22 migration for eui-dialog.\n *\n * - EuiDialogComponent.isOpen$ (BehaviorSubject) -> `isOpen` getter\n * - acceptButtonDisabled$ / dismissButtonDisabled$ -> WritableSignal (`.value` -> `()`, `.next(v)` -> `.set(v)`)\n * - EuiDialogService.getOpenedDialog() Observable -> Signal -> `toObservable(...)` where an injection context is certain\n * - EuiDialogComponent outputs used as Observables (`.subscribe/.pipe`, or passed to merge(...)) -> `outputToObservable(...)`\n * - EuiDialogContainerComponent `cd` / `onScroll()` removed -> TODO + warning\n *\n * Anything that cannot be rewritten without changing behavior is left untouched and flagged with a\n * `// TODO: [eUI v22 migration] ...` comment and a logger warning.\n *\n * shortcut: receivers are matched by member/variable NAME within one file (declared type, ViewChild\n * argument or inject()/viewChild() argument), not via the type checker; a same-named variable of another\n * type in the same file would be mis-identified. Upgrade to a ts.Program if that shows up.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\nconst BUTTON_PROPS = new Set(['acceptButtonDisabled$', 'dismissButtonDisabled$']);\nconst SIGNAL_INTEROP = '@angular/core/rxjs-interop';\nconst QUICK_CHECK = /isOpen\\$|ButtonDisabled\\$|getOpenedDialog|onScroll|EuiDialogContainerComponent|EuiDialogComponent/;\n/** EuiDialogComponent outputs (EventEmitter -> OutputEmitterRef): no `.pipe`/`.subscribe` anymore. */\nconst DIALOG_OUTPUTS = new Set(['accept', 'clickOutside', 'dialogClose', 'dialogOpen', 'dismiss', 'escape']);\nconst OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);\n\nexport function migrateEuiDialog(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n const original = buffer.toString('utf-8');\n if (!QUICK_CHECK.test(original)) return;\n\n const warn = (line: number, msg: string): void => context.logger.warn(`${path}:${line} - ${msg}`);\n const result = path.endsWith('.html')\n ? migrateTemplateText(original, original, (m) => warn(1, m))\n : migrateTs(path, original, warn);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-dialog usages in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n });\n\n context.logger.info(`Migrated eui-dialog API usages in ${count} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------\n\nconst REF = String.raw`[A-Za-z_$][\\w$]*(?:\\??\\.[A-Za-z_$][\\w$]*)*`;\n\n/** `context` is the full file text, used to decide whether the file deals with eui-dialog at all. */\nfunction migrateTemplateText(text: string, context: string, warn: (msg: string) => void): string {\n const hasDialog = /<eui-dialog\\b|euiDialog/.test(context);\n let out = text;\n\n if (hasDialog) {\n out = out\n .replace(new RegExp(String.raw`(${REF})\\.isOpen\\$\\s*\\|\\s*async\\b`, 'g'), '$1.isOpen')\n .replace(new RegExp(String.raw`(${REF})\\.isOpen\\$\\??\\.(?:value\\b|getValue\\(\\))`, 'g'), '$1.isOpen');\n }\n out = out\n .replace(new RegExp(String.raw`(${REF})\\.((?:accept|dismiss)ButtonDisabled\\$)\\s*\\|\\s*async\\b`, 'g'), '$1.$2()')\n .replace(new RegExp(String.raw`(${REF})\\.((?:accept|dismiss)ButtonDisabled\\$)\\??\\.(?:value\\b|getValue\\(\\))`, 'g'), '$1.$2()')\n .replace(new RegExp(String.raw`(${REF})\\.getOpenedDialog\\(\\)\\s*\\|\\s*async\\b`, 'g'), '$1.getOpenedDialog()()');\n\n const leftovers: string[] = [];\n if (hasDialog && /\\.isOpen\\$/.test(out)) leftovers.push('isOpen$');\n if (/ButtonDisabled\\$(?!\\(\\))/.test(out)) leftovers.push('acceptButtonDisabled$/dismissButtonDisabled$');\n if (/getOpenedDialog\\(\\)(?!\\s*\\()/.test(out)) leftovers.push('getOpenedDialog()');\n for (const l of leftovers) {\n warn(`Manual action needed: template still uses the removed Observable API \"${l}\". Read the signal/getter instead (see eUI 21 to 22 migration guide, eui-dialog).`);\n }\n return out;\n}\n\nfunction migrateInlineTemplates(source: string, warn: (msg: string) => void): string {\n return source.replace(/template\\s*:\\s*`([^`]*)`/gs, (match, content: string) => {\n const migrated = migrateTemplateText(content, content, warn);\n return migrated === content ? match : match.replace(content, () => migrated);\n });\n}\n\n// ---------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------\n\ntype Kind = 'dialog' | 'container' | 'service';\n\nfunction classify(text: string): Kind | null {\n if (/\\bEuiDialogContainerComponent\\b/.test(text)) return 'container';\n if (/\\bEuiDialogComponent\\b/.test(text)) return 'dialog';\n if (/\\bEuiDialogService\\b/.test(text)) return 'service';\n return null;\n}\n\nfunction migrateTs(path: string, original: string, warn: (line: number, msg: string) => void): string {\n const sf = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n const names: Record<Kind, Set<string>> = { dialog: new Set(), container: new Set(), service: new Set() };\n\n collectNames(sf, names);\n\n const edits: Edit[] = [];\n const todoStatements = new Set<number>();\n let needsToObservable = false;\n let needsOutputToObservable = false;\n\n const lineOf = (n: ts.Node): number => sf.getLineAndCharacterOfPosition(n.getStart()).line + 1;\n\n const todo = (node: ts.Node, msg: string): void => {\n warn(lineOf(node), `Manual action needed: ${msg}`);\n const stmt = enclosingStatement(node);\n const start = stmt.getStart();\n if (todoStatements.has(start)) return;\n todoStatements.add(start);\n const lineStart = original.lastIndexOf('\\n', start - 1) + 1;\n const indent = original.slice(lineStart, start).match(/^\\s*/)![0];\n const comment = `// ${TODO_PREFIX} ${msg}`;\n // idempotency: skip when the same comment already precedes the statement\n if (original.slice(0, lineStart).trimEnd().endsWith(comment)) return;\n const eol = original.includes('\\r\\n') ? '\\r\\n' : '\\n';\n edits.push({ start: lineStart, end: lineStart, text: `${indent}${comment}${eol}` });\n };\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const prop = node.name.text;\n const recv = receiverKey(node.expression);\n const isDialogLike = recv !== null && (names.dialog.has(recv) || names.container.has(recv));\n const isOpen = prop === 'isOpen$';\n\n if (isDialogLike && (isOpen || BUTTON_PROPS.has(prop))) {\n if (handleSubject(node, prop, isOpen, edits, todo)) return;\n } else if (recv !== null && names.dialog.has(recv) && DIALOG_OUTPUTS.has(prop) && isObservableUse(node) && !isShadowed(node.expression, names)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'outputToObservable(' });\n edits.push({ start: node.getEnd(), end: node.getEnd(), text: ')' });\n needsOutputToObservable = true;\n } else if (recv !== null && names.container.has(recv) && (prop === 'cd' || prop === 'onScroll')) {\n todo(node, `\"${prop}\" was removed from EuiDialogContainerComponent; change detection and scroll handling are internal now. Remove this usage.`);\n }\n } else if (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n node.expression.name.text === 'getOpenedDialog'\n ) {\n const recv = receiverKey(node.expression.expression);\n if (recv !== null && names.service.has(recv) && !isAlreadyMigrated(node)) {\n if (inInjectionContext(node)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'toObservable(' });\n edits.push({ start: node.getEnd(), end: node.getEnd(), text: ')' });\n needsToObservable = true;\n } else {\n todo(\n node,\n 'EuiDialogService.getOpenedDialog() now returns a Signal. Read it as getOpenedDialog()() inside computed/effect, or wrap it with toObservable() from @angular/core/rxjs-interop in an injection context.',\n );\n }\n // do not return: nested getOpenedDialog() calls cannot exist inside the receiver\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n\n if (needsToObservable || needsOutputToObservable) {\n const imp = importEdit(sf, original, [\n ...(needsToObservable ? ['toObservable'] : []),\n ...(needsOutputToObservable ? ['outputToObservable'] : []),\n ]);\n if (imp) edits.push(imp);\n }\n\n let result = original;\n // Apply from the end; for equal positions keep insertion order stable by iterating in reverse.\n const ordered = edits.map((e, i) => ({ e, i })).sort((a, b) => b.e.start - a.e.start || b.i - a.i);\n for (const { e } of ordered) {\n result = result.slice(0, e.start) + e.text + result.slice(e.end);\n }\n\n if (result.includes('template')) {\n result = migrateInlineTemplates(result, (m) => warn(1, m));\n }\n return result;\n}\n\n/** Returns true when the node was fully handled and its children must not be visited. */\nfunction handleSubject(\n node: ts.PropertyAccessExpression,\n prop: string,\n isOpen: boolean,\n edits: Edit[],\n todo: (n: ts.Node, msg: string) => void,\n): boolean {\n const parent = node.parent;\n const nameStart = node.name.getStart();\n const replacement = isOpen ? 'isOpen' : `${prop}()`;\n\n // already migrated: `acceptButtonDisabled$()`\n if (!isOpen && ts.isCallExpression(parent) && parent.expression === node) return true;\n\n if (ts.isPropertyAccessExpression(parent) && parent.expression === node) {\n const member = parent.name.text;\n if (member === 'set' || member === 'update') return true; // already a signal write\n const call = ts.isCallExpression(parent.parent) && parent.parent.expression === parent ? parent.parent : null;\n\n if (member === 'value' && !isAssignmentTarget(parent)) {\n edits.push({ start: nameStart, end: parent.getEnd(), text: replacement });\n return true;\n }\n if (member === 'getValue' && call && call.arguments.length === 0) {\n edits.push({ start: nameStart, end: call.getEnd(), text: replacement });\n return true;\n }\n if (member === 'next' && call && !isOpen) {\n edits.push({ start: parent.name.getStart(), end: parent.name.getEnd(), text: 'set' });\n return false; // arguments may contain further migratable accesses\n }\n }\n\n if (isOpen) {\n todo(\n node,\n 'EuiDialogComponent.isOpen$ was removed. Read the isOpen getter (boolean) instead; it is not an Observable, so subscribe/pipe usages must be reworked manually (e.g. via computed/effect or the dialogOpen/dialogClose outputs).',\n );\n } else {\n todo(\n node,\n `${prop} is now a WritableSignal. Use ${prop}() to read and ${prop}.set(v) to write; use toObservable(${prop}) from @angular/core/rxjs-interop if an Observable is needed.`,\n );\n }\n return true;\n}\n\nfunction isAssignmentTarget(node: ts.Node): boolean {\n const p = node.parent;\n return ts.isBinaryExpression(p) && p.left === node && p.operatorToken.kind === ts.SyntaxKind.EqualsToken;\n}\n\nfunction isAlreadyMigrated(call: ts.CallExpression): boolean {\n const p = call.parent;\n if (ts.isCallExpression(p)) {\n if (p.expression === call) return true; // getOpenedDialog()()\n if (ts.isIdentifier(p.expression) && p.expression.text === 'toObservable') return true;\n }\n return false;\n}\n\nfunction inInjectionContext(node: ts.Node): boolean {\n for (let n: ts.Node | undefined = node.parent; n; n = n.parent) {\n if (ts.isConstructorDeclaration(n)) return true;\n if (ts.isPropertyDeclaration(n)) return !n.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword);\n if (ts.isFunctionLike(n) || ts.isClassDeclaration(n) || ts.isClassExpression(n)) return false;\n }\n return false;\n}\n\nfunction enclosingStatement(node: ts.Node): ts.Node {\n let n: ts.Node = node;\n while (n.parent) {\n const p = n.parent;\n if (\n ts.isBlock(p) ||\n ts.isSourceFile(p) ||\n ts.isClassLike(p) ||\n ts.isModuleBlock(p) ||\n ts.isCaseClause(p) ||\n ts.isDefaultClause(p)\n ) {\n return n;\n }\n n = p;\n }\n return n;\n}\n\n/** Name of the variable/member a receiver expression refers to: `this.x`, `x`, `x()`, `x!`, `(x)`. */\nfunction receiverKey(expr: ts.Expression): string | null {\n let e: ts.Expression = expr;\n for (;;) {\n if (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n else if (ts.isCallExpression(e) && e.arguments.length === 0) e = e.expression;\n else break;\n }\n if (ts.isIdentifier(e)) return e.text;\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) return e.name.text;\n return null;\n}\n\nfunction collectNames(sf: ts.SourceFile, names: Record<Kind, Set<string>>): void {\n const add = (name: ts.Node | undefined, kind: Kind | null): void => {\n if (kind && name && ts.isIdentifier(name)) names[kind].add(name.text);\n };\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyDeclaration(node) || ts.isParameter(node) || ts.isVariableDeclaration(node)) {\n let kind: Kind | null = node.type ? classify(node.type.getText(sf)) : null;\n const init = node.initializer;\n if (!kind && init && ts.isCallExpression(init)) {\n const callee = init.expression.getText(sf);\n if (/^(inject|viewChild|viewChild\\.required|contentChild|contentChild\\.required)$/.test(callee)) {\n const typeArgs = init.typeArguments?.map((t) => t.getText(sf)).join(',') ?? '';\n const firstArg = init.arguments[0]?.getText(sf) ?? '';\n kind = classify(typeArgs) ?? classify(firstArg);\n }\n }\n if (!kind && ts.canHaveDecorators(node)) {\n for (const d of ts.getDecorators(node) ?? []) {\n if (ts.isCallExpression(d.expression) && /^(ViewChild|ContentChild)$/.test(d.expression.expression.getText(sf))) {\n kind = classify(d.expression.arguments[0]?.getText(sf) ?? '');\n }\n }\n }\n add(node.name, kind);\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n}\n\n/**\n * True when `node` (an output reference) is used as an Observable: receiver of subscribe/pipe/...,\n * or an argument (directly or inside an array literal) of another call such as merge(...).\n * Already wrapped (`outputToObservable(x.out)`) is not matched.\n */\nfunction isObservableUse(node: ts.PropertyAccessExpression): boolean {\n const p = node.parent;\n if (ts.isPropertyAccessExpression(p) && p.expression === node) {\n return OBSERVABLE_METHODS.has(p.name.text) && ts.isCallExpression(p.parent) && p.parent.expression === p;\n }\n const arg: ts.Node = ts.isArrayLiteralExpression(p) ? p : node;\n const call = arg.parent;\n if (ts.isCallExpression(call) && (call.arguments as readonly ts.Node[]).includes(arg)) {\n const callee = call.expression;\n return !(ts.isIdentifier(callee) && callee.text === 'outputToObservable');\n }\n return false;\n}\n\n/** A bare identifier receiver declared locally (parameter / variable) with a type that is not an eUI dialog. */\nfunction isShadowed(expr: ts.Expression, names: Record<Kind, Set<string>>): boolean {\n let e = expr;\n while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n if (!ts.isIdentifier(e)) return false;\n for (let n: ts.Node | undefined = e.parent; n; n = n.parent) {\n const decls: ts.Node[] = [];\n if (ts.isFunctionLike(n)) decls.push(...n.parameters);\n if (ts.isBlock(n)) n.statements.forEach((st) => ts.isVariableStatement(st) && decls.push(...st.declarationList.declarations));\n for (const d of decls) {\n const dd = d as ts.ParameterDeclaration | ts.VariableDeclaration;\n if (ts.isIdentifier(dd.name) && dd.name.text === e.text) {\n const t = dd.type?.getText();\n return !(t && classify(t) === 'dialog') && !(dd.initializer && classify(dd.initializer.getText()) === 'dialog');\n }\n }\n }\n return false;\n}\n\n/** Adds the given names to the rxjs-interop import, or creates the import after the last one. */\nfunction importEdit(sf: ts.SourceFile, source: string, wanted: string[]): Edit | null {\n const imports = sf.statements.filter(ts.isImportDeclaration);\n const existing = imports.find((i) => (i.moduleSpecifier as ts.StringLiteral).text === SIGNAL_INTEROP);\n const bindings = existing?.importClause?.namedBindings;\n if (existing && bindings && ts.isNamedImports(bindings)) {\n const missing = wanted.filter((w) => !bindings.elements.some((e) => e.name.text === w));\n if (!missing.length) return null;\n const last = bindings.elements[bindings.elements.length - 1];\n if (!last) return { start: bindings.getStart(), end: bindings.getEnd(), text: `{ ${missing.join(', ')} }` };\n return { start: last.getEnd(), end: last.getEnd(), text: `, ${missing.join(', ')}` };\n }\n const line = `import { ${wanted.join(', ')} } from '${SIGNAL_INTEROP}';`;\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lastImport = imports[imports.length - 1];\n if (lastImport) return { start: lastImport.getEnd(), end: lastImport.getEnd(), text: `${eol}${line}` };\n return { start: 0, end: 0, text: `${line}${eol}` };\n}\n",
|
|
5214
|
+
"sourceCode": "import { parseTemplate, TmplAstBoundAttribute, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nconst COMPONENT_TAG = 'eui-discussion-thread';\n\nexport function migrateEuiDiscussionThread(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n if (!original.includes(COMPONENT_TAG)) return;\n\n const result = path.endsWith('.html')\n ? migrateTemplate(original)\n : migrateInlineTemplates(original);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would remove [trackBy] binding in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n\n // Warn about TS usages inline\n if (path.endsWith('.ts') && !path.endsWith('.spec.ts') && original.includes('trackByFn')) {\n const sourceFile = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === 'trackByFn') {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"trackByFn\" has been removed from ${COMPONENT_TAG}. Remove this reference manually.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n }\n });\n\n context.logger.info(`Removed trackByFn-based [trackBy] bindings from ${COMPONENT_TAG} in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const removals: { start: number; end: number }[] = [];\n\n visitNodes(parsed.nodes, source, removals);\n\n let result = source;\n for (const { start, end } of removals.sort((a, b) => b.start - a.start)) {\n let adjustedStart = start;\n while (adjustedStart > 0 && (result[adjustedStart - 1] === ' ' || result[adjustedStart - 1] === '\\t')) {\n adjustedStart--;\n }\n result = result.slice(0, adjustedStart) + result.slice(end);\n }\n\n return result;\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const templateRegex = /template\\s*:\\s*`([^`]*)`/gs;\n return source.replace(templateRegex, (match, templateContent: string) => {\n if (!templateContent.includes(COMPONENT_TAG)) return match;\n const migrated = migrateTemplate(templateContent);\n if (migrated === templateContent) return match;\n return match.replace(templateContent, migrated);\n });\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, removals: { start: number; end: number }[]): void {\n forEachElement(nodes, (node) => {\n if (node.name === COMPONENT_TAG) collectRemovals(node, source, removals);\n });\n}\n\nfunction collectRemovals(element: TmplAstElement, source: string, removals: { start: number; end: number }[]): void {\n for (const input of element.inputs) {\n if (input.name === 'trackBy') {\n const valueSource = source.slice(input.sourceSpan.start.offset, input.sourceSpan.end.offset);\n if (valueSource.includes('trackByFn')) {\n removals.push({ start: input.sourceSpan.start.offset, end: input.sourceSpan.end.offset });\n }\n }\n }\n}\n",
|
|
5215
5215
|
"displayName": "Schema",
|
|
5216
5216
|
"properties": [
|
|
5217
5217
|
{
|
|
@@ -5223,7 +5223,7 @@
|
|
|
5223
5223
|
"indexKey": "",
|
|
5224
5224
|
"optional": true,
|
|
5225
5225
|
"description": "",
|
|
5226
|
-
"line":
|
|
5226
|
+
"line": 9,
|
|
5227
5227
|
"rawdescription": "\n"
|
|
5228
5228
|
},
|
|
5229
5229
|
{
|
|
@@ -5235,14 +5235,12 @@
|
|
|
5235
5235
|
"indexKey": "",
|
|
5236
5236
|
"optional": true,
|
|
5237
5237
|
"description": "",
|
|
5238
|
-
"line":
|
|
5238
|
+
"line": 8,
|
|
5239
5239
|
"rawdescription": "\n"
|
|
5240
5240
|
}
|
|
5241
5241
|
],
|
|
5242
5242
|
"indexSignatures": [],
|
|
5243
5243
|
"kind": 172,
|
|
5244
|
-
"description": "<p>eUI v21 -> v22 migration for eui-dialog.</p>\n<ul>\n<li>EuiDialogComponent.isOpen$ (BehaviorSubject) -> <code>isOpen</code> getter</li>\n<li>acceptButtonDisabled$ / dismissButtonDisabled$ -> WritableSignal (<code>.value</code> -> <code>()</code>, <code>.next(v)</code> -> <code>.set(v)</code>)</li>\n<li>EuiDialogService.getOpenedDialog() Observable -> Signal -> <code>toObservable(...)</code> where an injection context is certain</li>\n<li>EuiDialogComponent outputs used as Observables (<code>.subscribe/.pipe</code>, or passed to merge(...)) -> <code>outputToObservable(...)</code></li>\n<li>EuiDialogContainerComponent <code>cd</code> / <code>onScroll()</code> removed -> TODO + warning</li>\n</ul>\n<p>Anything that cannot be rewritten without changing behavior is left untouched and flagged with a\n<code>// TODO: [eUI v22 migration] ...</code> comment and a logger warning.</p>\n<p>shortcut: receivers are matched by member/variable NAME within one file (declared type, ViewChild\nargument or inject()/viewChild() argument), not via the type checker; a same-named variable of another\ntype in the same file would be mis-identified. Upgrade to a ts.Program if that shows up.</p>\n",
|
|
5245
|
-
"rawdescription": "\n\neUI v21 -> v22 migration for eui-dialog.\n\n- EuiDialogComponent.isOpen$ (BehaviorSubject) -> `isOpen` getter\n- acceptButtonDisabled$ / dismissButtonDisabled$ -> WritableSignal (`.value` -> `()`, `.next(v)` -> `.set(v)`)\n- EuiDialogService.getOpenedDialog() Observable -> Signal -> `toObservable(...)` where an injection context is certain\n- EuiDialogComponent outputs used as Observables (`.subscribe/.pipe`, or passed to merge(...)) -> `outputToObservable(...)`\n- EuiDialogContainerComponent `cd` / `onScroll()` removed -> TODO + warning\n\nAnything that cannot be rewritten without changing behavior is left untouched and flagged with a\n`// TODO: [eUI v22 migration] ...` comment and a logger warning.\n\nshortcut: receivers are matched by member/variable NAME within one file (declared type, ViewChild\nargument or inject()/viewChild() argument), not via the type checker; a same-named variable of another\ntype in the same file would be mis-identified. Upgrade to a ts.Program if that shows up.\n",
|
|
5246
5244
|
"methods": [],
|
|
5247
5245
|
"extends": [],
|
|
5248
5246
|
"isDuplicate": true,
|
|
@@ -5255,12 +5253,12 @@
|
|
|
5255
5253
|
},
|
|
5256
5254
|
{
|
|
5257
5255
|
"name": "Schema",
|
|
5258
|
-
"id": "interface-Schema-
|
|
5259
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
5256
|
+
"id": "interface-Schema-da76a6389e783ac252181859f64808f331cae86954ea6f3639260cfddc149589d564991186034ad0940b8e37bca5da4424e4486e09b5933ac73a4b1939dbfc1b-27",
|
|
5257
|
+
"file": "packages/core/schematics/migrate-eui-dialog/index.ts",
|
|
5260
5258
|
"deprecated": false,
|
|
5261
5259
|
"deprecationMessage": "",
|
|
5262
5260
|
"type": "interface",
|
|
5263
|
-
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\nconst COMPONENT_TAG = 'eui-editor';\nconst OLD_NAME = 'onEditorChanged';\nconst NEW_NAME = 'contentChange';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nexport function migrateEuiEditor(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n\n if (path.endsWith('.html')) {\n if (!original.includes(COMPONENT_TAG)) return;\n const result = migrateTemplate(original);\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would rename '${OLD_NAME}' → '${NEW_NAME}' in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n return;\n }\n\n // .ts file — handle both migration and warnings in one pass\n const hasTag = original.includes(COMPONENT_TAG);\n const hasOldName = original.includes(OLD_NAME);\n if (!hasTag && !hasOldName) return;\n\n if (hasTag) {\n const result = migrateInlineTemplates(original);\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would rename '${OLD_NAME}' → '${NEW_NAME}' in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n }\n\n // Warn about TS property access usages (skip spec files)\n if (hasOldName && !path.endsWith('.spec.ts')) {\n warnPropertyAccesses(path, original, context);\n }\n });\n\n context.logger.info(`Renamed '(${OLD_NAME})' → '(${NEW_NAME})' on ${COMPONENT_TAG} in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: { start: number; end: number; replacement: string }[] = [];\n\n visitNodes(parsed.nodes, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: { start: number; end: number; text: string }[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(COMPONENT_TAG)) {\n ts.forEachChild(node, visit); return;\n}\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, text: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n let result = source;\n for (const change of changes.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, change.start) + change.text + result.slice(change.end);\n }\n return result;\n}\n\nfunction warnPropertyAccesses(path: string, source: string, context: SchematicContext): void {\n const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === OLD_NAME) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"${OLD_NAME}\" has been renamed to \"${NEW_NAME}\" on ${COMPONENT_TAG}. Update this reference manually.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: { start: number; end: number; replacement: string }[]): void {\n forEachElement(nodes, (node) => {\n if (node.name === COMPONENT_TAG) collectRenames(node, edits);\n });\n}\n\nfunction collectRenames(element: TmplAstElement, edits: { start: number; end: number; replacement: string }[]): void {\n for (const output of element.outputs) {\n if (output.name === OLD_NAME) {\n edits.push({ start: output.keySpan!.start.offset, end: output.keySpan!.end.offset, replacement: NEW_NAME });\n }\n }\n}\n\nfunction applyEdits(source: string, edits: { start: number; end: number; replacement: string }[]): string {\n let result = source;\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n",
|
|
5261
|
+
"sourceCode": "import { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { TODO_PREFIX } from '../utils/todo-comment';\n\n/**\n * eUI v21 -> v22 migration for eui-dialog.\n *\n * - EuiDialogComponent.isOpen$ (BehaviorSubject) -> `isOpen` getter\n * - acceptButtonDisabled$ / dismissButtonDisabled$ -> WritableSignal (`.value` -> `()`, `.next(v)` -> `.set(v)`)\n * - EuiDialogService.getOpenedDialog() Observable -> Signal -> `toObservable(...)` where an injection context is certain\n * - EuiDialogComponent outputs used as Observables (`.subscribe/.pipe`, or passed to merge(...)) -> `outputToObservable(...)`\n * - EuiDialogContainerComponent `cd` / `onScroll()` removed -> TODO + warning\n *\n * Anything that cannot be rewritten without changing behavior is left untouched and flagged with a\n * `// TODO: [eUI v22 migration] ...` comment and a logger warning.\n *\n * shortcut: receivers are matched by member/variable NAME within one file (declared type, ViewChild\n * argument or inject()/viewChild() argument), not via the type checker; a same-named variable of another\n * type in the same file would be mis-identified. Upgrade to a ts.Program if that shows up.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\nconst BUTTON_PROPS = new Set(['acceptButtonDisabled$', 'dismissButtonDisabled$']);\nconst SIGNAL_INTEROP = '@angular/core/rxjs-interop';\nconst QUICK_CHECK = /isOpen\\$|ButtonDisabled\\$|getOpenedDialog|onScroll|EuiDialogContainerComponent|EuiDialogComponent/;\n/** EuiDialogComponent outputs (EventEmitter -> OutputEmitterRef): no `.pipe`/`.subscribe` anymore. */\nconst DIALOG_OUTPUTS = new Set(['accept', 'clickOutside', 'dialogClose', 'dialogOpen', 'dismiss', 'escape']);\nconst OBSERVABLE_METHODS = new Set(['subscribe', 'pipe', 'asObservable', 'forEach', 'toPromise']);\n\nexport function migrateEuiDialog(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n const original = buffer.toString('utf-8');\n if (!QUICK_CHECK.test(original)) return;\n\n const warn = (line: number, msg: string): void => context.logger.warn(`${path}:${line} - ${msg}`);\n const result = path.endsWith('.html')\n ? migrateTemplateText(original, original, (m) => warn(1, m))\n : migrateTs(path, original, warn);\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-dialog usages in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n });\n\n context.logger.info(`Migrated eui-dialog API usages in ${count} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------\n\nconst REF = String.raw`[A-Za-z_$][\\w$]*(?:\\??\\.[A-Za-z_$][\\w$]*)*`;\n\n/** `context` is the full file text, used to decide whether the file deals with eui-dialog at all. */\nfunction migrateTemplateText(text: string, context: string, warn: (msg: string) => void): string {\n const hasDialog = /<eui-dialog\\b|euiDialog/.test(context);\n let out = text;\n\n if (hasDialog) {\n out = out\n .replace(new RegExp(String.raw`(${REF})\\.isOpen\\$\\s*\\|\\s*async\\b`, 'g'), '$1.isOpen')\n .replace(new RegExp(String.raw`(${REF})\\.isOpen\\$\\??\\.(?:value\\b|getValue\\(\\))`, 'g'), '$1.isOpen');\n }\n out = out\n .replace(new RegExp(String.raw`(${REF})\\.((?:accept|dismiss)ButtonDisabled\\$)\\s*\\|\\s*async\\b`, 'g'), '$1.$2()')\n .replace(new RegExp(String.raw`(${REF})\\.((?:accept|dismiss)ButtonDisabled\\$)\\??\\.(?:value\\b|getValue\\(\\))`, 'g'), '$1.$2()')\n .replace(new RegExp(String.raw`(${REF})\\.getOpenedDialog\\(\\)\\s*\\|\\s*async\\b`, 'g'), '$1.getOpenedDialog()()');\n\n const leftovers: string[] = [];\n if (hasDialog && /\\.isOpen\\$/.test(out)) leftovers.push('isOpen$');\n if (/ButtonDisabled\\$(?!\\(\\))/.test(out)) leftovers.push('acceptButtonDisabled$/dismissButtonDisabled$');\n if (/getOpenedDialog\\(\\)(?!\\s*\\()/.test(out)) leftovers.push('getOpenedDialog()');\n for (const l of leftovers) {\n warn(`Manual action needed: template still uses the removed Observable API \"${l}\". Read the signal/getter instead (see eUI 21 to 22 migration guide, eui-dialog).`);\n }\n return out;\n}\n\nfunction migrateInlineTemplates(source: string, warn: (msg: string) => void): string {\n return source.replace(/template\\s*:\\s*`([^`]*)`/gs, (match, content: string) => {\n const migrated = migrateTemplateText(content, content, warn);\n return migrated === content ? match : match.replace(content, () => migrated);\n });\n}\n\n// ---------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------\n\ntype Kind = 'dialog' | 'container' | 'service';\n\nfunction classify(text: string): Kind | null {\n if (/\\bEuiDialogContainerComponent\\b/.test(text)) return 'container';\n if (/\\bEuiDialogComponent\\b/.test(text)) return 'dialog';\n if (/\\bEuiDialogService\\b/.test(text)) return 'service';\n return null;\n}\n\nfunction migrateTs(path: string, original: string, warn: (line: number, msg: string) => void): string {\n const sf = ts.createSourceFile(path, original, ts.ScriptTarget.Latest, true);\n const names: Record<Kind, Set<string>> = { dialog: new Set(), container: new Set(), service: new Set() };\n\n collectNames(sf, names);\n\n const edits: Edit[] = [];\n const todoStatements = new Set<number>();\n let needsToObservable = false;\n let needsOutputToObservable = false;\n\n const lineOf = (n: ts.Node): number => sf.getLineAndCharacterOfPosition(n.getStart()).line + 1;\n\n const todo = (node: ts.Node, msg: string): void => {\n warn(lineOf(node), `Manual action needed: ${msg}`);\n const stmt = enclosingStatement(node);\n const start = stmt.getStart();\n if (todoStatements.has(start)) return;\n todoStatements.add(start);\n const lineStart = original.lastIndexOf('\\n', start - 1) + 1;\n const indent = original.slice(lineStart, start).match(/^\\s*/)![0];\n const comment = `// ${TODO_PREFIX} ${msg}`;\n // idempotency: skip when the same comment already precedes the statement\n if (original.slice(0, lineStart).trimEnd().endsWith(comment)) return;\n const eol = original.includes('\\r\\n') ? '\\r\\n' : '\\n';\n edits.push({ start: lineStart, end: lineStart, text: `${indent}${comment}${eol}` });\n };\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const prop = node.name.text;\n const recv = receiverKey(node.expression);\n const isDialogLike = recv !== null && (names.dialog.has(recv) || names.container.has(recv));\n const isOpen = prop === 'isOpen$';\n\n if (isDialogLike && (isOpen || BUTTON_PROPS.has(prop))) {\n if (handleSubject(node, prop, isOpen, edits, todo)) return;\n } else if (recv !== null && names.dialog.has(recv) && DIALOG_OUTPUTS.has(prop) && isObservableUse(node) && !isShadowed(node.expression, names)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'outputToObservable(' });\n edits.push({ start: node.getEnd(), end: node.getEnd(), text: ')' });\n needsOutputToObservable = true;\n } else if (recv !== null && names.container.has(recv) && (prop === 'cd' || prop === 'onScroll')) {\n todo(node, `\"${prop}\" was removed from EuiDialogContainerComponent; change detection and scroll handling are internal now. Remove this usage.`);\n }\n } else if (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n node.expression.name.text === 'getOpenedDialog'\n ) {\n const recv = receiverKey(node.expression.expression);\n if (recv !== null && names.service.has(recv) && !isAlreadyMigrated(node)) {\n if (inInjectionContext(node)) {\n edits.push({ start: node.getStart(), end: node.getStart(), text: 'toObservable(' });\n edits.push({ start: node.getEnd(), end: node.getEnd(), text: ')' });\n needsToObservable = true;\n } else {\n todo(\n node,\n 'EuiDialogService.getOpenedDialog() now returns a Signal. Read it as getOpenedDialog()() inside computed/effect, or wrap it with toObservable() from @angular/core/rxjs-interop in an injection context.',\n );\n }\n // do not return: nested getOpenedDialog() calls cannot exist inside the receiver\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n\n if (needsToObservable || needsOutputToObservable) {\n const imp = importEdit(sf, original, [\n ...(needsToObservable ? ['toObservable'] : []),\n ...(needsOutputToObservable ? ['outputToObservable'] : []),\n ]);\n if (imp) edits.push(imp);\n }\n\n let result = original;\n // Apply from the end; for equal positions keep insertion order stable by iterating in reverse.\n const ordered = edits.map((e, i) => ({ e, i })).sort((a, b) => b.e.start - a.e.start || b.i - a.i);\n for (const { e } of ordered) {\n result = result.slice(0, e.start) + e.text + result.slice(e.end);\n }\n\n if (result.includes('template')) {\n result = migrateInlineTemplates(result, (m) => warn(1, m));\n }\n return result;\n}\n\n/** Returns true when the node was fully handled and its children must not be visited. */\nfunction handleSubject(\n node: ts.PropertyAccessExpression,\n prop: string,\n isOpen: boolean,\n edits: Edit[],\n todo: (n: ts.Node, msg: string) => void,\n): boolean {\n const parent = node.parent;\n const nameStart = node.name.getStart();\n const replacement = isOpen ? 'isOpen' : `${prop}()`;\n\n // already migrated: `acceptButtonDisabled$()`\n if (!isOpen && ts.isCallExpression(parent) && parent.expression === node) return true;\n\n if (ts.isPropertyAccessExpression(parent) && parent.expression === node) {\n const member = parent.name.text;\n if (member === 'set' || member === 'update') return true; // already a signal write\n const call = ts.isCallExpression(parent.parent) && parent.parent.expression === parent ? parent.parent : null;\n\n if (member === 'value' && !isAssignmentTarget(parent)) {\n edits.push({ start: nameStart, end: parent.getEnd(), text: replacement });\n return true;\n }\n if (member === 'getValue' && call && call.arguments.length === 0) {\n edits.push({ start: nameStart, end: call.getEnd(), text: replacement });\n return true;\n }\n if (member === 'next' && call && !isOpen) {\n edits.push({ start: parent.name.getStart(), end: parent.name.getEnd(), text: 'set' });\n return false; // arguments may contain further migratable accesses\n }\n }\n\n if (isOpen) {\n todo(\n node,\n 'EuiDialogComponent.isOpen$ was removed. Read the isOpen getter (boolean) instead; it is not an Observable, so subscribe/pipe usages must be reworked manually (e.g. via computed/effect or the dialogOpen/dialogClose outputs).',\n );\n } else {\n todo(\n node,\n `${prop} is now a WritableSignal. Use ${prop}() to read and ${prop}.set(v) to write; use toObservable(${prop}) from @angular/core/rxjs-interop if an Observable is needed.`,\n );\n }\n return true;\n}\n\nfunction isAssignmentTarget(node: ts.Node): boolean {\n const p = node.parent;\n return ts.isBinaryExpression(p) && p.left === node && p.operatorToken.kind === ts.SyntaxKind.EqualsToken;\n}\n\nfunction isAlreadyMigrated(call: ts.CallExpression): boolean {\n const p = call.parent;\n if (ts.isCallExpression(p)) {\n if (p.expression === call) return true; // getOpenedDialog()()\n if (ts.isIdentifier(p.expression) && p.expression.text === 'toObservable') return true;\n }\n return false;\n}\n\nfunction inInjectionContext(node: ts.Node): boolean {\n for (let n: ts.Node | undefined = node.parent; n; n = n.parent) {\n if (ts.isConstructorDeclaration(n)) return true;\n if (ts.isPropertyDeclaration(n)) return !n.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword);\n if (ts.isFunctionLike(n) || ts.isClassDeclaration(n) || ts.isClassExpression(n)) return false;\n }\n return false;\n}\n\nfunction enclosingStatement(node: ts.Node): ts.Node {\n let n: ts.Node = node;\n while (n.parent) {\n const p = n.parent;\n if (\n ts.isBlock(p) ||\n ts.isSourceFile(p) ||\n ts.isClassLike(p) ||\n ts.isModuleBlock(p) ||\n ts.isCaseClause(p) ||\n ts.isDefaultClause(p)\n ) {\n return n;\n }\n n = p;\n }\n return n;\n}\n\n/** Name of the variable/member a receiver expression refers to: `this.x`, `x`, `x()`, `x!`, `(x)`. */\nfunction receiverKey(expr: ts.Expression): string | null {\n let e: ts.Expression = expr;\n for (;;) {\n if (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n else if (ts.isCallExpression(e) && e.arguments.length === 0) e = e.expression;\n else break;\n }\n if (ts.isIdentifier(e)) return e.text;\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) return e.name.text;\n return null;\n}\n\nfunction collectNames(sf: ts.SourceFile, names: Record<Kind, Set<string>>): void {\n const add = (name: ts.Node | undefined, kind: Kind | null): void => {\n if (kind && name && ts.isIdentifier(name)) names[kind].add(name.text);\n };\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyDeclaration(node) || ts.isParameter(node) || ts.isVariableDeclaration(node)) {\n let kind: Kind | null = node.type ? classify(node.type.getText(sf)) : null;\n const init = node.initializer;\n if (!kind && init && ts.isCallExpression(init)) {\n const callee = init.expression.getText(sf);\n if (/^(inject|viewChild|viewChild\\.required|contentChild|contentChild\\.required)$/.test(callee)) {\n const typeArgs = init.typeArguments?.map((t) => t.getText(sf)).join(',') ?? '';\n const firstArg = init.arguments[0]?.getText(sf) ?? '';\n kind = classify(typeArgs) ?? classify(firstArg);\n }\n }\n if (!kind && ts.canHaveDecorators(node)) {\n for (const d of ts.getDecorators(node) ?? []) {\n if (ts.isCallExpression(d.expression) && /^(ViewChild|ContentChild)$/.test(d.expression.expression.getText(sf))) {\n kind = classify(d.expression.arguments[0]?.getText(sf) ?? '');\n }\n }\n }\n add(node.name, kind);\n }\n ts.forEachChild(node, visit);\n };\n visit(sf);\n}\n\n/**\n * True when `node` (an output reference) is used as an Observable: receiver of subscribe/pipe/...,\n * or an argument (directly or inside an array literal) of another call such as merge(...).\n * Already wrapped (`outputToObservable(x.out)`) is not matched.\n */\nfunction isObservableUse(node: ts.PropertyAccessExpression): boolean {\n const p = node.parent;\n if (ts.isPropertyAccessExpression(p) && p.expression === node) {\n return OBSERVABLE_METHODS.has(p.name.text) && ts.isCallExpression(p.parent) && p.parent.expression === p;\n }\n const arg: ts.Node = ts.isArrayLiteralExpression(p) ? p : node;\n const call = arg.parent;\n if (ts.isCallExpression(call) && (call.arguments as readonly ts.Node[]).includes(arg)) {\n const callee = call.expression;\n return !(ts.isIdentifier(callee) && callee.text === 'outputToObservable');\n }\n return false;\n}\n\n/** A bare identifier receiver declared locally (parameter / variable) with a type that is not an eUI dialog. */\nfunction isShadowed(expr: ts.Expression, names: Record<Kind, Set<string>>): boolean {\n let e = expr;\n while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n if (!ts.isIdentifier(e)) return false;\n for (let n: ts.Node | undefined = e.parent; n; n = n.parent) {\n const decls: ts.Node[] = [];\n if (ts.isFunctionLike(n)) decls.push(...n.parameters);\n if (ts.isBlock(n)) n.statements.forEach((st) => ts.isVariableStatement(st) && decls.push(...st.declarationList.declarations));\n for (const d of decls) {\n const dd = d as ts.ParameterDeclaration | ts.VariableDeclaration;\n if (ts.isIdentifier(dd.name) && dd.name.text === e.text) {\n const t = dd.type?.getText();\n return !(t && classify(t) === 'dialog') && !(dd.initializer && classify(dd.initializer.getText()) === 'dialog');\n }\n }\n }\n return false;\n}\n\n/** Adds the given names to the rxjs-interop import, or creates the import after the last one. */\nfunction importEdit(sf: ts.SourceFile, source: string, wanted: string[]): Edit | null {\n const imports = sf.statements.filter(ts.isImportDeclaration);\n const existing = imports.find((i) => (i.moduleSpecifier as ts.StringLiteral).text === SIGNAL_INTEROP);\n const bindings = existing?.importClause?.namedBindings;\n if (existing && bindings && ts.isNamedImports(bindings)) {\n const missing = wanted.filter((w) => !bindings.elements.some((e) => e.name.text === w));\n if (!missing.length) return null;\n const last = bindings.elements[bindings.elements.length - 1];\n if (!last) return { start: bindings.getStart(), end: bindings.getEnd(), text: `{ ${missing.join(', ')} }` };\n return { start: last.getEnd(), end: last.getEnd(), text: `, ${missing.join(', ')}` };\n }\n const line = `import { ${wanted.join(', ')} } from '${SIGNAL_INTEROP}';`;\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lastImport = imports[imports.length - 1];\n if (lastImport) return { start: lastImport.getEnd(), end: lastImport.getEnd(), text: `${eol}${line}` };\n return { start: 0, end: 0, text: `${line}${eol}` };\n}\n",
|
|
5264
5262
|
"displayName": "Schema",
|
|
5265
5263
|
"properties": [
|
|
5266
5264
|
{
|
|
@@ -5272,7 +5270,7 @@
|
|
|
5272
5270
|
"indexKey": "",
|
|
5273
5271
|
"optional": true,
|
|
5274
5272
|
"description": "",
|
|
5275
|
-
"line":
|
|
5273
|
+
"line": 27,
|
|
5276
5274
|
"rawdescription": "\n"
|
|
5277
5275
|
},
|
|
5278
5276
|
{
|
|
@@ -5284,12 +5282,14 @@
|
|
|
5284
5282
|
"indexKey": "",
|
|
5285
5283
|
"optional": true,
|
|
5286
5284
|
"description": "",
|
|
5287
|
-
"line":
|
|
5285
|
+
"line": 26,
|
|
5288
5286
|
"rawdescription": "\n"
|
|
5289
5287
|
}
|
|
5290
5288
|
],
|
|
5291
5289
|
"indexSignatures": [],
|
|
5292
5290
|
"kind": 172,
|
|
5291
|
+
"description": "<p>eUI v21 -> v22 migration for eui-dialog.</p>\n<ul>\n<li>EuiDialogComponent.isOpen$ (BehaviorSubject) -> <code>isOpen</code> getter</li>\n<li>acceptButtonDisabled$ / dismissButtonDisabled$ -> WritableSignal (<code>.value</code> -> <code>()</code>, <code>.next(v)</code> -> <code>.set(v)</code>)</li>\n<li>EuiDialogService.getOpenedDialog() Observable -> Signal -> <code>toObservable(...)</code> where an injection context is certain</li>\n<li>EuiDialogComponent outputs used as Observables (<code>.subscribe/.pipe</code>, or passed to merge(...)) -> <code>outputToObservable(...)</code></li>\n<li>EuiDialogContainerComponent <code>cd</code> / <code>onScroll()</code> removed -> TODO + warning</li>\n</ul>\n<p>Anything that cannot be rewritten without changing behavior is left untouched and flagged with a\n<code>// TODO: [eUI v22 migration] ...</code> comment and a logger warning.</p>\n<p>shortcut: receivers are matched by member/variable NAME within one file (declared type, ViewChild\nargument or inject()/viewChild() argument), not via the type checker; a same-named variable of another\ntype in the same file would be mis-identified. Upgrade to a ts.Program if that shows up.</p>\n",
|
|
5292
|
+
"rawdescription": "\n\neUI v21 -> v22 migration for eui-dialog.\n\n- EuiDialogComponent.isOpen$ (BehaviorSubject) -> `isOpen` getter\n- acceptButtonDisabled$ / dismissButtonDisabled$ -> WritableSignal (`.value` -> `()`, `.next(v)` -> `.set(v)`)\n- EuiDialogService.getOpenedDialog() Observable -> Signal -> `toObservable(...)` where an injection context is certain\n- EuiDialogComponent outputs used as Observables (`.subscribe/.pipe`, or passed to merge(...)) -> `outputToObservable(...)`\n- EuiDialogContainerComponent `cd` / `onScroll()` removed -> TODO + warning\n\nAnything that cannot be rewritten without changing behavior is left untouched and flagged with a\n`// TODO: [eUI v22 migration] ...` comment and a logger warning.\n\nshortcut: receivers are matched by member/variable NAME within one file (declared type, ViewChild\nargument or inject()/viewChild() argument), not via the type checker; a same-named variable of another\ntype in the same file would be mis-identified. Upgrade to a ts.Program if that shows up.\n",
|
|
5293
5293
|
"methods": [],
|
|
5294
5294
|
"extends": [],
|
|
5295
5295
|
"isDuplicate": true,
|
|
@@ -5302,12 +5302,12 @@
|
|
|
5302
5302
|
},
|
|
5303
5303
|
{
|
|
5304
5304
|
"name": "Schema",
|
|
5305
|
-
"id": "interface-Schema-
|
|
5306
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
5305
|
+
"id": "interface-Schema-02ee32463d7ba8e004b8f83e0703d6b91d0b1783fc207f7dba79da8447e0c222e30ace350bd47ca996cf8404c19b03f72e1f127768439f53d566f12f8ef2fe78-28",
|
|
5306
|
+
"file": "packages/core/schematics/migrate-eui-editor/index.ts",
|
|
5307
5307
|
"deprecated": false,
|
|
5308
5308
|
"deprecationMessage": "",
|
|
5309
5309
|
"type": "interface",
|
|
5310
|
-
"sourceCode": "import { parseTemplate,
|
|
5310
|
+
"sourceCode": "import { parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { forEachElement } from '../utils/template-walk';\n\nconst COMPONENT_TAG = 'eui-editor';\nconst OLD_NAME = 'onEditorChanged';\nconst NEW_NAME = 'contentChange';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\nexport function migrateEuiEditor(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let count = 0;\n\n const dir = tree.getDir(scanPath || '/');\n visitDir(dir, (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n\n if (path.endsWith('.html')) {\n if (!original.includes(COMPONENT_TAG)) return;\n const result = migrateTemplate(original);\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would rename '${OLD_NAME}' → '${NEW_NAME}' in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n return;\n }\n\n // .ts file — handle both migration and warnings in one pass\n const hasTag = original.includes(COMPONENT_TAG);\n const hasOldName = original.includes(OLD_NAME);\n if (!hasTag && !hasOldName) return;\n\n if (hasTag) {\n const result = migrateInlineTemplates(original);\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would rename '${OLD_NAME}' → '${NEW_NAME}' in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n count++;\n }\n }\n\n // Warn about TS property access usages (skip spec files)\n if (hasOldName && !path.endsWith('.spec.ts')) {\n warnPropertyAccesses(path, original, context);\n }\n });\n\n context.logger.info(`Renamed '(${OLD_NAME})' → '(${NEW_NAME})' on ${COMPONENT_TAG} in ${count} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.html') && !file.endsWith('.ts')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n\nfunction migrateTemplate(source: string): string {\n const parsed = parseTemplate(source, '', { preserveWhitespaces: true });\n const edits: { start: number; end: number; replacement: string }[] = [];\n\n visitNodes(parsed.nodes, edits);\n\n return applyEdits(source, edits);\n}\n\nfunction migrateInlineTemplates(source: string): string {\n const sourceFile = ts.createSourceFile('', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const changes: { start: number; end: number; text: string }[] = [];\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAssignment(node) && isTemplateProperty(node) && isComponentMetadataProperty(node)) {\n const init = unwrapExpression(node.initializer);\n if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {\n const start = init.getStart(sourceFile) + 1;\n const end = init.getEnd() - 1;\n const rawTemplate = source.slice(start, end);\n if (!rawTemplate.includes(COMPONENT_TAG)) {\n ts.forEachChild(node, visit); return;\n}\n const migrated = migrateTemplate(rawTemplate);\n if (migrated !== rawTemplate) changes.push({ start, end, text: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n let result = source;\n for (const change of changes.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, change.start) + change.text + result.slice(change.end);\n }\n return result;\n}\n\nfunction warnPropertyAccesses(path: string, source: string, context: SchematicContext): void {\n const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);\n\n const visit = (node: ts.Node): void => {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name) && node.name.text === OLD_NAME) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n context.logger.warn(`${path}:${line + 1} - \"${OLD_NAME}\" has been renamed to \"${NEW_NAME}\" on ${COMPONENT_TAG}. Update this reference manually.`);\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n}\n\nfunction isTemplateProperty(node: ts.PropertyAssignment): boolean {\n const name = node.name;\n return (ts.isIdentifier(name) && name.text === 'template') || (ts.isStringLiteral(name) && name.text === 'template');\n}\n\nfunction isComponentMetadataProperty(node: ts.PropertyAssignment): boolean {\n const objectLiteral = node.parent;\n if (!ts.isObjectLiteralExpression(objectLiteral)) return false;\n const callExpression = objectLiteral.parent;\n if (!ts.isCallExpression(callExpression) || callExpression.arguments[0] !== objectLiteral) return false;\n return ts.isDecorator(callExpression.parent) && ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'Component';\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression;\n while (ts.isParenthesizedExpression(current)) current = current.expression;\n return current;\n}\n\nfunction visitNodes(nodes: TmplAstNode[], edits: { start: number; end: number; replacement: string }[]): void {\n forEachElement(nodes, (node) => {\n if (node.name === COMPONENT_TAG) collectRenames(node, edits);\n });\n}\n\nfunction collectRenames(element: TmplAstElement, edits: { start: number; end: number; replacement: string }[]): void {\n for (const output of element.outputs) {\n if (output.name === OLD_NAME) {\n edits.push({ start: output.keySpan!.start.offset, end: output.keySpan!.end.offset, replacement: NEW_NAME });\n }\n }\n}\n\nfunction applyEdits(source: string, edits: { start: number; end: number; replacement: string }[]): string {\n let result = source;\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n",
|
|
5311
5311
|
"displayName": "Schema",
|
|
5312
5312
|
"properties": [
|
|
5313
5313
|
{
|
|
@@ -5319,7 +5319,7 @@
|
|
|
5319
5319
|
"indexKey": "",
|
|
5320
5320
|
"optional": true,
|
|
5321
5321
|
"description": "",
|
|
5322
|
-
"line":
|
|
5322
|
+
"line": 13,
|
|
5323
5323
|
"rawdescription": "\n"
|
|
5324
5324
|
},
|
|
5325
5325
|
{
|
|
@@ -5331,7 +5331,7 @@
|
|
|
5331
5331
|
"indexKey": "",
|
|
5332
5332
|
"optional": true,
|
|
5333
5333
|
"description": "",
|
|
5334
|
-
"line":
|
|
5334
|
+
"line": 12,
|
|
5335
5335
|
"rawdescription": "\n"
|
|
5336
5336
|
}
|
|
5337
5337
|
],
|
|
@@ -5868,12 +5868,12 @@
|
|
|
5868
5868
|
},
|
|
5869
5869
|
{
|
|
5870
5870
|
"name": "Schema",
|
|
5871
|
-
"id": "interface-Schema-
|
|
5872
|
-
"file": "packages/core/schematics/migrate-
|
|
5871
|
+
"id": "interface-Schema-85d506677a88d24ac5314a45baa87ebcf9819f4d8375ebff75fd7dd3eb56602606744787c8eaa07b0049a17bfeb30b2ad99fb4b760709d0c66b30365ae949899-40",
|
|
5872
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
5873
5873
|
"deprecated": false,
|
|
5874
5874
|
"deprecationMessage": "",
|
|
5875
5875
|
"type": "interface",
|
|
5876
|
-
"sourceCode": "import { BindingType, parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit } from '../utils/todo-comment';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst OLD_CLASS = 'EuiTooltipConfig';\nconst NEW_INTERFACE = 'EuiTooltipInterface';\nconst REMOVED_ANIMATION = 'showHide';\nconst DIRECTIVE_CLASS = 'EuiTooltipDirective';\n\nconst RENAMED_INPUTS: Record<string, string> = {\n isPrimary: 'euiTooltipPrimary',\n isSecondary: 'euiTooltipSecondary',\n isInfo: 'euiTooltipInfo',\n isSuccess: 'euiTooltipSuccess',\n isWarning: 'euiTooltipWarning',\n isDanger: 'euiTooltipDanger',\n isAccent: 'euiTooltipAccent',\n};\n\nexport function migrateEuiTooltip(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n let result = original;\n if (path.endsWith('.html')) {\n if (!original.includes('euiTooltip')) return;\n result = migrateTemplate(original, path, context);\n } else {\n if (\n !original.includes(OLD_CLASS) &&\n !original.includes(REMOVED_ANIMATION) &&\n !original.includes('euiTooltip') &&\n !original.includes(DIRECTIVE_CLASS)\n ) {\n return;\n }\n if (original.includes(OLD_CLASS)) result = migrateTypeScript(result, path, context);\n if (result.includes(DIRECTIVE_CLASS)) result = migrateProgrammaticUsage(result, path, context);\n if (result.includes(REMOVED_ANIMATION)) result = removeShowHideAnimation(result, path, context);\n if (result.includes('euiTooltip')) result = migrateInlineTemplates(result, path, context);\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-tooltip usages in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated eui-tooltip usages in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n // Track if EuiTooltipInterface is already imported\n let hasInterfaceImport = false;\n let classImportDecl: ts.ImportDeclaration | null = null;\n let classImportModuleSpecifier: string | null = null;\n\n // First pass: analyze imports\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n for (const specifier of namedBindings.elements) {\n if (specifier.name.text === NEW_INTERFACE) {\n hasInterfaceImport = true;\n }\n if (specifier.name.text === OLD_CLASS) {\n classImportDecl = stmt;\n classImportModuleSpecifier = (stmt.moduleSpecifier as ts.StringLiteral).text;\n }\n }\n }\n\n // Second pass: handle import declarations\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n const specifiers = namedBindings.elements;\n const classSpecifier = specifiers.find((s) => s.name.text === OLD_CLASS);\n if (!classSpecifier) continue;\n\n if (hasInterfaceImport) {\n // EuiTooltipInterface is already imported elsewhere → remove EuiTooltipConfig from this import\n removeImportSpecifier(namedBindings, classSpecifier, sourceFile, edits);\n } else {\n // Rename EuiTooltipConfig → EuiTooltipInterface in the import\n edits.push({\n start: classSpecifier.name.getStart(sourceFile),\n end: classSpecifier.name.getEnd(),\n replacement: NEW_INTERFACE,\n });\n hasInterfaceImport = true;\n }\n }\n\n // Third pass: replace `new EuiTooltipConfig(...)` → spread/cast to interface\n const visitNewExpressions = (node: ts.Node): void => {\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) {\n const args = node.arguments;\n if (args !== undefined && args.length === 1) {\n const arg = args[0];\n // `new EuiTooltipConfig({ ... })` → `{ ... } as EuiTooltipInterface`\n // But if the argument is just a variable, we keep it: `varName as EuiTooltipInterface`\n const argText = source.slice(arg.getStart(sourceFile), arg.getEnd());\n\n if (ts.isObjectLiteralExpression(arg)) {\n // Inline object: `new EuiTooltipConfig({ x: 1 })` → `{ x: 1 }`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n } else {\n // Variable or expression: `new EuiTooltipConfig(opts)` → `opts`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n }\n } else if (args === undefined || args.length === 0) {\n // `new EuiTooltipConfig()` → `{} as EuiTooltipInterface`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: `{} as ${NEW_INTERFACE}`,\n });\n }\n return; // don't recurse into children we've already replaced\n }\n ts.forEachChild(node, visitNewExpressions);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitNewExpressions(stmt);\n }\n }\n\n // Fourth pass: rename all remaining identifier references (type annotations, etc.)\n const visitRefs = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n // Skip nodes we already covered in new expressions\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) return;\n\n if (ts.isIdentifier(node) && node.text === OLD_CLASS) {\n // Ensure this is not part of an import declaration\n if (!isPartOfImport(node)) {\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: NEW_INTERFACE,\n });\n }\n }\n ts.forEachChild(node, visitRefs);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitRefs(stmt);\n }\n }\n\n return applyEdits(source, edits);\n}\n\n/** Removes the `showHide` animation (import + `animations: [...]` entries) imported from an @eui package. */\nfunction removeShowHideAnimation(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n let found = false;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;\n if (!stmt.moduleSpecifier.text.startsWith('@eui/')) continue;\n const named = stmt.importClause?.namedBindings;\n if (!named || !ts.isNamedImports(named)) continue;\n const spec = named.elements.find((e) => e.name.text === REMOVED_ANIMATION && !e.propertyName);\n if (!spec) continue;\n found = true;\n removeImportSpecifier(named, spec, sourceFile, edits);\n }\n if (!found) return source;\n\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'animations' &&\n ts.isArrayLiteralExpression(node.initializer)\n ) {\n const arr = node.initializer;\n const kept = arr.elements.filter((e) => !(ts.isIdentifier(e) && e.text === REMOVED_ANIMATION));\n if (kept.length !== arr.elements.length) {\n if (kept.length === 0) {\n removeObjectProperty(node, sourceFile, edits);\n } else {\n edits.push({\n start: arr.getStart(sourceFile) + 1,\n end: arr.getEnd() - 1,\n replacement: kept.map((e) => e.getText(sourceFile)).join(', '),\n });\n }\n }\n } else if (ts.isIdentifier(node) && node.text === REMOVED_ANIMATION && !isPartOfImport(node) && !isInRemovedArray(node)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));\n context.logger.warn(`${filePath}:${line + 1} - Manual action needed: the \"showHide\" animation has been removed from @eui/components.`);\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction isInRemovedArray(node: ts.Node): boolean {\n const parent = node.parent;\n return (\n !!parent &&\n ts.isArrayLiteralExpression(parent) &&\n ts.isPropertyAssignment(parent.parent) &&\n ts.isIdentifier(parent.parent.name) &&\n parent.parent.name.text === 'animations'\n );\n}\n\nfunction removeObjectProperty(prop: ts.PropertyAssignment, sourceFile: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sourceFile.getFullText();\n let start = prop.getFullStart();\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getFullStart();\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\nfunction migrateInlineTemplates(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'template' &&\n (ts.isNoSubstitutionTemplateLiteral(node.initializer) || ts.isStringLiteral(node.initializer))\n ) {\n const lit = node.initializer;\n const start = lit.getStart(sourceFile) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (raw.includes('euiTooltip')) {\n const migrated = migrateTemplate(raw, filePath, context);\n if (migrated !== raw) edits.push({ start, end: lit.getEnd() - 1, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string, filePath: string, context: SchematicContext): string {\n const parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, source, filePath, context, edits);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n forEachElement(nodes, (node) => collectElementEdits(node, source, filePath, context, edits));\n}\n\nfunction collectElementEdits(el: TmplAstElement, source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n const tooltipAttr = el.attributes.find((a) => a.name === 'euiTooltip');\n const tooltipInput = el.inputs.find((i) => i.name === 'euiTooltip' && i.type === BindingType.Property);\n if (!tooltipAttr && !tooltipInput) return;\n\n // All messages of one element are merged into ONE comment: several TODOs would be inserted at the\n // same offset and overwrite each other.\n const messages: string[] = [];\n const warn = (offset: number, message: string): void => {\n messages.push(message);\n const { line } = lineOf(source, offset);\n context.logger.warn(`${filePath}:${line} - Manual action needed on <${el.name}>: ${message}`);\n };\n\n for (const attr of el.attributes) {\n if (RENAMED_INPUTS[attr.name]) {\n edits.push({ start: attr.keySpan!.start.offset, end: attr.keySpan!.end.offset, replacement: RENAMED_INPUTS[attr.name] });\n }\n }\n for (const input of el.inputs) {\n if (input.type === BindingType.Property && RENAMED_INPUTS[input.name]) {\n edits.push({ start: input.keySpan!.start.offset, end: input.keySpan!.end.offset, replacement: RENAMED_INPUTS[input.name] });\n }\n }\n\n // `position`: the migration guide lists it as removed, but EuiTooltipDirective still declares it\n // (model()). Deleting it would silently change behavior, so it is kept and flagged.\n const position = [\n ...el.attributes.filter((a) => a.name === 'position'),\n ...el.inputs.filter((i) => i.type === BindingType.Property && i.name === 'position'),\n ][0];\n if (position) {\n warn(\n position.sourceSpan.start.offset,\n 'input position of euiTooltip is documented as removed in eUI v22 but is still declared by EuiTooltipDirective. It was kept unchanged; verify it against the version you upgrade to.',\n );\n }\n\n const config = el.inputs.find((i) => i.type === BindingType.Property && i.name === 'config');\n if (config) {\n warn(\n config.sourceSpan.start.offset,\n 'input config of euiTooltip has been removed. Use the individual inputs (euiTooltip, euiTooltipPrimary, showDelay, hideDelay, contentAlignment, isDisabled) instead.',\n );\n }\n\n if (tooltipAttr && !tooltipAttr.value && !tooltipInput) {\n warn(tooltipAttr.sourceSpan.start.offset, 'input euiTooltip is now required and needs a value, e.g. euiTooltip=\"My tooltip\".');\n }\n\n if (messages.length > 0) {\n const todo = createTodoEdit(source, el.startSourceSpan.start.offset, messages.join(' '));\n if (todo) edits.push(todo);\n }\n}\n\n/**\n * Programmatic usage of a `EuiTooltipDirective` reference (`tt.isPrimary = true`, `tt.config`).\n * Renamed flags are renamed; `config` cannot be migrated and is flagged. Name based, scope aware for\n * parameters/variables (a differently typed parameter with the same name is left alone).\n * shortcut: only `this.x` and locals/params typed `EuiTooltipDirective` are followed; aliases are not.\n */\nfunction migrateProgrammaticUsage(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const isTyped = (t: ts.TypeNode | undefined): boolean =>\n !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === DIRECTIVE_CLASS;\n const isViewChildOf = (n: ts.PropertyDeclaration): boolean =>\n (ts.getDecorators?.(n) ?? []).some(\n (d) =>\n ts.isCallExpression(d.expression) &&\n ['ViewChild', 'ContentChild'].includes(d.expression.expression.getText(sourceFile)) &&\n d.expression.arguments[0]?.getText(sourceFile) === DIRECTIVE_CLASS,\n );\n\n const props = new Set<string>();\n const collect = (n: ts.Node): void => {\n if (ts.isPropertyDeclaration(n) && ts.isIdentifier(n.name) && (isTyped(n.type) || isViewChildOf(n))) props.add(n.name.text);\n ts.forEachChild(n, collect);\n };\n collect(sourceFile);\n\n /** Nearest declaration of a bare identifier: true = typed directive, false = something else, undefined = none found. */\n const bareIsDirective = (id: ts.Identifier): boolean | undefined => {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if ((ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) && cur.initializer && ts.isVariableDeclarationList(cur.initializer)) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return isTyped(d.type);\n }\n return undefined;\n };\n\n const visit = (n: ts.Node): void => {\n if (ts.isPropertyAccessExpression(n) && (RENAMED_INPUTS[n.name.text] || n.name.text === 'config')) {\n const target = n.expression;\n const tracked =\n (ts.isPropertyAccessExpression(target) && target.expression.kind === ts.SyntaxKind.ThisKeyword && props.has(target.name.text)) ||\n (ts.isIdentifier(target) && bareIsDirective(target) === true);\n if (tracked) {\n if (RENAMED_INPUTS[n.name.text]) {\n edits.push({ start: n.name.getStart(sourceFile), end: n.name.getEnd(), replacement: RENAMED_INPUTS[n.name.text] });\n } else {\n const { line } = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));\n context.logger.warn(\n `${filePath}:${line + 1} - Manual action needed: the \"config\" input of EuiTooltipDirective has been removed. Use the individual inputs instead.`,\n );\n }\n }\n }\n ts.forEachChild(n, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction lineOf(source: string, offset: number): { line: number } {\n return { line: source.slice(0, offset).split('\\n').length };\n}\n\nfunction isPartOfImport(node: ts.Node): boolean {\n let current: ts.Node | undefined = node.parent;\n while (current) {\n if (ts.isImportDeclaration(current)) return true;\n current = current.parent;\n }\n return false;\n}\n\nfunction removeImportSpecifier(\n namedImports: ts.NamedImports,\n specifier: ts.ImportSpecifier,\n sourceFile: ts.SourceFile,\n edits: Edit[],\n): void {\n const elements = namedImports.elements;\n if (elements.length === 1) {\n // Remove the entire import declaration\n const importDecl = namedImports.parent.parent;\n let end = importDecl.getEnd();\n // Also remove trailing newline if present\n const fullText = sourceFile.getFullText();\n if (fullText[end] === '\\n') end++;\n edits.push({\n start: importDecl.getStart(sourceFile),\n end,\n replacement: '',\n });\n } else {\n // Remove just this specifier with surrounding comma/whitespace\n const idx = elements.indexOf(specifier);\n let start: number;\n let end: number;\n if (idx < elements.length - 1) {\n // Not the last → remove from this specifier start to next specifier start\n start = specifier.getStart(sourceFile);\n end = elements[idx + 1].getStart(sourceFile);\n } else {\n // Last element → remove from previous element end to this end\n start = elements[idx - 1].getEnd();\n end = specifier.getEnd();\n }\n edits.push({ start, end, replacement: '' });\n }\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
5876
|
+
"sourceCode": "import {\n Binary,\n BindingPipe,\n BindingType,\n CombinedRecursiveAstVisitor,\n ImplicitReceiver,\n parseTemplate,\n PropertyRead,\n SafePropertyRead,\n TmplAstElement,\n TmplAstText,\n} from '@angular/compiler';\nimport { dirname, join, normalize } from '@angular-devkit/core';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit, TODO_PREFIX } from '../utils/todo-comment';\n\n/**\n * Migrates @ngx-translate/core v17 -> v18 breaking changes.\n *\n * No type checker is used: a `TranslateService` receiver is resolved from its declaration in the same\n * file (`: TranslateService`, `inject(TranslateService)`, constructor parameter properties) and, for\n * templates, from the component class that owns the template.\n * shortcut: receivers that are aliased, destructured, passed through other types or declared in another\n * file are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst CORE = '@ngx-translate/core';\nconst HTTP_LOADER = '@ngx-translate/http-loader';\n\nconst TOKEN_PROVIDERS: Record<string, string> = {\n TranslateLoader: 'provideTranslateLoader',\n TranslateCompiler: 'provideTranslateCompiler',\n TranslateParser: 'provideTranslateParser',\n MissingTranslationHandler: 'provideMissingTranslationHandler',\n};\nconst PLUGIN_KEYS = ['loader', 'compiler', 'parser', 'missingTranslationHandler'];\nconst MEMBER_RENAMES: Record<string, string> = {\n setDefaultLang: 'setFallbackLang',\n getDefaultLang: 'getFallbackLang',\n onDefaultLangChange: 'onFallbackLangChange',\n};\nconst ASSIGN_OPS = new Set<ts.SyntaxKind>([\n ts.SyntaxKind.EqualsToken,\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n]);\n\nexport function migrateNgxTranslate18(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n const tsFiles: string[] = [];\n const htmlFiles: string[] = [];\n visitDir(tree.getDir(scanPath || '/'), (path) => (path.endsWith('.html') ? htmlFiles : tsFiles).push(path));\n\n const projectUsesNgx = tsFiles.some((f) => tree.read(f)?.toString('utf-8').includes(CORE));\n const read = (p: string): string | undefined => tree.read(p)?.toString('utf-8');\n // forChild({ extend: true }) services merge translations; setTranslation(lang, t) callers need a review then.\n const projectHasExtend = tsFiles.some((f) => {\n const s = read(f);\n return !!s && s.includes('forChild') && /extend\\s*:\\s*true/.test(s);\n });\n\n let fileCount = 0;\n const write = (path: string, original: string, result: string): void => {\n if (result === original) return;\n if (options.dryRun) logDryRun(context, `Would migrate @ngx-translate/core usages in ${path}`);\n else tree.overwrite(path, result);\n fileCount++;\n };\n\n for (const path of tsFiles) {\n const original = read(path);\n if (!original) continue;\n const hasCore = original.includes(CORE) || original.includes(HTTP_LOADER);\n if (!hasCore && !(original.includes('template') && original.includes('translate'))) continue;\n write(path, original, migrateTypeScript(original, path, context, { projectHasExtend, projectUsesNgx, read }));\n }\n\n for (const path of htmlFiles) {\n const original = read(path);\n if (!original || !/translate|currentLang/.test(original)) continue;\n const members = membersForExternalTemplate(path, tsFiles, read);\n const scan = scanTemplate(original, path, context, {\n members,\n allowKeyRewrite: true,\n checkAttributes: projectUsesNgx,\n where: (o) => `${path}:${lineOf(original, o)}`,\n });\n write(path, original, applyEdits(original, scan.edits));\n }\n\n context.logger.info(`Migrated @ngx-translate/core usages in ${fileCount} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TemplateScan {\n edits: Edit[];\n usage: { pipe: boolean; directive: boolean };\n}\n\nfunction scanTemplate(\n source: string,\n filePath: string,\n context: SchematicContext,\n opts: {\n members: Set<string>;\n allowKeyRewrite: boolean;\n checkAttributes?: boolean;\n where: (offset: number) => string;\n quiet?: boolean\n }\n): TemplateScan {\n const result: TemplateScan = { edits: [], usage: { pipe: false, directive: false } };\n let parsed;\n try {\n parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n } catch {\n return result;\n }\n if (parsed.errors && parsed.errors.length > 0) return result;\n\n const seenWarnings = new Set<string>();\n const warn = (offset: number, message: string): void => {\n const text = `${opts.where(offset)} - Manual action needed: ${message}`;\n if (opts.quiet || seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const writes = new Set<unknown>();\n const isSvc = (r: unknown): boolean =>\n r instanceof PropertyRead && r.receiver instanceof ImplicitReceiver && opts.members.has(r.name);\n\n const visitor = new (class extends CombinedRecursiveAstVisitor {\n override visitBinary(ast: Binary, context: unknown): void {\n if (ast.operation.endsWith('=') && !['==', '===', '!=', '!==', '<=', '>='].includes(ast.operation)) {\n const left = ast.left;\n if ((left instanceof PropertyRead || left instanceof SafePropertyRead) && left.name === 'currentLang' && isSvc(left.receiver)) {\n writes.add(left);\n warn(left.sourceSpan.start, 'TranslateService.currentLang is a read-only Signal in @ngx-translate/core v18; use translate.use(lang) instead of assigning it.');\n }\n }\n super.visitBinary(ast, context);\n }\n\n override visitPropertyRead(ast: PropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitPropertyRead(ast, context);\n }\n\n override visitSafePropertyRead(ast: SafePropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitSafePropertyRead(ast, context);\n }\n\n override visitPipe(ast: BindingPipe, context: unknown): void {\n if (ast.name === 'translate') result.usage.pipe = true;\n super.visitPipe(ast, context);\n }\n\n override visitElement(el: TmplAstElement): void {\n this.checkTranslateAttribute(el);\n super.visitElement(el);\n }\n\n override visitTemplate(t: Parameters<CombinedRecursiveAstVisitor['visitTemplate']>[0]): void {\n if (\n [...t.attributes, ...t.inputs, ...t.templateAttrs].some((a) => a.name === 'translate' || a.name === 'ngx-translate')\n ) {\n result.usage.directive = true;\n }\n super.visitTemplate(t);\n }\n\n private rewriteCurrentLang(ast: PropertyRead | SafePropertyRead): void {\n if (ast.name !== 'currentLang' || writes.has(ast) || !isSvc(ast.receiver)) return;\n const end = ast.nameSpan.end;\n if (/^\\s*\\(/.test(source.slice(end))) return; // already a call\n result.edits.push({ start: end, end, replacement: '()' });\n }\n\n private checkTranslateAttribute(el: TmplAstElement): void {\n if (opts.checkAttributes === false) return;\n const textAttr = el.attributes.find((a) => a.name === 'translate' || a.name === 'ngx-translate');\n const bound = el.inputs.find((i) => i.name === 'translate' && i.type === BindingType.Property);\n if (textAttr || bound) result.usage.directive = true;\n const at = el.startSourceSpan.start.offset;\n const todo = (message: string): void => {\n warn(at, `<${el.name}> ${message}`);\n const edit = createTodoEdit(source, at, message);\n if (edit) result.edits.push(edit);\n };\n\n // 7: [translate]=\"'KEY'\" now sets textContent: element children are overwritten.\n if (bound && el.children.some((c) => !(c instanceof TmplAstText))) {\n todo(\n 'with [translate] the element content is replaced by the translation (textContent) in @ngx-translate/core v18, child elements are lost. Restructure the markup.'\n );\n return;\n }\n\n // 8: <el translate>KEY</el> (text as key) is deprecated.\n if (!textAttr || textAttr.name !== 'translate' || textAttr.value !== '' || bound) return;\n const meaningful = el.children.filter((c) => !(c instanceof TmplAstText && c.value.trim() === ''));\n if (meaningful.length === 0) return;\n const only = meaningful[0];\n const isPlain =\n meaningful.length === 1 &&\n el.children.length === 1 &&\n only instanceof TmplAstText &&\n !!el.endSourceSpan &&\n source.slice(el.startSourceSpan.end.offset, el.endSourceSpan.start.offset) === only.value &&\n !/[\"'`&<>{}\\\\]/.test(only.value);\n if (!isPlain) {\n todo(\n 'uses its text content as translation key, which is deprecated and not safely convertible here (interpolation or nested elements). Use [translate]=\"\\'KEY\\'\", the translate pipe or *translateBlock.'\n );\n return;\n }\n if (!opts.allowKeyRewrite) {\n warn(at, `<${el.name}> text as translation key is deprecated; replace with [translate]=\"'KEY'\" (not rewritten inside a quoted inline template).`);\n return;\n }\n const key = (only as TmplAstText).value.trim();\n result.edits.push({\n start: textAttr.sourceSpan.start.offset,\n end: textAttr.sourceSpan.end.offset,\n replacement: `[translate]=\"'${key}'\"`,\n });\n result.edits.push({ start: el.startSourceSpan.end.offset, end: el.endSourceSpan!.start.offset, replacement: '' });\n }\n })();\n\n for (const node of parsed.nodes) visitor.visit(node);\n return result;\n}\n\n/** Members typed/injected as TranslateService of the component whose templateUrl points at `htmlPath`. */\nfunction membersForExternalTemplate(htmlPath: string, tsFiles: string[], read: (p: string) => string | undefined): Set<string> {\n const dir = dirOf(htmlPath);\n for (const f of tsFiles) {\n if (dirOf(f) !== dir || f.endsWith('.spec.ts')) continue;\n const src = read(f);\n if (!src || !src.includes('templateUrl') || !src.includes(CORE)) continue;\n const sf = ts.createSourceFile(f, src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const helper = new ServiceResolver(sf);\n for (const stmt of sf.statements) {\n if (!ts.isClassDeclaration(stmt)) continue;\n const url = componentProp(stmt, 'templateUrl');\n if (url && ts.isStringLiteralLike(url.initializer) && resolveUrl(dir, url.initializer.text) === normalize(htmlPath)) {\n return helper.members(stmt);\n }\n }\n }\n return new Set();\n}\n\nfunction componentObject(cls: ts.ClassDeclaration): ts.ObjectLiteralExpression | undefined {\n for (const d of ts.getDecorators(cls) ?? []) {\n if (ts.isCallExpression(d.expression) && ts.isIdentifier(d.expression.expression) && d.expression.expression.text === 'Component') {\n const arg = d.expression.arguments[0];\n if (arg && ts.isObjectLiteralExpression(arg)) return arg;\n }\n }\n return undefined;\n}\n\nfunction componentProp(cls: ts.ClassDeclaration, name: string): ts.PropertyAssignment | undefined {\n return componentObject(cls)?.properties.find(\n (p): p is ts.PropertyAssignment => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === name\n );\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TranslateService receiver resolution\n// ---------------------------------------------------------------------------------------------------------------------\n\nclass ServiceResolver {\n readonly svcName: string | undefined;\n private cache = new Map<ts.Node, Set<string>>();\n\n constructor(private readonly sf: ts.SourceFile, typeName = 'TranslateService') {\n this.svcName = importedLocalName(sf, typeName);\n }\n\n isType(t: ts.TypeNode | undefined): boolean {\n return !!this.svcName && !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === this.svcName;\n }\n\n isInject(e: ts.Expression | undefined): boolean {\n if (!this.svcName || !e) return false;\n const x = unwrap(e);\n if (!ts.isCallExpression(x)) return false;\n const c = x.expression;\n const named = (ts.isIdentifier(c) && c.text === 'inject') || (ts.isPropertyAccessExpression(c) && c.name.text === 'inject');\n const a = x.arguments[0];\n return named && !!a && ts.isIdentifier(a) && a.text === this.svcName;\n }\n\n members(cls: ts.ClassLikeDeclaration): Set<string> {\n const cached = this.cache.get(cls);\n if (cached) return cached;\n const set = new Set<string>();\n for (const m of cls.members) {\n if (ts.isPropertyDeclaration(m) && ts.isIdentifier(m.name) && (this.isType(m.type) || this.isInject(m.initializer))) set.add(m.name.text);\n if (ts.isConstructorDeclaration(m)) {\n for (const p of m.parameters) {\n const isProp = ts.getModifiers(p)?.some((x) =>\n [ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(x.kind)\n );\n if (isProp && ts.isIdentifier(p.name) && this.isType(p.type)) set.add(p.name.text);\n }\n }\n }\n this.cache.set(cls, set);\n return set;\n }\n\n /** true: declared as TranslateService, false: declared as something else, undefined: not found. */\n bare(id: ts.Identifier): boolean | undefined {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur) || ts.isModuleBlock(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if (\n (ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) &&\n cur.initializer &&\n ts.isVariableDeclarationList(cur.initializer)\n ) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return this.isType(d.type) || (ts.isVariableDeclaration(d) && this.isInject(d.initializer));\n }\n return undefined;\n }\n\n isService(expr: ts.Expression): boolean {\n const e = unwrap(expr);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) {\n for (let cur: ts.Node | undefined = e.parent; cur; cur = cur.parent) {\n if (ts.isClassLike(cur)) return this.members(cur).has(e.name.text);\n }\n return false;\n }\n return ts.isIdentifier(e) && this.bare(e) === true;\n }\n}\n\nfunction unwrap(e: ts.Expression): ts.Expression {\n while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n return e;\n}\n\n/** Local name of a non-type-only named import of `imported` from @ngx-translate/core. */\nfunction importedLocalName(sf: ts.SourceFile, imported: string, module = CORE): string | undefined {\n for (const stmt of sf.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier) || stmt.moduleSpecifier.text !== module) continue;\n const nb = stmt.importClause?.namedBindings;\n if (!nb || !ts.isNamedImports(nb)) continue;\n for (const el of nb.elements) if ((el.propertyName ?? el.name).text === imported) return el.name.text;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TsEnv {\n projectHasExtend: boolean;\n projectUsesNgx: boolean;\n read: (p: string) => string | undefined;\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext, env: TsEnv): string {\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const resolver = new ServiceResolver(sf);\n const edits: Edit[] = [];\n const todos = new Map<number, { anchor: ts.Node; messages: string[] }>();\n const needed = new Set<string>();\n const touched = new Set<string>();\n const handled = new Set<ts.Node>();\n const moves = new Map<ts.ObjectLiteralExpression, { calls: ts.CallExpression[]; texts: string[] }>();\n const moduleName = importedLocalName(sf, 'TranslateModule') === 'TranslateModule' ? 'TranslateModule' : undefined;\n const setValueName = importedLocalName(sf, 'setValue') === 'setValue' ? 'setValue' : undefined;\n const defaultEvent = importedLocalName(sf, 'DefaultLangChangeEvent') === 'DefaultLangChangeEvent';\n const tokenImported = (t: string): boolean => importedLocalName(sf, t) === t;\n const providerNames = new Set(['provideTranslateService'].filter((n) => importedLocalName(sf, n) === n));\n let importProvidersTouched = false;\n\n const seenWarnings = new Set<string>();\n const warnOnce = (text: string): void => {\n if (seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const storeResolver = new ServiceResolver(sf, 'TranslateStore');\n const httpNames = new Set(\n ['provideTranslateHttpLoader', 'TranslateHttpLoader'].map((n) => importedLocalName(sf, n, HTTP_LOADER)).filter((n): n is string => !!n)\n );\n const iServiceName = importedLocalName(sf, 'ITranslateService');\n const lineNo = (node: ts.Node): number => sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;\n const flag = (node: ts.Node, message: string, comment = true): void => {\n warnOnce(`${filePath}:${lineNo(node)} - Manual action needed: ${message}`);\n if (!comment) return;\n const anchor = anchorOf(node);\n const key = anchor.getStart(sf);\n const entry = todos.get(key) ?? { anchor, messages: [] };\n const clean = sanitize(message);\n if (!entry.messages.includes(clean)) entry.messages.push(clean);\n todos.set(key, entry);\n };\n\n const nameOf = (n: ts.PropertyName | undefined): string | undefined =>\n n && (ts.isIdentifier(n) || ts.isStringLiteral(n)) ? n.text : undefined;\n const propOf = (obj: ts.ObjectLiteralExpression, name: string): ts.ObjectLiteralElementLike | undefined =>\n obj.properties.find((p) => !!p.name && nameOf(p.name) === name);\n\n // ----- config object transforms (defaultLanguage, useDefaultLang, plugin providers, extend/isolate) -----\n const CHILD_UNSUPPORTED = ['defaultLanguage', 'fallbackLang', 'lang', 'langs', 'useDefaultLang'];\n const transformConfig = (obj: ts.ObjectLiteralExpression, dropChildProps: boolean, out: Edit[], childTarget = false): number => {\n const drop = new Set<ts.ObjectLiteralElementLike>();\n for (const p of obj.properties) {\n const name = nameOf(p.name);\n if (!name) continue;\n if (childTarget && CHILD_UNSUPPORTED.includes(name) && ts.isPropertyAssignment(p)) {\n drop.add(p);\n flag(p, `${name} was removed: ChildTranslateServiceConfig has no such option, child services inherit the parent's fallbackLang and language. Set it on the root provideTranslateService() if needed.`);\n continue;\n }\n if (name === 'defaultLanguage') {\n if (ts.isPropertyAssignment(p)) out.push({\n start: p.name.getStart(sf),\n end: p.name.getEnd(),\n replacement: 'fallbackLang',\n });\n else if (ts.isShorthandPropertyAssignment(p)) out.push({\n start: p.getStart(sf),\n end: p.getEnd(),\n replacement: 'fallbackLang: defaultLanguage',\n });\n } else if (name === 'useDefaultLang' && ts.isPropertyAssignment(p)) {\n if (p.initializer.kind === ts.SyntaxKind.TrueKeyword) {\n drop.add(p);\n } else {\n flag(\n p,\n 'useDefaultLang was removed in @ngx-translate/core v18 and is kept only because its value is false: v18 always falls back to fallbackLang when it is set. Remove the leftover property manually (it does not compile as is); drop fallbackLang too if you relied on useDefaultLang: false.'\n );\n }\n } else if (dropChildProps && (name === 'extend' || name === 'isolate') && ts.isPropertyAssignment(p)) {\n drop.add(p);\n } else if (PLUGIN_KEYS.includes(name) && ts.isPropertyAssignment(p) && ts.isObjectLiteralExpression(p.initializer)) {\n const init = p.initializer;\n const provide = propOf(init, 'provide');\n const token = provide && ts.isPropertyAssignment(provide) && ts.isIdentifier(provide.initializer) ? provide.initializer.text : undefined;\n if (!token || !TOKEN_PROVIDERS[token]) continue;\n const useClass = propOf(init, 'useClass');\n if (init.properties.length === 2 && useClass && ts.isPropertyAssignment(useClass) && tokenImported(token)) {\n const fn = TOKEN_PROVIDERS[token];\n out.push({\n start: init.getStart(sf),\n end: init.getEnd(),\n replacement: `${fn}(${useClass.initializer.getText(sf)})`,\n });\n needed.add(fn);\n touched.add(token);\n } else {\n flag(\n p,\n `the ${token} provider uses a form other than { provide, useClass } (useFactory/useValue/deps). Convert it manually to ${TOKEN_PROVIDERS[token]}(...).`\n );\n }\n }\n }\n if (drop.size > 0) out.push(...removeArrayElements(obj, new Set([...drop].map((d) => obj.properties.indexOf(d))), sf));\n return drop.size;\n };\n\n // ----- TranslateModule.forRoot / forChild -----\n const convertModuleCall = (call: ts.CallExpression): void => {\n const callee = call.expression as ts.PropertyAccessExpression;\n handled.add(callee.expression);\n const method = callee.name.text;\n const args = call.arguments;\n const undecidable = (why: string): void =>\n flag(call, `TranslateModule.${method}() was left unchanged: ${why}. Use provideTranslateService() / provideChildTranslateService() manually.`);\n\n if (args.length > 1 || (args.length === 1 && !ts.isObjectLiteralExpression(args[0]))) return undecidable('its config is not an object literal');\n const obj = args[0] as ts.ObjectLiteralExpression | undefined;\n let fn = method === 'forRoot' ? 'provideTranslateService' : 'provideChildTranslateService';\n let hadExtendTrue = false;\n if (method === 'forChild' && obj) {\n for (const p of obj.properties) {\n const name = p.name ? nameOf(p.name) : undefined;\n if (ts.isSpreadAssignment(p)) return undecidable('its config contains a spread');\n if (name !== 'isolate' && name !== 'extend') continue;\n const init = ts.isPropertyAssignment(p) ? p.initializer.kind : undefined;\n if (init !== ts.SyntaxKind.TrueKeyword && init !== ts.SyntaxKind.FalseKeyword) return undecidable(`${name} is not a boolean literal`);\n if (name === 'isolate' && init === ts.SyntaxKind.TrueKeyword) fn = 'provideTranslateService';\n if (name === 'extend' && init === ts.SyntaxKind.TrueKeyword) hadExtendTrue = true;\n }\n }\n\n // the placement is decided first, so nothing is emitted for an unmovable call\n const parent = call.parent;\n let move: ts.ObjectLiteralExpression | undefined;\n let unwrapImportProviders: ts.CallExpression | undefined;\n if (ts.isArrayLiteralExpression(parent) && ts.isPropertyAssignment(parent.parent) && nameOf(parent.parent.name) === 'imports' && ts.isObjectLiteralExpression(parent.parent.parent)) {\n const owner = parent.parent.parent;\n const decorator = owner.parent;\n if (ts.isCallExpression(decorator) && ts.isIdentifier(decorator.expression) && decorator.expression.text === 'Component') {\n return undecidable('a standalone @Component cannot take environment providers; provide it in the application/route providers instead');\n }\n move = owner;\n } else if (ts.isCallExpression(parent) && ts.isIdentifier(parent.expression) && parent.expression.text === 'importProvidersFrom') {\n if (parent.arguments.length !== 1) return undecidable('it is combined with other sources in importProvidersFrom()');\n unwrapImportProviders = parent;\n }\n\n const local: Edit[] = [];\n const removed = obj ? transformConfig(obj, method === 'forChild', local, fn === 'provideChildTranslateService') : 0;\n const keepConfig = !!obj && obj.properties.length - removed > 0;\n const cfgText = keepConfig ? applyEdits(source.slice(obj!.getStart(sf), obj!.getEnd()), shift(local, -obj!.getStart(sf))) : '';\n const text = `${fn}(${cfgText})`;\n needed.add(fn);\n touched.add('TranslateModule');\n if (method === 'forChild') {\n warnOnce(\n `${filePath}:${lineNo(call)} - forChild() was converted to ${fn}(): v18 child services use their own store with parent fallback, review isolation semantics.${hadExtendTrue ? ' extend: true was removed: setTranslation(lang, t) no longer merges, pass true as third argument where needed.' : ''}`\n );\n }\n\n if (move) {\n const g = moves.get(move) ?? { calls: [], texts: [] };\n g.calls.push(call);\n g.texts.push(text);\n moves.set(move, g);\n } else if (unwrapImportProviders) {\n edits.push({ start: unwrapImportProviders.getStart(sf), end: unwrapImportProviders.getEnd(), replacement: text });\n importProvidersTouched = true;\n } else {\n edits.push({ start: call.getStart(sf), end: call.getEnd(), replacement: text });\n }\n };\n\n // ----- bare TranslateModule in imports/exports -----\n const convertBareModule = (id: ts.Identifier, arr: ts.ArrayLiteralExpression, owner: ts.ObjectLiteralExpression): void => {\n handled.add(id);\n const callNode = owner.parent;\n const kind = ts.isCallExpression(callNode) && ts.isIdentifier(callNode.expression) ? callNode.expression.text : '';\n let names = ['TranslatePipe', 'TranslateDirective'];\n if (kind === 'Component') {\n const u = componentUsage(owner);\n if (u) names = [u.pipe ? 'TranslatePipe' : '', u.directive ? 'TranslateDirective' : ''].filter(Boolean);\n }\n const present = new Set(arr.elements.filter(ts.isIdentifier).map((e) => e.text));\n const add = names.filter((n) => !present.has(n));\n touched.add('TranslateModule');\n for (const n of names) needed.add(n);\n if (add.length > 0) {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: add.join(', ') });\n } else {\n edits.push(...removeArrayElements(arr, new Set([arr.elements.indexOf(id)]), sf));\n }\n };\n\n const componentUsage = (owner: ts.ObjectLiteralExpression): { pipe: boolean; directive: boolean } | null => {\n const tpl = propOf(owner, 'template');\n const url = propOf(owner, 'templateUrl');\n const quiet = { members: new Set<string>(), allowKeyRewrite: false, where: (): string => '', quiet: true };\n if (tpl && ts.isPropertyAssignment(tpl) && (ts.isNoSubstitutionTemplateLiteral(tpl.initializer) || ts.isStringLiteral(tpl.initializer))) {\n const lit = tpl.initializer;\n return scanTemplate(source.slice(lit.getStart(sf) + 1, lit.getEnd() - 1), filePath, context, quiet).usage;\n }\n if (url && ts.isPropertyAssignment(url) && ts.isStringLiteralLike(url.initializer)) {\n const target = resolveUrl(dirOf(filePath), url.initializer.text);\n const html = env.read(target);\n if (html !== undefined) return scanTemplate(html, target, context, quiet).usage;\n }\n return null;\n };\n\n // ----- visitor -----\n const visit = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n\n if (ts.isCallExpression(node)) visitCall(node);\n else if (ts.isPropertyAccessExpression(node)) visitMember(node);\n else if (ts.isVariableDeclaration(node)) visitAlias(node.name, node.initializer, node);\n else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) visitAlias(undefined, node.right, node);\n else if (ts.isIdentifier(node)) visitIdentifier(node);\n else if (ts.isClassDeclaration(node)) visitInlineTemplate(node);\n\n ts.forEachChild(node, visit);\n };\n\n const visitCall = (call: ts.CallExpression): void => {\n const c = call.expression;\n if (moduleName && ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === moduleName && (c.name.text === 'forRoot' || c.name.text === 'forChild')) {\n convertModuleCall(call);\n return;\n }\n if (ts.isIdentifier(c) && providerNames.has(c.text) && call.arguments[0] && ts.isObjectLiteralExpression(call.arguments[0])) {\n transformConfig(call.arguments[0], false, edits);\n }\n if (setValueName && ts.isIdentifier(c) && c.text === setValueName) {\n const a0 = call.arguments[0];\n const assignable = !!a0 && (ts.isIdentifier(a0) || ts.isPropertyAccessExpression(a0) || ts.isElementAccessExpression(a0));\n if (ts.isExpressionStatement(call.parent) && call.arguments.length === 3 && assignable) {\n edits.push({ start: c.getStart(sf), end: c.getEnd(), replacement: `${a0.getText(sf)} = insertValue` });\n needed.add('insertValue');\n touched.add('setValue');\n } else {\n flag(call, 'setValue() was replaced by insertValue(), which returns a new object instead of mutating its argument. Use `target = insertValue(target, key, value)` manually.');\n }\n }\n if (ts.isPropertyAccessExpression(c) && resolver.isService(c.expression)) {\n if (c.name.text === 'getCurrentLang') {\n flag(call, 'getCurrentLang() returns Language | null in @ngx-translate/core v18 (null before a language is set). Handle the null case, e.g. `?? fallback`.');\n } else if (c.name.text === 'setTranslation' && call.arguments.length === 2 && env.projectHasExtend) {\n flag(call, 'setTranslation(lang, translations) no longer merges for services that used forChild({ extend: true }); pass `true` as third argument if you relied on merging.');\n }\n }\n };\n\n const visitMember = (n: ts.PropertyAccessExpression): void => {\n const member = n.name.text;\n if ((member === 'onTranslationChange' || member === 'getValue') && storeResolver.isService(n.expression)) {\n edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: member === 'getValue' ? 'getTranslationValue' : 'translationChange$',\n });\n return;\n }\n const isTracked = ['currentLang', 'langs', 'defaultLang', ...Object.keys(MEMBER_RENAMES)].includes(member);\n if (!isTracked || !resolver.isService(n.expression)) return;\n const parent = n.parent;\n if (MEMBER_RENAMES[member]) {\n edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: MEMBER_RENAMES[member] });\n return;\n }\n if (ts.isCallExpression(parent) && parent.expression === n) return; // already `currentLang()` etc.\n const isWrite =\n (ts.isBinaryExpression(parent) && parent.left === n && ASSIGN_OPS.has(parent.operatorToken.kind)) ||\n ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) ||\n ts.isDeleteExpression(parent);\n if (isWrite) {\n flag(n, `${member} cannot be assigned in @ngx-translate/core v18 (read-only Signal / removed). Use use(), setFallbackLang() or setTranslation() instead.`);\n return;\n }\n if (member === 'currentLang') edits.push({ start: n.getEnd(), end: n.getEnd(), replacement: '()' });\n else if (member === 'langs') edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: 'getLangs()',\n });\n else edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: 'fallbackLang()' });\n };\n\n const visitAlias = (name: ts.BindingName | undefined, init: ts.Expression | undefined, at: ts.Node): void => {\n if (!init) return;\n if (!resolver.isService(init) && !(name && ts.isObjectBindingPattern(name) && resolver.isInject(init))) return;\n if (name && ts.isIdentifier(name) && ts.isVariableDeclaration(at) && resolver.isType(at.type)) return; // typed alias is tracked\n flag(\n at,\n 'TranslateService is aliased or destructured here, so currentLang/default*/langs usages through it are not migrated automatically. Review them against the v18 API (currentLang() signal, fallbackLang, getLangs()).'\n );\n };\n\n const visitIdentifier = (id: ts.Identifier): void => {\n const p = id.parent;\n if ((ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id)) return;\n if (httpNames.has(id.text)) {\n const call = ts.isCallExpression(p) && p.expression === id ? p : undefined;\n const cfg = call?.arguments[0];\n const hasFlag = !!cfg && ts.isObjectLiteralExpression(cfg) && !!propOf(cfg, 'failOnError');\n if (!hasFlag) {\n flag(id, 'the v18 http-loader no longer fails the whole language load when a translation file request fails (it logs a warning and uses {}). Pass failOnError: true to provideTranslateHttpLoader() if you rely on the v17 behaviour.');\n }\n }\n if (iServiceName && id.text === iServiceName && ts.isExpressionWithTypeArguments(p) && ts.isHeritageClause(p.parent) && p.parent.token === ts.SyntaxKind.ImplementsKeyword) {\n flag(id, 'ITranslateService gained isLoading: Signal<boolean> in @ngx-translate/core v18. Add isLoading = signal(false).asReadonly() to this class.');\n }\n if (defaultEvent && id.text === 'DefaultLangChangeEvent') {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: 'FallbackLangChangeEvent' });\n needed.add('FallbackLangChangeEvent');\n touched.add('DefaultLangChangeEvent');\n }\n if (moduleName && id.text === moduleName && !handled.has(id)) {\n // `TranslateModule` as an element of imports / exports\n if (ts.isArrayLiteralExpression(p) && ts.isPropertyAssignment(p.parent) && ['imports', 'exports'].includes(nameOf(p.parent.name) ?? '') && ts.isObjectLiteralExpression(p.parent.parent)) {\n convertBareModule(id, p, p.parent.parent);\n }\n }\n };\n\n const visitInlineTemplate = (cls: ts.ClassDeclaration): void => {\n const tpl = componentProp(cls, 'template');\n if (!tpl) return;\n const lit = tpl.initializer;\n if (!ts.isNoSubstitutionTemplateLiteral(lit) && !ts.isStringLiteral(lit)) return;\n const start = lit.getStart(sf) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (!/translate|currentLang/.test(raw)) return;\n const baseLine = sf.getLineAndCharacterOfPosition(start).line;\n const scan = scanTemplate(raw, filePath, context, {\n members: resolver.members(cls),\n allowKeyRewrite: ts.isNoSubstitutionTemplateLiteral(lit),\n checkAttributes: env.projectUsesNgx,\n where: (o) => `${filePath}:${baseLine + lineOf(raw, o)}`,\n });\n edits.push(...shift(scan.edits, start));\n };\n\n visit(sf);\n\n // moved forRoot/forChild calls: imports -> providers\n for (const [obj, g] of moves) {\n const importsProp = propOf(obj, 'imports') as ts.PropertyAssignment;\n const arr = importsProp.initializer as ts.ArrayLiteralExpression;\n const providersProp = propOf(obj, 'providers');\n if (providersProp && !(ts.isPropertyAssignment(providersProp) && ts.isArrayLiteralExpression(providersProp.initializer))) {\n for (const call of g.calls) flag(call, 'the providers property is not an array literal, so the converted provider could not be moved there. Move it manually.');\n continue;\n }\n const texts = g.texts.join(', ');\n const movedIdx = new Set(g.calls.map((c) => arr.elements.indexOf(c)));\n const keepsOthers = arr.elements.length > movedIdx.size;\n if (providersProp) {\n const parr = (providersProp as ts.PropertyAssignment).initializer as ts.ArrayLiteralExpression;\n if (parr.elements.length > 0) {\n edits.push({\n start: parr.elements[parr.elements.length - 1].getEnd(),\n end: parr.elements[parr.elements.length - 1].getEnd(),\n replacement: `, ${texts}`,\n });\n } else {\n edits.push({ start: parr.getStart(sf) + 1, end: parr.getEnd() - 1, replacement: texts });\n }\n if (keepsOthers) edits.push(...removeArrayElements(arr, movedIdx, sf));\n else removeObjectProperty(importsProp, sf, edits);\n } else if (!keepsOthers) {\n edits.push({ start: importsProp.getStart(sf), end: importsProp.getEnd(), replacement: `providers: [${texts}]` });\n } else {\n edits.push(...removeArrayElements(arr, movedIdx, sf));\n const multiline = source.slice(obj.getStart(sf), importsProp.getEnd()).includes('\\n');\n const indent = multiline ? /[ \\t]*$/.exec(source.slice(0, importsProp.getStart(sf)))![0] : '';\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n edits.push({\n start: importsProp.getEnd(),\n end: importsProp.getEnd(),\n replacement: multiline ? `,${eol}${indent}providers: [${texts}]` : `, providers: [${texts}]`,\n });\n }\n }\n\n // remaining references to the removed module\n if (moduleName) {\n const mark = (n: ts.Node): void => {\n if (ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === moduleName && !handled.has(n) && !isPropertyName(n)) {\n flag(n, 'TranslateModule was removed in @ngx-translate/core v18. Use provideTranslateService() / provideChildTranslateService() and import TranslatePipe / TranslateDirective directly.');\n }\n ts.forEachChild(n, mark);\n };\n mark(sf);\n }\n\n // TODO comments, one line above the anchor, never duplicated\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n for (const { anchor, messages } of todos.values()) {\n const start = anchor.getStart(sf);\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))![0];\n const above = new Set<string>();\n const lines = source.slice(0, lineStart).split(/\\r?\\n/);\n for (let i = lines.length - 2; i >= 0 && lines[i].trim().startsWith('// ' + TODO_PREFIX); i--) above.add(lines[i].trim());\n const fresh = messages.map((m) => `// ${TODO_PREFIX} ${m}`).filter((l) => !above.has(l));\n if (fresh.length > 0) edits.push({\n start: lineStart,\n end: lineStart,\n replacement: fresh.map((l) => `${indent}${l}${eol}`).join(''),\n });\n }\n\n let result = applyEdits(source, edits);\n if (result === source) return source;\n result = fixImports(result, filePath, CORE, needed, touched);\n if (importProvidersTouched) result = fixImports(result, filePath, '@angular/core', new Set(), new Set(['importProvidersFrom']));\n return result;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Imports\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst RENAME_IN_PLACE: Record<string, string> = {\n DefaultLangChangeEvent: 'FallbackLangChangeEvent',\n setValue: 'insertValue',\n};\n\n/**\n * Drops `touched` specifiers that are no longer referenced (renaming in place when a rename is known) and\n * appends the `needed` names to the first named import of `moduleName`.\n */\nfunction fixImports(text: string, filePath: string, moduleName: string, needed: Set<string>, touched: Set<string>): string {\n const sf = ts.createSourceFile(filePath, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const referenced = (name: string): boolean => {\n let found = false;\n const walk = (n: ts.Node): void => {\n if (found || ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === name && !isPropertyName(n)) found = true;\n ts.forEachChild(n, walk);\n };\n walk(sf);\n return found;\n };\n\n const decls = sf.statements.filter(\n (s): s is ts.ImportDeclaration =>\n ts.isImportDeclaration(s) &&\n ts.isStringLiteral(s.moduleSpecifier) &&\n s.moduleSpecifier.text === moduleName &&\n !!s.importClause?.namedBindings &&\n ts.isNamedImports(s.importClause.namedBindings) &&\n !s.importClause.isTypeOnly\n );\n if (decls.length === 0) return text;\n\n const all = new Set<string>();\n for (const d of decls) for (const e of (d.importClause!.namedBindings as ts.NamedImports).elements) all.add(e.name.text);\n const placed = new Set<string>();\n const edits: Edit[] = [];\n const pendingNeeded = [...needed];\n\n decls.forEach((d, di) => {\n const named = d.importClause!.namedBindings as ts.NamedImports;\n const items: string[] = [];\n for (const e of named.elements) {\n const name = e.name.text;\n if (touched.has(name) && !e.propertyName && !referenced(name)) {\n const to = RENAME_IN_PLACE[name];\n if (to && needed.has(to) && !all.has(to) && !placed.has(to)) {\n items.push(to);\n placed.add(to);\n }\n continue;\n }\n items.push(e.getText(sf));\n }\n if (di === 0) {\n for (const n of pendingNeeded) if (!all.has(n) && !placed.has(n) && !items.includes(n)) items.push(n);\n }\n const before = named.elements.map((e) => e.getText(sf));\n if (items.length === before.length && items.every((v, i) => v === before[i])) return;\n if (items.length === 0 && !d.importClause!.name) {\n let end = d.getEnd();\n if (text[end] === '\\r') end++;\n if (text[end] === '\\n') end++;\n edits.push({ start: d.getStart(sf), end, replacement: '' });\n } else {\n const multiline = named.getText(sf).includes('\\n');\n const body = multiline ? `{\\n ${items.join(',\\n ')},\\n}` : `{ ${items.join(', ')} }`;\n edits.push({ start: named.getStart(sf), end: named.getEnd(), replacement: body });\n }\n });\n return applyEdits(text, edits);\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------------------------------------------------\n\nfunction isPropertyName(id: ts.Identifier): boolean {\n const p = id.parent;\n return (ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id);\n}\n\nfunction sanitize(message: string): string {\n return message.replace(/\\s+/g, ' ').trim();\n}\n\n/** Nearest ancestor that is a statement, class member or object property: the TODO goes on the line above it. */\nfunction anchorOf(node: ts.Node): ts.Node {\n let cur = node;\n while (cur.parent) {\n const p = cur.parent;\n if (ts.isSourceFile(p) || ts.isBlock(p) || ts.isModuleBlock(p) || ts.isClassLike(p) || ts.isObjectLiteralExpression(p) || ts.isCaseClause(p) || ts.isDefaultClause(p)) {\n return cur;\n }\n cur = p;\n }\n return cur;\n}\n\nconst dirOf = (p: string): string => dirname(normalize(p));\nconst resolveUrl = (dir: string, url: string): string => normalize(join(normalize(dir), url));\n\nfunction lineOf(source: string, offset: number): number {\n return source.slice(0, offset).split('\\n').length;\n}\n\nfunction shift(edits: Edit[], by: number): Edit[] {\n return edits.map((e) => ({ ...e, start: e.start + by, end: e.end + by }));\n}\n\n/** Removes one object property together with its separating comma. */\nfunction removeObjectProperty(prop: ts.ObjectLiteralElementLike, sf: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sf.getFullText();\n let start = prop.getStart(sf);\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getStart(sf);\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\n/** Removes the array elements at `indices`; non-overlapping ranges even for neighbouring elements. */\nfunction removeArrayElements(arr: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression, indices: Set<number>, sf: ts.SourceFile): Edit[] {\n const els: readonly ts.Node[] = ts.isArrayLiteralExpression(arr) ? arr.elements : arr.properties;\n const keptIdx = els.findIndex((_, i) => !indices.has(i));\n if (keptIdx === -1) return [{ start: arr.getStart(sf) + 1, end: arr.getEnd() - 1, replacement: '' }];\n const out: Edit[] = [];\n if (keptIdx > 0) out.push({ start: els[0].getStart(sf), end: els[keptIdx].getStart(sf), replacement: '' });\n for (let i = keptIdx + 1; i < els.length; i++) {\n if (indices.has(i)) out.push({ start: els[i - 1].getEnd(), end: els[i].getEnd(), replacement: '' });\n }\n return out;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const seen = new Map<string, Edit>();\n for (const e of edits) seen.set(`${e.start}:${e.end}:${e.replacement}`, e);\n let result = source;\n for (const e of [...seen.values()].sort((a, b) => b.start - a.start || b.end - a.end)) {\n result = result.slice(0, e.start) + e.replacement + result.slice(e.end);\n }\n return result;\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
5877
5877
|
"displayName": "Schema",
|
|
5878
5878
|
"properties": [
|
|
5879
5879
|
{
|
|
@@ -5885,7 +5885,7 @@
|
|
|
5885
5885
|
"indexKey": "",
|
|
5886
5886
|
"optional": true,
|
|
5887
5887
|
"description": "",
|
|
5888
|
-
"line":
|
|
5888
|
+
"line": 32,
|
|
5889
5889
|
"rawdescription": "\n"
|
|
5890
5890
|
},
|
|
5891
5891
|
{
|
|
@@ -5897,12 +5897,14 @@
|
|
|
5897
5897
|
"indexKey": "",
|
|
5898
5898
|
"optional": true,
|
|
5899
5899
|
"description": "",
|
|
5900
|
-
"line":
|
|
5900
|
+
"line": 31,
|
|
5901
5901
|
"rawdescription": "\n"
|
|
5902
5902
|
}
|
|
5903
5903
|
],
|
|
5904
5904
|
"indexSignatures": [],
|
|
5905
5905
|
"kind": 172,
|
|
5906
|
+
"description": "<p>Migrates @ngx-translate/core v17 -> v18 breaking changes.</p>\n<p>No type checker is used: a <code>TranslateService</code> receiver is resolved from its declaration in the same\nfile (<code>: TranslateService</code>, <code>inject(TranslateService)</code>, constructor parameter properties) and, for\ntemplates, from the component class that owns the template.\nshortcut: receivers that are aliased, destructured, passed through other types or declared in another\nfile are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.</p>\n",
|
|
5907
|
+
"rawdescription": "\n\nMigrates @ngx-translate/core v17 -> v18 breaking changes.\n\nNo type checker is used: a `TranslateService` receiver is resolved from its declaration in the same\nfile (`: TranslateService`, `inject(TranslateService)`, constructor parameter properties) and, for\ntemplates, from the component class that owns the template.\nshortcut: receivers that are aliased, destructured, passed through other types or declared in another\nfile are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.\n",
|
|
5906
5908
|
"methods": [],
|
|
5907
5909
|
"extends": [],
|
|
5908
5910
|
"isDuplicate": true,
|
|
@@ -5915,12 +5917,12 @@
|
|
|
5915
5917
|
},
|
|
5916
5918
|
{
|
|
5917
5919
|
"name": "Schema",
|
|
5918
|
-
"id": "interface-Schema-
|
|
5919
|
-
"file": "packages/core/schematics/migrate-
|
|
5920
|
+
"id": "interface-Schema-e82ad5d05a8363ecab95140e3f129427949eb3d53d4272814efdb8f6458ebc01b92b07c76d5e15e5491679d59f5b9b723c3f191c3c12257261a751583757f3fe-41",
|
|
5921
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
5920
5922
|
"deprecated": false,
|
|
5921
5923
|
"deprecationMessage": "",
|
|
5922
5924
|
"type": "interface",
|
|
5923
|
-
"sourceCode": "import {\n Binary,\n BindingPipe,\n BindingType,\n CombinedRecursiveAstVisitor,\n ImplicitReceiver,\n parseTemplate,\n PropertyRead,\n SafePropertyRead,\n TmplAstElement,\n TmplAstText,\n} from '@angular/compiler';\nimport { dirname, join, normalize } from '@angular-devkit/core';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit, TODO_PREFIX } from '../utils/todo-comment';\n\n/**\n * Migrates @ngx-translate/core v17 -> v18 breaking changes.\n *\n * No type checker is used: a `TranslateService` receiver is resolved from its declaration in the same\n * file (`: TranslateService`, `inject(TranslateService)`, constructor parameter properties) and, for\n * templates, from the component class that owns the template.\n * shortcut: receivers that are aliased, destructured, passed through other types or declared in another\n * file are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.\n */\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst CORE = '@ngx-translate/core';\nconst HTTP_LOADER = '@ngx-translate/http-loader';\n\nconst TOKEN_PROVIDERS: Record<string, string> = {\n TranslateLoader: 'provideTranslateLoader',\n TranslateCompiler: 'provideTranslateCompiler',\n TranslateParser: 'provideTranslateParser',\n MissingTranslationHandler: 'provideMissingTranslationHandler',\n};\nconst PLUGIN_KEYS = ['loader', 'compiler', 'parser', 'missingTranslationHandler'];\nconst MEMBER_RENAMES: Record<string, string> = {\n setDefaultLang: 'setFallbackLang',\n getDefaultLang: 'getFallbackLang',\n onDefaultLangChange: 'onFallbackLangChange',\n};\nconst ASSIGN_OPS = new Set<ts.SyntaxKind>([\n ts.SyntaxKind.EqualsToken,\n ts.SyntaxKind.PlusEqualsToken,\n ts.SyntaxKind.MinusEqualsToken,\n ts.SyntaxKind.QuestionQuestionEqualsToken,\n ts.SyntaxKind.BarBarEqualsToken,\n ts.SyntaxKind.AmpersandAmpersandEqualsToken,\n]);\n\nexport function migrateNgxTranslate18(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n const tsFiles: string[] = [];\n const htmlFiles: string[] = [];\n visitDir(tree.getDir(scanPath || '/'), (path) => (path.endsWith('.html') ? htmlFiles : tsFiles).push(path));\n\n const projectUsesNgx = tsFiles.some((f) => tree.read(f)?.toString('utf-8').includes(CORE));\n const read = (p: string): string | undefined => tree.read(p)?.toString('utf-8');\n // forChild({ extend: true }) services merge translations; setTranslation(lang, t) callers need a review then.\n const projectHasExtend = tsFiles.some((f) => {\n const s = read(f);\n return !!s && s.includes('forChild') && /extend\\s*:\\s*true/.test(s);\n });\n\n let fileCount = 0;\n const write = (path: string, original: string, result: string): void => {\n if (result === original) return;\n if (options.dryRun) logDryRun(context, `Would migrate @ngx-translate/core usages in ${path}`);\n else tree.overwrite(path, result);\n fileCount++;\n };\n\n for (const path of tsFiles) {\n const original = read(path);\n if (!original) continue;\n const hasCore = original.includes(CORE) || original.includes(HTTP_LOADER);\n if (!hasCore && !(original.includes('template') && original.includes('translate'))) continue;\n write(path, original, migrateTypeScript(original, path, context, { projectHasExtend, projectUsesNgx, read }));\n }\n\n for (const path of htmlFiles) {\n const original = read(path);\n if (!original || !/translate|currentLang/.test(original)) continue;\n const members = membersForExternalTemplate(path, tsFiles, read);\n const scan = scanTemplate(original, path, context, {\n members,\n allowKeyRewrite: true,\n checkAttributes: projectUsesNgx,\n where: (o) => `${path}:${lineOf(original, o)}`,\n });\n write(path, original, applyEdits(original, scan.edits));\n }\n\n context.logger.info(`Migrated @ngx-translate/core usages in ${fileCount} file(s).`);\n if (options.dryRun) logDryRunNote(context);\n return tree;\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Templates\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TemplateScan {\n edits: Edit[];\n usage: { pipe: boolean; directive: boolean };\n}\n\nfunction scanTemplate(\n source: string,\n filePath: string,\n context: SchematicContext,\n opts: {\n members: Set<string>;\n allowKeyRewrite: boolean;\n checkAttributes?: boolean;\n where: (offset: number) => string;\n quiet?: boolean\n }\n): TemplateScan {\n const result: TemplateScan = { edits: [], usage: { pipe: false, directive: false } };\n let parsed;\n try {\n parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n } catch {\n return result;\n }\n if (parsed.errors && parsed.errors.length > 0) return result;\n\n const seenWarnings = new Set<string>();\n const warn = (offset: number, message: string): void => {\n const text = `${opts.where(offset)} - Manual action needed: ${message}`;\n if (opts.quiet || seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const writes = new Set<unknown>();\n const isSvc = (r: unknown): boolean =>\n r instanceof PropertyRead && r.receiver instanceof ImplicitReceiver && opts.members.has(r.name);\n\n const visitor = new (class extends CombinedRecursiveAstVisitor {\n override visitBinary(ast: Binary, context: unknown): void {\n if (ast.operation.endsWith('=') && !['==', '===', '!=', '!==', '<=', '>='].includes(ast.operation)) {\n const left = ast.left;\n if ((left instanceof PropertyRead || left instanceof SafePropertyRead) && left.name === 'currentLang' && isSvc(left.receiver)) {\n writes.add(left);\n warn(left.sourceSpan.start, 'TranslateService.currentLang is a read-only Signal in @ngx-translate/core v18; use translate.use(lang) instead of assigning it.');\n }\n }\n super.visitBinary(ast, context);\n }\n\n override visitPropertyRead(ast: PropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitPropertyRead(ast, context);\n }\n\n override visitSafePropertyRead(ast: SafePropertyRead, context: unknown): void {\n this.rewriteCurrentLang(ast);\n super.visitSafePropertyRead(ast, context);\n }\n\n override visitPipe(ast: BindingPipe, context: unknown): void {\n if (ast.name === 'translate') result.usage.pipe = true;\n super.visitPipe(ast, context);\n }\n\n override visitElement(el: TmplAstElement): void {\n this.checkTranslateAttribute(el);\n super.visitElement(el);\n }\n\n override visitTemplate(t: Parameters<CombinedRecursiveAstVisitor['visitTemplate']>[0]): void {\n if (\n [...t.attributes, ...t.inputs, ...t.templateAttrs].some((a) => a.name === 'translate' || a.name === 'ngx-translate')\n ) {\n result.usage.directive = true;\n }\n super.visitTemplate(t);\n }\n\n private rewriteCurrentLang(ast: PropertyRead | SafePropertyRead): void {\n if (ast.name !== 'currentLang' || writes.has(ast) || !isSvc(ast.receiver)) return;\n const end = ast.nameSpan.end;\n if (/^\\s*\\(/.test(source.slice(end))) return; // already a call\n result.edits.push({ start: end, end, replacement: '()' });\n }\n\n private checkTranslateAttribute(el: TmplAstElement): void {\n if (opts.checkAttributes === false) return;\n const textAttr = el.attributes.find((a) => a.name === 'translate' || a.name === 'ngx-translate');\n const bound = el.inputs.find((i) => i.name === 'translate' && i.type === BindingType.Property);\n if (textAttr || bound) result.usage.directive = true;\n const at = el.startSourceSpan.start.offset;\n const todo = (message: string): void => {\n warn(at, `<${el.name}> ${message}`);\n const edit = createTodoEdit(source, at, message);\n if (edit) result.edits.push(edit);\n };\n\n // 7: [translate]=\"'KEY'\" now sets textContent: element children are overwritten.\n if (bound && el.children.some((c) => !(c instanceof TmplAstText))) {\n todo(\n 'with [translate] the element content is replaced by the translation (textContent) in @ngx-translate/core v18, child elements are lost. Restructure the markup.'\n );\n return;\n }\n\n // 8: <el translate>KEY</el> (text as key) is deprecated.\n if (!textAttr || textAttr.name !== 'translate' || textAttr.value !== '' || bound) return;\n const meaningful = el.children.filter((c) => !(c instanceof TmplAstText && c.value.trim() === ''));\n if (meaningful.length === 0) return;\n const only = meaningful[0];\n const isPlain =\n meaningful.length === 1 &&\n el.children.length === 1 &&\n only instanceof TmplAstText &&\n !!el.endSourceSpan &&\n source.slice(el.startSourceSpan.end.offset, el.endSourceSpan.start.offset) === only.value &&\n !/[\"'`&<>{}\\\\]/.test(only.value);\n if (!isPlain) {\n todo(\n 'uses its text content as translation key, which is deprecated and not safely convertible here (interpolation or nested elements). Use [translate]=\"\\'KEY\\'\", the translate pipe or *translateBlock.'\n );\n return;\n }\n if (!opts.allowKeyRewrite) {\n warn(at, `<${el.name}> text as translation key is deprecated; replace with [translate]=\"'KEY'\" (not rewritten inside a quoted inline template).`);\n return;\n }\n const key = (only as TmplAstText).value.trim();\n result.edits.push({\n start: textAttr.sourceSpan.start.offset,\n end: textAttr.sourceSpan.end.offset,\n replacement: `[translate]=\"'${key}'\"`,\n });\n result.edits.push({ start: el.startSourceSpan.end.offset, end: el.endSourceSpan!.start.offset, replacement: '' });\n }\n })();\n\n for (const node of parsed.nodes) visitor.visit(node);\n return result;\n}\n\n/** Members typed/injected as TranslateService of the component whose templateUrl points at `htmlPath`. */\nfunction membersForExternalTemplate(htmlPath: string, tsFiles: string[], read: (p: string) => string | undefined): Set<string> {\n const dir = dirOf(htmlPath);\n for (const f of tsFiles) {\n if (dirOf(f) !== dir || f.endsWith('.spec.ts')) continue;\n const src = read(f);\n if (!src || !src.includes('templateUrl') || !src.includes(CORE)) continue;\n const sf = ts.createSourceFile(f, src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const helper = new ServiceResolver(sf);\n for (const stmt of sf.statements) {\n if (!ts.isClassDeclaration(stmt)) continue;\n const url = componentProp(stmt, 'templateUrl');\n if (url && ts.isStringLiteralLike(url.initializer) && resolveUrl(dir, url.initializer.text) === normalize(htmlPath)) {\n return helper.members(stmt);\n }\n }\n }\n return new Set();\n}\n\nfunction componentObject(cls: ts.ClassDeclaration): ts.ObjectLiteralExpression | undefined {\n for (const d of ts.getDecorators(cls) ?? []) {\n if (ts.isCallExpression(d.expression) && ts.isIdentifier(d.expression.expression) && d.expression.expression.text === 'Component') {\n const arg = d.expression.arguments[0];\n if (arg && ts.isObjectLiteralExpression(arg)) return arg;\n }\n }\n return undefined;\n}\n\nfunction componentProp(cls: ts.ClassDeclaration, name: string): ts.PropertyAssignment | undefined {\n return componentObject(cls)?.properties.find(\n (p): p is ts.PropertyAssignment => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === name\n );\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TranslateService receiver resolution\n// ---------------------------------------------------------------------------------------------------------------------\n\nclass ServiceResolver {\n readonly svcName: string | undefined;\n private cache = new Map<ts.Node, Set<string>>();\n\n constructor(private readonly sf: ts.SourceFile, typeName = 'TranslateService') {\n this.svcName = importedLocalName(sf, typeName);\n }\n\n isType(t: ts.TypeNode | undefined): boolean {\n return !!this.svcName && !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === this.svcName;\n }\n\n isInject(e: ts.Expression | undefined): boolean {\n if (!this.svcName || !e) return false;\n const x = unwrap(e);\n if (!ts.isCallExpression(x)) return false;\n const c = x.expression;\n const named = (ts.isIdentifier(c) && c.text === 'inject') || (ts.isPropertyAccessExpression(c) && c.name.text === 'inject');\n const a = x.arguments[0];\n return named && !!a && ts.isIdentifier(a) && a.text === this.svcName;\n }\n\n members(cls: ts.ClassLikeDeclaration): Set<string> {\n const cached = this.cache.get(cls);\n if (cached) return cached;\n const set = new Set<string>();\n for (const m of cls.members) {\n if (ts.isPropertyDeclaration(m) && ts.isIdentifier(m.name) && (this.isType(m.type) || this.isInject(m.initializer))) set.add(m.name.text);\n if (ts.isConstructorDeclaration(m)) {\n for (const p of m.parameters) {\n const isProp = ts.getModifiers(p)?.some((x) =>\n [ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(x.kind)\n );\n if (isProp && ts.isIdentifier(p.name) && this.isType(p.type)) set.add(p.name.text);\n }\n }\n }\n this.cache.set(cls, set);\n return set;\n }\n\n /** true: declared as TranslateService, false: declared as something else, undefined: not found. */\n bare(id: ts.Identifier): boolean | undefined {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur) || ts.isModuleBlock(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if (\n (ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) &&\n cur.initializer &&\n ts.isVariableDeclarationList(cur.initializer)\n ) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return this.isType(d.type) || (ts.isVariableDeclaration(d) && this.isInject(d.initializer));\n }\n return undefined;\n }\n\n isService(expr: ts.Expression): boolean {\n const e = unwrap(expr);\n if (ts.isPropertyAccessExpression(e) && e.expression.kind === ts.SyntaxKind.ThisKeyword) {\n for (let cur: ts.Node | undefined = e.parent; cur; cur = cur.parent) {\n if (ts.isClassLike(cur)) return this.members(cur).has(e.name.text);\n }\n return false;\n }\n return ts.isIdentifier(e) && this.bare(e) === true;\n }\n}\n\nfunction unwrap(e: ts.Expression): ts.Expression {\n while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e)) e = e.expression;\n return e;\n}\n\n/** Local name of a non-type-only named import of `imported` from @ngx-translate/core. */\nfunction importedLocalName(sf: ts.SourceFile, imported: string, module = CORE): string | undefined {\n for (const stmt of sf.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier) || stmt.moduleSpecifier.text !== module) continue;\n const nb = stmt.importClause?.namedBindings;\n if (!nb || !ts.isNamedImports(nb)) continue;\n for (const el of nb.elements) if ((el.propertyName ?? el.name).text === imported) return el.name.text;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// TypeScript\n// ---------------------------------------------------------------------------------------------------------------------\n\ninterface TsEnv {\n projectHasExtend: boolean;\n projectUsesNgx: boolean;\n read: (p: string) => string | undefined;\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext, env: TsEnv): string {\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const resolver = new ServiceResolver(sf);\n const edits: Edit[] = [];\n const todos = new Map<number, { anchor: ts.Node; messages: string[] }>();\n const needed = new Set<string>();\n const touched = new Set<string>();\n const handled = new Set<ts.Node>();\n const moves = new Map<ts.ObjectLiteralExpression, { calls: ts.CallExpression[]; texts: string[] }>();\n const moduleName = importedLocalName(sf, 'TranslateModule') === 'TranslateModule' ? 'TranslateModule' : undefined;\n const setValueName = importedLocalName(sf, 'setValue') === 'setValue' ? 'setValue' : undefined;\n const defaultEvent = importedLocalName(sf, 'DefaultLangChangeEvent') === 'DefaultLangChangeEvent';\n const tokenImported = (t: string): boolean => importedLocalName(sf, t) === t;\n const providerNames = new Set(['provideTranslateService'].filter((n) => importedLocalName(sf, n) === n));\n let importProvidersTouched = false;\n\n const seenWarnings = new Set<string>();\n const warnOnce = (text: string): void => {\n if (seenWarnings.has(text)) return;\n seenWarnings.add(text);\n context.logger.warn(text);\n };\n const storeResolver = new ServiceResolver(sf, 'TranslateStore');\n const httpNames = new Set(\n ['provideTranslateHttpLoader', 'TranslateHttpLoader'].map((n) => importedLocalName(sf, n, HTTP_LOADER)).filter((n): n is string => !!n)\n );\n const iServiceName = importedLocalName(sf, 'ITranslateService');\n const lineNo = (node: ts.Node): number => sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;\n const flag = (node: ts.Node, message: string, comment = true): void => {\n warnOnce(`${filePath}:${lineNo(node)} - Manual action needed: ${message}`);\n if (!comment) return;\n const anchor = anchorOf(node);\n const key = anchor.getStart(sf);\n const entry = todos.get(key) ?? { anchor, messages: [] };\n const clean = sanitize(message);\n if (!entry.messages.includes(clean)) entry.messages.push(clean);\n todos.set(key, entry);\n };\n\n const nameOf = (n: ts.PropertyName | undefined): string | undefined =>\n n && (ts.isIdentifier(n) || ts.isStringLiteral(n)) ? n.text : undefined;\n const propOf = (obj: ts.ObjectLiteralExpression, name: string): ts.ObjectLiteralElementLike | undefined =>\n obj.properties.find((p) => !!p.name && nameOf(p.name) === name);\n\n // ----- config object transforms (defaultLanguage, useDefaultLang, plugin providers, extend/isolate) -----\n const CHILD_UNSUPPORTED = ['defaultLanguage', 'fallbackLang', 'lang', 'langs', 'useDefaultLang'];\n const transformConfig = (obj: ts.ObjectLiteralExpression, dropChildProps: boolean, out: Edit[], childTarget = false): number => {\n const drop = new Set<ts.ObjectLiteralElementLike>();\n for (const p of obj.properties) {\n const name = nameOf(p.name);\n if (!name) continue;\n if (childTarget && CHILD_UNSUPPORTED.includes(name) && ts.isPropertyAssignment(p)) {\n drop.add(p);\n flag(p, `${name} was removed: ChildTranslateServiceConfig has no such option, child services inherit the parent's fallbackLang and language. Set it on the root provideTranslateService() if needed.`);\n continue;\n }\n if (name === 'defaultLanguage') {\n if (ts.isPropertyAssignment(p)) out.push({\n start: p.name.getStart(sf),\n end: p.name.getEnd(),\n replacement: 'fallbackLang',\n });\n else if (ts.isShorthandPropertyAssignment(p)) out.push({\n start: p.getStart(sf),\n end: p.getEnd(),\n replacement: 'fallbackLang: defaultLanguage',\n });\n } else if (name === 'useDefaultLang' && ts.isPropertyAssignment(p)) {\n if (p.initializer.kind === ts.SyntaxKind.TrueKeyword) {\n drop.add(p);\n } else {\n flag(\n p,\n 'useDefaultLang was removed in @ngx-translate/core v18 and is kept only because its value is false: v18 always falls back to fallbackLang when it is set. Remove the leftover property manually (it does not compile as is); drop fallbackLang too if you relied on useDefaultLang: false.'\n );\n }\n } else if (dropChildProps && (name === 'extend' || name === 'isolate') && ts.isPropertyAssignment(p)) {\n drop.add(p);\n } else if (PLUGIN_KEYS.includes(name) && ts.isPropertyAssignment(p) && ts.isObjectLiteralExpression(p.initializer)) {\n const init = p.initializer;\n const provide = propOf(init, 'provide');\n const token = provide && ts.isPropertyAssignment(provide) && ts.isIdentifier(provide.initializer) ? provide.initializer.text : undefined;\n if (!token || !TOKEN_PROVIDERS[token]) continue;\n const useClass = propOf(init, 'useClass');\n if (init.properties.length === 2 && useClass && ts.isPropertyAssignment(useClass) && tokenImported(token)) {\n const fn = TOKEN_PROVIDERS[token];\n out.push({\n start: init.getStart(sf),\n end: init.getEnd(),\n replacement: `${fn}(${useClass.initializer.getText(sf)})`,\n });\n needed.add(fn);\n touched.add(token);\n } else {\n flag(\n p,\n `the ${token} provider uses a form other than { provide, useClass } (useFactory/useValue/deps). Convert it manually to ${TOKEN_PROVIDERS[token]}(...).`\n );\n }\n }\n }\n if (drop.size > 0) out.push(...removeArrayElements(obj, new Set([...drop].map((d) => obj.properties.indexOf(d))), sf));\n return drop.size;\n };\n\n // ----- TranslateModule.forRoot / forChild -----\n const convertModuleCall = (call: ts.CallExpression): void => {\n const callee = call.expression as ts.PropertyAccessExpression;\n handled.add(callee.expression);\n const method = callee.name.text;\n const args = call.arguments;\n const undecidable = (why: string): void =>\n flag(call, `TranslateModule.${method}() was left unchanged: ${why}. Use provideTranslateService() / provideChildTranslateService() manually.`);\n\n if (args.length > 1 || (args.length === 1 && !ts.isObjectLiteralExpression(args[0]))) return undecidable('its config is not an object literal');\n const obj = args[0] as ts.ObjectLiteralExpression | undefined;\n let fn = method === 'forRoot' ? 'provideTranslateService' : 'provideChildTranslateService';\n let hadExtendTrue = false;\n if (method === 'forChild' && obj) {\n for (const p of obj.properties) {\n const name = p.name ? nameOf(p.name) : undefined;\n if (ts.isSpreadAssignment(p)) return undecidable('its config contains a spread');\n if (name !== 'isolate' && name !== 'extend') continue;\n const init = ts.isPropertyAssignment(p) ? p.initializer.kind : undefined;\n if (init !== ts.SyntaxKind.TrueKeyword && init !== ts.SyntaxKind.FalseKeyword) return undecidable(`${name} is not a boolean literal`);\n if (name === 'isolate' && init === ts.SyntaxKind.TrueKeyword) fn = 'provideTranslateService';\n if (name === 'extend' && init === ts.SyntaxKind.TrueKeyword) hadExtendTrue = true;\n }\n }\n\n // the placement is decided first, so nothing is emitted for an unmovable call\n const parent = call.parent;\n let move: ts.ObjectLiteralExpression | undefined;\n let unwrapImportProviders: ts.CallExpression | undefined;\n if (ts.isArrayLiteralExpression(parent) && ts.isPropertyAssignment(parent.parent) && nameOf(parent.parent.name) === 'imports' && ts.isObjectLiteralExpression(parent.parent.parent)) {\n const owner = parent.parent.parent;\n const decorator = owner.parent;\n if (ts.isCallExpression(decorator) && ts.isIdentifier(decorator.expression) && decorator.expression.text === 'Component') {\n return undecidable('a standalone @Component cannot take environment providers; provide it in the application/route providers instead');\n }\n move = owner;\n } else if (ts.isCallExpression(parent) && ts.isIdentifier(parent.expression) && parent.expression.text === 'importProvidersFrom') {\n if (parent.arguments.length !== 1) return undecidable('it is combined with other sources in importProvidersFrom()');\n unwrapImportProviders = parent;\n }\n\n const local: Edit[] = [];\n const removed = obj ? transformConfig(obj, method === 'forChild', local, fn === 'provideChildTranslateService') : 0;\n const keepConfig = !!obj && obj.properties.length - removed > 0;\n const cfgText = keepConfig ? applyEdits(source.slice(obj!.getStart(sf), obj!.getEnd()), shift(local, -obj!.getStart(sf))) : '';\n const text = `${fn}(${cfgText})`;\n needed.add(fn);\n touched.add('TranslateModule');\n if (method === 'forChild') {\n warnOnce(\n `${filePath}:${lineNo(call)} - forChild() was converted to ${fn}(): v18 child services use their own store with parent fallback, review isolation semantics.${hadExtendTrue ? ' extend: true was removed: setTranslation(lang, t) no longer merges, pass true as third argument where needed.' : ''}`\n );\n }\n\n if (move) {\n const g = moves.get(move) ?? { calls: [], texts: [] };\n g.calls.push(call);\n g.texts.push(text);\n moves.set(move, g);\n } else if (unwrapImportProviders) {\n edits.push({ start: unwrapImportProviders.getStart(sf), end: unwrapImportProviders.getEnd(), replacement: text });\n importProvidersTouched = true;\n } else {\n edits.push({ start: call.getStart(sf), end: call.getEnd(), replacement: text });\n }\n };\n\n // ----- bare TranslateModule in imports/exports -----\n const convertBareModule = (id: ts.Identifier, arr: ts.ArrayLiteralExpression, owner: ts.ObjectLiteralExpression): void => {\n handled.add(id);\n const callNode = owner.parent;\n const kind = ts.isCallExpression(callNode) && ts.isIdentifier(callNode.expression) ? callNode.expression.text : '';\n let names = ['TranslatePipe', 'TranslateDirective'];\n if (kind === 'Component') {\n const u = componentUsage(owner);\n if (u) names = [u.pipe ? 'TranslatePipe' : '', u.directive ? 'TranslateDirective' : ''].filter(Boolean);\n }\n const present = new Set(arr.elements.filter(ts.isIdentifier).map((e) => e.text));\n const add = names.filter((n) => !present.has(n));\n touched.add('TranslateModule');\n for (const n of names) needed.add(n);\n if (add.length > 0) {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: add.join(', ') });\n } else {\n edits.push(...removeArrayElements(arr, new Set([arr.elements.indexOf(id)]), sf));\n }\n };\n\n const componentUsage = (owner: ts.ObjectLiteralExpression): { pipe: boolean; directive: boolean } | null => {\n const tpl = propOf(owner, 'template');\n const url = propOf(owner, 'templateUrl');\n const quiet = { members: new Set<string>(), allowKeyRewrite: false, where: (): string => '', quiet: true };\n if (tpl && ts.isPropertyAssignment(tpl) && (ts.isNoSubstitutionTemplateLiteral(tpl.initializer) || ts.isStringLiteral(tpl.initializer))) {\n const lit = tpl.initializer;\n return scanTemplate(source.slice(lit.getStart(sf) + 1, lit.getEnd() - 1), filePath, context, quiet).usage;\n }\n if (url && ts.isPropertyAssignment(url) && ts.isStringLiteralLike(url.initializer)) {\n const target = resolveUrl(dirOf(filePath), url.initializer.text);\n const html = env.read(target);\n if (html !== undefined) return scanTemplate(html, target, context, quiet).usage;\n }\n return null;\n };\n\n // ----- visitor -----\n const visit = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n\n if (ts.isCallExpression(node)) visitCall(node);\n else if (ts.isPropertyAccessExpression(node)) visitMember(node);\n else if (ts.isVariableDeclaration(node)) visitAlias(node.name, node.initializer, node);\n else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) visitAlias(undefined, node.right, node);\n else if (ts.isIdentifier(node)) visitIdentifier(node);\n else if (ts.isClassDeclaration(node)) visitInlineTemplate(node);\n\n ts.forEachChild(node, visit);\n };\n\n const visitCall = (call: ts.CallExpression): void => {\n const c = call.expression;\n if (moduleName && ts.isPropertyAccessExpression(c) && ts.isIdentifier(c.expression) && c.expression.text === moduleName && (c.name.text === 'forRoot' || c.name.text === 'forChild')) {\n convertModuleCall(call);\n return;\n }\n if (ts.isIdentifier(c) && providerNames.has(c.text) && call.arguments[0] && ts.isObjectLiteralExpression(call.arguments[0])) {\n transformConfig(call.arguments[0], false, edits);\n }\n if (setValueName && ts.isIdentifier(c) && c.text === setValueName) {\n const a0 = call.arguments[0];\n const assignable = !!a0 && (ts.isIdentifier(a0) || ts.isPropertyAccessExpression(a0) || ts.isElementAccessExpression(a0));\n if (ts.isExpressionStatement(call.parent) && call.arguments.length === 3 && assignable) {\n edits.push({ start: c.getStart(sf), end: c.getEnd(), replacement: `${a0.getText(sf)} = insertValue` });\n needed.add('insertValue');\n touched.add('setValue');\n } else {\n flag(call, 'setValue() was replaced by insertValue(), which returns a new object instead of mutating its argument. Use `target = insertValue(target, key, value)` manually.');\n }\n }\n if (ts.isPropertyAccessExpression(c) && resolver.isService(c.expression)) {\n if (c.name.text === 'getCurrentLang') {\n flag(call, 'getCurrentLang() returns Language | null in @ngx-translate/core v18 (null before a language is set). Handle the null case, e.g. `?? fallback`.');\n } else if (c.name.text === 'setTranslation' && call.arguments.length === 2 && env.projectHasExtend) {\n flag(call, 'setTranslation(lang, translations) no longer merges for services that used forChild({ extend: true }); pass `true` as third argument if you relied on merging.');\n }\n }\n };\n\n const visitMember = (n: ts.PropertyAccessExpression): void => {\n const member = n.name.text;\n if ((member === 'onTranslationChange' || member === 'getValue') && storeResolver.isService(n.expression)) {\n edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: member === 'getValue' ? 'getTranslationValue' : 'translationChange$',\n });\n return;\n }\n const isTracked = ['currentLang', 'langs', 'defaultLang', ...Object.keys(MEMBER_RENAMES)].includes(member);\n if (!isTracked || !resolver.isService(n.expression)) return;\n const parent = n.parent;\n if (MEMBER_RENAMES[member]) {\n edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: MEMBER_RENAMES[member] });\n return;\n }\n if (ts.isCallExpression(parent) && parent.expression === n) return; // already `currentLang()` etc.\n const isWrite =\n (ts.isBinaryExpression(parent) && parent.left === n && ASSIGN_OPS.has(parent.operatorToken.kind)) ||\n ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) &&\n (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) ||\n ts.isDeleteExpression(parent);\n if (isWrite) {\n flag(n, `${member} cannot be assigned in @ngx-translate/core v18 (read-only Signal / removed). Use use(), setFallbackLang() or setTranslation() instead.`);\n return;\n }\n if (member === 'currentLang') edits.push({ start: n.getEnd(), end: n.getEnd(), replacement: '()' });\n else if (member === 'langs') edits.push({\n start: n.name.getStart(sf),\n end: n.name.getEnd(),\n replacement: 'getLangs()',\n });\n else edits.push({ start: n.name.getStart(sf), end: n.name.getEnd(), replacement: 'fallbackLang()' });\n };\n\n const visitAlias = (name: ts.BindingName | undefined, init: ts.Expression | undefined, at: ts.Node): void => {\n if (!init) return;\n if (!resolver.isService(init) && !(name && ts.isObjectBindingPattern(name) && resolver.isInject(init))) return;\n if (name && ts.isIdentifier(name) && ts.isVariableDeclaration(at) && resolver.isType(at.type)) return; // typed alias is tracked\n flag(\n at,\n 'TranslateService is aliased or destructured here, so currentLang/default*/langs usages through it are not migrated automatically. Review them against the v18 API (currentLang() signal, fallbackLang, getLangs()).'\n );\n };\n\n const visitIdentifier = (id: ts.Identifier): void => {\n const p = id.parent;\n if ((ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id)) return;\n if (httpNames.has(id.text)) {\n const call = ts.isCallExpression(p) && p.expression === id ? p : undefined;\n const cfg = call?.arguments[0];\n const hasFlag = !!cfg && ts.isObjectLiteralExpression(cfg) && !!propOf(cfg, 'failOnError');\n if (!hasFlag) {\n flag(id, 'the v18 http-loader no longer fails the whole language load when a translation file request fails (it logs a warning and uses {}). Pass failOnError: true to provideTranslateHttpLoader() if you rely on the v17 behaviour.');\n }\n }\n if (iServiceName && id.text === iServiceName && ts.isExpressionWithTypeArguments(p) && ts.isHeritageClause(p.parent) && p.parent.token === ts.SyntaxKind.ImplementsKeyword) {\n flag(id, 'ITranslateService gained isLoading: Signal<boolean> in @ngx-translate/core v18. Add isLoading = signal(false).asReadonly() to this class.');\n }\n if (defaultEvent && id.text === 'DefaultLangChangeEvent') {\n edits.push({ start: id.getStart(sf), end: id.getEnd(), replacement: 'FallbackLangChangeEvent' });\n needed.add('FallbackLangChangeEvent');\n touched.add('DefaultLangChangeEvent');\n }\n if (moduleName && id.text === moduleName && !handled.has(id)) {\n // `TranslateModule` as an element of imports / exports\n if (ts.isArrayLiteralExpression(p) && ts.isPropertyAssignment(p.parent) && ['imports', 'exports'].includes(nameOf(p.parent.name) ?? '') && ts.isObjectLiteralExpression(p.parent.parent)) {\n convertBareModule(id, p, p.parent.parent);\n }\n }\n };\n\n const visitInlineTemplate = (cls: ts.ClassDeclaration): void => {\n const tpl = componentProp(cls, 'template');\n if (!tpl) return;\n const lit = tpl.initializer;\n if (!ts.isNoSubstitutionTemplateLiteral(lit) && !ts.isStringLiteral(lit)) return;\n const start = lit.getStart(sf) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (!/translate|currentLang/.test(raw)) return;\n const baseLine = sf.getLineAndCharacterOfPosition(start).line;\n const scan = scanTemplate(raw, filePath, context, {\n members: resolver.members(cls),\n allowKeyRewrite: ts.isNoSubstitutionTemplateLiteral(lit),\n checkAttributes: env.projectUsesNgx,\n where: (o) => `${filePath}:${baseLine + lineOf(raw, o)}`,\n });\n edits.push(...shift(scan.edits, start));\n };\n\n visit(sf);\n\n // moved forRoot/forChild calls: imports -> providers\n for (const [obj, g] of moves) {\n const importsProp = propOf(obj, 'imports') as ts.PropertyAssignment;\n const arr = importsProp.initializer as ts.ArrayLiteralExpression;\n const providersProp = propOf(obj, 'providers');\n if (providersProp && !(ts.isPropertyAssignment(providersProp) && ts.isArrayLiteralExpression(providersProp.initializer))) {\n for (const call of g.calls) flag(call, 'the providers property is not an array literal, so the converted provider could not be moved there. Move it manually.');\n continue;\n }\n const texts = g.texts.join(', ');\n const movedIdx = new Set(g.calls.map((c) => arr.elements.indexOf(c)));\n const keepsOthers = arr.elements.length > movedIdx.size;\n if (providersProp) {\n const parr = (providersProp as ts.PropertyAssignment).initializer as ts.ArrayLiteralExpression;\n if (parr.elements.length > 0) {\n edits.push({\n start: parr.elements[parr.elements.length - 1].getEnd(),\n end: parr.elements[parr.elements.length - 1].getEnd(),\n replacement: `, ${texts}`,\n });\n } else {\n edits.push({ start: parr.getStart(sf) + 1, end: parr.getEnd() - 1, replacement: texts });\n }\n if (keepsOthers) edits.push(...removeArrayElements(arr, movedIdx, sf));\n else removeObjectProperty(importsProp, sf, edits);\n } else if (!keepsOthers) {\n edits.push({ start: importsProp.getStart(sf), end: importsProp.getEnd(), replacement: `providers: [${texts}]` });\n } else {\n edits.push(...removeArrayElements(arr, movedIdx, sf));\n const multiline = source.slice(obj.getStart(sf), importsProp.getEnd()).includes('\\n');\n const indent = multiline ? /[ \\t]*$/.exec(source.slice(0, importsProp.getStart(sf)))![0] : '';\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n edits.push({\n start: importsProp.getEnd(),\n end: importsProp.getEnd(),\n replacement: multiline ? `,${eol}${indent}providers: [${texts}]` : `, providers: [${texts}]`,\n });\n }\n }\n\n // remaining references to the removed module\n if (moduleName) {\n const mark = (n: ts.Node): void => {\n if (ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === moduleName && !handled.has(n) && !isPropertyName(n)) {\n flag(n, 'TranslateModule was removed in @ngx-translate/core v18. Use provideTranslateService() / provideChildTranslateService() and import TranslatePipe / TranslateDirective directly.');\n }\n ts.forEachChild(n, mark);\n };\n mark(sf);\n }\n\n // TODO comments, one line above the anchor, never duplicated\n const eol = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n for (const { anchor, messages } of todos.values()) {\n const start = anchor.getStart(sf);\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))![0];\n const above = new Set<string>();\n const lines = source.slice(0, lineStart).split(/\\r?\\n/);\n for (let i = lines.length - 2; i >= 0 && lines[i].trim().startsWith('// ' + TODO_PREFIX); i--) above.add(lines[i].trim());\n const fresh = messages.map((m) => `// ${TODO_PREFIX} ${m}`).filter((l) => !above.has(l));\n if (fresh.length > 0) edits.push({\n start: lineStart,\n end: lineStart,\n replacement: fresh.map((l) => `${indent}${l}${eol}`).join(''),\n });\n }\n\n let result = applyEdits(source, edits);\n if (result === source) return source;\n result = fixImports(result, filePath, CORE, needed, touched);\n if (importProvidersTouched) result = fixImports(result, filePath, '@angular/core', new Set(), new Set(['importProvidersFrom']));\n return result;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Imports\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst RENAME_IN_PLACE: Record<string, string> = {\n DefaultLangChangeEvent: 'FallbackLangChangeEvent',\n setValue: 'insertValue',\n};\n\n/**\n * Drops `touched` specifiers that are no longer referenced (renaming in place when a rename is known) and\n * appends the `needed` names to the first named import of `moduleName`.\n */\nfunction fixImports(text: string, filePath: string, moduleName: string, needed: Set<string>, touched: Set<string>): string {\n const sf = ts.createSourceFile(filePath, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const referenced = (name: string): boolean => {\n let found = false;\n const walk = (n: ts.Node): void => {\n if (found || ts.isImportDeclaration(n)) return;\n if (ts.isIdentifier(n) && n.text === name && !isPropertyName(n)) found = true;\n ts.forEachChild(n, walk);\n };\n walk(sf);\n return found;\n };\n\n const decls = sf.statements.filter(\n (s): s is ts.ImportDeclaration =>\n ts.isImportDeclaration(s) &&\n ts.isStringLiteral(s.moduleSpecifier) &&\n s.moduleSpecifier.text === moduleName &&\n !!s.importClause?.namedBindings &&\n ts.isNamedImports(s.importClause.namedBindings) &&\n !s.importClause.isTypeOnly\n );\n if (decls.length === 0) return text;\n\n const all = new Set<string>();\n for (const d of decls) for (const e of (d.importClause!.namedBindings as ts.NamedImports).elements) all.add(e.name.text);\n const placed = new Set<string>();\n const edits: Edit[] = [];\n const pendingNeeded = [...needed];\n\n decls.forEach((d, di) => {\n const named = d.importClause!.namedBindings as ts.NamedImports;\n const items: string[] = [];\n for (const e of named.elements) {\n const name = e.name.text;\n if (touched.has(name) && !e.propertyName && !referenced(name)) {\n const to = RENAME_IN_PLACE[name];\n if (to && needed.has(to) && !all.has(to) && !placed.has(to)) {\n items.push(to);\n placed.add(to);\n }\n continue;\n }\n items.push(e.getText(sf));\n }\n if (di === 0) {\n for (const n of pendingNeeded) if (!all.has(n) && !placed.has(n) && !items.includes(n)) items.push(n);\n }\n const before = named.elements.map((e) => e.getText(sf));\n if (items.length === before.length && items.every((v, i) => v === before[i])) return;\n if (items.length === 0 && !d.importClause!.name) {\n let end = d.getEnd();\n if (text[end] === '\\r') end++;\n if (text[end] === '\\n') end++;\n edits.push({ start: d.getStart(sf), end, replacement: '' });\n } else {\n const multiline = named.getText(sf).includes('\\n');\n const body = multiline ? `{\\n ${items.join(',\\n ')},\\n}` : `{ ${items.join(', ')} }`;\n edits.push({ start: named.getStart(sf), end: named.getEnd(), replacement: body });\n }\n });\n return applyEdits(text, edits);\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------------------------------------------------\n\nfunction isPropertyName(id: ts.Identifier): boolean {\n const p = id.parent;\n return (ts.isPropertyAccessExpression(p) && p.name === id) || (ts.isPropertyAssignment(p) && p.name === id);\n}\n\nfunction sanitize(message: string): string {\n return message.replace(/\\s+/g, ' ').trim();\n}\n\n/** Nearest ancestor that is a statement, class member or object property: the TODO goes on the line above it. */\nfunction anchorOf(node: ts.Node): ts.Node {\n let cur = node;\n while (cur.parent) {\n const p = cur.parent;\n if (ts.isSourceFile(p) || ts.isBlock(p) || ts.isModuleBlock(p) || ts.isClassLike(p) || ts.isObjectLiteralExpression(p) || ts.isCaseClause(p) || ts.isDefaultClause(p)) {\n return cur;\n }\n cur = p;\n }\n return cur;\n}\n\nconst dirOf = (p: string): string => dirname(normalize(p));\nconst resolveUrl = (dir: string, url: string): string => normalize(join(normalize(dir), url));\n\nfunction lineOf(source: string, offset: number): number {\n return source.slice(0, offset).split('\\n').length;\n}\n\nfunction shift(edits: Edit[], by: number): Edit[] {\n return edits.map((e) => ({ ...e, start: e.start + by, end: e.end + by }));\n}\n\n/** Removes one object property together with its separating comma. */\nfunction removeObjectProperty(prop: ts.ObjectLiteralElementLike, sf: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sf.getFullText();\n let start = prop.getStart(sf);\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getStart(sf);\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\n/** Removes the array elements at `indices`; non-overlapping ranges even for neighbouring elements. */\nfunction removeArrayElements(arr: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression, indices: Set<number>, sf: ts.SourceFile): Edit[] {\n const els: readonly ts.Node[] = ts.isArrayLiteralExpression(arr) ? arr.elements : arr.properties;\n const keptIdx = els.findIndex((_, i) => !indices.has(i));\n if (keptIdx === -1) return [{ start: arr.getStart(sf) + 1, end: arr.getEnd() - 1, replacement: '' }];\n const out: Edit[] = [];\n if (keptIdx > 0) out.push({ start: els[0].getStart(sf), end: els[keptIdx].getStart(sf), replacement: '' });\n for (let i = keptIdx + 1; i < els.length; i++) {\n if (indices.has(i)) out.push({ start: els[i - 1].getEnd(), end: els[i].getEnd(), replacement: '' });\n }\n return out;\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const seen = new Map<string, Edit>();\n for (const e of edits) seen.set(`${e.start}:${e.end}:${e.replacement}`, e);\n let result = source;\n for (const e of [...seen.values()].sort((a, b) => b.start - a.start || b.end - a.end)) {\n result = result.slice(0, e.start) + e.replacement + result.slice(e.end);\n }\n return result;\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
5925
|
+
"sourceCode": "import { BindingType, parseTemplate, TmplAstElement, TmplAstNode } from '@angular/compiler';\nimport { DirEntry, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { logDryRun, logDryRunNote } from '../utils/dry-run';\nimport { createTodoEdit } from '../utils/todo-comment';\nimport { forEachElement } from '../utils/template-walk';\n\ninterface Schema {\n path?: string;\n dryRun?: boolean;\n}\n\ninterface Edit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst OLD_CLASS = 'EuiTooltipConfig';\nconst NEW_INTERFACE = 'EuiTooltipInterface';\nconst REMOVED_ANIMATION = 'showHide';\nconst DIRECTIVE_CLASS = 'EuiTooltipDirective';\n\nconst RENAMED_INPUTS: Record<string, string> = {\n isPrimary: 'euiTooltipPrimary',\n isSecondary: 'euiTooltipSecondary',\n isInfo: 'euiTooltipInfo',\n isSuccess: 'euiTooltipSuccess',\n isWarning: 'euiTooltipWarning',\n isDanger: 'euiTooltipDanger',\n isAccent: 'euiTooltipAccent',\n};\n\nexport function migrateEuiTooltip(options: Schema = {}): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const scanPath = options.path ? '/' + options.path.replace(/^\\.?\\//, '').replace(/\\/$/, '') : '';\n let fileCount = 0;\n\n visitDir(tree.getDir(scanPath || '/'), (path) => {\n const buffer = tree.read(path);\n if (!buffer) return;\n\n const original = buffer.toString('utf-8');\n let result = original;\n if (path.endsWith('.html')) {\n if (!original.includes('euiTooltip')) return;\n result = migrateTemplate(original, path, context);\n } else {\n if (\n !original.includes(OLD_CLASS) &&\n !original.includes(REMOVED_ANIMATION) &&\n !original.includes('euiTooltip') &&\n !original.includes(DIRECTIVE_CLASS)\n ) {\n return;\n }\n if (original.includes(OLD_CLASS)) result = migrateTypeScript(result, path, context);\n if (result.includes(DIRECTIVE_CLASS)) result = migrateProgrammaticUsage(result, path, context);\n if (result.includes(REMOVED_ANIMATION)) result = removeShowHideAnimation(result, path, context);\n if (result.includes('euiTooltip')) result = migrateInlineTemplates(result, path, context);\n }\n\n if (result !== original) {\n if (options.dryRun) {\n logDryRun(context, `Would migrate eui-tooltip usages in ${path}`);\n } else {\n tree.overwrite(path, result);\n }\n fileCount++;\n }\n });\n\n context.logger.info(`Migrated eui-tooltip usages in ${fileCount} file(s).`);\n if (options.dryRun) {\n logDryRunNote(context);\n }\n return tree;\n };\n}\n\nfunction migrateTypeScript(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n\n // Track if EuiTooltipInterface is already imported\n let hasInterfaceImport = false;\n let classImportDecl: ts.ImportDeclaration | null = null;\n let classImportModuleSpecifier: string | null = null;\n\n // First pass: analyze imports\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n for (const specifier of namedBindings.elements) {\n if (specifier.name.text === NEW_INTERFACE) {\n hasInterfaceImport = true;\n }\n if (specifier.name.text === OLD_CLASS) {\n classImportDecl = stmt;\n classImportModuleSpecifier = (stmt.moduleSpecifier as ts.StringLiteral).text;\n }\n }\n }\n\n // Second pass: handle import declarations\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const namedBindings = stmt.importClause?.namedBindings;\n if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;\n\n const specifiers = namedBindings.elements;\n const classSpecifier = specifiers.find((s) => s.name.text === OLD_CLASS);\n if (!classSpecifier) continue;\n\n if (hasInterfaceImport) {\n // EuiTooltipInterface is already imported elsewhere → remove EuiTooltipConfig from this import\n removeImportSpecifier(namedBindings, classSpecifier, sourceFile, edits);\n } else {\n // Rename EuiTooltipConfig → EuiTooltipInterface in the import\n edits.push({\n start: classSpecifier.name.getStart(sourceFile),\n end: classSpecifier.name.getEnd(),\n replacement: NEW_INTERFACE,\n });\n hasInterfaceImport = true;\n }\n }\n\n // Third pass: replace `new EuiTooltipConfig(...)` → spread/cast to interface\n const visitNewExpressions = (node: ts.Node): void => {\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) {\n const args = node.arguments;\n if (args !== undefined && args.length === 1) {\n const arg = args[0];\n // `new EuiTooltipConfig({ ... })` → `{ ... } as EuiTooltipInterface`\n // But if the argument is just a variable, we keep it: `varName as EuiTooltipInterface`\n const argText = source.slice(arg.getStart(sourceFile), arg.getEnd());\n\n if (ts.isObjectLiteralExpression(arg)) {\n // Inline object: `new EuiTooltipConfig({ x: 1 })` → `{ x: 1 }`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n } else {\n // Variable or expression: `new EuiTooltipConfig(opts)` → `opts`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: argText,\n });\n }\n } else if (args === undefined || args.length === 0) {\n // `new EuiTooltipConfig()` → `{} as EuiTooltipInterface`\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: `{} as ${NEW_INTERFACE}`,\n });\n }\n return; // don't recurse into children we've already replaced\n }\n ts.forEachChild(node, visitNewExpressions);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitNewExpressions(stmt);\n }\n }\n\n // Fourth pass: rename all remaining identifier references (type annotations, etc.)\n const visitRefs = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node)) return;\n // Skip nodes we already covered in new expressions\n if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === OLD_CLASS) return;\n\n if (ts.isIdentifier(node) && node.text === OLD_CLASS) {\n // Ensure this is not part of an import declaration\n if (!isPartOfImport(node)) {\n edits.push({\n start: node.getStart(sourceFile),\n end: node.getEnd(),\n replacement: NEW_INTERFACE,\n });\n }\n }\n ts.forEachChild(node, visitRefs);\n };\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) {\n visitRefs(stmt);\n }\n }\n\n return applyEdits(source, edits);\n}\n\n/** Removes the `showHide` animation (import + `animations: [...]` entries) imported from an @eui package. */\nfunction removeShowHideAnimation(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n let found = false;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;\n if (!stmt.moduleSpecifier.text.startsWith('@eui/')) continue;\n const named = stmt.importClause?.namedBindings;\n if (!named || !ts.isNamedImports(named)) continue;\n const spec = named.elements.find((e) => e.name.text === REMOVED_ANIMATION && !e.propertyName);\n if (!spec) continue;\n found = true;\n removeImportSpecifier(named, spec, sourceFile, edits);\n }\n if (!found) return source;\n\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'animations' &&\n ts.isArrayLiteralExpression(node.initializer)\n ) {\n const arr = node.initializer;\n const kept = arr.elements.filter((e) => !(ts.isIdentifier(e) && e.text === REMOVED_ANIMATION));\n if (kept.length !== arr.elements.length) {\n if (kept.length === 0) {\n removeObjectProperty(node, sourceFile, edits);\n } else {\n edits.push({\n start: arr.getStart(sourceFile) + 1,\n end: arr.getEnd() - 1,\n replacement: kept.map((e) => e.getText(sourceFile)).join(', '),\n });\n }\n }\n } else if (ts.isIdentifier(node) && node.text === REMOVED_ANIMATION && !isPartOfImport(node) && !isInRemovedArray(node)) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));\n context.logger.warn(`${filePath}:${line + 1} - Manual action needed: the \"showHide\" animation has been removed from @eui/components.`);\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction isInRemovedArray(node: ts.Node): boolean {\n const parent = node.parent;\n return (\n !!parent &&\n ts.isArrayLiteralExpression(parent) &&\n ts.isPropertyAssignment(parent.parent) &&\n ts.isIdentifier(parent.parent.name) &&\n parent.parent.name.text === 'animations'\n );\n}\n\nfunction removeObjectProperty(prop: ts.PropertyAssignment, sourceFile: ts.SourceFile, edits: Edit[]): void {\n const obj = prop.parent as ts.ObjectLiteralExpression;\n const props = obj.properties;\n const idx = props.indexOf(prop);\n const text = sourceFile.getFullText();\n let start = prop.getFullStart();\n let end = prop.getEnd();\n if (idx < props.length - 1) {\n end = props[idx + 1].getFullStart();\n } else if (idx > 0) {\n start = props[idx - 1].getEnd();\n } else if (text[end] === ',') {\n end++;\n }\n edits.push({ start, end, replacement: '' });\n}\n\nfunction migrateInlineTemplates(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const visit = (node: ts.Node): void => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'template' &&\n (ts.isNoSubstitutionTemplateLiteral(node.initializer) || ts.isStringLiteral(node.initializer))\n ) {\n const lit = node.initializer;\n const start = lit.getStart(sourceFile) + 1;\n const raw = source.slice(start, lit.getEnd() - 1);\n if (raw.includes('euiTooltip')) {\n const migrated = migrateTemplate(raw, filePath, context);\n if (migrated !== raw) edits.push({ start, end: lit.getEnd() - 1, replacement: migrated });\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction migrateTemplate(source: string, filePath: string, context: SchematicContext): string {\n const parsed = parseTemplate(source, filePath, { preserveWhitespaces: true });\n const edits: Edit[] = [];\n visitNodes(parsed.nodes, source, filePath, context, edits);\n return applyEdits(source, edits);\n}\n\nfunction visitNodes(nodes: TmplAstNode[], source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n forEachElement(nodes, (node) => collectElementEdits(node, source, filePath, context, edits));\n}\n\nfunction collectElementEdits(el: TmplAstElement, source: string, filePath: string, context: SchematicContext, edits: Edit[]): void {\n const tooltipAttr = el.attributes.find((a) => a.name === 'euiTooltip');\n const tooltipInput = el.inputs.find((i) => i.name === 'euiTooltip' && i.type === BindingType.Property);\n if (!tooltipAttr && !tooltipInput) return;\n\n // All messages of one element are merged into ONE comment: several TODOs would be inserted at the\n // same offset and overwrite each other.\n const messages: string[] = [];\n const warn = (offset: number, message: string): void => {\n messages.push(message);\n const { line } = lineOf(source, offset);\n context.logger.warn(`${filePath}:${line} - Manual action needed on <${el.name}>: ${message}`);\n };\n\n for (const attr of el.attributes) {\n if (RENAMED_INPUTS[attr.name]) {\n edits.push({ start: attr.keySpan!.start.offset, end: attr.keySpan!.end.offset, replacement: RENAMED_INPUTS[attr.name] });\n }\n }\n for (const input of el.inputs) {\n if (input.type === BindingType.Property && RENAMED_INPUTS[input.name]) {\n edits.push({ start: input.keySpan!.start.offset, end: input.keySpan!.end.offset, replacement: RENAMED_INPUTS[input.name] });\n }\n }\n\n // `position`: the migration guide lists it as removed, but EuiTooltipDirective still declares it\n // (model()). Deleting it would silently change behavior, so it is kept and flagged.\n const position = [\n ...el.attributes.filter((a) => a.name === 'position'),\n ...el.inputs.filter((i) => i.type === BindingType.Property && i.name === 'position'),\n ][0];\n if (position) {\n warn(\n position.sourceSpan.start.offset,\n 'input position of euiTooltip is documented as removed in eUI v22 but is still declared by EuiTooltipDirective. It was kept unchanged; verify it against the version you upgrade to.',\n );\n }\n\n const config = el.inputs.find((i) => i.type === BindingType.Property && i.name === 'config');\n if (config) {\n warn(\n config.sourceSpan.start.offset,\n 'input config of euiTooltip has been removed. Use the individual inputs (euiTooltip, euiTooltipPrimary, showDelay, hideDelay, contentAlignment, isDisabled) instead.',\n );\n }\n\n if (tooltipAttr && !tooltipAttr.value && !tooltipInput) {\n warn(tooltipAttr.sourceSpan.start.offset, 'input euiTooltip is now required and needs a value, e.g. euiTooltip=\"My tooltip\".');\n }\n\n if (messages.length > 0) {\n const todo = createTodoEdit(source, el.startSourceSpan.start.offset, messages.join(' '));\n if (todo) edits.push(todo);\n }\n}\n\n/**\n * Programmatic usage of a `EuiTooltipDirective` reference (`tt.isPrimary = true`, `tt.config`).\n * Renamed flags are renamed; `config` cannot be migrated and is flagged. Name based, scope aware for\n * parameters/variables (a differently typed parameter with the same name is left alone).\n * shortcut: only `this.x` and locals/params typed `EuiTooltipDirective` are followed; aliases are not.\n */\nfunction migrateProgrammaticUsage(source: string, filePath: string, context: SchematicContext): string {\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const edits: Edit[] = [];\n const isTyped = (t: ts.TypeNode | undefined): boolean =>\n !!t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && t.typeName.text === DIRECTIVE_CLASS;\n const isViewChildOf = (n: ts.PropertyDeclaration): boolean =>\n (ts.getDecorators?.(n) ?? []).some(\n (d) =>\n ts.isCallExpression(d.expression) &&\n ['ViewChild', 'ContentChild'].includes(d.expression.expression.getText(sourceFile)) &&\n d.expression.arguments[0]?.getText(sourceFile) === DIRECTIVE_CLASS,\n );\n\n const props = new Set<string>();\n const collect = (n: ts.Node): void => {\n if (ts.isPropertyDeclaration(n) && ts.isIdentifier(n.name) && (isTyped(n.type) || isViewChildOf(n))) props.add(n.name.text);\n ts.forEachChild(n, collect);\n };\n collect(sourceFile);\n\n /** Nearest declaration of a bare identifier: true = typed directive, false = something else, undefined = none found. */\n const bareIsDirective = (id: ts.Identifier): boolean | undefined => {\n for (let cur: ts.Node | undefined = id.parent; cur; cur = cur.parent) {\n let decls: readonly (ts.ParameterDeclaration | ts.VariableDeclaration)[] = [];\n if (ts.isFunctionLike(cur)) decls = cur.parameters;\n else if (ts.isBlock(cur) || ts.isSourceFile(cur)) {\n decls = cur.statements.filter(ts.isVariableStatement).flatMap((s) => [...s.declarationList.declarations]);\n } else if (ts.isCatchClause(cur) && cur.variableDeclaration) decls = [cur.variableDeclaration];\n else if ((ts.isForStatement(cur) || ts.isForOfStatement(cur) || ts.isForInStatement(cur)) && cur.initializer && ts.isVariableDeclarationList(cur.initializer)) {\n decls = cur.initializer.declarations;\n }\n const d = decls.find((x) => ts.isIdentifier(x.name) && x.name.text === id.text);\n if (d) return isTyped(d.type);\n }\n return undefined;\n };\n\n const visit = (n: ts.Node): void => {\n if (ts.isPropertyAccessExpression(n) && (RENAMED_INPUTS[n.name.text] || n.name.text === 'config')) {\n const target = n.expression;\n const tracked =\n (ts.isPropertyAccessExpression(target) && target.expression.kind === ts.SyntaxKind.ThisKeyword && props.has(target.name.text)) ||\n (ts.isIdentifier(target) && bareIsDirective(target) === true);\n if (tracked) {\n if (RENAMED_INPUTS[n.name.text]) {\n edits.push({ start: n.name.getStart(sourceFile), end: n.name.getEnd(), replacement: RENAMED_INPUTS[n.name.text] });\n } else {\n const { line } = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));\n context.logger.warn(\n `${filePath}:${line + 1} - Manual action needed: the \"config\" input of EuiTooltipDirective has been removed. Use the individual inputs instead.`,\n );\n }\n }\n }\n ts.forEachChild(n, visit);\n };\n visit(sourceFile);\n return applyEdits(source, edits);\n}\n\nfunction lineOf(source: string, offset: number): { line: number } {\n return { line: source.slice(0, offset).split('\\n').length };\n}\n\nfunction isPartOfImport(node: ts.Node): boolean {\n let current: ts.Node | undefined = node.parent;\n while (current) {\n if (ts.isImportDeclaration(current)) return true;\n current = current.parent;\n }\n return false;\n}\n\nfunction removeImportSpecifier(\n namedImports: ts.NamedImports,\n specifier: ts.ImportSpecifier,\n sourceFile: ts.SourceFile,\n edits: Edit[],\n): void {\n const elements = namedImports.elements;\n if (elements.length === 1) {\n // Remove the entire import declaration\n const importDecl = namedImports.parent.parent;\n let end = importDecl.getEnd();\n // Also remove trailing newline if present\n const fullText = sourceFile.getFullText();\n if (fullText[end] === '\\n') end++;\n edits.push({\n start: importDecl.getStart(sourceFile),\n end,\n replacement: '',\n });\n } else {\n // Remove just this specifier with surrounding comma/whitespace\n const idx = elements.indexOf(specifier);\n let start: number;\n let end: number;\n if (idx < elements.length - 1) {\n // Not the last → remove from this specifier start to next specifier start\n start = specifier.getStart(sourceFile);\n end = elements[idx + 1].getStart(sourceFile);\n } else {\n // Last element → remove from previous element end to this end\n start = elements[idx - 1].getEnd();\n end = specifier.getEnd();\n }\n edits.push({ start, end, replacement: '' });\n }\n}\n\nfunction applyEdits(source: string, edits: Edit[]): string {\n const unique = deduplicateEdits(edits);\n let result = source;\n for (const edit of unique.sort((a, b) => b.start - a.start)) {\n result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n }\n return result;\n}\n\nfunction deduplicateEdits(edits: Edit[]): Edit[] {\n const seen = new Map<string, Edit>();\n for (const edit of edits) {\n const key = `${edit.start}:${edit.end}`;\n seen.set(key, edit);\n }\n return Array.from(seen.values());\n}\n\nfunction visitDir(dir: DirEntry, callback: (path: string) => void): void {\n for (const file of dir.subfiles) {\n if (file.endsWith('.d.ts')) continue;\n if (!file.endsWith('.ts') && !file.endsWith('.html')) continue;\n callback(`${dir.path}/${file}`);\n }\n for (const sub of dir.subdirs) {\n if (sub === 'node_modules' || sub === 'dist') continue;\n visitDir(dir.dir(sub), callback);\n }\n}\n",
|
|
5924
5926
|
"displayName": "Schema",
|
|
5925
5927
|
"properties": [
|
|
5926
5928
|
{
|
|
@@ -5932,7 +5934,7 @@
|
|
|
5932
5934
|
"indexKey": "",
|
|
5933
5935
|
"optional": true,
|
|
5934
5936
|
"description": "",
|
|
5935
|
-
"line":
|
|
5937
|
+
"line": 10,
|
|
5936
5938
|
"rawdescription": "\n"
|
|
5937
5939
|
},
|
|
5938
5940
|
{
|
|
@@ -5944,14 +5946,12 @@
|
|
|
5944
5946
|
"indexKey": "",
|
|
5945
5947
|
"optional": true,
|
|
5946
5948
|
"description": "",
|
|
5947
|
-
"line":
|
|
5949
|
+
"line": 9,
|
|
5948
5950
|
"rawdescription": "\n"
|
|
5949
5951
|
}
|
|
5950
5952
|
],
|
|
5951
5953
|
"indexSignatures": [],
|
|
5952
5954
|
"kind": 172,
|
|
5953
|
-
"description": "<p>Migrates @ngx-translate/core v17 -> v18 breaking changes.</p>\n<p>No type checker is used: a <code>TranslateService</code> receiver is resolved from its declaration in the same\nfile (<code>: TranslateService</code>, <code>inject(TranslateService)</code>, constructor parameter properties) and, for\ntemplates, from the component class that owns the template.\nshortcut: receivers that are aliased, destructured, passed through other types or declared in another\nfile are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.</p>\n",
|
|
5954
|
-
"rawdescription": "\n\nMigrates @ngx-translate/core v17 -> v18 breaking changes.\n\nNo type checker is used: a `TranslateService` receiver is resolved from its declaration in the same\nfile (`: TranslateService`, `inject(TranslateService)`, constructor parameter properties) and, for\ntemplates, from the component class that owns the template.\nshortcut: receivers that are aliased, destructured, passed through other types or declared in another\nfile are not followed (they are flagged where detectable); upgrade to a ts.Program when needed.\n",
|
|
5955
5955
|
"methods": [],
|
|
5956
5956
|
"extends": [],
|
|
5957
5957
|
"isDuplicate": true,
|
|
@@ -26260,23 +26260,23 @@
|
|
|
26260
26260
|
"name": "COMPONENT_TAG",
|
|
26261
26261
|
"ctype": "miscellaneous",
|
|
26262
26262
|
"subtype": "variable",
|
|
26263
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
26263
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
26264
26264
|
"coverageIgnore": false,
|
|
26265
26265
|
"deprecated": false,
|
|
26266
26266
|
"deprecationMessage": "",
|
|
26267
26267
|
"type": "string",
|
|
26268
|
-
"defaultValue": "'eui-
|
|
26268
|
+
"defaultValue": "'eui-discussion-thread'"
|
|
26269
26269
|
},
|
|
26270
26270
|
{
|
|
26271
26271
|
"name": "COMPONENT_TAG",
|
|
26272
26272
|
"ctype": "miscellaneous",
|
|
26273
26273
|
"subtype": "variable",
|
|
26274
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
26274
|
+
"file": "packages/core/schematics/migrate-eui-editor/index.ts",
|
|
26275
26275
|
"coverageIgnore": false,
|
|
26276
26276
|
"deprecated": false,
|
|
26277
26277
|
"deprecationMessage": "",
|
|
26278
26278
|
"type": "string",
|
|
26279
|
-
"defaultValue": "'eui-
|
|
26279
|
+
"defaultValue": "'eui-editor'"
|
|
26280
26280
|
},
|
|
26281
26281
|
{
|
|
26282
26282
|
"name": "COMPONENT_TAG",
|
|
@@ -30745,7 +30745,7 @@
|
|
|
30745
30745
|
},
|
|
30746
30746
|
{
|
|
30747
30747
|
"name": "applyEdits",
|
|
30748
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
30748
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
30749
30749
|
"ctype": "miscellaneous",
|
|
30750
30750
|
"subtype": "function",
|
|
30751
30751
|
"coverageIgnore": false,
|
|
@@ -30790,7 +30790,7 @@
|
|
|
30790
30790
|
},
|
|
30791
30791
|
{
|
|
30792
30792
|
"name": "applyEdits",
|
|
30793
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
30793
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
30794
30794
|
"ctype": "miscellaneous",
|
|
30795
30795
|
"subtype": "function",
|
|
30796
30796
|
"coverageIgnore": false,
|
|
@@ -31375,7 +31375,7 @@
|
|
|
31375
31375
|
},
|
|
31376
31376
|
{
|
|
31377
31377
|
"name": "applyEdits",
|
|
31378
|
-
"file": "packages/core/schematics/migrate-
|
|
31378
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
31379
31379
|
"ctype": "miscellaneous",
|
|
31380
31380
|
"subtype": "function",
|
|
31381
31381
|
"coverageIgnore": false,
|
|
@@ -31420,7 +31420,7 @@
|
|
|
31420
31420
|
},
|
|
31421
31421
|
{
|
|
31422
31422
|
"name": "applyEdits",
|
|
31423
|
-
"file": "packages/core/schematics/migrate-
|
|
31423
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
31424
31424
|
"ctype": "miscellaneous",
|
|
31425
31425
|
"subtype": "function",
|
|
31426
31426
|
"coverageIgnore": false,
|
|
@@ -32961,7 +32961,7 @@
|
|
|
32961
32961
|
},
|
|
32962
32962
|
{
|
|
32963
32963
|
"name": "collectElementRename",
|
|
32964
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
32964
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
32965
32965
|
"ctype": "miscellaneous",
|
|
32966
32966
|
"subtype": "function",
|
|
32967
32967
|
"coverageIgnore": false,
|
|
@@ -32977,12 +32977,6 @@
|
|
|
32977
32977
|
"deprecated": false,
|
|
32978
32978
|
"deprecationMessage": ""
|
|
32979
32979
|
},
|
|
32980
|
-
{
|
|
32981
|
-
"name": "mapping",
|
|
32982
|
-
"type": "SelectorMapping",
|
|
32983
|
-
"deprecated": false,
|
|
32984
|
-
"deprecationMessage": ""
|
|
32985
|
-
},
|
|
32986
32980
|
{
|
|
32987
32981
|
"name": "edits",
|
|
32988
32982
|
"deprecated": false,
|
|
@@ -33000,15 +32994,6 @@
|
|
|
33000
32994
|
"text": "param"
|
|
33001
32995
|
}
|
|
33002
32996
|
},
|
|
33003
|
-
{
|
|
33004
|
-
"name": "mapping",
|
|
33005
|
-
"type": "SelectorMapping",
|
|
33006
|
-
"deprecated": false,
|
|
33007
|
-
"deprecationMessage": "",
|
|
33008
|
-
"tagName": {
|
|
33009
|
-
"text": "param"
|
|
33010
|
-
}
|
|
33011
|
-
},
|
|
33012
32997
|
{
|
|
33013
32998
|
"name": "edits",
|
|
33014
32999
|
"deprecated": false,
|
|
@@ -33021,7 +33006,7 @@
|
|
|
33021
33006
|
},
|
|
33022
33007
|
{
|
|
33023
33008
|
"name": "collectElementRename",
|
|
33024
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
33009
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
33025
33010
|
"ctype": "miscellaneous",
|
|
33026
33011
|
"subtype": "function",
|
|
33027
33012
|
"coverageIgnore": false,
|
|
@@ -33037,6 +33022,12 @@
|
|
|
33037
33022
|
"deprecated": false,
|
|
33038
33023
|
"deprecationMessage": ""
|
|
33039
33024
|
},
|
|
33025
|
+
{
|
|
33026
|
+
"name": "mapping",
|
|
33027
|
+
"type": "SelectorMapping",
|
|
33028
|
+
"deprecated": false,
|
|
33029
|
+
"deprecationMessage": ""
|
|
33030
|
+
},
|
|
33040
33031
|
{
|
|
33041
33032
|
"name": "edits",
|
|
33042
33033
|
"deprecated": false,
|
|
@@ -33054,6 +33045,15 @@
|
|
|
33054
33045
|
"text": "param"
|
|
33055
33046
|
}
|
|
33056
33047
|
},
|
|
33048
|
+
{
|
|
33049
|
+
"name": "mapping",
|
|
33050
|
+
"type": "SelectorMapping",
|
|
33051
|
+
"deprecated": false,
|
|
33052
|
+
"deprecationMessage": "",
|
|
33053
|
+
"tagName": {
|
|
33054
|
+
"text": "param"
|
|
33055
|
+
}
|
|
33056
|
+
},
|
|
33057
33057
|
{
|
|
33058
33058
|
"name": "edits",
|
|
33059
33059
|
"deprecated": false,
|
|
@@ -36069,7 +36069,7 @@
|
|
|
36069
36069
|
},
|
|
36070
36070
|
{
|
|
36071
36071
|
"name": "deduplicateEdits",
|
|
36072
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
36072
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
36073
36073
|
"ctype": "miscellaneous",
|
|
36074
36074
|
"subtype": "function",
|
|
36075
36075
|
"coverageIgnore": false,
|
|
@@ -36099,7 +36099,7 @@
|
|
|
36099
36099
|
},
|
|
36100
36100
|
{
|
|
36101
36101
|
"name": "deduplicateEdits",
|
|
36102
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
36102
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
36103
36103
|
"ctype": "miscellaneous",
|
|
36104
36104
|
"subtype": "function",
|
|
36105
36105
|
"coverageIgnore": false,
|
|
@@ -40964,7 +40964,7 @@
|
|
|
40964
40964
|
},
|
|
40965
40965
|
{
|
|
40966
40966
|
"name": "isComponentMetadataProperty",
|
|
40967
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
40967
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
40968
40968
|
"ctype": "miscellaneous",
|
|
40969
40969
|
"subtype": "function",
|
|
40970
40970
|
"coverageIgnore": false,
|
|
@@ -40994,7 +40994,7 @@
|
|
|
40994
40994
|
},
|
|
40995
40995
|
{
|
|
40996
40996
|
"name": "isComponentMetadataProperty",
|
|
40997
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
40997
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
40998
40998
|
"ctype": "miscellaneous",
|
|
40999
40999
|
"subtype": "function",
|
|
41000
41000
|
"coverageIgnore": false,
|
|
@@ -42411,7 +42411,7 @@
|
|
|
42411
42411
|
},
|
|
42412
42412
|
{
|
|
42413
42413
|
"name": "isTemplateProperty",
|
|
42414
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
42414
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
42415
42415
|
"ctype": "miscellaneous",
|
|
42416
42416
|
"subtype": "function",
|
|
42417
42417
|
"coverageIgnore": false,
|
|
@@ -42441,7 +42441,7 @@
|
|
|
42441
42441
|
},
|
|
42442
42442
|
{
|
|
42443
42443
|
"name": "isTemplateProperty",
|
|
42444
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
42444
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
42445
42445
|
"ctype": "miscellaneous",
|
|
42446
42446
|
"subtype": "function",
|
|
42447
42447
|
"coverageIgnore": false,
|
|
@@ -42955,7 +42955,7 @@
|
|
|
42955
42955
|
},
|
|
42956
42956
|
{
|
|
42957
42957
|
"name": "lineOf",
|
|
42958
|
-
"file": "packages/core/schematics/migrate-
|
|
42958
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
42959
42959
|
"ctype": "miscellaneous",
|
|
42960
42960
|
"subtype": "function",
|
|
42961
42961
|
"coverageIgnore": false,
|
|
@@ -42978,7 +42978,7 @@
|
|
|
42978
42978
|
"deprecationMessage": ""
|
|
42979
42979
|
}
|
|
42980
42980
|
],
|
|
42981
|
-
"returnType": "
|
|
42981
|
+
"returnType": "number",
|
|
42982
42982
|
"jsdoctags": [
|
|
42983
42983
|
{
|
|
42984
42984
|
"name": "source",
|
|
@@ -43002,7 +43002,7 @@
|
|
|
43002
43002
|
},
|
|
43003
43003
|
{
|
|
43004
43004
|
"name": "lineOf",
|
|
43005
|
-
"file": "packages/core/schematics/migrate-
|
|
43005
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
43006
43006
|
"ctype": "miscellaneous",
|
|
43007
43007
|
"subtype": "function",
|
|
43008
43008
|
"coverageIgnore": false,
|
|
@@ -43025,7 +43025,7 @@
|
|
|
43025
43025
|
"deprecationMessage": ""
|
|
43026
43026
|
}
|
|
43027
43027
|
],
|
|
43028
|
-
"returnType": "number",
|
|
43028
|
+
"returnType": "{ line: number }",
|
|
43029
43029
|
"jsdoctags": [
|
|
43030
43030
|
{
|
|
43031
43031
|
"name": "source",
|
|
@@ -45751,7 +45751,7 @@
|
|
|
45751
45751
|
},
|
|
45752
45752
|
{
|
|
45753
45753
|
"name": "migrateInlineTemplates",
|
|
45754
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
45754
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
45755
45755
|
"ctype": "miscellaneous",
|
|
45756
45756
|
"subtype": "function",
|
|
45757
45757
|
"coverageIgnore": false,
|
|
@@ -45766,11 +45766,6 @@
|
|
|
45766
45766
|
"type": "string",
|
|
45767
45767
|
"deprecated": false,
|
|
45768
45768
|
"deprecationMessage": ""
|
|
45769
|
-
},
|
|
45770
|
-
{
|
|
45771
|
-
"name": "warn",
|
|
45772
|
-
"deprecated": false,
|
|
45773
|
-
"deprecationMessage": ""
|
|
45774
45769
|
}
|
|
45775
45770
|
],
|
|
45776
45771
|
"returnType": "string",
|
|
@@ -45783,20 +45778,12 @@
|
|
|
45783
45778
|
"tagName": {
|
|
45784
45779
|
"text": "param"
|
|
45785
45780
|
}
|
|
45786
|
-
},
|
|
45787
|
-
{
|
|
45788
|
-
"name": "warn",
|
|
45789
|
-
"deprecated": false,
|
|
45790
|
-
"deprecationMessage": "",
|
|
45791
|
-
"tagName": {
|
|
45792
|
-
"text": "param"
|
|
45793
|
-
}
|
|
45794
45781
|
}
|
|
45795
45782
|
]
|
|
45796
45783
|
},
|
|
45797
45784
|
{
|
|
45798
45785
|
"name": "migrateInlineTemplates",
|
|
45799
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
45786
|
+
"file": "packages/core/schematics/migrate-eui-dialog/index.ts",
|
|
45800
45787
|
"ctype": "miscellaneous",
|
|
45801
45788
|
"subtype": "function",
|
|
45802
45789
|
"coverageIgnore": false,
|
|
@@ -45811,6 +45798,11 @@
|
|
|
45811
45798
|
"type": "string",
|
|
45812
45799
|
"deprecated": false,
|
|
45813
45800
|
"deprecationMessage": ""
|
|
45801
|
+
},
|
|
45802
|
+
{
|
|
45803
|
+
"name": "warn",
|
|
45804
|
+
"deprecated": false,
|
|
45805
|
+
"deprecationMessage": ""
|
|
45814
45806
|
}
|
|
45815
45807
|
],
|
|
45816
45808
|
"returnType": "string",
|
|
@@ -45823,12 +45815,20 @@
|
|
|
45823
45815
|
"tagName": {
|
|
45824
45816
|
"text": "param"
|
|
45825
45817
|
}
|
|
45818
|
+
},
|
|
45819
|
+
{
|
|
45820
|
+
"name": "warn",
|
|
45821
|
+
"deprecated": false,
|
|
45822
|
+
"deprecationMessage": "",
|
|
45823
|
+
"tagName": {
|
|
45824
|
+
"text": "param"
|
|
45825
|
+
}
|
|
45826
45826
|
}
|
|
45827
45827
|
]
|
|
45828
45828
|
},
|
|
45829
45829
|
{
|
|
45830
45830
|
"name": "migrateInlineTemplates",
|
|
45831
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
45831
|
+
"file": "packages/core/schematics/migrate-eui-editor/index.ts",
|
|
45832
45832
|
"ctype": "miscellaneous",
|
|
45833
45833
|
"subtype": "function",
|
|
45834
45834
|
"coverageIgnore": false,
|
|
@@ -46894,7 +46894,7 @@
|
|
|
46894
46894
|
},
|
|
46895
46895
|
{
|
|
46896
46896
|
"name": "migrateTemplate",
|
|
46897
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
46897
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
46898
46898
|
"ctype": "miscellaneous",
|
|
46899
46899
|
"subtype": "function",
|
|
46900
46900
|
"coverageIgnore": false,
|
|
@@ -46926,7 +46926,7 @@
|
|
|
46926
46926
|
},
|
|
46927
46927
|
{
|
|
46928
46928
|
"name": "migrateTemplate",
|
|
46929
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
46929
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
46930
46930
|
"ctype": "miscellaneous",
|
|
46931
46931
|
"subtype": "function",
|
|
46932
46932
|
"coverageIgnore": false,
|
|
@@ -47150,7 +47150,7 @@
|
|
|
47150
47150
|
},
|
|
47151
47151
|
{
|
|
47152
47152
|
"name": "migrateTemplate",
|
|
47153
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
47153
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
47154
47154
|
"ctype": "miscellaneous",
|
|
47155
47155
|
"subtype": "function",
|
|
47156
47156
|
"coverageIgnore": false,
|
|
@@ -47182,7 +47182,7 @@
|
|
|
47182
47182
|
},
|
|
47183
47183
|
{
|
|
47184
47184
|
"name": "migrateTemplate",
|
|
47185
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
47185
|
+
"file": "packages/core/schematics/migrate-eui-editor/index.ts",
|
|
47186
47186
|
"ctype": "miscellaneous",
|
|
47187
47187
|
"subtype": "function",
|
|
47188
47188
|
"coverageIgnore": false,
|
|
@@ -48605,7 +48605,7 @@
|
|
|
48605
48605
|
},
|
|
48606
48606
|
{
|
|
48607
48607
|
"name": "migrateTypeScript",
|
|
48608
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
48608
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
48609
48609
|
"ctype": "miscellaneous",
|
|
48610
48610
|
"subtype": "function",
|
|
48611
48611
|
"coverageIgnore": false,
|
|
@@ -48652,7 +48652,7 @@
|
|
|
48652
48652
|
},
|
|
48653
48653
|
{
|
|
48654
48654
|
"name": "migrateTypeScript",
|
|
48655
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
48655
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
48656
48656
|
"ctype": "miscellaneous",
|
|
48657
48657
|
"subtype": "function",
|
|
48658
48658
|
"coverageIgnore": false,
|
|
@@ -48823,7 +48823,7 @@
|
|
|
48823
48823
|
},
|
|
48824
48824
|
{
|
|
48825
48825
|
"name": "migrateTypeScript",
|
|
48826
|
-
"file": "packages/core/schematics/migrate-
|
|
48826
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
48827
48827
|
"ctype": "miscellaneous",
|
|
48828
48828
|
"subtype": "function",
|
|
48829
48829
|
"coverageIgnore": false,
|
|
@@ -48850,6 +48850,12 @@
|
|
|
48850
48850
|
"type": "SchematicContext",
|
|
48851
48851
|
"deprecated": false,
|
|
48852
48852
|
"deprecationMessage": ""
|
|
48853
|
+
},
|
|
48854
|
+
{
|
|
48855
|
+
"name": "env",
|
|
48856
|
+
"type": "TsEnv",
|
|
48857
|
+
"deprecated": false,
|
|
48858
|
+
"deprecationMessage": ""
|
|
48853
48859
|
}
|
|
48854
48860
|
],
|
|
48855
48861
|
"returnType": "string",
|
|
@@ -48880,12 +48886,21 @@
|
|
|
48880
48886
|
"tagName": {
|
|
48881
48887
|
"text": "param"
|
|
48882
48888
|
}
|
|
48889
|
+
},
|
|
48890
|
+
{
|
|
48891
|
+
"name": "env",
|
|
48892
|
+
"type": "TsEnv",
|
|
48893
|
+
"deprecated": false,
|
|
48894
|
+
"deprecationMessage": "",
|
|
48895
|
+
"tagName": {
|
|
48896
|
+
"text": "param"
|
|
48897
|
+
}
|
|
48883
48898
|
}
|
|
48884
48899
|
]
|
|
48885
48900
|
},
|
|
48886
48901
|
{
|
|
48887
48902
|
"name": "migrateTypeScript",
|
|
48888
|
-
"file": "packages/core/schematics/migrate-
|
|
48903
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
48889
48904
|
"ctype": "miscellaneous",
|
|
48890
48905
|
"subtype": "function",
|
|
48891
48906
|
"coverageIgnore": false,
|
|
@@ -48912,12 +48927,6 @@
|
|
|
48912
48927
|
"type": "SchematicContext",
|
|
48913
48928
|
"deprecated": false,
|
|
48914
48929
|
"deprecationMessage": ""
|
|
48915
|
-
},
|
|
48916
|
-
{
|
|
48917
|
-
"name": "env",
|
|
48918
|
-
"type": "TsEnv",
|
|
48919
|
-
"deprecated": false,
|
|
48920
|
-
"deprecationMessage": ""
|
|
48921
48930
|
}
|
|
48922
48931
|
],
|
|
48923
48932
|
"returnType": "string",
|
|
@@ -48948,15 +48957,6 @@
|
|
|
48948
48957
|
"tagName": {
|
|
48949
48958
|
"text": "param"
|
|
48950
48959
|
}
|
|
48951
|
-
},
|
|
48952
|
-
{
|
|
48953
|
-
"name": "env",
|
|
48954
|
-
"type": "TsEnv",
|
|
48955
|
-
"deprecated": false,
|
|
48956
|
-
"deprecationMessage": "",
|
|
48957
|
-
"tagName": {
|
|
48958
|
-
"text": "param"
|
|
48959
|
-
}
|
|
48960
48960
|
}
|
|
48961
48961
|
]
|
|
48962
48962
|
},
|
|
@@ -50348,14 +50348,14 @@
|
|
|
50348
50348
|
},
|
|
50349
50349
|
{
|
|
50350
50350
|
"name": "removeObjectProperty",
|
|
50351
|
-
"file": "packages/core/schematics/migrate-
|
|
50351
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
50352
50352
|
"ctype": "miscellaneous",
|
|
50353
50353
|
"subtype": "function",
|
|
50354
50354
|
"coverageIgnore": false,
|
|
50355
50355
|
"deprecated": false,
|
|
50356
50356
|
"deprecationMessage": "",
|
|
50357
|
-
"rawdescription": "",
|
|
50358
|
-
"description": "",
|
|
50357
|
+
"rawdescription": "Removes one object property together with its separating comma.",
|
|
50358
|
+
"description": "<p>Removes one object property together with its separating comma.</p>\n",
|
|
50359
50359
|
"displayName": "removeObjectProperty",
|
|
50360
50360
|
"args": [
|
|
50361
50361
|
{
|
|
@@ -50364,7 +50364,7 @@
|
|
|
50364
50364
|
"deprecationMessage": ""
|
|
50365
50365
|
},
|
|
50366
50366
|
{
|
|
50367
|
-
"name": "
|
|
50367
|
+
"name": "sf",
|
|
50368
50368
|
"deprecated": false,
|
|
50369
50369
|
"deprecationMessage": ""
|
|
50370
50370
|
},
|
|
@@ -50385,7 +50385,7 @@
|
|
|
50385
50385
|
}
|
|
50386
50386
|
},
|
|
50387
50387
|
{
|
|
50388
|
-
"name": "
|
|
50388
|
+
"name": "sf",
|
|
50389
50389
|
"deprecated": false,
|
|
50390
50390
|
"deprecationMessage": "",
|
|
50391
50391
|
"tagName": {
|
|
@@ -50404,14 +50404,14 @@
|
|
|
50404
50404
|
},
|
|
50405
50405
|
{
|
|
50406
50406
|
"name": "removeObjectProperty",
|
|
50407
|
-
"file": "packages/core/schematics/migrate-
|
|
50407
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
50408
50408
|
"ctype": "miscellaneous",
|
|
50409
50409
|
"subtype": "function",
|
|
50410
50410
|
"coverageIgnore": false,
|
|
50411
50411
|
"deprecated": false,
|
|
50412
50412
|
"deprecationMessage": "",
|
|
50413
|
-
"rawdescription": "
|
|
50414
|
-
"description": "
|
|
50413
|
+
"rawdescription": "",
|
|
50414
|
+
"description": "",
|
|
50415
50415
|
"displayName": "removeObjectProperty",
|
|
50416
50416
|
"args": [
|
|
50417
50417
|
{
|
|
@@ -50420,7 +50420,7 @@
|
|
|
50420
50420
|
"deprecationMessage": ""
|
|
50421
50421
|
},
|
|
50422
50422
|
{
|
|
50423
|
-
"name": "
|
|
50423
|
+
"name": "sourceFile",
|
|
50424
50424
|
"deprecated": false,
|
|
50425
50425
|
"deprecationMessage": ""
|
|
50426
50426
|
},
|
|
@@ -50441,7 +50441,7 @@
|
|
|
50441
50441
|
}
|
|
50442
50442
|
},
|
|
50443
50443
|
{
|
|
50444
|
-
"name": "
|
|
50444
|
+
"name": "sourceFile",
|
|
50445
50445
|
"deprecated": false,
|
|
50446
50446
|
"deprecationMessage": "",
|
|
50447
50447
|
"tagName": {
|
|
@@ -54053,7 +54053,7 @@
|
|
|
54053
54053
|
},
|
|
54054
54054
|
{
|
|
54055
54055
|
"name": "unwrapExpression",
|
|
54056
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
54056
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
54057
54057
|
"ctype": "miscellaneous",
|
|
54058
54058
|
"subtype": "function",
|
|
54059
54059
|
"coverageIgnore": false,
|
|
@@ -54083,7 +54083,7 @@
|
|
|
54083
54083
|
},
|
|
54084
54084
|
{
|
|
54085
54085
|
"name": "unwrapExpression",
|
|
54086
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
54086
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
54087
54087
|
"ctype": "miscellaneous",
|
|
54088
54088
|
"subtype": "function",
|
|
54089
54089
|
"coverageIgnore": false,
|
|
@@ -55281,6 +55281,51 @@
|
|
|
55281
55281
|
}
|
|
55282
55282
|
]
|
|
55283
55283
|
},
|
|
55284
|
+
{
|
|
55285
|
+
"name": "visitDir",
|
|
55286
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
55287
|
+
"ctype": "miscellaneous",
|
|
55288
|
+
"subtype": "function",
|
|
55289
|
+
"coverageIgnore": false,
|
|
55290
|
+
"deprecated": false,
|
|
55291
|
+
"deprecationMessage": "",
|
|
55292
|
+
"rawdescription": "",
|
|
55293
|
+
"description": "",
|
|
55294
|
+
"displayName": "visitDir",
|
|
55295
|
+
"args": [
|
|
55296
|
+
{
|
|
55297
|
+
"name": "dir",
|
|
55298
|
+
"type": "DirEntry",
|
|
55299
|
+
"deprecated": false,
|
|
55300
|
+
"deprecationMessage": ""
|
|
55301
|
+
},
|
|
55302
|
+
{
|
|
55303
|
+
"name": "callback",
|
|
55304
|
+
"deprecated": false,
|
|
55305
|
+
"deprecationMessage": ""
|
|
55306
|
+
}
|
|
55307
|
+
],
|
|
55308
|
+
"returnType": "void",
|
|
55309
|
+
"jsdoctags": [
|
|
55310
|
+
{
|
|
55311
|
+
"name": "dir",
|
|
55312
|
+
"type": "DirEntry",
|
|
55313
|
+
"deprecated": false,
|
|
55314
|
+
"deprecationMessage": "",
|
|
55315
|
+
"tagName": {
|
|
55316
|
+
"text": "param"
|
|
55317
|
+
}
|
|
55318
|
+
},
|
|
55319
|
+
{
|
|
55320
|
+
"name": "callback",
|
|
55321
|
+
"deprecated": false,
|
|
55322
|
+
"deprecationMessage": "",
|
|
55323
|
+
"tagName": {
|
|
55324
|
+
"text": "param"
|
|
55325
|
+
}
|
|
55326
|
+
}
|
|
55327
|
+
]
|
|
55328
|
+
},
|
|
55284
55329
|
{
|
|
55285
55330
|
"name": "visitDir",
|
|
55286
55331
|
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
@@ -55328,52 +55373,52 @@
|
|
|
55328
55373
|
},
|
|
55329
55374
|
{
|
|
55330
55375
|
"name": "visitDir",
|
|
55331
|
-
"file": "packages/core/schematics/migrate-
|
|
55332
|
-
"ctype": "miscellaneous",
|
|
55333
|
-
"subtype": "function",
|
|
55334
|
-
"coverageIgnore": false,
|
|
55335
|
-
"deprecated": false,
|
|
55336
|
-
"deprecationMessage": "",
|
|
55337
|
-
"rawdescription": "",
|
|
55338
|
-
"description": "",
|
|
55339
|
-
"displayName": "visitDir",
|
|
55340
|
-
"args": [
|
|
55341
|
-
{
|
|
55342
|
-
"name": "dir",
|
|
55343
|
-
"type": "DirEntry",
|
|
55344
|
-
"deprecated": false,
|
|
55345
|
-
"deprecationMessage": ""
|
|
55346
|
-
},
|
|
55347
|
-
{
|
|
55348
|
-
"name": "callback",
|
|
55349
|
-
"deprecated": false,
|
|
55350
|
-
"deprecationMessage": ""
|
|
55351
|
-
}
|
|
55352
|
-
],
|
|
55353
|
-
"returnType": "void",
|
|
55354
|
-
"jsdoctags": [
|
|
55355
|
-
{
|
|
55356
|
-
"name": "dir",
|
|
55357
|
-
"type": "DirEntry",
|
|
55358
|
-
"deprecated": false,
|
|
55359
|
-
"deprecationMessage": "",
|
|
55360
|
-
"tagName": {
|
|
55361
|
-
"text": "param"
|
|
55362
|
-
}
|
|
55363
|
-
},
|
|
55364
|
-
{
|
|
55365
|
-
"name": "callback",
|
|
55366
|
-
"deprecated": false,
|
|
55367
|
-
"deprecationMessage": "",
|
|
55368
|
-
"tagName": {
|
|
55369
|
-
"text": "param"
|
|
55370
|
-
}
|
|
55371
|
-
}
|
|
55372
|
-
]
|
|
55373
|
-
},
|
|
55374
|
-
{
|
|
55375
|
-
"name": "visitDir",
|
|
55376
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
55376
|
+
"file": "packages/core/schematics/migrate-eui-accent/index.ts",
|
|
55377
|
+
"ctype": "miscellaneous",
|
|
55378
|
+
"subtype": "function",
|
|
55379
|
+
"coverageIgnore": false,
|
|
55380
|
+
"deprecated": false,
|
|
55381
|
+
"deprecationMessage": "",
|
|
55382
|
+
"rawdescription": "",
|
|
55383
|
+
"description": "",
|
|
55384
|
+
"displayName": "visitDir",
|
|
55385
|
+
"args": [
|
|
55386
|
+
{
|
|
55387
|
+
"name": "dir",
|
|
55388
|
+
"type": "DirEntry",
|
|
55389
|
+
"deprecated": false,
|
|
55390
|
+
"deprecationMessage": ""
|
|
55391
|
+
},
|
|
55392
|
+
{
|
|
55393
|
+
"name": "callback",
|
|
55394
|
+
"deprecated": false,
|
|
55395
|
+
"deprecationMessage": ""
|
|
55396
|
+
}
|
|
55397
|
+
],
|
|
55398
|
+
"returnType": "void",
|
|
55399
|
+
"jsdoctags": [
|
|
55400
|
+
{
|
|
55401
|
+
"name": "dir",
|
|
55402
|
+
"type": "DirEntry",
|
|
55403
|
+
"deprecated": false,
|
|
55404
|
+
"deprecationMessage": "",
|
|
55405
|
+
"tagName": {
|
|
55406
|
+
"text": "param"
|
|
55407
|
+
}
|
|
55408
|
+
},
|
|
55409
|
+
{
|
|
55410
|
+
"name": "callback",
|
|
55411
|
+
"deprecated": false,
|
|
55412
|
+
"deprecationMessage": "",
|
|
55413
|
+
"tagName": {
|
|
55414
|
+
"text": "param"
|
|
55415
|
+
}
|
|
55416
|
+
}
|
|
55417
|
+
]
|
|
55418
|
+
},
|
|
55419
|
+
{
|
|
55420
|
+
"name": "visitDir",
|
|
55421
|
+
"file": "packages/core/schematics/migrate-eui-alert/index.ts",
|
|
55377
55422
|
"ctype": "miscellaneous",
|
|
55378
55423
|
"subtype": "function",
|
|
55379
55424
|
"coverageIgnore": false,
|
|
@@ -55418,7 +55463,7 @@
|
|
|
55418
55463
|
},
|
|
55419
55464
|
{
|
|
55420
55465
|
"name": "visitDir",
|
|
55421
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
55466
|
+
"file": "packages/core/schematics/migrate-eui-autocomplete/index.ts",
|
|
55422
55467
|
"ctype": "miscellaneous",
|
|
55423
55468
|
"subtype": "function",
|
|
55424
55469
|
"coverageIgnore": false,
|
|
@@ -55643,7 +55688,7 @@
|
|
|
55643
55688
|
},
|
|
55644
55689
|
{
|
|
55645
55690
|
"name": "visitDir",
|
|
55646
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
55691
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
55647
55692
|
"ctype": "miscellaneous",
|
|
55648
55693
|
"subtype": "function",
|
|
55649
55694
|
"coverageIgnore": false,
|
|
@@ -55776,51 +55821,6 @@
|
|
|
55776
55821
|
}
|
|
55777
55822
|
]
|
|
55778
55823
|
},
|
|
55779
|
-
{
|
|
55780
|
-
"name": "visitDir",
|
|
55781
|
-
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
55782
|
-
"ctype": "miscellaneous",
|
|
55783
|
-
"subtype": "function",
|
|
55784
|
-
"coverageIgnore": false,
|
|
55785
|
-
"deprecated": false,
|
|
55786
|
-
"deprecationMessage": "",
|
|
55787
|
-
"rawdescription": "",
|
|
55788
|
-
"description": "",
|
|
55789
|
-
"displayName": "visitDir",
|
|
55790
|
-
"args": [
|
|
55791
|
-
{
|
|
55792
|
-
"name": "dir",
|
|
55793
|
-
"type": "DirEntry",
|
|
55794
|
-
"deprecated": false,
|
|
55795
|
-
"deprecationMessage": ""
|
|
55796
|
-
},
|
|
55797
|
-
{
|
|
55798
|
-
"name": "callback",
|
|
55799
|
-
"deprecated": false,
|
|
55800
|
-
"deprecationMessage": ""
|
|
55801
|
-
}
|
|
55802
|
-
],
|
|
55803
|
-
"returnType": "void",
|
|
55804
|
-
"jsdoctags": [
|
|
55805
|
-
{
|
|
55806
|
-
"name": "dir",
|
|
55807
|
-
"type": "DirEntry",
|
|
55808
|
-
"deprecated": false,
|
|
55809
|
-
"deprecationMessage": "",
|
|
55810
|
-
"tagName": {
|
|
55811
|
-
"text": "param"
|
|
55812
|
-
}
|
|
55813
|
-
},
|
|
55814
|
-
{
|
|
55815
|
-
"name": "callback",
|
|
55816
|
-
"deprecated": false,
|
|
55817
|
-
"deprecationMessage": "",
|
|
55818
|
-
"tagName": {
|
|
55819
|
-
"text": "param"
|
|
55820
|
-
}
|
|
55821
|
-
}
|
|
55822
|
-
]
|
|
55823
|
-
},
|
|
55824
55824
|
{
|
|
55825
55825
|
"name": "visitDir",
|
|
55826
55826
|
"file": "packages/core/schematics/migrate-eui-fieldset/index.ts",
|
|
@@ -56273,7 +56273,7 @@
|
|
|
56273
56273
|
},
|
|
56274
56274
|
{
|
|
56275
56275
|
"name": "visitDir",
|
|
56276
|
-
"file": "packages/core/schematics/migrate-
|
|
56276
|
+
"file": "packages/core/schematics/migrate-ngx-translate-18/index.ts",
|
|
56277
56277
|
"ctype": "miscellaneous",
|
|
56278
56278
|
"subtype": "function",
|
|
56279
56279
|
"coverageIgnore": false,
|
|
@@ -56318,7 +56318,7 @@
|
|
|
56318
56318
|
},
|
|
56319
56319
|
{
|
|
56320
56320
|
"name": "visitDir",
|
|
56321
|
-
"file": "packages/core/schematics/migrate-
|
|
56321
|
+
"file": "packages/core/schematics/migrate-eui-tooltip/index.ts",
|
|
56322
56322
|
"ctype": "miscellaneous",
|
|
56323
56323
|
"subtype": "function",
|
|
56324
56324
|
"coverageIgnore": false,
|
|
@@ -57078,7 +57078,7 @@
|
|
|
57078
57078
|
},
|
|
57079
57079
|
{
|
|
57080
57080
|
"name": "visitNodes",
|
|
57081
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
57081
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
57082
57082
|
"ctype": "miscellaneous",
|
|
57083
57083
|
"subtype": "function",
|
|
57084
57084
|
"coverageIgnore": false,
|
|
@@ -57121,7 +57121,7 @@
|
|
|
57121
57121
|
},
|
|
57122
57122
|
{
|
|
57123
57123
|
"name": "visitNodes",
|
|
57124
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
57124
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
57125
57125
|
"ctype": "miscellaneous",
|
|
57126
57126
|
"subtype": "function",
|
|
57127
57127
|
"coverageIgnore": false,
|
|
@@ -57394,7 +57394,7 @@
|
|
|
57394
57394
|
},
|
|
57395
57395
|
{
|
|
57396
57396
|
"name": "visitNodes",
|
|
57397
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
57397
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
57398
57398
|
"ctype": "miscellaneous",
|
|
57399
57399
|
"subtype": "function",
|
|
57400
57400
|
"coverageIgnore": false,
|
|
@@ -57410,7 +57410,13 @@
|
|
|
57410
57410
|
"deprecationMessage": ""
|
|
57411
57411
|
},
|
|
57412
57412
|
{
|
|
57413
|
-
"name": "
|
|
57413
|
+
"name": "source",
|
|
57414
|
+
"type": "string",
|
|
57415
|
+
"deprecated": false,
|
|
57416
|
+
"deprecationMessage": ""
|
|
57417
|
+
},
|
|
57418
|
+
{
|
|
57419
|
+
"name": "removals",
|
|
57414
57420
|
"deprecated": false,
|
|
57415
57421
|
"deprecationMessage": ""
|
|
57416
57422
|
}
|
|
@@ -57426,7 +57432,16 @@
|
|
|
57426
57432
|
}
|
|
57427
57433
|
},
|
|
57428
57434
|
{
|
|
57429
|
-
"name": "
|
|
57435
|
+
"name": "source",
|
|
57436
|
+
"type": "string",
|
|
57437
|
+
"deprecated": false,
|
|
57438
|
+
"deprecationMessage": "",
|
|
57439
|
+
"tagName": {
|
|
57440
|
+
"text": "param"
|
|
57441
|
+
}
|
|
57442
|
+
},
|
|
57443
|
+
{
|
|
57444
|
+
"name": "removals",
|
|
57430
57445
|
"deprecated": false,
|
|
57431
57446
|
"deprecationMessage": "",
|
|
57432
57447
|
"tagName": {
|
|
@@ -57437,7 +57452,7 @@
|
|
|
57437
57452
|
},
|
|
57438
57453
|
{
|
|
57439
57454
|
"name": "visitNodes",
|
|
57440
|
-
"file": "packages/core/schematics/migrate-eui-
|
|
57455
|
+
"file": "packages/core/schematics/migrate-eui-editor/index.ts",
|
|
57441
57456
|
"ctype": "miscellaneous",
|
|
57442
57457
|
"subtype": "function",
|
|
57443
57458
|
"coverageIgnore": false,
|
|
@@ -57453,13 +57468,7 @@
|
|
|
57453
57468
|
"deprecationMessage": ""
|
|
57454
57469
|
},
|
|
57455
57470
|
{
|
|
57456
|
-
"name": "
|
|
57457
|
-
"type": "string",
|
|
57458
|
-
"deprecated": false,
|
|
57459
|
-
"deprecationMessage": ""
|
|
57460
|
-
},
|
|
57461
|
-
{
|
|
57462
|
-
"name": "removals",
|
|
57471
|
+
"name": "edits",
|
|
57463
57472
|
"deprecated": false,
|
|
57464
57473
|
"deprecationMessage": ""
|
|
57465
57474
|
}
|
|
@@ -57475,16 +57484,7 @@
|
|
|
57475
57484
|
}
|
|
57476
57485
|
},
|
|
57477
57486
|
{
|
|
57478
|
-
"name": "
|
|
57479
|
-
"type": "string",
|
|
57480
|
-
"deprecated": false,
|
|
57481
|
-
"deprecationMessage": "",
|
|
57482
|
-
"tagName": {
|
|
57483
|
-
"text": "param"
|
|
57484
|
-
}
|
|
57485
|
-
},
|
|
57486
|
-
{
|
|
57487
|
-
"name": "removals",
|
|
57487
|
+
"name": "edits",
|
|
57488
57488
|
"deprecated": false,
|
|
57489
57489
|
"deprecationMessage": "",
|
|
57490
57490
|
"tagName": {
|
|
@@ -60802,6 +60802,19 @@
|
|
|
60802
60802
|
"description": "<p>Provides read-only equivalent of jQuery's position function:\n<a href=\"http://api.jquery.com/position/\">http://api.jquery.com/position/</a></p>\n"
|
|
60803
60803
|
}
|
|
60804
60804
|
],
|
|
60805
|
+
"packages/core/schematics/migrate-eui-discussion-thread/index.ts": [
|
|
60806
|
+
{
|
|
60807
|
+
"name": "COMPONENT_TAG",
|
|
60808
|
+
"ctype": "miscellaneous",
|
|
60809
|
+
"subtype": "variable",
|
|
60810
|
+
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
60811
|
+
"coverageIgnore": false,
|
|
60812
|
+
"deprecated": false,
|
|
60813
|
+
"deprecationMessage": "",
|
|
60814
|
+
"type": "string",
|
|
60815
|
+
"defaultValue": "'eui-discussion-thread'"
|
|
60816
|
+
}
|
|
60817
|
+
],
|
|
60805
60818
|
"packages/core/schematics/migrate-eui-editor/index.ts": [
|
|
60806
60819
|
{
|
|
60807
60820
|
"name": "COMPONENT_TAG",
|
|
@@ -60837,19 +60850,6 @@
|
|
|
60837
60850
|
"defaultValue": "'onEditorChanged'"
|
|
60838
60851
|
}
|
|
60839
60852
|
],
|
|
60840
|
-
"packages/core/schematics/migrate-eui-discussion-thread/index.ts": [
|
|
60841
|
-
{
|
|
60842
|
-
"name": "COMPONENT_TAG",
|
|
60843
|
-
"ctype": "miscellaneous",
|
|
60844
|
-
"subtype": "variable",
|
|
60845
|
-
"file": "packages/core/schematics/migrate-eui-discussion-thread/index.ts",
|
|
60846
|
-
"coverageIgnore": false,
|
|
60847
|
-
"deprecated": false,
|
|
60848
|
-
"deprecationMessage": "",
|
|
60849
|
-
"type": "string",
|
|
60850
|
-
"defaultValue": "'eui-discussion-thread'"
|
|
60851
|
-
}
|
|
60852
|
-
],
|
|
60853
60853
|
"packages/core/schematics/migrate-eui-fieldset/index.ts": [
|
|
60854
60854
|
{
|
|
60855
60855
|
"name": "COMPONENT_TAG",
|
|
@@ -76860,10 +76860,10 @@
|
|
|
76860
76860
|
]
|
|
76861
76861
|
}
|
|
76862
76862
|
],
|
|
76863
|
-
"packages/core/schematics/migrate-ecl-
|
|
76863
|
+
"packages/core/schematics/migrate-ecl-tabs/index.ts": [
|
|
76864
76864
|
{
|
|
76865
76865
|
"name": "applyEdits",
|
|
76866
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
76866
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
76867
76867
|
"ctype": "miscellaneous",
|
|
76868
76868
|
"subtype": "function",
|
|
76869
76869
|
"coverageIgnore": false,
|
|
@@ -76908,7 +76908,7 @@
|
|
|
76908
76908
|
},
|
|
76909
76909
|
{
|
|
76910
76910
|
"name": "collectElementRename",
|
|
76911
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
76911
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
76912
76912
|
"ctype": "miscellaneous",
|
|
76913
76913
|
"subtype": "function",
|
|
76914
76914
|
"coverageIgnore": false,
|
|
@@ -76924,12 +76924,6 @@
|
|
|
76924
76924
|
"deprecated": false,
|
|
76925
76925
|
"deprecationMessage": ""
|
|
76926
76926
|
},
|
|
76927
|
-
{
|
|
76928
|
-
"name": "mapping",
|
|
76929
|
-
"type": "SelectorMapping",
|
|
76930
|
-
"deprecated": false,
|
|
76931
|
-
"deprecationMessage": ""
|
|
76932
|
-
},
|
|
76933
76927
|
{
|
|
76934
76928
|
"name": "edits",
|
|
76935
76929
|
"deprecated": false,
|
|
@@ -76947,15 +76941,6 @@
|
|
|
76947
76941
|
"text": "param"
|
|
76948
76942
|
}
|
|
76949
76943
|
},
|
|
76950
|
-
{
|
|
76951
|
-
"name": "mapping",
|
|
76952
|
-
"type": "SelectorMapping",
|
|
76953
|
-
"deprecated": false,
|
|
76954
|
-
"deprecationMessage": "",
|
|
76955
|
-
"tagName": {
|
|
76956
|
-
"text": "param"
|
|
76957
|
-
}
|
|
76958
|
-
},
|
|
76959
76944
|
{
|
|
76960
76945
|
"name": "edits",
|
|
76961
76946
|
"deprecated": false,
|
|
@@ -76968,7 +76953,7 @@
|
|
|
76968
76953
|
},
|
|
76969
76954
|
{
|
|
76970
76955
|
"name": "deduplicateEdits",
|
|
76971
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
76956
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
76972
76957
|
"ctype": "miscellaneous",
|
|
76973
76958
|
"subtype": "function",
|
|
76974
76959
|
"coverageIgnore": false,
|
|
@@ -76998,7 +76983,7 @@
|
|
|
76998
76983
|
},
|
|
76999
76984
|
{
|
|
77000
76985
|
"name": "isComponentMetadataProperty",
|
|
77001
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
76986
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77002
76987
|
"ctype": "miscellaneous",
|
|
77003
76988
|
"subtype": "function",
|
|
77004
76989
|
"coverageIgnore": false,
|
|
@@ -77028,7 +77013,7 @@
|
|
|
77028
77013
|
},
|
|
77029
77014
|
{
|
|
77030
77015
|
"name": "isTemplateProperty",
|
|
77031
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77016
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77032
77017
|
"ctype": "miscellaneous",
|
|
77033
77018
|
"subtype": "function",
|
|
77034
77019
|
"coverageIgnore": false,
|
|
@@ -77057,8 +77042,8 @@
|
|
|
77057
77042
|
]
|
|
77058
77043
|
},
|
|
77059
77044
|
{
|
|
77060
|
-
"name": "
|
|
77061
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77045
|
+
"name": "migrateEclTabs",
|
|
77046
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77062
77047
|
"ctype": "miscellaneous",
|
|
77063
77048
|
"subtype": "function",
|
|
77064
77049
|
"coverageIgnore": false,
|
|
@@ -77066,7 +77051,7 @@
|
|
|
77066
77051
|
"deprecationMessage": "",
|
|
77067
77052
|
"rawdescription": "",
|
|
77068
77053
|
"description": "",
|
|
77069
|
-
"displayName": "
|
|
77054
|
+
"displayName": "migrateEclTabs",
|
|
77070
77055
|
"args": [
|
|
77071
77056
|
{
|
|
77072
77057
|
"name": "options",
|
|
@@ -77092,7 +77077,7 @@
|
|
|
77092
77077
|
},
|
|
77093
77078
|
{
|
|
77094
77079
|
"name": "migrateTemplate",
|
|
77095
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77080
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77096
77081
|
"ctype": "miscellaneous",
|
|
77097
77082
|
"subtype": "function",
|
|
77098
77083
|
"coverageIgnore": false,
|
|
@@ -77124,7 +77109,7 @@
|
|
|
77124
77109
|
},
|
|
77125
77110
|
{
|
|
77126
77111
|
"name": "migrateTypeScript",
|
|
77127
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77112
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77128
77113
|
"ctype": "miscellaneous",
|
|
77129
77114
|
"subtype": "function",
|
|
77130
77115
|
"coverageIgnore": false,
|
|
@@ -77171,7 +77156,7 @@
|
|
|
77171
77156
|
},
|
|
77172
77157
|
{
|
|
77173
77158
|
"name": "unwrapExpression",
|
|
77174
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77159
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77175
77160
|
"ctype": "miscellaneous",
|
|
77176
77161
|
"subtype": "function",
|
|
77177
77162
|
"coverageIgnore": false,
|
|
@@ -77201,7 +77186,7 @@
|
|
|
77201
77186
|
},
|
|
77202
77187
|
{
|
|
77203
77188
|
"name": "visitDir",
|
|
77204
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77189
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77205
77190
|
"ctype": "miscellaneous",
|
|
77206
77191
|
"subtype": "function",
|
|
77207
77192
|
"coverageIgnore": false,
|
|
@@ -77246,7 +77231,7 @@
|
|
|
77246
77231
|
},
|
|
77247
77232
|
{
|
|
77248
77233
|
"name": "visitNodes",
|
|
77249
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77234
|
+
"file": "packages/core/schematics/migrate-ecl-tabs/index.ts",
|
|
77250
77235
|
"ctype": "miscellaneous",
|
|
77251
77236
|
"subtype": "function",
|
|
77252
77237
|
"coverageIgnore": false,
|
|
@@ -77288,10 +77273,10 @@
|
|
|
77288
77273
|
]
|
|
77289
77274
|
}
|
|
77290
77275
|
],
|
|
77291
|
-
"packages/core/schematics/migrate-ecl-
|
|
77276
|
+
"packages/core/schematics/migrate-ecl-timeline/index.ts": [
|
|
77292
77277
|
{
|
|
77293
77278
|
"name": "applyEdits",
|
|
77294
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77279
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77295
77280
|
"ctype": "miscellaneous",
|
|
77296
77281
|
"subtype": "function",
|
|
77297
77282
|
"coverageIgnore": false,
|
|
@@ -77336,7 +77321,7 @@
|
|
|
77336
77321
|
},
|
|
77337
77322
|
{
|
|
77338
77323
|
"name": "collectElementRename",
|
|
77339
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77324
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77340
77325
|
"ctype": "miscellaneous",
|
|
77341
77326
|
"subtype": "function",
|
|
77342
77327
|
"coverageIgnore": false,
|
|
@@ -77352,6 +77337,12 @@
|
|
|
77352
77337
|
"deprecated": false,
|
|
77353
77338
|
"deprecationMessage": ""
|
|
77354
77339
|
},
|
|
77340
|
+
{
|
|
77341
|
+
"name": "mapping",
|
|
77342
|
+
"type": "SelectorMapping",
|
|
77343
|
+
"deprecated": false,
|
|
77344
|
+
"deprecationMessage": ""
|
|
77345
|
+
},
|
|
77355
77346
|
{
|
|
77356
77347
|
"name": "edits",
|
|
77357
77348
|
"deprecated": false,
|
|
@@ -77369,6 +77360,15 @@
|
|
|
77369
77360
|
"text": "param"
|
|
77370
77361
|
}
|
|
77371
77362
|
},
|
|
77363
|
+
{
|
|
77364
|
+
"name": "mapping",
|
|
77365
|
+
"type": "SelectorMapping",
|
|
77366
|
+
"deprecated": false,
|
|
77367
|
+
"deprecationMessage": "",
|
|
77368
|
+
"tagName": {
|
|
77369
|
+
"text": "param"
|
|
77370
|
+
}
|
|
77371
|
+
},
|
|
77372
77372
|
{
|
|
77373
77373
|
"name": "edits",
|
|
77374
77374
|
"deprecated": false,
|
|
@@ -77381,7 +77381,7 @@
|
|
|
77381
77381
|
},
|
|
77382
77382
|
{
|
|
77383
77383
|
"name": "deduplicateEdits",
|
|
77384
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77384
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77385
77385
|
"ctype": "miscellaneous",
|
|
77386
77386
|
"subtype": "function",
|
|
77387
77387
|
"coverageIgnore": false,
|
|
@@ -77411,7 +77411,7 @@
|
|
|
77411
77411
|
},
|
|
77412
77412
|
{
|
|
77413
77413
|
"name": "isComponentMetadataProperty",
|
|
77414
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77414
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77415
77415
|
"ctype": "miscellaneous",
|
|
77416
77416
|
"subtype": "function",
|
|
77417
77417
|
"coverageIgnore": false,
|
|
@@ -77441,7 +77441,7 @@
|
|
|
77441
77441
|
},
|
|
77442
77442
|
{
|
|
77443
77443
|
"name": "isTemplateProperty",
|
|
77444
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77444
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77445
77445
|
"ctype": "miscellaneous",
|
|
77446
77446
|
"subtype": "function",
|
|
77447
77447
|
"coverageIgnore": false,
|
|
@@ -77470,8 +77470,8 @@
|
|
|
77470
77470
|
]
|
|
77471
77471
|
},
|
|
77472
77472
|
{
|
|
77473
|
-
"name": "
|
|
77474
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77473
|
+
"name": "migrateEclTimeline",
|
|
77474
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77475
77475
|
"ctype": "miscellaneous",
|
|
77476
77476
|
"subtype": "function",
|
|
77477
77477
|
"coverageIgnore": false,
|
|
@@ -77479,7 +77479,7 @@
|
|
|
77479
77479
|
"deprecationMessage": "",
|
|
77480
77480
|
"rawdescription": "",
|
|
77481
77481
|
"description": "",
|
|
77482
|
-
"displayName": "
|
|
77482
|
+
"displayName": "migrateEclTimeline",
|
|
77483
77483
|
"args": [
|
|
77484
77484
|
{
|
|
77485
77485
|
"name": "options",
|
|
@@ -77505,7 +77505,7 @@
|
|
|
77505
77505
|
},
|
|
77506
77506
|
{
|
|
77507
77507
|
"name": "migrateTemplate",
|
|
77508
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77508
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77509
77509
|
"ctype": "miscellaneous",
|
|
77510
77510
|
"subtype": "function",
|
|
77511
77511
|
"coverageIgnore": false,
|
|
@@ -77537,7 +77537,7 @@
|
|
|
77537
77537
|
},
|
|
77538
77538
|
{
|
|
77539
77539
|
"name": "migrateTypeScript",
|
|
77540
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77540
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77541
77541
|
"ctype": "miscellaneous",
|
|
77542
77542
|
"subtype": "function",
|
|
77543
77543
|
"coverageIgnore": false,
|
|
@@ -77584,7 +77584,7 @@
|
|
|
77584
77584
|
},
|
|
77585
77585
|
{
|
|
77586
77586
|
"name": "unwrapExpression",
|
|
77587
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77587
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77588
77588
|
"ctype": "miscellaneous",
|
|
77589
77589
|
"subtype": "function",
|
|
77590
77590
|
"coverageIgnore": false,
|
|
@@ -77614,7 +77614,7 @@
|
|
|
77614
77614
|
},
|
|
77615
77615
|
{
|
|
77616
77616
|
"name": "visitDir",
|
|
77617
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77617
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77618
77618
|
"ctype": "miscellaneous",
|
|
77619
77619
|
"subtype": "function",
|
|
77620
77620
|
"coverageIgnore": false,
|
|
@@ -77659,7 +77659,7 @@
|
|
|
77659
77659
|
},
|
|
77660
77660
|
{
|
|
77661
77661
|
"name": "visitNodes",
|
|
77662
|
-
"file": "packages/core/schematics/migrate-ecl-
|
|
77662
|
+
"file": "packages/core/schematics/migrate-ecl-timeline/index.ts",
|
|
77663
77663
|
"ctype": "miscellaneous",
|
|
77664
77664
|
"subtype": "function",
|
|
77665
77665
|
"coverageIgnore": false,
|