@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,273 @@
|
|
|
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 {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
10
|
+
import {isLiteral, J} from "@openrewrite/rewrite/java";
|
|
11
|
+
import {hasSearchResult, propertyName} from "../components/lst";
|
|
12
|
+
import {FindRemovedSymbols, RemovedSymbol} from "../components/symbols";
|
|
13
|
+
import {mapOpeningTags, withoutHtmlComments} from "../components/templates";
|
|
14
|
+
import {attributeNamed, descendants, parseElements} from "../components/template-elements";
|
|
15
|
+
import {FindRemovedMaterialMembers, RemovedMember} from "./find-removed-material-members";
|
|
16
|
+
import {beforeMaterialVersion, MaterialProjects, materialProjectScanner} from "./material-version";
|
|
17
|
+
|
|
18
|
+
const GUIDE = "See the Angular Material v15 MDC migration guide.";
|
|
19
|
+
|
|
20
|
+
const CHIPS = "Chips were rewritten in @angular/material 15. Use `<mat-chip-listbox>` with `<mat-chip-option>` " +
|
|
21
|
+
"for selectable chips, or `<mat-chip-grid>` with `<mat-chip-row>` for chips with a text input.";
|
|
22
|
+
const SLIDER = "The slider was rewritten in @angular/material 15. Put an `<input matSliderThumb>` inside `<mat-slider>` " +
|
|
23
|
+
"and move `value`, `(change)` and `(input)` to it; `thumbLabel` became `discrete`, and `tickInterval`, `displayValue`, " +
|
|
24
|
+
"`valueText`, `invert` and `vertical` were removed.";
|
|
25
|
+
const LIST = "List items were reworked in @angular/material 15. Use `matListItemTitle` and `matListItemLine` instead " +
|
|
26
|
+
"of `matLine`, and `matListItemIcon` and `matListItemAvatar` instead of `matListIcon` and `matListAvatar`.";
|
|
27
|
+
|
|
28
|
+
function removed(entryPoint: string, names: string[], hint: string): RemovedSymbol[] {
|
|
29
|
+
return names.map(name => ({
|
|
30
|
+
module: `@angular/material/${entryPoint}`,
|
|
31
|
+
name,
|
|
32
|
+
message: `\`${name}\` was removed from \`@angular/material/${entryPoint}\` in @angular/material 15. ${hint}`,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class FindRemovedMaterial15Apis extends FindRemovedSymbols {
|
|
37
|
+
readonly name = "org.openrewrite.angular.material.FindRemovedMaterial15Apis";
|
|
38
|
+
readonly displayName = "Find APIs removed by the Angular Material 15 MDC components";
|
|
39
|
+
readonly description = "Finds imports of the chips, form field, list and slider APIs that the MDC-based components " +
|
|
40
|
+
"of Angular Material 15 no longer export, such as `MatChipList` and `MatPlaceholder`.";
|
|
41
|
+
|
|
42
|
+
protected readonly symbols = [
|
|
43
|
+
...removed('chips', ['MatChipList', 'MatChipListChange'],
|
|
44
|
+
"Use `MatChipListbox` and `MatChipListboxChange`, or `MatChipGrid` for chips with a text input."),
|
|
45
|
+
...removed('form-field', ['MatPlaceholder'], "Use `<mat-label>` or the `placeholder` of the input instead."),
|
|
46
|
+
...removed('list', ['MatListAvatarCssMatStyler', 'MatListIconCssMatStyler'],
|
|
47
|
+
"Use the `matListItemAvatar` and `matListItemIcon` directives instead."),
|
|
48
|
+
...removed('slider', ['MAT_SLIDER_VALUE_ACCESSOR'], "The `<input matSliderThumb>` inside the slider is the form control now."),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function members(classNames: string[], names: string[], message: string): RemovedMember[] {
|
|
53
|
+
return names.map(name => ({classNames, name, message: `\`${classNames[0]}.${name}\` ${message}`}));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Members that the MDC-based components of Material 15 removed or changed. */
|
|
57
|
+
export const MATERIAL_15_MEMBERS: RemovedMember[] = [
|
|
58
|
+
...members(['MatChip'], ['selected', 'selectable', 'selectionChange', 'ariaSelected', 'select', 'deselect',
|
|
59
|
+
'selectViaInteraction', 'toggleSelected', 'chipListSelectable', 'avatar', 'rippleConfig', 'rippleDisabled'],
|
|
60
|
+
"was removed in @angular/material 15. Selection moved to `MatChipOption` inside a `<mat-chip-listbox>`."),
|
|
61
|
+
...members(['MatChipInput'], ['chipList'], "was removed in @angular/material 15. Use `chipGrid` instead."),
|
|
62
|
+
...members(['MatSlider', '_MatSliderBase'], ['value', 'valueChange', 'change', 'input', 'focus', 'blur', 'tabIndex', 'thumbLabel',
|
|
63
|
+
'tickInterval', 'valueText', 'displayValue', 'invert', 'vertical', 'percent', 'defaultTabIndex', 'onTouched',
|
|
64
|
+
'writeValue', 'registerOnChange', 'registerOnTouched', 'setDisabledState'],
|
|
65
|
+
"was removed in @angular/material 15. The value, its events and focus moved to the `MatSliderThumb` input inside the slider."),
|
|
66
|
+
...members(['MatFormField'], ['updateOutlineGap', 'defaultColor'], "was removed in @angular/material 15."),
|
|
67
|
+
...members(['MatListOption'], ['selectionList'], "was removed in @angular/material 15."),
|
|
68
|
+
...members(['MatButton', 'MatAnchor'], ['isRoundButton', 'isIconButton'],
|
|
69
|
+
"was removed in @angular/material 15. Icon buttons and FABs are separate components now."),
|
|
70
|
+
...members(['MatProgressBar'], ['progressbarId'], "was removed in @angular/material 15."),
|
|
71
|
+
...members(['MatSnackBar', '_MatSnackBarBase'], ['openFromComponent', 'openFromTemplate'],
|
|
72
|
+
"shows custom content with the MDC snack bar as of @angular/material 15. Mark the text with " +
|
|
73
|
+
"`matSnackBarLabel`, the action container with `matSnackBarActions` and each action with `matSnackBarAction`, " +
|
|
74
|
+
"or all content is treated as the label."),
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
export class FindRemovedMaterial15Members extends FindRemovedMaterialMembers {
|
|
78
|
+
readonly name = "org.openrewrite.angular.material.FindRemovedMaterial15Members";
|
|
79
|
+
readonly displayName = "Find members removed by the Angular Material 15 MDC components";
|
|
80
|
+
readonly description = "Finds uses of the chip, slider, form field, list, button and progress bar members that the " +
|
|
81
|
+
"MDC-based components of Angular Material 15 removed, and the custom snack bar content that needs the new " +
|
|
82
|
+
"snack bar directives.";
|
|
83
|
+
|
|
84
|
+
protected readonly version = 15;
|
|
85
|
+
protected readonly members = MATERIAL_15_MEMBERS;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const LIST_TAGS = /<(mat-list|mat-nav-list|mat-action-list|mat-selection-list|mat-list-item|mat-list-option)\b|mat-list-item/;
|
|
89
|
+
|
|
90
|
+
/** The MDC migration problems of one template, as distinct messages. */
|
|
91
|
+
export function mdcTemplateFindings(source: string): string[] {
|
|
92
|
+
const template = withoutHtmlComments(source);
|
|
93
|
+
const findings = new Set<string>();
|
|
94
|
+
const migratedSlider = /matSlider(Start|End)?Thumb/.test(template);
|
|
95
|
+
const usesLists = LIST_TAGS.test(template);
|
|
96
|
+
mapOpeningTags(template, (tag, attrs) => {
|
|
97
|
+
const names = attrs.replace(/"[^"]*"|'[^']*'/g, '""');
|
|
98
|
+
const has = (name: string) => new RegExp(`(^|\\s)[\\[(]*${name}[\\])]*(?=[\\s=/]|$)`).test(names);
|
|
99
|
+
if (tag === 'mat-chip-list') findings.add(CHIPS);
|
|
100
|
+
if ((tag === 'mat-chip' || tag === 'mat-basic-chip' || has('mat-chip') || has('mat-basic-chip')) &&
|
|
101
|
+
(has('selected') || has('selectable') || has('selectionChange'))) {
|
|
102
|
+
findings.add(CHIPS);
|
|
103
|
+
}
|
|
104
|
+
if ((tag === 'mat-chip-grid' && (has('multiple') || has('selectable') || has('compareWith'))) ||
|
|
105
|
+
(tag === 'mat-chip-row' && (has('selected') || has('selectable') || has('selectionChange')))) {
|
|
106
|
+
findings.add("Chips in a `<mat-chip-grid>` can't be selected as of @angular/material 15, so its `multiple` " +
|
|
107
|
+
"and `compareWith` and the `selected` and `selectionChange` of its chips are gone. " +
|
|
108
|
+
"Remove them, or use `<mat-chip-listbox>` with `<mat-chip-option>` for selectable chips.");
|
|
109
|
+
}
|
|
110
|
+
if (tag === 'mat-slider' && !migratedSlider) findings.add(SLIDER);
|
|
111
|
+
if (tag === 'mat-form-field' && /(^|\s)(appearance\s*=\s*["']\s*(legacy|standard)\s*["']|\[appearance\]\s*=\s*["']\s*'(legacy|standard)'\s*["'])/.test(attrs)) {
|
|
112
|
+
findings.add("The `legacy` and `standard` form field appearances were removed in @angular/material 15. " +
|
|
113
|
+
"Use `fill` or `outline`, and add a `<mat-label>` where the placeholder served as the label.");
|
|
114
|
+
}
|
|
115
|
+
if (tag === 'mat-form-field' && /(^|\s)(floatLabel\s*=\s*["']\s*never\s*["']|\[floatLabel\]\s*=\s*["']\s*'never'\s*["'])/.test(attrs)) {
|
|
116
|
+
findings.add("`floatLabel=\"never\"` was removed in @angular/material 15. Use the `placeholder` of the input instead.");
|
|
117
|
+
}
|
|
118
|
+
if (has('matListIcon') || has('mat-list-icon') || has('matListAvatar') || has('mat-list-avatar')) {
|
|
119
|
+
findings.add(usesLists ? LIST : "`matListIcon` and `matListAvatar` were removed in @angular/material 15, so " +
|
|
120
|
+
"outside a list they no longer add the `mat-list-icon` and `mat-list-avatar` classes. Remove them, or " +
|
|
121
|
+
"add the class and its styles yourself.");
|
|
122
|
+
}
|
|
123
|
+
if (usesLists && (has('matLine') || has('mat-line'))) findings.add(LIST);
|
|
124
|
+
if (tag === 'mat-placeholder') {
|
|
125
|
+
findings.add("`<mat-placeholder>` was removed in @angular/material 15. Use `<mat-label>` or the `placeholder` of the input instead.");
|
|
126
|
+
}
|
|
127
|
+
if (has('mat-tab-nav-bar') && !has('tabPanel')) {
|
|
128
|
+
findings.add("A `mat-tab-nav-bar` needs a `[tabPanel]` as of @angular/material 15. Wrap the routed content in " +
|
|
129
|
+
"`<mat-tab-nav-panel #tabPanel>` and bind it with `[tabPanel]=\"tabPanel\"`.");
|
|
130
|
+
}
|
|
131
|
+
if (has('mat-card-content') || has('matCardContent')) {
|
|
132
|
+
findings.add("`mat-card-content` only matches the element as of @angular/material 15. Use `<mat-card-content>` instead of the attribute.");
|
|
133
|
+
}
|
|
134
|
+
return attrs;
|
|
135
|
+
});
|
|
136
|
+
return [...findings];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const PLACEHOLDER_LABEL = "A `<mat-form-field>` without a `<mat-label>` showed the placeholder of its control as the " +
|
|
140
|
+
"floating label only with the `legacy` appearance, the default before @angular/material 15. Add a `<mat-label>` to " +
|
|
141
|
+
"keep the label.";
|
|
142
|
+
|
|
143
|
+
/** Form fields that relied on the `legacy` appearance to show the placeholder of their control as the label. */
|
|
144
|
+
export function placeholderLabelFields(template: string): {explicit: boolean, implicit: boolean} {
|
|
145
|
+
const result = {explicit: false, implicit: false};
|
|
146
|
+
if (!template.includes('mat-form-field')) return result;
|
|
147
|
+
for (const field of parseElements(template).filter(e => e.name === 'mat-form-field')) {
|
|
148
|
+
const inside = descendants(field);
|
|
149
|
+
if (inside.some(e => e.name === 'mat-label') || !inside.some(e => attributeNamed(e, 'placeholder'))) continue;
|
|
150
|
+
const appearance = attributeNamed(field, 'appearance');
|
|
151
|
+
const value = appearance?.name.startsWith('[') ? appearance.value?.trim().match(/^'(\w+)'$/)?.[1] : appearance?.value?.trim();
|
|
152
|
+
if (!appearance) result.implicit = true;
|
|
153
|
+
else if (value === 'legacy' || value === 'standard') result.explicit = true;
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface MdcTemplateScan extends MaterialProjects {
|
|
159
|
+
/** Source paths whose form fields relied on the `legacy` appearance, explicitly or as the default. */
|
|
160
|
+
explicitLegacy: Set<string>;
|
|
161
|
+
implicitLegacy: Set<string>;
|
|
162
|
+
defaultsToken: boolean;
|
|
163
|
+
defaultsAppearance: boolean;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class FindMdcTemplateChanges extends ScanningRecipe<MdcTemplateScan> {
|
|
167
|
+
readonly name: string = "org.openrewrite.angular.material.FindMdcTemplateChanges";
|
|
168
|
+
readonly displayName: string = "Find templates affected by the Angular Material 15 MDC components";
|
|
169
|
+
readonly description: string = "Finds `.html` templates and inline `template` metadata of projects not on Material 15 yet that use component APIs the MDC-based " +
|
|
170
|
+
"components of Angular Material 15 changed: `<mat-chip-list>` and chip selection, the old slider markup, the " +
|
|
171
|
+
"`legacy` and `standard` form field appearances, `floatLabel=\"never\"`, `<mat-placeholder>`, `matLine`, " +
|
|
172
|
+
"`matListIcon` and `matListAvatar` in lists, a `mat-tab-nav-bar` without `tabPanel`, and the " +
|
|
173
|
+
"`mat-card-content` attribute, selection on chips in a `<mat-chip-grid>`, and form fields that relied on the " +
|
|
174
|
+
"`legacy` appearance to show the placeholder as the label, unless `MAT_FORM_FIELD_DEFAULT_OPTIONS` sets another " +
|
|
175
|
+
"default appearance.";
|
|
176
|
+
|
|
177
|
+
/** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
|
|
178
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
179
|
+
return beforeMaterialVersion(projects.majors, sourcePath, 15);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
initialValue(_ctx: ExecutionContext): MdcTemplateScan {
|
|
183
|
+
return {majors: new Map(), legacyPaths: new Set(), explicitLegacy: new Set(), implicitLegacy: new Set(), defaultsToken: false, defaultsAppearance: false};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async scanner(acc: MdcTemplateScan): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
187
|
+
const majors = materialProjectScanner(acc);
|
|
188
|
+
const record = (sourcePath: string, template: string) => {
|
|
189
|
+
const fields = placeholderLabelFields(template);
|
|
190
|
+
if (fields.explicit) acc.explicitLegacy.add(sourcePath);
|
|
191
|
+
if (fields.implicit) acc.implicitLegacy.add(sourcePath);
|
|
192
|
+
};
|
|
193
|
+
const html = new class extends PlainTextVisitor<ExecutionContext> {
|
|
194
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
195
|
+
if (text.sourcePath.endsWith('.html')) record(text.sourcePath, text.text);
|
|
196
|
+
return text;
|
|
197
|
+
}
|
|
198
|
+
}();
|
|
199
|
+
const typescript = new class extends JavaScriptVisitor<ExecutionContext> {
|
|
200
|
+
private sourcePath = '';
|
|
201
|
+
|
|
202
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
203
|
+
this.sourcePath = cu.sourcePath;
|
|
204
|
+
return super.visitJsCompilationUnit(cu, p);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
protected async visitIdentifier(identifier: J.Identifier, p: ExecutionContext): Promise<J | undefined> {
|
|
208
|
+
if (identifier.simpleName === 'MAT_FORM_FIELD_DEFAULT_OPTIONS') acc.defaultsToken = true;
|
|
209
|
+
return super.visitIdentifier(identifier, p);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
protected async visitPropertyAssignment(property: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
|
|
213
|
+
const name = propertyName(property.name.element);
|
|
214
|
+
const initializer = property.initializer;
|
|
215
|
+
if (initializer && isLiteral(initializer) && typeof initializer.value === 'string') {
|
|
216
|
+
if (name === 'template') record(this.sourcePath, initializer.value);
|
|
217
|
+
if (name === 'appearance' && ['fill', 'outline'].includes(initializer.value)) acc.defaultsAppearance = true;
|
|
218
|
+
}
|
|
219
|
+
return super.visitPropertyAssignment(property, p);
|
|
220
|
+
}
|
|
221
|
+
}();
|
|
222
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
223
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
224
|
+
await majors.visit(tree, p, parent);
|
|
225
|
+
await html.visit(tree, p, parent);
|
|
226
|
+
await typescript.visit(tree, p, parent);
|
|
227
|
+
return tree as R;
|
|
228
|
+
}
|
|
229
|
+
}();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async editorWithData(acc: MdcTemplateScan): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
233
|
+
const defaults = acc.defaultsToken && acc.defaultsAppearance;
|
|
234
|
+
const reliesOnPlaceholder = (sourcePath: string) =>
|
|
235
|
+
acc.explicitLegacy.has(sourcePath) || (!defaults && acc.implicitLegacy.has(sourcePath));
|
|
236
|
+
const message = (findings: string[]) => `${findings.join(' ')} ${GUIDE}`;
|
|
237
|
+
const applies = (sourcePath: string) => this.appliesTo(acc, sourcePath);
|
|
238
|
+
const html = new class extends PlainTextVisitor<ExecutionContext> {
|
|
239
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
240
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
241
|
+
if (!t || !t.sourcePath.endsWith('.html') || !applies(t.sourcePath) || hasSearchResult(t, GUIDE)) return t;
|
|
242
|
+
const findings = mdcTemplateFindings(t.text);
|
|
243
|
+
if (reliesOnPlaceholder(t.sourcePath)) findings.push(PLACEHOLDER_LABEL);
|
|
244
|
+
return findings.length === 0 ? t : foundSearchResult(t, message(findings));
|
|
245
|
+
}
|
|
246
|
+
}();
|
|
247
|
+
const inline = new class extends JavaScriptVisitor<ExecutionContext> {
|
|
248
|
+
private sourcePath = '';
|
|
249
|
+
|
|
250
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
251
|
+
this.sourcePath = cu.sourcePath;
|
|
252
|
+
return applies(cu.sourcePath) ? super.visitJsCompilationUnit(cu, p) : cu;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
protected async visitPropertyAssignment(property: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
|
|
256
|
+
const prop = await super.visitPropertyAssignment(property, p) as JS.PropertyAssignment;
|
|
257
|
+
const initializer = prop.initializer;
|
|
258
|
+
if (propertyName(prop.name.element) !== 'template' || hasSearchResult(prop, GUIDE)) return prop;
|
|
259
|
+
if (!initializer || !isLiteral(initializer) || typeof initializer.value !== 'string') return prop;
|
|
260
|
+
const findings = mdcTemplateFindings(initializer.value);
|
|
261
|
+
if (reliesOnPlaceholder(this.sourcePath) && placeholderLabelFields(initializer.value).implicit) findings.push(PLACEHOLDER_LABEL);
|
|
262
|
+
return findings.length === 0 ? prop : foundSearchResult(prop, message(findings));
|
|
263
|
+
}
|
|
264
|
+
}();
|
|
265
|
+
// Each visitor returns a source file it does not accept unchanged.
|
|
266
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
267
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
268
|
+
const visited = await html.visit<Tree>(tree, p, parent);
|
|
269
|
+
return visited && await inline.visit(visited, p, parent) as R | undefined;
|
|
270
|
+
}
|
|
271
|
+
}();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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 {extendedClassName, hasSearchResult} from "../components/lst";
|
|
12
|
+
|
|
13
|
+
export class FindMixinErrorStateWithoutStateChanges extends Recipe {
|
|
14
|
+
readonly name = "org.openrewrite.angular.material.FindMixinErrorStateWithoutStateChanges";
|
|
15
|
+
readonly displayName = "Find `mixinErrorState` classes without `stateChanges`";
|
|
16
|
+
readonly description = "Material 14 stopped declaring `stateChanges` in the class that `mixinErrorState` returns. " +
|
|
17
|
+
"Finds classes that extend a `mixinErrorState(...)` class when neither they nor the mixed-in base class " +
|
|
18
|
+
"declare `stateChanges`.";
|
|
19
|
+
|
|
20
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
21
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
22
|
+
private mixin = '';
|
|
23
|
+
/** Mixin classes of the file, mapped to the base class each passes to `mixinErrorState`. */
|
|
24
|
+
private mixins = new Map<string, string>();
|
|
25
|
+
private withStateChanges = new Set<string>();
|
|
26
|
+
|
|
27
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
28
|
+
const mixin = [...importedNames(cu, '@angular/material/core', ['mixinErrorState']).keys()][0];
|
|
29
|
+
if (!mixin) return cu;
|
|
30
|
+
this.mixin = mixin;
|
|
31
|
+
this.mixins = new Map();
|
|
32
|
+
this.withStateChanges = new Set();
|
|
33
|
+
for (const statement of cu.statements.map(s => s.element)) {
|
|
34
|
+
if (statement.kind === J.Kind.ClassDeclaration && declaresStateChanges(statement as J.ClassDeclaration)) {
|
|
35
|
+
this.withStateChanges.add((statement as J.ClassDeclaration).name.simpleName);
|
|
36
|
+
}
|
|
37
|
+
if (statement.kind !== J.Kind.VariableDeclarations) continue;
|
|
38
|
+
for (const variable of (statement as J.VariableDeclarations).variables.map(v => v.element)) {
|
|
39
|
+
const initializer = variable.initializer?.element;
|
|
40
|
+
const mixedIn = initializer && mixedInBase(initializer, mixin);
|
|
41
|
+
if (mixedIn !== undefined && isIdentifier(variable.name)) this.mixins.set(variable.name.simpleName, mixedIn);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return super.visitJsCompilationUnit(cu, p);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected async visitClassDeclaration(classDecl: J.ClassDeclaration, p: ExecutionContext): Promise<J | undefined> {
|
|
48
|
+
const c = await super.visitClassDeclaration(classDecl, p) as J.ClassDeclaration;
|
|
49
|
+
const extended = c.extends?.element;
|
|
50
|
+
if (!extended || declaresStateChanges(c) || hasSearchResult(c, "`mixinErrorState` no longer declares `stateChanges`")) return c;
|
|
51
|
+
const name = extendedClassName(c);
|
|
52
|
+
const base = name !== undefined && this.mixins.has(name)
|
|
53
|
+
? this.mixins.get(name)
|
|
54
|
+
: mixedInBase(extended.kind === JS.Kind.TypeTreeExpression ? (extended as JS.TypeTreeExpression).expression : extended, this.mixin);
|
|
55
|
+
if (base === undefined || this.withStateChanges.has(base)) return c;
|
|
56
|
+
return foundSearchResult(c, "`mixinErrorState` no longer declares `stateChanges` as of @angular/material 14. " +
|
|
57
|
+
"Declare `readonly stateChanges = new Subject<void>()` in this class.");
|
|
58
|
+
}
|
|
59
|
+
}();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The base class name that an expression passes to `mixinErrorState`, an empty string if it passes something else, or
|
|
65
|
+
* `undefined` if the expression does not call `mixinErrorState`.
|
|
66
|
+
*/
|
|
67
|
+
function mixedInBase(expression: J, mixin: string): string | undefined {
|
|
68
|
+
if (expression.kind !== J.Kind.MethodInvocation) return undefined;
|
|
69
|
+
const call = expression as J.MethodInvocation;
|
|
70
|
+
const args = call.arguments.elements.map(a => a.element);
|
|
71
|
+
if (call.name.simpleName === mixin && !call.select) {
|
|
72
|
+
const base = args[0];
|
|
73
|
+
return base && isIdentifier(base) ? base.simpleName : '';
|
|
74
|
+
}
|
|
75
|
+
for (const arg of args) {
|
|
76
|
+
const base = mixedInBase(arg, mixin);
|
|
77
|
+
if (base !== undefined) return base;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function declaresStateChanges(classDecl: J.ClassDeclaration): boolean {
|
|
83
|
+
return classDecl.body.statements.some(s => {
|
|
84
|
+
const member = s.element;
|
|
85
|
+
if (member.kind === J.Kind.MethodDeclaration) return (member as J.MethodDeclaration).name.simpleName === 'stateChanges';
|
|
86
|
+
if (member.kind !== J.Kind.VariableDeclarations) return false;
|
|
87
|
+
return (member as J.VariableDeclarations).variables.some(v => isIdentifier(v.element.name) && v.element.name.simpleName === 'stateChanges');
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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 {maskComments, SASS_ARGUMENTS} from "../components/stylesheets";
|
|
10
|
+
import {beforeMaterialVersion, MaterialProjects, materialProjects, materialProjectScanner, usesLegacyComponents} from "./material-version";
|
|
11
|
+
import {hasSearchResult} from "../components/lst";
|
|
12
|
+
|
|
13
|
+
interface PaletteScan extends MaterialProjects {
|
|
14
|
+
/** Variables that a stylesheet sets to a map of palette hues, such as `$orange-palette: (50: #f9e9e1, ...)`. */
|
|
15
|
+
rawPalettes: Set<string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const VARIABLE_MAP = new RegExp(`^[ \\t]*\\$([\\w-]+)\\s*:\\s*\\((${SASS_ARGUMENTS})\\)`, 'gm');
|
|
19
|
+
const THEME_CALL = new RegExp(`(?:define-|mat-)(?:light|dark)-theme\\((${SASS_ARGUMENTS})\\)`, 'g');
|
|
20
|
+
|
|
21
|
+
/** The variables a stylesheet whose comments are masked sets to a map of palette hues with their contrast colors. */
|
|
22
|
+
export function rawPaletteDeclarations(content: string): string[] {
|
|
23
|
+
return [...content.matchAll(VARIABLE_MAP)]
|
|
24
|
+
.filter(m => /(?:^|[\s,(])50\s*:/.test(m[2]) && /(?:^|[\s,(])contrast\s*:/.test(m[2]))
|
|
25
|
+
.map(m => m[1]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The palette maps that the themes of a stylesheet whose comments are masked take without `define-palette`. */
|
|
29
|
+
export function unwrappedPalettes(content: string, rawPalettes: Set<string>): string[] {
|
|
30
|
+
const found = new Set<string>();
|
|
31
|
+
for (const call of content.matchAll(THEME_CALL)) {
|
|
32
|
+
for (const ref of call[1].matchAll(/(define-palette\(\s*)?\$([\w-]+)/g)) {
|
|
33
|
+
if (!ref[1] && rawPalettes.has(ref[2])) found.add(ref[2]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return [...found];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class FindRawPaletteThemes extends ScanningRecipe<PaletteScan> {
|
|
40
|
+
readonly name: string = "org.openrewrite.angular.material.FindRawPaletteThemes";
|
|
41
|
+
readonly displayName: string = "Find themes built from palette maps without `define-palette`";
|
|
42
|
+
readonly description: string = "Finds stylesheets whose `define-light-theme` or `define-dark-theme` takes a map of " +
|
|
43
|
+
"palette hues, such as `primary: $orange-palette`, rather than the result of `define-palette`, in projects that " +
|
|
44
|
+
"are not on Material 15 yet. The legacy components accepted such a map, while the MDC-based components of " +
|
|
45
|
+
"Angular Material 15 read hues that only `define-palette` adds, such as `default`, and fail the build with " +
|
|
46
|
+
"`$color: null is not a color`.";
|
|
47
|
+
|
|
48
|
+
/** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
|
|
49
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
50
|
+
return beforeMaterialVersion(projects.majors, sourcePath, 15);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
initialValue(_ctx: ExecutionContext): PaletteScan {
|
|
54
|
+
return {...materialProjects(), rawPalettes: new Set()};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async scanner(acc: PaletteScan): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
58
|
+
const projects = materialProjectScanner(acc);
|
|
59
|
+
const palettes = new class extends PlainTextVisitor<ExecutionContext> {
|
|
60
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
61
|
+
if (text.sourcePath.endsWith('.scss')) rawPaletteDeclarations(maskComments(text.text)).forEach(name => acc.rawPalettes.add(name));
|
|
62
|
+
return text;
|
|
63
|
+
}
|
|
64
|
+
}();
|
|
65
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
66
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
67
|
+
await projects.visit(tree, p, parent);
|
|
68
|
+
await palettes.visit(tree, p, parent);
|
|
69
|
+
return tree as R;
|
|
70
|
+
}
|
|
71
|
+
}();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async editorWithData(acc: PaletteScan): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
75
|
+
const applies = (sourcePath: string) => this.appliesTo(acc, sourcePath);
|
|
76
|
+
return new class extends PlainTextVisitor<ExecutionContext> {
|
|
77
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
78
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
79
|
+
if (!t || !t.sourcePath.endsWith('.scss') || hasSearchResult(t, "as a map of palette hues") || !applies(t.sourcePath)) return t;
|
|
80
|
+
const names = unwrappedPalettes(maskComments(t.text), acc.rawPalettes);
|
|
81
|
+
if (names.length === 0) return t;
|
|
82
|
+
return foundSearchResult(t, `This theme takes ${names.map(n => `\`$${n}\``).join(', ')} as a map of palette ` +
|
|
83
|
+
"hues. The MDC-based components of Angular Material read hues that only `define-palette` adds, such as " +
|
|
84
|
+
"`default`, and fail the build with `$color: null is not a color`. Pass the map through " +
|
|
85
|
+
"`mat.define-palette(...)` instead.");
|
|
86
|
+
}
|
|
87
|
+
}();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class FindLegacyRawPaletteThemes extends FindRawPaletteThemes {
|
|
92
|
+
readonly name = "org.openrewrite.angular.material.FindLegacyRawPaletteThemes";
|
|
93
|
+
readonly displayName = "Find legacy Angular Material themes built from palette maps";
|
|
94
|
+
readonly description = "Finds the themes that `FindRawPaletteThemes` finds in projects that still use the " +
|
|
95
|
+
"`legacy-*` components of Material 15 and 16, which Material 17 removed.";
|
|
96
|
+
|
|
97
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
98
|
+
return usesLegacyComponents(projects, sourcePath);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 {FindRemovedSymbols, RemovedSymbol} from "../components/symbols";
|
|
8
|
+
|
|
9
|
+
function removed(entryPoint: string, version: number, names: string[], hint: string): RemovedSymbol[] {
|
|
10
|
+
return names.map(name => ({
|
|
11
|
+
module: `@angular/material/${entryPoint}`,
|
|
12
|
+
name,
|
|
13
|
+
message: `\`${name}\` was removed in @angular/material ${version}. ${hint}`,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class FindRemovedMaterial10Apis extends FindRemovedSymbols {
|
|
18
|
+
readonly name = "org.openrewrite.angular.material.FindRemovedMaterial10Apis";
|
|
19
|
+
readonly displayName = "Find APIs removed in Angular Material 10";
|
|
20
|
+
readonly description = "Finds imports of the HammerJS gesture APIs, such as `GestureConfig` and `HammerInput`, " +
|
|
21
|
+
"that `@angular/material/core` 10 removed.";
|
|
22
|
+
|
|
23
|
+
protected readonly symbols = removed('core', 10, [
|
|
24
|
+
'MAT_HAMMER_OPTIONS', 'GestureConfig', 'HammerInput', 'HammerStatic', 'Recognizer', 'RecognizerStatic',
|
|
25
|
+
'HammerInstance', 'HammerManager', 'HammerOptions',
|
|
26
|
+
], "Material components no longer use HammerJS. Provide `HAMMER_GESTURE_CONFIG` from `@angular/platform-browser` " +
|
|
27
|
+
"with your own `HammerGestureConfig` if the application still needs gestures.");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class FindRemovedMaterial11Apis extends FindRemovedSymbols {
|
|
31
|
+
readonly name = "org.openrewrite.angular.material.FindRemovedMaterial11Apis";
|
|
32
|
+
readonly displayName = "Find APIs removed in Angular Material 11";
|
|
33
|
+
readonly description = "Finds imports of the month constants of `@angular/material/core` and of " +
|
|
34
|
+
"`MAT_CHECKBOX_CLICK_ACTION`, which Angular Material 11 removed.";
|
|
35
|
+
|
|
36
|
+
protected readonly symbols = [
|
|
37
|
+
...removed('core', 11, ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'],
|
|
38
|
+
"Use the zero-based month number instead, such as `0` for January."),
|
|
39
|
+
...removed('checkbox', 11, ['MAT_CHECKBOX_CLICK_ACTION'],
|
|
40
|
+
"Provide `MAT_CHECKBOX_DEFAULT_OPTIONS` with `useValue: {clickAction: ...}` instead."),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class FindRemovedMaterial13Apis extends FindRemovedSymbols {
|
|
45
|
+
readonly name = "org.openrewrite.angular.material.FindRemovedMaterial13Apis";
|
|
46
|
+
readonly displayName = "Find APIs removed in Angular Material 13";
|
|
47
|
+
readonly description = "Finds imports of the mixin constructor types, such as `CanColorCtor`, that " +
|
|
48
|
+
"`@angular/material/core` 13 removed.";
|
|
49
|
+
|
|
50
|
+
protected readonly symbols = removed('core', 13, [
|
|
51
|
+
'CanColorCtor', 'CanDisableRippleCtor', 'CanDisableCtor', 'CanUpdateErrorStateCtor', 'HasInitializedCtor',
|
|
52
|
+
'HasTabIndexCtor',
|
|
53
|
+
], "Remove the type annotation, since the mixin function now returns a type that describes the class.");
|
|
54
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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 {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
10
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
11
|
+
import {isStylesheet, maskComments} from "../components/stylesheets";
|
|
12
|
+
import {beforeMaterialVersion, MaterialProjects, materialProjects, materialProjectScanner} from "./material-version";
|
|
13
|
+
import {withoutHtmlComments} from "../components/templates";
|
|
14
|
+
import {REMOVED_CLASSES, RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
|
|
15
|
+
import {hasSearchResult} from "../components/lst";
|
|
16
|
+
|
|
17
|
+
/** The removed or renamed Material classes that a stylesheet selects, such as `.mat-form-field-wrapper`. */
|
|
18
|
+
function selectedClasses(content: string): string[] {
|
|
19
|
+
return [...new Set([...maskComments(content).matchAll(/\.(mat-[a-z0-9-]*[a-z0-9])(?![\w-])/g)].map(m => m[1]))]
|
|
20
|
+
.filter(c => c in REMOVED_CLASSES || c in RENAMED_TYPOGRAPHY_CLASSES);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The removed or renamed Material classes that a template applies through `class` attributes or `[class.x]` bindings. */
|
|
24
|
+
function appliedClasses(source: string): string[] {
|
|
25
|
+
const template = withoutHtmlComments(source);
|
|
26
|
+
const classes = [
|
|
27
|
+
...[...template.matchAll(/(?:^|\s)class\s*=\s*(["'])([^"']*)\1/g)].flatMap(m => m[2].split(/\s+/)),
|
|
28
|
+
...[...template.matchAll(/\[class\.([\w-]+)\]/g)].map(m => m[1]),
|
|
29
|
+
];
|
|
30
|
+
return [...new Set(classes)].filter(c => c in REMOVED_CLASSES || c in RENAMED_TYPOGRAPHY_CLASSES);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Elements of the pre-MDC components that Material 15 no longer renders, with the elements that replace them. */
|
|
34
|
+
const REMOVED_ELEMENTS: Record<string, string | null> = {
|
|
35
|
+
'mat-chip-list': '`mat-chip-grid` or `mat-chip-listbox`',
|
|
36
|
+
'mat-ink-bar': null,
|
|
37
|
+
'mat-placeholder': '`mat-label`',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const STOP_MATCHING = "styles and queries that target them stop matching";
|
|
41
|
+
|
|
42
|
+
/** The removed Material elements that the selectors of a stylesheet or a query string select, such as `mat-chip-list`. */
|
|
43
|
+
function selectedElements(content: string): string[] {
|
|
44
|
+
const masked = maskComments(content);
|
|
45
|
+
const selectors = masked.includes('{') ? [...masked.matchAll(/([^{};]*)\{/g)].map(m => m[1]) : [masked];
|
|
46
|
+
const element = new RegExp(`(?<![\\w.#$@%/<-])(${Object.keys(REMOVED_ELEMENTS).join('|')})(?![\\w-])`, 'g');
|
|
47
|
+
return [...new Set(selectors.flatMap(selector => [...selector.matchAll(element)].map(m => m[1])))];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Lists up to eight names in backticks, each followed by its replacement if it has one. */
|
|
51
|
+
function listed(names: string[], replacementOf: (name: string) => string | null | undefined): string {
|
|
52
|
+
const shown = names.slice(0, 8).map(n => {
|
|
53
|
+
const replacement = replacementOf(n);
|
|
54
|
+
return replacement ? `\`${n}\` (now ${replacement})` : `\`${n}\``;
|
|
55
|
+
});
|
|
56
|
+
return shown.join(', ') + (names.length > 8 ? ` and ${names.length - 8} more` : '');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function describe(classes: string[], elements: string[]): string {
|
|
60
|
+
const prefix = "The MDC-based components of @angular/material 15 no longer";
|
|
61
|
+
const elementList = listed(elements, e => REMOVED_ELEMENTS[e]);
|
|
62
|
+
if (classes.length === 0) return `${prefix} render these elements, so ${STOP_MATCHING}: ${elementList}.`;
|
|
63
|
+
const classList = listed(classes, c => {
|
|
64
|
+
const replacement = RENAMED_TYPOGRAPHY_CLASSES[c] ?? REMOVED_CLASSES[c];
|
|
65
|
+
return replacement && `\`${replacement}\``;
|
|
66
|
+
});
|
|
67
|
+
return `${prefix} apply these classes, so ${STOP_MATCHING}: ${classList}. ` +
|
|
68
|
+
"Typography classes were renamed to the 2018 type scale." +
|
|
69
|
+
(elements.length === 0 ? "" : ` They no longer render these elements either: ${elementList}.`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class FindRemovedMaterialClasses extends ScanningRecipe<MaterialProjects> {
|
|
73
|
+
readonly name: string = "org.openrewrite.angular.material.FindRemovedMaterialClasses";
|
|
74
|
+
readonly displayName: string = "Find styles targeting classes removed by the MDC components";
|
|
75
|
+
readonly description: string = "Finds stylesheets, templates and TypeScript strings that select or apply classes of the " +
|
|
76
|
+
"pre-MDC components, such as `.mat-form-field-wrapper` or `.mat-card`, which the MDC-based components of " +
|
|
77
|
+
"Angular Material 15 no longer apply, and the typography classes Material 15 renamed, such as `mat-title`, in " +
|
|
78
|
+
"projects that are not on Material 15 yet, along with selectors of the elements Material 15 no longer " +
|
|
79
|
+
"renders, such as `mat-chip-list`. The marker names the replacement where there is one.";
|
|
80
|
+
|
|
81
|
+
/** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
|
|
82
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
83
|
+
return beforeMaterialVersion(projects.majors, sourcePath, 15);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
initialValue(_ctx: ExecutionContext): MaterialProjects {
|
|
87
|
+
return materialProjects();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async scanner(projects: MaterialProjects): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
91
|
+
return materialProjectScanner(projects);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async editorWithData(projects: MaterialProjects): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
95
|
+
const applies = (sourcePath: string) => this.appliesTo(projects, sourcePath);
|
|
96
|
+
const files = new class extends PlainTextVisitor<ExecutionContext> {
|
|
97
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
98
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
99
|
+
if (!t || hasSearchResult(t, STOP_MATCHING) || !applies(t.sourcePath)) return t;
|
|
100
|
+
const stylesheet = isStylesheet(t.sourcePath);
|
|
101
|
+
const classes = stylesheet ? selectedClasses(t.text) : t.sourcePath.endsWith('.html') ? appliedClasses(t.text) : [];
|
|
102
|
+
const elements = stylesheet ? selectedElements(t.text) : [];
|
|
103
|
+
return classes.length === 0 && elements.length === 0 ? t : foundSearchResult(t, describe(classes, elements));
|
|
104
|
+
}
|
|
105
|
+
}();
|
|
106
|
+
const literals = new class extends JavaScriptVisitor<ExecutionContext> {
|
|
107
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
108
|
+
return applies(cu.sourcePath) ? super.visitJsCompilationUnit(cu, p) : cu;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected async visitLiteral(literal: J.Literal, p: ExecutionContext): Promise<J | undefined> {
|
|
112
|
+
const l = await super.visitLiteral(literal, p) as J.Literal;
|
|
113
|
+
if (typeof l.value !== 'string' || hasSearchResult(l, STOP_MATCHING)) return l;
|
|
114
|
+
const classes = [...new Set([...selectedClasses(l.value), ...appliedClasses(l.value)])];
|
|
115
|
+
const elements = selectedElements(l.value);
|
|
116
|
+
return classes.length === 0 && elements.length === 0 ? l : foundSearchResult(l, describe(classes, elements));
|
|
117
|
+
}
|
|
118
|
+
}();
|
|
119
|
+
// Each visitor returns a source file it does not accept unchanged.
|
|
120
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
121
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
122
|
+
const visited = await files.visit<Tree>(tree, p, parent);
|
|
123
|
+
return visited && await literals.visit(visited, p, parent) as R | undefined;
|
|
124
|
+
}
|
|
125
|
+
}();
|
|
126
|
+
}
|
|
127
|
+
}
|