@openrewrite/recipes-angular 1.26.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/libraries/primeng/18/migrate-primeng-config.d.ts.map +1 -1
- package/dist/libraries/primeng/18/migrate-primeng-config.js +0 -59
- package/dist/libraries/primeng/18/migrate-primeng-config.js.map +1 -1
- package/dist/libraries/primeng/18/rename-calendar-to-datepicker.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-calendar-to-datepicker.js +0 -65
- package/dist/libraries/primeng/18/rename-calendar-to-datepicker.js.map +1 -1
- package/dist/libraries/primeng/18/rename-dropdown-to-select.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-dropdown-to-select.js +0 -65
- package/dist/libraries/primeng/18/rename-dropdown-to-select.js.map +1 -1
- package/dist/libraries/primeng/18/rename-inputswitch-to-toggleswitch.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-inputswitch-to-toggleswitch.js +0 -65
- package/dist/libraries/primeng/18/rename-inputswitch-to-toggleswitch.js.map +1 -1
- package/dist/libraries/primeng/18/rename-overlaypanel-to-popover.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-overlaypanel-to-popover.js +0 -65
- package/dist/libraries/primeng/18/rename-overlaypanel-to-popover.js.map +1 -1
- package/dist/libraries/primeng/18/rename-sidebar-to-drawer.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-sidebar-to-drawer.js +0 -65
- package/dist/libraries/primeng/18/rename-sidebar-to-drawer.js.map +1 -1
- package/dist/migration/rename-after-render.d.ts +2 -2
- package/dist/migration/rename-after-render.d.ts.map +1 -1
- package/dist/migration/rename-after-render.js +9 -25
- package/dist/migration/rename-after-render.js.map +1 -1
- package/dist/migration/rename-check-no-changes.d.ts +2 -2
- package/dist/migration/rename-check-no-changes.d.ts.map +1 -1
- package/dist/migration/rename-check-no-changes.js +23 -19
- package/dist/migration/rename-check-no-changes.js.map +1 -1
- package/dist/migration/rename-pending-tasks.d.ts +2 -2
- package/dist/migration/rename-pending-tasks.d.ts.map +1 -1
- package/dist/migration/rename-pending-tasks.js +9 -22
- package/dist/migration/rename-pending-tasks.js.map +1 -1
- package/dist/migration/rename-zoneless-provider.d.ts +2 -2
- package/dist/migration/rename-zoneless-provider.d.ts.map +1 -1
- package/dist/migration/rename-zoneless-provider.js +9 -21
- package/dist/migration/rename-zoneless-provider.js.map +1 -1
- 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/libraries/primeng/18/migrate-primeng-config.ts +2 -43
- package/src/libraries/primeng/18/rename-calendar-to-datepicker.ts +2 -50
- package/src/libraries/primeng/18/rename-dropdown-to-select.ts +2 -50
- package/src/libraries/primeng/18/rename-inputswitch-to-toggleswitch.ts +2 -50
- package/src/libraries/primeng/18/rename-overlaypanel-to-popover.ts +2 -50
- package/src/libraries/primeng/18/rename-sidebar-to-drawer.ts +2 -50
- package/src/migration/rename-after-render.ts +11 -24
- package/src/migration/rename-check-no-changes.ts +21 -18
- package/src/migration/rename-pending-tasks.ts +11 -22
- package/src/migration/rename-zoneless-provider.ts +11 -21
- 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,113 @@
|
|
|
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
|
+
/** An attribute of an opening tag, with offsets into the template. */
|
|
8
|
+
export interface TemplateAttribute {
|
|
9
|
+
/** The name as written, such as `[(ngModel)]` or `#slider`. */
|
|
10
|
+
name: string;
|
|
11
|
+
value?: string;
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** An element of a template, with offsets into the template. */
|
|
17
|
+
export interface TemplateElement {
|
|
18
|
+
name: string;
|
|
19
|
+
start: number;
|
|
20
|
+
/** The offset right after the `>` of the opening tag. */
|
|
21
|
+
openEnd: number;
|
|
22
|
+
attributes: TemplateAttribute[];
|
|
23
|
+
/** The offsets of the closing tag, absent for void and self-closing elements. */
|
|
24
|
+
closeStart?: number;
|
|
25
|
+
closeEnd?: number;
|
|
26
|
+
parent?: TemplateElement;
|
|
27
|
+
children: TemplateElement[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const VOID_ELEMENTS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
|
|
31
|
+
|
|
32
|
+
/** Parses the elements of an Angular template, skipping comments and honoring quoted attribute values. */
|
|
33
|
+
export function parseElements(template: string): TemplateElement[] {
|
|
34
|
+
const elements: TemplateElement[] = [];
|
|
35
|
+
const open: TemplateElement[] = [];
|
|
36
|
+
const tag = /<!--[\s\S]*?(?:-->|$)|<\/([a-zA-Z][\w-]*)\s*>|<([a-zA-Z][\w-]*)/g;
|
|
37
|
+
let match: RegExpExecArray | null;
|
|
38
|
+
while ((match = tag.exec(template)) !== null) {
|
|
39
|
+
if (match[1]) {
|
|
40
|
+
const name = match[1].toLowerCase();
|
|
41
|
+
const index = open.map(e => e.name).lastIndexOf(name);
|
|
42
|
+
if (index > -1) {
|
|
43
|
+
open[index].closeStart = match.index;
|
|
44
|
+
open[index].closeEnd = match.index + match[0].length;
|
|
45
|
+
open.length = index;
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!match[2]) continue;
|
|
50
|
+
const {attributes, end, selfClosing} = parseAttributes(template, match.index + match[0].length);
|
|
51
|
+
const parent = open[open.length - 1];
|
|
52
|
+
const element: TemplateElement = {
|
|
53
|
+
name: match[2].toLowerCase(), start: match.index, openEnd: end, attributes, parent, children: [],
|
|
54
|
+
};
|
|
55
|
+
parent?.children.push(element);
|
|
56
|
+
elements.push(element);
|
|
57
|
+
if (!selfClosing && !VOID_ELEMENTS.has(element.name)) open.push(element);
|
|
58
|
+
tag.lastIndex = end;
|
|
59
|
+
}
|
|
60
|
+
return elements;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parseAttributes(template: string, from: number): {attributes: TemplateAttribute[], end: number, selfClosing: boolean} {
|
|
64
|
+
const attributes: TemplateAttribute[] = [];
|
|
65
|
+
const attribute = /\s*(?:(\/?>)|([^\s=/>"']+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>"']+)))?|(\S))/y;
|
|
66
|
+
attribute.lastIndex = from;
|
|
67
|
+
let match: RegExpExecArray | null;
|
|
68
|
+
while ((match = attribute.exec(template)) !== null) {
|
|
69
|
+
if (match[1]) return {attributes, end: attribute.lastIndex, selfClosing: match[1] === '/>'};
|
|
70
|
+
if (match[2]) {
|
|
71
|
+
const start = attribute.lastIndex - match[0].trimStart().length;
|
|
72
|
+
attributes.push({name: match[2], value: match[3] ?? match[4] ?? match[5], start, end: attribute.lastIndex});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {attributes, end: template.length, selfClosing: false};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The plain name of an attribute without binding syntax, such as `ngModel` for `[(ngModel)]`. */
|
|
79
|
+
export function bareName(attribute: TemplateAttribute): string {
|
|
80
|
+
return attribute.name.replace(/^(?:\[\(|\[|\(|bind-|on-|bindon-)/, '').replace(/(?:\)\]|\]|\))$/, '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function attributeNamed(element: TemplateElement, name: string): TemplateAttribute | undefined {
|
|
84
|
+
return element.attributes.find(a => bareName(a) === name);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function descendants(element: TemplateElement): TemplateElement[] {
|
|
88
|
+
return element.children.flatMap(child => [child, ...descendants(child)]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A replacement of the template text between two offsets. */
|
|
92
|
+
export interface TemplateEdit {
|
|
93
|
+
start: number;
|
|
94
|
+
end: number;
|
|
95
|
+
text: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Applies edits that do not overlap, keeping the order of edits that insert at the same offset. */
|
|
99
|
+
export function applyEdits(template: string, edits: TemplateEdit[]): string {
|
|
100
|
+
const sorted = edits.map((edit, i) => ({edit, i}))
|
|
101
|
+
.sort((a, b) => b.edit.start - a.edit.start || b.edit.end - a.edit.end || b.i - a.i)
|
|
102
|
+
.map(({edit}) => edit);
|
|
103
|
+
let result = template;
|
|
104
|
+
for (const {start, end, text} of sorted) result = result.slice(0, start) + text + result.slice(end);
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** An edit that removes an attribute together with the whitespace before it. */
|
|
109
|
+
export function removeAttribute(template: string, attribute: TemplateAttribute): TemplateEdit {
|
|
110
|
+
let start = attribute.start;
|
|
111
|
+
while (start > 0 && /\s/.test(template[start - 1])) start--;
|
|
112
|
+
return {start, end: attribute.end, text: ''};
|
|
113
|
+
}
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
import {Cursor, ExecutionContext, Recipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
8
|
import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
|
|
9
9
|
import {JavaScriptVisitor} from "@openrewrite/rewrite/javascript";
|
|
10
|
-
import {
|
|
10
|
+
import {isLiteral, J} from "@openrewrite/rewrite/java";
|
|
11
11
|
import {create} from "mutative";
|
|
12
|
+
import {propertyName} from "./lst";
|
|
12
13
|
import {escapeRegExp} from "./stylesheets";
|
|
13
14
|
|
|
14
15
|
/** A directive selector or input that a major version renamed, as it appears in a template attribute. */
|
|
@@ -45,8 +46,7 @@ export abstract class RenameTemplateAttributes extends Recipe {
|
|
|
45
46
|
const inline = new class extends JavaScriptVisitor<ExecutionContext> {
|
|
46
47
|
protected async visitPropertyAssignment(property: any, p: ExecutionContext): Promise<J | undefined> {
|
|
47
48
|
const prop = await super.visitPropertyAssignment(property, p) as any;
|
|
48
|
-
|
|
49
|
-
if (!isIdentifier(name) || name.simpleName !== 'template') return prop;
|
|
49
|
+
if (propertyName(prop?.name?.element) !== 'template') return prop;
|
|
50
50
|
|
|
51
51
|
const initializer = prop.initializer;
|
|
52
52
|
if (!initializer || !isLiteral(initializer) || typeof initializer.value !== 'string') return prop;
|
|
@@ -94,8 +94,22 @@ function renameAttribute(attrs: string, name: string, newName: string): string {
|
|
|
94
94
|
return mapOutsideQuotes(attrs, segment => segment.replace(pattern, `$1$2${newName}`));
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** Quotes a migrated inline template with the delimiter of its original string literal. */
|
|
98
|
+
export function requote(valueSource: string, value: string): string {
|
|
99
|
+
const quote = valueSource[0];
|
|
100
|
+
let escaped = value.replace(/\\/g, '\\\\');
|
|
101
|
+
escaped = quote === '`' ? escaped.replace(/`/g, '\\`').replace(/\$\{/g, '\\${')
|
|
102
|
+
: escaped.replace(new RegExp(quote, 'g'), `\\${quote}`).replace(/\n/g, '\\n').replace(/\r/g, '\\r');
|
|
103
|
+
return `${quote}${escaped}${quote}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A template without its comments, for checks that only care about live markup. */
|
|
107
|
+
export function withoutHtmlComments(template: string): string {
|
|
108
|
+
return template.replace(/<!--[\s\S]*?(?:-->|$)/g, '');
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
/** Calls `fn` for the attribute text of every opening tag, honoring quoted attribute values that contain `>`. */
|
|
98
|
-
function mapOpeningTags(template: string, fn: (tagName: string, attrs: string) => string): string {
|
|
112
|
+
export function mapOpeningTags(template: string, fn: (tagName: string, attrs: string) => string): string {
|
|
99
113
|
let result = '';
|
|
100
114
|
let index = 0;
|
|
101
115
|
const tagStart = /<([a-zA-Z][\w-]*)/g;
|
|
@@ -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
|
+
}
|