@openrewrite/recipes-angular 1.27.0 → 1.28.0
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/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +188 -1
- package/dist/index.js.map +1 -1
- package/dist/libraries/components/lst.d.ts +7 -0
- package/dist/libraries/components/lst.d.ts.map +1 -1
- package/dist/libraries/components/lst.js +12 -0
- package/dist/libraries/components/lst.js.map +1 -1
- package/dist/libraries/components/style-sources.d.ts +15 -0
- package/dist/libraries/components/style-sources.d.ts.map +1 -0
- package/dist/libraries/components/style-sources.js +108 -0
- package/dist/libraries/components/style-sources.js.map +1 -0
- package/dist/libraries/components/stylesheets.d.ts +12 -0
- package/dist/libraries/components/stylesheets.d.ts.map +1 -1
- package/dist/libraries/components/stylesheets.js +37 -1
- package/dist/libraries/components/stylesheets.js.map +1 -1
- package/dist/libraries/components/symbols.d.ts +21 -1
- package/dist/libraries/components/symbols.d.ts.map +1 -1
- package/dist/libraries/components/symbols.js +124 -9
- package/dist/libraries/components/symbols.js.map +1 -1
- package/dist/libraries/components/template-elements.d.ts +38 -0
- package/dist/libraries/components/template-elements.d.ts.map +1 -0
- package/dist/libraries/components/template-elements.js +90 -0
- package/dist/libraries/components/template-elements.js.map +1 -0
- package/dist/libraries/components/templates.d.ts +6 -0
- package/dist/libraries/components/templates.d.ts.map +1 -1
- package/dist/libraries/components/templates.js +17 -2
- package/dist/libraries/components/templates.js.map +1 -1
- package/dist/libraries/material/add-system-variables-prefix.d.ts +9 -0
- package/dist/libraries/material/add-system-variables-prefix.d.ts.map +1 -0
- package/dist/libraries/material/add-system-variables-prefix.js +74 -0
- package/dist/libraries/material/add-system-variables-prefix.js.map +1 -0
- package/dist/libraries/material/add-theme-base-mixins.d.ts +19 -0
- package/dist/libraries/material/add-theme-base-mixins.d.ts.map +1 -0
- package/dist/libraries/material/add-theme-base-mixins.js +176 -0
- package/dist/libraries/material/add-theme-base-mixins.js.map +1 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.d.ts +8 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.d.ts.map +1 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.js +95 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.js.map +1 -0
- package/dist/libraries/material/find-legacy-material-usage.d.ts +8 -0
- package/dist/libraries/material/find-legacy-material-usage.d.ts.map +1 -0
- package/dist/libraries/material/find-legacy-material-usage.js +103 -0
- package/dist/libraries/material/find-legacy-material-usage.js.map +1 -0
- package/dist/libraries/material/find-material-constructor-changes.d.ts +74 -0
- package/dist/libraries/material/find-material-constructor-changes.d.ts.map +1 -0
- package/dist/libraries/material/find-material-constructor-changes.js +267 -0
- package/dist/libraries/material/find-material-constructor-changes.js.map +1 -0
- package/dist/libraries/material/find-mdc-breaking-changes.d.ts +45 -0
- package/dist/libraries/material/find-mdc-breaking-changes.d.ts.map +1 -0
- package/dist/libraries/material/find-mdc-breaking-changes.js +326 -0
- package/dist/libraries/material/find-mdc-breaking-changes.js.map +1 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.d.ts +8 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.d.ts.map +1 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.js +125 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.js.map +1 -0
- package/dist/libraries/material/find-raw-palette-themes.d.ts +28 -0
- package/dist/libraries/material/find-raw-palette-themes.d.ts.map +1 -0
- package/dist/libraries/material/find-raw-palette-themes.js +124 -0
- package/dist/libraries/material/find-raw-palette-themes.js.map +1 -0
- package/dist/libraries/material/find-removed-material-apis.d.ts +20 -0
- package/dist/libraries/material/find-removed-material-apis.d.ts.map +1 -0
- package/dist/libraries/material/find-removed-material-apis.js +60 -0
- package/dist/libraries/material/find-removed-material-apis.js.map +1 -0
- package/dist/libraries/material/find-removed-material-classes.d.ts +13 -0
- package/dist/libraries/material/find-removed-material-classes.d.ts.map +1 -0
- package/dist/libraries/material/find-removed-material-classes.js +154 -0
- package/dist/libraries/material/find-removed-material-classes.js.map +1 -0
- package/dist/libraries/material/find-removed-material-members.d.ts +67 -0
- package/dist/libraries/material/find-removed-material-members.d.ts.map +1 -0
- package/dist/libraries/material/find-removed-material-members.js +168 -0
- package/dist/libraries/material/find-removed-material-members.js.map +1 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.d.ts +8 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.d.ts.map +1 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.js +102 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.js.map +1 -0
- package/dist/libraries/material/material-15-classes.d.ts +6 -0
- package/dist/libraries/material/material-15-classes.d.ts.map +1 -0
- package/dist/libraries/material/material-15-classes.js +435 -0
- package/dist/libraries/material/material-15-classes.js.map +1 -0
- package/dist/libraries/material/material-entry-points.d.ts +3 -0
- package/dist/libraries/material/material-entry-points.d.ts.map +1 -0
- package/dist/libraries/material/material-entry-points.js +201 -0
- package/dist/libraries/material/material-entry-points.js.map +1 -0
- package/dist/libraries/material/material-legacy-symbols.d.ts +2 -0
- package/dist/libraries/material/material-legacy-symbols.d.ts.map +1 -0
- package/dist/libraries/material/material-legacy-symbols.js +559 -0
- package/dist/libraries/material/material-legacy-symbols.js.map +1 -0
- package/dist/libraries/material/material-theming-api.d.ts +23 -0
- package/dist/libraries/material/material-theming-api.d.ts.map +1 -0
- package/dist/libraries/material/material-theming-api.js +446 -0
- package/dist/libraries/material/material-theming-api.js.map +1 -0
- package/dist/libraries/material/material-version.d.ts +24 -0
- package/dist/libraries/material/material-version.d.ts.map +1 -0
- package/dist/libraries/material/material-version.js +160 -0
- package/dist/libraries/material/material-version.js.map +1 -0
- package/dist/libraries/material/migrate-legacy-material.d.ts +60 -0
- package/dist/libraries/material/migrate-legacy-material.d.ts.map +1 -0
- package/dist/libraries/material/migrate-legacy-material.js +230 -0
- package/dist/libraries/material/migrate-legacy-material.js.map +1 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.d.ts +8 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.d.ts.map +1 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.js +62 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.js.map +1 -0
- package/dist/libraries/material/migrate-m2-theming-api.d.ts +12 -0
- package/dist/libraries/material/migrate-m2-theming-api.d.ts.map +1 -0
- package/dist/libraries/material/migrate-m2-theming-api.js +120 -0
- package/dist/libraries/material/migrate-m2-theming-api.js.map +1 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts +9 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts.map +1 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js +36 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js.map +1 -0
- package/dist/libraries/material/migrate-material-15-typography.d.ts +21 -0
- package/dist/libraries/material/migrate-material-15-typography.d.ts.map +1 -0
- package/dist/libraries/material/migrate-material-15-typography.js +185 -0
- package/dist/libraries/material/migrate-material-15-typography.js.map +1 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.d.ts +8 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.d.ts.map +1 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.js +157 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.js.map +1 -0
- package/dist/libraries/material/migrate-material-theming-api.d.ts +17 -0
- package/dist/libraries/material/migrate-material-theming-api.d.ts.map +1 -0
- package/dist/libraries/material/migrate-material-theming-api.js +190 -0
- package/dist/libraries/material/migrate-material-theming-api.js.map +1 -0
- package/dist/libraries/material/migrate-mdc-styles.d.ts +23 -0
- package/dist/libraries/material/migrate-mdc-styles.d.ts.map +1 -0
- package/dist/libraries/material/migrate-mdc-styles.js +145 -0
- package/dist/libraries/material/migrate-mdc-styles.js.map +1 -0
- package/dist/libraries/material/migrate-mdc-templates.d.ts +18 -0
- package/dist/libraries/material/migrate-mdc-templates.d.ts.map +1 -0
- package/dist/libraries/material/migrate-mdc-templates.js +306 -0
- package/dist/libraries/material/migrate-mdc-templates.js.map +1 -0
- package/dist/libraries/material/migrate-selection-list-change-option.d.ts +8 -0
- package/dist/libraries/material/migrate-selection-list-change-option.d.ts.map +1 -0
- package/dist/libraries/material/migrate-selection-list-change-option.js +49 -0
- package/dist/libraries/material/migrate-selection-list-change-option.js.map +1 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.d.ts +8 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.d.ts.map +1 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.js +72 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.js.map +1 -0
- package/dist/libraries/material/remove-update-active-link-argument.d.ts +8 -0
- package/dist/libraries/material/remove-update-active-link-argument.d.ts.map +1 -0
- package/dist/libraries/material/remove-update-active-link-argument.js +54 -0
- package/dist/libraries/material/remove-update-active-link-argument.js.map +1 -0
- package/dist/libraries/material/rename-material-members.d.ts +51 -0
- package/dist/libraries/material/rename-material-members.d.ts.map +1 -0
- package/dist/libraries/material/rename-material-members.js +125 -0
- package/dist/libraries/material/rename-material-members.js.map +1 -0
- package/dist/libraries/material/rename-material-style-names.d.ts +28 -0
- package/dist/libraries/material/rename-material-style-names.d.ts.map +1 -0
- package/dist/libraries/material/rename-material-style-names.js +148 -0
- package/dist/libraries/material/rename-material-style-names.js.map +1 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts +20 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts.map +1 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.js +32 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.js.map +1 -0
- package/dist/libraries/material/upgrade-to-material.d.ts +74 -0
- package/dist/libraries/material/upgrade-to-material.d.ts.map +1 -0
- package/dist/libraries/material/upgrade-to-material.js +324 -0
- package/dist/libraries/material/upgrade-to-material.js.map +1 -0
- package/dist/migration/upgrade-angular-dependencies.d.ts +2 -0
- package/dist/migration/upgrade-angular-dependencies.d.ts.map +1 -1
- package/dist/migration/upgrade-angular-dependencies.js +6 -0
- package/dist/migration/upgrade-angular-dependencies.js.map +1 -1
- package/dist/migration/upgrade-to-angular-10.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-10.js +5 -1
- package/dist/migration/upgrade-to-angular-10.js.map +1 -1
- package/dist/migration/upgrade-to-angular-11.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-11.js +10 -1
- package/dist/migration/upgrade-to-angular-11.js.map +1 -1
- package/dist/migration/upgrade-to-angular-12.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-12.js +5 -1
- package/dist/migration/upgrade-to-angular-12.js.map +1 -1
- package/dist/migration/upgrade-to-angular-13.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-13.js +5 -1
- package/dist/migration/upgrade-to-angular-13.js.map +1 -1
- package/dist/migration/upgrade-to-angular-14.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-14.js +5 -1
- package/dist/migration/upgrade-to-angular-14.js.map +1 -1
- package/dist/migration/upgrade-to-angular-15.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-15.js +5 -1
- package/dist/migration/upgrade-to-angular-15.js.map +1 -1
- package/dist/migration/upgrade-to-angular-16.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-16.js +2 -1
- package/dist/migration/upgrade-to-angular-16.js.map +1 -1
- package/dist/migration/upgrade-to-angular-17.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-17.js +5 -1
- package/dist/migration/upgrade-to-angular-17.js.map +1 -1
- package/dist/migration/upgrade-to-angular-18.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-18.js +5 -1
- package/dist/migration/upgrade-to-angular-18.js.map +1 -1
- package/dist/migration/upgrade-to-angular-19.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-19.js +5 -1
- package/dist/migration/upgrade-to-angular-19.js.map +1 -1
- package/dist/migration/upgrade-to-angular-20.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-20.js +5 -1
- package/dist/migration/upgrade-to-angular-20.js.map +1 -1
- package/dist/migration/upgrade-to-angular-21.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-21.js +2 -1
- package/dist/migration/upgrade-to-angular-21.js.map +1 -1
- package/dist/migration/upgrade-to-angular-22.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-22.js +2 -1
- package/dist/migration/upgrade-to-angular-22.js.map +1 -1
- package/dist/migration/upgrade-to-angular-8.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-8.js +6 -1
- package/dist/migration/upgrade-to-angular-8.js.map +1 -1
- package/dist/migration/upgrade-to-angular-9.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-9.js +5 -1
- package/dist/migration/upgrade-to-angular-9.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +189 -0
- package/src/libraries/components/lst.ts +13 -2
- package/src/libraries/components/style-sources.ts +80 -0
- package/src/libraries/components/stylesheets.ts +37 -0
- package/src/libraries/components/symbols.ts +95 -10
- package/src/libraries/components/template-elements.ts +113 -0
- package/src/libraries/components/templates.ts +18 -4
- package/src/libraries/material/add-system-variables-prefix.ts +71 -0
- package/src/libraries/material/add-theme-base-mixins.ts +159 -0
- package/src/libraries/material/find-chip-input-event-without-chip-input.ts +63 -0
- package/src/libraries/material/find-legacy-material-usage.ts +73 -0
- package/src/libraries/material/find-material-constructor-changes.ts +231 -0
- package/src/libraries/material/find-mdc-breaking-changes.ts +273 -0
- package/src/libraries/material/find-mixin-error-state-without-state-changes.ts +89 -0
- package/src/libraries/material/find-raw-palette-themes.ts +100 -0
- package/src/libraries/material/find-removed-material-apis.ts +54 -0
- package/src/libraries/material/find-removed-material-classes.ts +127 -0
- package/src/libraries/material/find-removed-material-members.ts +146 -0
- package/src/libraries/material/find-slide-toggle-drag-options.ts +69 -0
- package/src/libraries/material/material-15-classes.ts +435 -0
- package/src/libraries/material/material-entry-points.ts +198 -0
- package/src/libraries/material/material-legacy-symbols.ts +557 -0
- package/src/libraries/material/material-theming-api.ts +454 -0
- package/src/libraries/material/material-version.ts +142 -0
- package/src/libraries/material/migrate-legacy-material.ts +202 -0
- package/src/libraries/material/migrate-list-item-harness-content-loader.ts +39 -0
- package/src/libraries/material/migrate-m2-theming-api.ts +98 -0
- package/src/libraries/material/migrate-mat-core-to-elevation-classes.ts +32 -0
- package/src/libraries/material/migrate-material-15-typography.ts +153 -0
- package/src/libraries/material/migrate-material-secondary-entry-points.ts +154 -0
- package/src/libraries/material/migrate-material-theming-api.ts +189 -0
- package/src/libraries/material/migrate-mdc-styles.ts +117 -0
- package/src/libraries/material/migrate-mdc-templates.ts +269 -0
- package/src/libraries/material/migrate-selection-list-change-option.ts +28 -0
- package/src/libraries/material/remove-mat-stepper-document-argument.ts +44 -0
- package/src/libraries/material/remove-update-active-link-argument.ts +33 -0
- package/src/libraries/material/rename-material-members.ts +109 -0
- package/src/libraries/material/rename-material-style-names.ts +116 -0
- package/src/libraries/material/rename-textarea-autosize-attributes.ts +27 -0
- package/src/libraries/material/upgrade-to-material.ts +286 -0
- package/src/migration/upgrade-angular-dependencies.ts +6 -0
- package/src/migration/upgrade-to-angular-10.ts +6 -2
- package/src/migration/upgrade-to-angular-11.ts +11 -2
- package/src/migration/upgrade-to-angular-12.ts +6 -2
- package/src/migration/upgrade-to-angular-13.ts +6 -2
- package/src/migration/upgrade-to-angular-14.ts +6 -2
- package/src/migration/upgrade-to-angular-15.ts +6 -2
- package/src/migration/upgrade-to-angular-16.ts +3 -2
- package/src/migration/upgrade-to-angular-17.ts +6 -2
- package/src/migration/upgrade-to-angular-18.ts +6 -2
- package/src/migration/upgrade-to-angular-19.ts +6 -2
- package/src/migration/upgrade-to-angular-20.ts +6 -2
- package/src/migration/upgrade-to-angular-21.ts +3 -2
- package/src/migration/upgrade-to-angular-22.ts +3 -2
- package/src/migration/upgrade-to-angular-8.ts +6 -1
- package/src/migration/upgrade-to-angular-9.ts +6 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {StylesheetRecipe, withoutComments} from "../components/stylesheets";
|
|
8
|
+
|
|
9
|
+
const KEY = 'use-system-variables';
|
|
10
|
+
|
|
11
|
+
const PREFIX_KEY = 'system-variables-prefix';
|
|
12
|
+
|
|
13
|
+
export class AddSystemVariablesPrefix extends StylesheetRecipe {
|
|
14
|
+
readonly name = "org.openrewrite.angular.material.AddSystemVariablesPrefix";
|
|
15
|
+
readonly displayName = "Add an explicit `system-variables-prefix` to themes that use system variables";
|
|
16
|
+
readonly description = "Material 19 changed the default prefix of the CSS variables that themes with " +
|
|
17
|
+
"`use-system-variables: true` emit. Adds `system-variables-prefix: sys` to those theme maps so the variables " +
|
|
18
|
+
"keep their names. This is the system variable prefix migration of the `@angular/material` 19 `ng update`.";
|
|
19
|
+
|
|
20
|
+
protected acceptsPath(sourcePath: string): boolean {
|
|
21
|
+
return sourcePath.endsWith('.scss');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected migrate(content: string): string {
|
|
25
|
+
if (!content.includes('@angular/material') || !content.includes(KEY)) return content;
|
|
26
|
+
return withoutComments(content, addPrefix);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function addPrefix(content: string): string {
|
|
31
|
+
const insertions: {at: number, text: string}[] = [];
|
|
32
|
+
let index = content.indexOf(KEY);
|
|
33
|
+
while (index > -1) {
|
|
34
|
+
const colon = content.indexOf(':', index);
|
|
35
|
+
const valueEnd = colon === -1 ? -1 : endOfValue(content, colon);
|
|
36
|
+
if (valueEnd === -1) {
|
|
37
|
+
index = content.indexOf(KEY, index + KEY.length);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const value = content.slice(colon + 1, valueEnd + 1).trim();
|
|
41
|
+
if (value.startsWith('true') && !hasPrefix(content, index)) {
|
|
42
|
+
insertions.push({at: insertIndex(content, valueEnd), text: `${value.endsWith(',') ? '' : ','}\n ${PREFIX_KEY}: sys,`});
|
|
43
|
+
}
|
|
44
|
+
index = content.indexOf(KEY, valueEnd);
|
|
45
|
+
}
|
|
46
|
+
let migrated = content;
|
|
47
|
+
for (const {at, text} of insertions.reverse()) migrated = migrated.slice(0, at) + text + migrated.slice(at);
|
|
48
|
+
return migrated;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function endOfValue(content: string, from: number): number {
|
|
52
|
+
for (let i = from + 1; i < content.length; i++) {
|
|
53
|
+
if (content[i] === ',' || content[i] === '\n' || content[i] === ')') return i;
|
|
54
|
+
}
|
|
55
|
+
return -1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function insertIndex(content: string, valueEnd: number): number {
|
|
59
|
+
for (let i = valueEnd; i < content.length; i++) {
|
|
60
|
+
if (content[i] === '\n' || content[i] === ')') return i;
|
|
61
|
+
}
|
|
62
|
+
return valueEnd;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Whether the map that enables system variables already sets their prefix. */
|
|
66
|
+
function hasPrefix(content: string, keyIndex: number): boolean {
|
|
67
|
+
const mapEnd = content.indexOf(')', keyIndex);
|
|
68
|
+
if (mapEnd === -1) return false;
|
|
69
|
+
const mapStart = content.lastIndexOf('(', keyIndex);
|
|
70
|
+
return mapStart > -1 && content.slice(mapStart, mapEnd).includes(PREFIX_KEY);
|
|
71
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {Cursor, ExecutionContext, foundSearchResult, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
|
|
9
|
+
import {escapeRegExp, includePattern, maskComments, withoutComments, withSemicolon} from "../components/stylesheets";
|
|
10
|
+
import {beforeMaterialVersion, materialMajorScanner, materialNamespaces} from "./material-version";
|
|
11
|
+
import {withMdcMixins} from "./migrate-legacy-material";
|
|
12
|
+
import {hasSearchResult} from "../components/lst";
|
|
13
|
+
|
|
14
|
+
/** The comment that the `@angular/material` 17 `ng update` puts above the base mixins it adds. */
|
|
15
|
+
const PREAMBLE = `
|
|
16
|
+
// The following mixins include base theme styles that are only needed once per application. These
|
|
17
|
+
// theme styles do not depend on the color, typography, or density settings in your theme. However,
|
|
18
|
+
// these styles may differ depending on the theme's design system. Currently all themes use the
|
|
19
|
+
// Material 2 design system, but in the future it may be possible to create theme based on other
|
|
20
|
+
// design systems, such as Material 3.
|
|
21
|
+
//
|
|
22
|
+
// Please note: you do not need to include the 'base' mixins, if you include the corresponding
|
|
23
|
+
// 'theme' mixin elsewhere in your Sass. The full 'theme' mixins already include the base styles.
|
|
24
|
+
//
|
|
25
|
+
// To learn more about "base" theme styles visit our theming guide:
|
|
26
|
+
// https://material.angular.io/guide/theming#theming-dimensions
|
|
27
|
+
//
|
|
28
|
+
// TODO(v17): Please move these @include statements to the preferred place in your Sass, and pass
|
|
29
|
+
// your theme to them. This will ensure the correct values for your app are included.`.split('\n');
|
|
30
|
+
|
|
31
|
+
interface MixinSet {
|
|
32
|
+
theme: string;
|
|
33
|
+
color: string;
|
|
34
|
+
typography: string;
|
|
35
|
+
density: string;
|
|
36
|
+
base: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const MIXIN_SETS: MixinSet[] = [
|
|
40
|
+
{theme: 'all-component-themes', color: 'all-component-colors', typography: 'all-component-typographies',
|
|
41
|
+
density: 'all-component-densities', base: 'all-component-bases'},
|
|
42
|
+
...['core', 'card', 'progress-bar', 'tooltip', 'form-field', 'input', 'select', 'autocomplete', 'dialog', 'chips',
|
|
43
|
+
'slide-toggle', 'radio', 'slider', 'menu', 'list', 'paginator', 'tabs', 'checkbox', 'button', 'icon-button',
|
|
44
|
+
'fab', 'snack-bar', 'table', 'progress-spinner', 'badge', 'bottom-sheet', 'button-toggle', 'datepicker',
|
|
45
|
+
'divider', 'expansion', 'grid-list', 'icon', 'sidenav', 'stepper', 'sort', 'toolbar', 'tree']
|
|
46
|
+
.map(c => ({theme: `${c}-theme`, color: `${c}-color`, typography: `${c}-typography`, density: `${c}-density`, base: `${c}-base`})),
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
interface Accumulator {
|
|
50
|
+
majors: Map<string, number>;
|
|
51
|
+
found: Set<string>;
|
|
52
|
+
missing: Set<string>;
|
|
53
|
+
/** The arguments that stylesheets pass to color, typography and density mixins. */
|
|
54
|
+
themes: Set<string>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function includes(content: string, ns: string, mixin: string): string[] {
|
|
58
|
+
return [...content.matchAll(includePattern(`${ns}${mixin}`))].map(m => (m[2] ?? '').split(',')[0].trim());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class AddThemeBaseMixins extends ScanningRecipe<Accumulator> {
|
|
62
|
+
readonly name = "org.openrewrite.angular.material.AddThemeBaseMixins";
|
|
63
|
+
readonly displayName = "Add the theme base mixins of Angular Material 17";
|
|
64
|
+
readonly description = "Material 17 moved the base styles of each component out of its color, typography and " +
|
|
65
|
+
"density mixins into a separate `base` mixin, which only the full `theme` mixin includes. When the stylesheets " +
|
|
66
|
+
"of a project include such partial mixins, such as `mat.button-color`, but neither the matching `theme` nor " +
|
|
67
|
+
"`base` mixin, adds the missing `base` mixins after `@include mat.core()`, or after the declaration of the theme " +
|
|
68
|
+
"when every partial mixin uses the same theme variable. A stylesheet that includes `mat.core()` without such a " +
|
|
69
|
+
"theme in scope is marked instead of getting `base` mixins without a theme, which would not compile. This is the " +
|
|
70
|
+
"theme base migration of the `@angular/material` 17 `ng update`, applied to projects that are not on Material 17 yet.";
|
|
71
|
+
|
|
72
|
+
initialValue(_ctx: ExecutionContext): Accumulator {
|
|
73
|
+
return {majors: new Map(), found: new Set(), missing: new Set(), themes: new Set()};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async scanner(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
77
|
+
const packageJson = materialMajorScanner((directory, major) => acc.majors.set(directory, major));
|
|
78
|
+
const stylesheets = new class extends PlainTextVisitor<ExecutionContext> {
|
|
79
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
80
|
+
if (!text.sourcePath.endsWith('.scss')) return text;
|
|
81
|
+
const content = withMdcMixins(maskComments(text.text));
|
|
82
|
+
for (const ns of materialNamespaces(content)) {
|
|
83
|
+
for (const set of MIXIN_SETS) {
|
|
84
|
+
if (includes(content, ns, set.theme).length > 0 || includes(content, ns, set.base).length > 0) {
|
|
85
|
+
acc.found.add(set.base);
|
|
86
|
+
acc.missing.delete(set.base);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const partial = [set.color, set.typography, set.density].flatMap(m => includes(content, ns, m));
|
|
90
|
+
if (partial.length === 0) continue;
|
|
91
|
+
partial.forEach(theme => acc.themes.add(theme));
|
|
92
|
+
if (!acc.found.has(set.base)) acc.missing.add(set.base);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
}();
|
|
98
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
99
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
100
|
+
await packageJson.visit(tree, p, parent);
|
|
101
|
+
return await stylesheets.visit(tree, p, parent) as R | undefined;
|
|
102
|
+
}
|
|
103
|
+
}();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async editorWithData(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
107
|
+
const missing = acc.found.has('all-component-bases') ? new Set<string>()
|
|
108
|
+
: acc.missing.has('all-component-bases') ? new Set(['all-component-bases']) : acc.missing;
|
|
109
|
+
const theme = acc.themes.size === 1 ? [...acc.themes][0] : undefined;
|
|
110
|
+
return new class extends PlainTextVisitor<ExecutionContext> {
|
|
111
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
112
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
113
|
+
if (!t || missing.size === 0 || !t.sourcePath.endsWith('.scss') || !beforeMaterialVersion(acc.majors, t.sourcePath, 17)) return t;
|
|
114
|
+
const mixins = [...missing].sort();
|
|
115
|
+
const updated = withoutComments(t.text, content => addBaseMixins(content, mixins, theme));
|
|
116
|
+
if (updated !== t.text) return {...t, text: updated, snippets: []};
|
|
117
|
+
const ns = materialNamespaces(maskComments(t.text)).find(n => includePattern(`${n}core`).test(maskComments(t.text)));
|
|
118
|
+
if (ns === undefined || hasSearchResult(t, "Material 17 moved the base styles")) return t;
|
|
119
|
+
return foundSearchResult(t, "Material 17 moved the base styles of the components out of their color, " +
|
|
120
|
+
"typography and density mixins, which the stylesheets of this project include without the full theme " +
|
|
121
|
+
`mixin. Include ${mixins.map(m => `\`${ns}${m}($theme)\``).join(', ')} once with your theme.`);
|
|
122
|
+
}
|
|
123
|
+
}();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function addBaseMixins(content: string, mixins: string[], theme: string | undefined): string {
|
|
128
|
+
let migrated = content;
|
|
129
|
+
for (const ns of materialNamespaces(content)) {
|
|
130
|
+
const declaration = theme?.startsWith('$') ? declarationEnd(migrated, theme) : -1;
|
|
131
|
+
migrated = migrated.replace(includePattern(`${ns}core`), (include, indent: string, _args, offset: number) => {
|
|
132
|
+
const lines = (argument: string) => [
|
|
133
|
+
...PREAMBLE.map(line => line === '' ? '' : `${indent}${line}`),
|
|
134
|
+
...mixins.map(mixin => `${indent}@include ${ns}${mixin}(${argument});`),
|
|
135
|
+
].join('\n');
|
|
136
|
+
if (declaration === -1) return include;
|
|
137
|
+
if (declaration < offset) return `${withSemicolon(include)}\n${lines(theme!)}`;
|
|
138
|
+
return include;
|
|
139
|
+
});
|
|
140
|
+
if (declaration > -1 && !migrated.includes(`${ns}${mixins[0]}(${theme})`)) {
|
|
141
|
+
const at = declarationEnd(migrated, theme!);
|
|
142
|
+
migrated = `${migrated.slice(0, at)}\n${PREAMBLE.join('\n')}\n${mixins.map(m => `@include ${ns}${m}(${theme});`).join('\n')}${migrated.slice(at)}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return migrated;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The index after the `;` that ends the top-level declaration of a variable, or `-1` if the stylesheet does not declare it. */
|
|
149
|
+
function declarationEnd(content: string, variable: string): number {
|
|
150
|
+
const match = new RegExp(`^${escapeRegExp(variable)}\\s*:`, 'm').exec(content);
|
|
151
|
+
if (!match) return -1;
|
|
152
|
+
let depth = 0;
|
|
153
|
+
for (let i = match.index + match[0].length; i < content.length; i++) {
|
|
154
|
+
if (content[i] === '(') depth++;
|
|
155
|
+
else if (content[i] === ')') depth--;
|
|
156
|
+
else if (content[i] === ';' && depth === 0) return i + 1;
|
|
157
|
+
}
|
|
158
|
+
return -1;
|
|
159
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
10
|
+
import {importedNames} from "../components/symbols";
|
|
11
|
+
import {hasSearchResult} from "../components/lst";
|
|
12
|
+
|
|
13
|
+
export class FindChipInputEventWithoutChipInput extends Recipe {
|
|
14
|
+
readonly name = "org.openrewrite.angular.material.FindChipInputEventWithoutChipInput";
|
|
15
|
+
readonly displayName = "Find `MatChipInputEvent` objects without `chipInput`";
|
|
16
|
+
readonly description = "Material 14 made `MatChipInputEvent.chipInput` required. Finds object literals declared or " +
|
|
17
|
+
"cast as a `MatChipInputEvent`, as tests often build them, that do not set `chipInput`.";
|
|
18
|
+
|
|
19
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
20
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
21
|
+
private chipInputEvent = new Map<string, string>();
|
|
22
|
+
|
|
23
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
24
|
+
this.chipInputEvent = importedNames(cu, '@angular/material/chips', ['MatChipInputEvent']);
|
|
25
|
+
return this.chipInputEvent.size === 0 ? cu : super.visitJsCompilationUnit(cu, p);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
|
|
29
|
+
const n = await super.visitNewClass(newClass, p) as J.NewClass;
|
|
30
|
+
if (n.class || !n.body || hasSearchResult(n, "`MatChipInputEvent.chipInput` is required")) return n;
|
|
31
|
+
const declared = this.declaredType();
|
|
32
|
+
if (!declared || !isIdentifier(declared) || !this.chipInputEvent.has(declared.simpleName)) return n;
|
|
33
|
+
const keys = n.body.statements.map(s => s.element);
|
|
34
|
+
if (keys.some(k => k.kind === JS.Kind.Spread || propertyName(k) === 'chipInput')) return n;
|
|
35
|
+
return foundSearchResult(n, "`MatChipInputEvent.chipInput` is required as of @angular/material 14. Set it " +
|
|
36
|
+
"to the `MatChipInput` that emitted the event.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The type an object literal is declared or cast as, from the closest enclosing declaration or cast. */
|
|
40
|
+
private declaredType(): J | undefined {
|
|
41
|
+
const parent = this.cursor.parentTree()?.value;
|
|
42
|
+
if (parent?.kind === J.Kind.NamedVariable) {
|
|
43
|
+
const declarations = this.cursor.parentTree()?.parentTree()?.value as J.VariableDeclarations | undefined;
|
|
44
|
+
return typeName(declarations?.typeExpression);
|
|
45
|
+
}
|
|
46
|
+
if (parent?.kind === JS.Kind.As) return typeName((parent as JS.As).right);
|
|
47
|
+
if (parent?.kind === J.Kind.TypeCast) return typeName((parent as J.TypeCast).class.tree.element);
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function typeName(typeTree: J | undefined): J | undefined {
|
|
55
|
+
return typeTree?.kind === JS.Kind.TypeInfo ? (typeTree as JS.TypeInfo).typeIdentifier : typeTree;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function propertyName(member: J): string | undefined {
|
|
59
|
+
if (isIdentifier(member)) return member.simpleName;
|
|
60
|
+
if (member.kind !== JS.Kind.PropertyAssignment) return undefined;
|
|
61
|
+
const name = (member as JS.PropertyAssignment).name.element;
|
|
62
|
+
return isIdentifier(name) ? name.simpleName : undefined;
|
|
63
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {Cursor, ExecutionContext, foundSearchResult, Recipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
|
|
9
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
10
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
11
|
+
import {maskComments} from "../components/stylesheets";
|
|
12
|
+
import {importedName, moduleOf} from "../components/symbols";
|
|
13
|
+
import {UNMAPPED_LEGACY_HINTS} from "./migrate-legacy-material";
|
|
14
|
+
import {hasSearchResult} from "../components/lst";
|
|
15
|
+
|
|
16
|
+
const LEGACY_SASS = /@include\s+[\w-]*\.?(all-legacy-component-[\w-]+|legacy-[\w-]+)|[\w-]+\.define-legacy-typography-config\(/;
|
|
17
|
+
|
|
18
|
+
function legacySymbols(imp: JS.Import): string[] {
|
|
19
|
+
const namedBindings = imp.importClause?.namedBindings;
|
|
20
|
+
if (namedBindings?.kind !== JS.Kind.NamedImports) return [];
|
|
21
|
+
return (namedBindings as JS.NamedImports).elements.elements
|
|
22
|
+
.map(element => importedName(element.element as JS.ImportSpecifier))
|
|
23
|
+
.filter((name): name is string => name !== undefined);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const REMOVED_ENTRY_POINT = "was removed in @angular/material 17. Import the MDC-based component";
|
|
27
|
+
|
|
28
|
+
function removedEntryPoint(module: string): string {
|
|
29
|
+
return `\`${module}\` ${REMOVED_ENTRY_POINT} from ` +
|
|
30
|
+
`\`${module.replace('/legacy-', '/')}\` instead, renaming \`MatLegacy*\` symbols to \`Mat*\`.`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class FindLegacyMaterialUsage extends Recipe {
|
|
34
|
+
readonly name = "org.openrewrite.angular.material.FindLegacyMaterialUsage";
|
|
35
|
+
readonly displayName = "Find uses of the legacy Angular Material components";
|
|
36
|
+
readonly description = "Finds imports, dynamic imports and re-exports of the `@angular/material/legacy-*` entry points and stylesheets that " +
|
|
37
|
+
"include the `legacy-*` theme mixins, which Angular Material 17 removed. Move them to the MDC-based components " +
|
|
38
|
+
"of the matching entry point.";
|
|
39
|
+
|
|
40
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
41
|
+
const stylesheets = new class extends PlainTextVisitor<ExecutionContext> {
|
|
42
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
43
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
44
|
+
if (!t || !t.sourcePath.endsWith('.scss') || hasSearchResult(t, "The legacy component theme mixins were removed")) return t;
|
|
45
|
+
if (!LEGACY_SASS.test(maskComments(t.text))) return t;
|
|
46
|
+
return foundSearchResult(t, "The legacy component theme mixins were removed in @angular/material 17. " +
|
|
47
|
+
"Include the theme mixins of the MDC-based components instead, such as `mat.button-theme`.");
|
|
48
|
+
}
|
|
49
|
+
}();
|
|
50
|
+
const imports = new class extends JavaScriptVisitor<ExecutionContext> {
|
|
51
|
+
protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
|
|
52
|
+
const module = moduleOf(jsImport);
|
|
53
|
+
if (!module?.startsWith('@angular/material/legacy-') || hasSearchResult(jsImport, REMOVED_ENTRY_POINT)) return jsImport;
|
|
54
|
+
const hints = legacySymbols(jsImport).filter(name => name in UNMAPPED_LEGACY_HINTS)
|
|
55
|
+
.map(name => `\`${name}\` has no counterpart there. ${UNMAPPED_LEGACY_HINTS[name]}`);
|
|
56
|
+
return foundSearchResult(jsImport, [removedEntryPoint(module), ...hints].join(' '));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async visitLiteral(literal: J.Literal, p: ExecutionContext): Promise<J | undefined> {
|
|
60
|
+
const l = await super.visitLiteral(literal, p) as J.Literal;
|
|
61
|
+
if (typeof l.value !== 'string' || !l.value.startsWith('@angular/material/legacy-') || hasSearchResult(l, REMOVED_ENTRY_POINT)) return l;
|
|
62
|
+
return foundSearchResult(l, removedEntryPoint(l.value));
|
|
63
|
+
}
|
|
64
|
+
}();
|
|
65
|
+
// Each visitor returns a source file it does not accept unchanged.
|
|
66
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
67
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
68
|
+
const visited = await stylesheets.visit<Tree>(tree, p, parent);
|
|
69
|
+
return visited && await imports.visit(visited, p, parent) as R | undefined;
|
|
70
|
+
}
|
|
71
|
+
}();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {ExecutionContext, foundSearchResult, ScanningRecipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
10
|
+
import {importedNames} from "../components/symbols";
|
|
11
|
+
import {extendedClassName, hasSearchResult, isSuperCall} from "../components/lst";
|
|
12
|
+
import {argumentCount} from "../cdk/find-cdk-signature-changes";
|
|
13
|
+
import {beforeMaterialVersion, MATERIAL, materialMajorScanner} from "./material-version";
|
|
14
|
+
|
|
15
|
+
/** The number of arguments the constructor of an `@angular/material` class accepts as of a major version. */
|
|
16
|
+
interface ChangedConstructor {
|
|
17
|
+
module: string;
|
|
18
|
+
name: string;
|
|
19
|
+
min: number;
|
|
20
|
+
max: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Marks constructor calls that no longer fit a changed `@angular/material` constructor, in files whose `package.json` is not on that major yet. */
|
|
24
|
+
export abstract class FindMaterialConstructorChanges extends ScanningRecipe<Map<string, number>> {
|
|
25
|
+
protected abstract readonly version: number;
|
|
26
|
+
protected abstract readonly constructors: ChangedConstructor[];
|
|
27
|
+
|
|
28
|
+
initialValue(_ctx: ExecutionContext): Map<string, number> {
|
|
29
|
+
return new Map();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async scanner(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
33
|
+
return materialMajorScanner((directory, major) => majors.set(directory, major));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async editorWithData(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
37
|
+
const version = this.version;
|
|
38
|
+
const constructors = this.constructors;
|
|
39
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
40
|
+
private classes = new Map<string, ChangedConstructor>();
|
|
41
|
+
|
|
42
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
43
|
+
if (!beforeMaterialVersion(majors, cu.sourcePath, version)) return cu;
|
|
44
|
+
this.classes = new Map();
|
|
45
|
+
for (const c of constructors) {
|
|
46
|
+
for (const local of importedNames(cu, c.module, [c.name]).keys()) this.classes.set(local, c);
|
|
47
|
+
}
|
|
48
|
+
return this.classes.size === 0 ? cu : super.visitJsCompilationUnit(cu, p);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
|
|
52
|
+
const n = await super.visitNewClass(newClass, p) as J.NewClass;
|
|
53
|
+
const changed = n.class && isIdentifier(n.class) ? this.classes.get(n.class.simpleName) : undefined;
|
|
54
|
+
return changed ? mark(n, n.arguments, changed) : n;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected async visitFunctionCall(functionCall: JS.FunctionCall, p: ExecutionContext): Promise<J | undefined> {
|
|
58
|
+
const call = await super.visitFunctionCall(functionCall, p) as JS.FunctionCall;
|
|
59
|
+
if (!isSuperCall(call)) return call;
|
|
60
|
+
const classDecl = this.cursor.firstEnclosing((t: any): t is J.ClassDeclaration => t?.kind === J.Kind.ClassDeclaration);
|
|
61
|
+
const extended = classDecl && extendedClassName(classDecl);
|
|
62
|
+
const changed = extended ? this.classes.get(extended) : undefined;
|
|
63
|
+
return changed ? mark(call, call.arguments, changed) : call;
|
|
64
|
+
}
|
|
65
|
+
}();
|
|
66
|
+
|
|
67
|
+
function mark<T extends J>(call: T, args: J.Container<J>, changed: ChangedConstructor): T {
|
|
68
|
+
const count = argumentCount(args);
|
|
69
|
+
const spread = args.elements.some(a => a.element.kind === JS.Kind.Spread);
|
|
70
|
+
if (spread || (count >= changed.min && count <= changed.max) || hasSearchResult(call, `changed in @angular/material ${version} and takes`)) return call;
|
|
71
|
+
const expected = changed.min === changed.max ? `${changed.min}` : `${changed.min} to ${changed.max}`;
|
|
72
|
+
return foundSearchResult(call, `The constructor of \`${changed.name}\` changed in @angular/material ${version} ` +
|
|
73
|
+
`and takes ${expected} arguments. Update the arguments to match it.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function constructorOf(module: string, name: string, min: number, max: number): ChangedConstructor {
|
|
79
|
+
return {module: `${MATERIAL}/${module}`, name, min, max};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class FindMaterial8ConstructorChanges extends FindMaterialConstructorChanges {
|
|
83
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial8ConstructorChanges";
|
|
84
|
+
readonly displayName = "Find constructor calls broken by Angular Material 8";
|
|
85
|
+
readonly description = "Finds `new` and `super(...)` calls of Angular Material classes whose constructor changed in " +
|
|
86
|
+
"version 8, such as `MatFormField` and `MatButton`, when they pass a number of arguments the new constructor does not accept.";
|
|
87
|
+
|
|
88
|
+
protected readonly version = 8;
|
|
89
|
+
protected readonly constructors = [
|
|
90
|
+
constructorOf('form-field', 'MatFormField', 8, 8),
|
|
91
|
+
constructorOf('tabs', 'MatTabLink', 7, 8),
|
|
92
|
+
constructorOf('stepper', 'MatVerticalStepper', 2, 4),
|
|
93
|
+
constructorOf('badge', 'MatBadge', 4, 5),
|
|
94
|
+
constructorOf('button', 'MatButton', 3, 3),
|
|
95
|
+
constructorOf('button', 'MatAnchor', 3, 3),
|
|
96
|
+
constructorOf('progress-spinner', 'MatSpinner', 4, 5),
|
|
97
|
+
constructorOf('progress-spinner', 'MatProgressSpinner', 4, 5),
|
|
98
|
+
constructorOf('list', 'MatList', 1, 1),
|
|
99
|
+
constructorOf('list', 'MatListItem', 2, 4),
|
|
100
|
+
constructorOf('expansion', 'MatExpansionPanel', 6, 7),
|
|
101
|
+
constructorOf('tabs', 'MatTabHeader', 6, 7),
|
|
102
|
+
constructorOf('tabs', 'MatTabBody', 3, 3),
|
|
103
|
+
constructorOf('slide-toggle', 'MatSlideToggle', 6, 8),
|
|
104
|
+
constructorOf('sidenav', 'MatDrawerContainer', 5, 7),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class FindMaterial9ConstructorChanges extends FindMaterialConstructorChanges {
|
|
109
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial9ConstructorChanges";
|
|
110
|
+
readonly displayName = "Find constructor calls broken by Angular Material 9";
|
|
111
|
+
readonly description = "Finds `new` and `super(...)` calls of `MatSelect` and `MatDialogRef`, whose constructor " +
|
|
112
|
+
"changed in Angular Material 9, when they pass a number of arguments the new constructor does not accept.";
|
|
113
|
+
|
|
114
|
+
protected readonly version = 9;
|
|
115
|
+
protected readonly constructors = [
|
|
116
|
+
constructorOf('select', 'MatSelect', 13, 14),
|
|
117
|
+
constructorOf('dialog', 'MatDialogRef', 2, 3),
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class FindMaterial10ConstructorChanges extends FindMaterialConstructorChanges {
|
|
122
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial10ConstructorChanges";
|
|
123
|
+
readonly displayName = "Find constructor calls broken by Angular Material 10";
|
|
124
|
+
readonly description = "Finds `new` and `super(...)` calls of Angular Material classes whose constructor changed in " +
|
|
125
|
+
"version 10, such as `MatTooltip` and `MatIcon`, when they pass a number of arguments the new constructor does not accept.";
|
|
126
|
+
|
|
127
|
+
protected readonly version = 10;
|
|
128
|
+
protected readonly constructors = [
|
|
129
|
+
constructorOf('slide-toggle', 'MatSlideToggle', 5, 6),
|
|
130
|
+
constructorOf('slider', 'MatSlider', 7, 8),
|
|
131
|
+
constructorOf('sort', 'MatSortHeader', 6, 6),
|
|
132
|
+
constructorOf('autocomplete', 'MatAutocompleteTrigger', 10, 10),
|
|
133
|
+
constructorOf('tooltip', 'MatTooltip', 11, 11),
|
|
134
|
+
constructorOf('icon', 'MatIcon', 5, 5),
|
|
135
|
+
constructorOf('icon', 'MatIconRegistry', 4, 4),
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export class FindMaterial11ConstructorChanges extends FindMaterialConstructorChanges {
|
|
140
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial11ConstructorChanges";
|
|
141
|
+
readonly displayName = "Find constructor calls broken by Angular Material 11";
|
|
142
|
+
readonly description = "Finds `new` and `super(...)` calls of Angular Material classes whose constructor changed in " +
|
|
143
|
+
"version 11, such as `MatChip` and `MatCheckbox`, when they pass a number of arguments the new constructor does not accept.";
|
|
144
|
+
|
|
145
|
+
protected readonly version = 11;
|
|
146
|
+
protected readonly constructors = [
|
|
147
|
+
constructorOf('chips', 'MatChip', 6, 8),
|
|
148
|
+
constructorOf('chips', 'MatChipRemove', 2, 2),
|
|
149
|
+
constructorOf('datepicker', 'MatDatepickerContent', 5, 6),
|
|
150
|
+
constructorOf('bottom-sheet', 'MatBottomSheet', 3, 4),
|
|
151
|
+
constructorOf('bottom-sheet', 'MatBottomSheetRef', 2, 2),
|
|
152
|
+
constructorOf('checkbox', 'MatCheckbox', 5, 7),
|
|
153
|
+
constructorOf('tabs', 'MatTabBodyPortal', 4, 4),
|
|
154
|
+
constructorOf('tabs', 'MatTabNav', 6, 7),
|
|
155
|
+
constructorOf('tabs', 'MatTab', 2, 2),
|
|
156
|
+
constructorOf('core', 'MatCommonModule', 3, 3),
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class FindMaterial12ConstructorChanges extends FindMaterialConstructorChanges {
|
|
161
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial12ConstructorChanges";
|
|
162
|
+
readonly displayName = "Find constructor calls broken by Angular Material 12";
|
|
163
|
+
readonly description = "Finds `new` and `super(...)` calls of Angular Material classes whose constructor changed in " +
|
|
164
|
+
"version 12, such as `MatTooltip` and `MatStep`, when they pass a number of arguments the new constructor does not accept.";
|
|
165
|
+
|
|
166
|
+
protected readonly version = 12;
|
|
167
|
+
protected readonly constructors = [
|
|
168
|
+
constructorOf('tooltip', 'MatTooltip', 12, 12),
|
|
169
|
+
constructorOf('datepicker', 'MatDatepickerContent', 6, 6),
|
|
170
|
+
constructorOf('stepper', 'MatVerticalStepper', 4, 4),
|
|
171
|
+
constructorOf('stepper', 'MatStep', 3, 4),
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export class FindMaterial13ConstructorChanges extends FindMaterialConstructorChanges {
|
|
176
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial13ConstructorChanges";
|
|
177
|
+
readonly displayName = "Find constructor calls broken by Angular Material 13";
|
|
178
|
+
readonly description = "Finds `new` and `super(...)` calls of Angular Material classes whose constructor changed in " +
|
|
179
|
+
"version 13, such as `MatFormField` and `MatDatepicker`, when they pass a number of arguments the new constructor does not accept.";
|
|
180
|
+
|
|
181
|
+
protected readonly version = 13;
|
|
182
|
+
protected readonly constructors = [
|
|
183
|
+
constructorOf('form-field', 'MatFormField', 7, 7),
|
|
184
|
+
constructorOf('datepicker', 'MatDatepicker', 7, 7),
|
|
185
|
+
constructorOf('datepicker', 'MatDateRangePicker', 7, 7),
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class FindMaterial14ConstructorChanges extends FindMaterialConstructorChanges {
|
|
190
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial14ConstructorChanges";
|
|
191
|
+
readonly displayName = "Find constructor calls broken by Angular Material 14";
|
|
192
|
+
readonly description = "Finds `new` and `super(...)` calls of `MatSelectionList`, `MatSelectionListChange` and " +
|
|
193
|
+
"`MatStepper`, whose constructor changed in Angular Material 14, when they pass a number of arguments the new " +
|
|
194
|
+
"constructor does not accept.";
|
|
195
|
+
|
|
196
|
+
protected readonly version = 14;
|
|
197
|
+
protected readonly constructors = [
|
|
198
|
+
constructorOf('list', 'MatSelectionList', 3, 3),
|
|
199
|
+
constructorOf('list', 'MatSelectionListChange', 2, 2),
|
|
200
|
+
constructorOf('stepper', 'MatStepper', 3, 3),
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export class FindMaterial15ConstructorChanges extends FindMaterialConstructorChanges {
|
|
205
|
+
readonly name = "org.openrewrite.angular.material.FindMaterial15ConstructorChanges";
|
|
206
|
+
readonly displayName = "Find constructor calls broken by Angular Material 15";
|
|
207
|
+
readonly description = "Finds `new` and `super(...)` calls of the Angular Material classes whose constructor the " +
|
|
208
|
+
"MDC-based components of version 15 changed, such as `MatFormField` and `MatListItem`, when they pass a number " +
|
|
209
|
+
"of arguments the new constructor does not accept.";
|
|
210
|
+
|
|
211
|
+
protected readonly version = 15;
|
|
212
|
+
protected readonly constructors = [
|
|
213
|
+
constructorOf('button', 'MatButton', 3, 4),
|
|
214
|
+
constructorOf('checkbox', 'MatCheckbox', 4, 6),
|
|
215
|
+
constructorOf('chips', 'MatChip', 5, 8),
|
|
216
|
+
constructorOf('chips', 'MatChipInput', 2, 3),
|
|
217
|
+
constructorOf('chips', 'MatChipTrailingIcon', 2, 2),
|
|
218
|
+
constructorOf('dialog', 'MatDialogContainer', 7, 9),
|
|
219
|
+
constructorOf('form-field', 'MatFormField', 5, 8),
|
|
220
|
+
constructorOf('list', 'MatList', 0, 0),
|
|
221
|
+
constructorOf('list', 'MatListItem', 4, 6),
|
|
222
|
+
constructorOf('list', 'MatListOption', 5, 7),
|
|
223
|
+
constructorOf('list', 'MatSelectionList', 2, 2),
|
|
224
|
+
constructorOf('progress-bar', 'MatProgressBar', 3, 5),
|
|
225
|
+
constructorOf('progress-spinner', 'MatProgressSpinner', 2, 3),
|
|
226
|
+
constructorOf('slider', 'MatSlider', 5, 7),
|
|
227
|
+
constructorOf('tabs', 'MatInkBar', 1, 1),
|
|
228
|
+
constructorOf('tabs', 'MatTabLink', 5, 6),
|
|
229
|
+
constructorOf('tabs', 'MatTabNav', 6, 8),
|
|
230
|
+
];
|
|
231
|
+
}
|